1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.tv.common.ui.setup; 18 19 import android.os.Bundle; 20 import android.support.annotation.Nullable; 21 import android.util.Log; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 import android.view.ViewGroup; 25 import android.view.ViewGroup.MarginLayoutParams; 26 27 import com.android.tv.common.R; 28 29 /** 30 * A fragment for channel source info/setup. 31 */ 32 public abstract class SetupMultiPaneFragment extends SetupFragment { 33 private static final String TAG = "SetupMultiPaneFragment"; 34 private static final boolean DEBUG = false; 35 36 public static final int ACTION_DONE = Integer.MAX_VALUE; 37 public static final int ACTION_SKIP = ACTION_DONE - 1; 38 39 private static final String CONTENT_FRAGMENT_TAG = "content_fragment"; 40 41 @Override 42 public View onCreateView(LayoutInflater inflater, ViewGroup container, 43 Bundle savedInstanceState) { 44 if (DEBUG) { 45 Log.d(TAG, "onCreateView(" + inflater + ", " + container + ", " + savedInstanceState 46 + ")"); 47 } 48 View view = super.onCreateView(inflater, container, savedInstanceState); 49 if (savedInstanceState == null) { 50 SetupGuidedStepFragment contentFragment = onCreateContentFragment(); 51 getChildFragmentManager().beginTransaction() 52 .replace(R.id.guided_step_fragment_container, contentFragment, 53 CONTENT_FRAGMENT_TAG).commit(); 54 } 55 if (needsDoneButton()) { 56 setOnClickAction(view.findViewById(R.id.button_done), getActionCategory(), ACTION_DONE); 57 } 58 if (needsSkipButton()) { 59 view.findViewById(R.id.button_skip).setVisibility(View.VISIBLE); 60 setOnClickAction(view.findViewById(R.id.button_skip), getActionCategory(), ACTION_SKIP); 61 } 62 if (!needsDoneButton() && !needsSkipButton()) { 63 View doneButtonContainer = view.findViewById(R.id.done_button_container); 64 // Use content view to check layout direction while view is being created. 65 if (getResources().getConfiguration().getLayoutDirection() 66 == View.LAYOUT_DIRECTION_LTR) { 67 ((MarginLayoutParams) doneButtonContainer.getLayoutParams()).rightMargin = 68 -getResources().getDimensionPixelOffset( 69 R.dimen.setup_done_button_container_width); 70 } else { 71 ((MarginLayoutParams) doneButtonContainer.getLayoutParams()).leftMargin = 72 -getResources().getDimensionPixelOffset( 73 R.dimen.setup_done_button_container_width); 74 } 75 view.findViewById(R.id.button_done).setFocusable(false); 76 } 77 return view; 78 } 79 80 @Override 81 protected int getLayoutResourceId() { 82 return R.layout.fragment_setup_multi_pane; 83 } 84 85 abstract protected SetupGuidedStepFragment onCreateContentFragment(); 86 87 @Nullable 88 protected SetupGuidedStepFragment getContentFragment() { 89 return (SetupGuidedStepFragment) getChildFragmentManager() 90 .findFragmentByTag(CONTENT_FRAGMENT_TAG); 91 } 92 93 abstract protected String getActionCategory(); 94 95 protected boolean needsDoneButton() { 96 return true; 97 } 98 99 protected boolean needsSkipButton() { 100 return false; 101 } 102 103 @Override 104 protected int[] getParentIdsForDelay() { 105 return new int[] {R.id.content_fragment, R.id.guidedactions_list}; 106 } 107 108 @Override 109 public int[] getSharedElementIds() { 110 return new int[] {R.id.action_fragment_background, R.id.done_button_container}; 111 } 112 }