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.view.LayoutInflater; 21 import android.view.View; 22 import android.view.ViewGroup; 23 import android.view.ViewGroup.MarginLayoutParams; 24 25 import com.android.tv.common.R; 26 27 /** 28 * A fragment for channel source info/setup. 29 */ 30 public abstract class SetupMultiPaneFragment extends SetupFragment { 31 public static final int ACTION_DONE = Integer.MAX_VALUE; 32 33 @Override onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)34 public View onCreateView(LayoutInflater inflater, ViewGroup container, 35 Bundle savedInstanceState) { 36 View view = super.onCreateView(inflater, container, savedInstanceState); 37 SetupGuidedStepFragment contentFragment = onCreateContentFragment(); 38 getChildFragmentManager().beginTransaction() 39 .replace(R.id.guided_step_fragment_container, contentFragment).commit(); 40 if (needsDoneButton()) { 41 setOnClickAction(view.findViewById(R.id.button_done), getActionCategory(), ACTION_DONE); 42 } else { 43 View doneButtonContainer = view.findViewById(R.id.done_button_container); 44 // Use content view to check layout direction while view is being created. 45 if (getResources().getConfiguration().getLayoutDirection() 46 == View.LAYOUT_DIRECTION_LTR) { 47 ((MarginLayoutParams) doneButtonContainer.getLayoutParams()).rightMargin = 48 -getResources().getDimensionPixelOffset( 49 R.dimen.setup_done_button_container_width); 50 } else { 51 ((MarginLayoutParams) doneButtonContainer.getLayoutParams()).leftMargin = 52 -getResources().getDimensionPixelOffset( 53 R.dimen.setup_done_button_container_width); 54 } 55 view.findViewById(R.id.button_done).setFocusable(false); 56 } 57 return view; 58 } 59 60 @Override getLayoutResourceId()61 protected int getLayoutResourceId() { 62 return R.layout.fragment_setup_multi_pane; 63 } 64 onCreateContentFragment()65 abstract protected SetupGuidedStepFragment onCreateContentFragment(); 66 getActionCategory()67 abstract protected String getActionCategory(); 68 needsDoneButton()69 protected boolean needsDoneButton() { 70 return true; 71 } 72 73 @Override getParentIdsForDelay()74 protected int[] getParentIdsForDelay() { 75 return new int[] {R.id.content_fragment, R.id.guidedactions_list}; 76 } 77 78 @Override getSharedElementIds()79 public int[] getSharedElementIds() { 80 return new int[] {R.id.action_fragment_background, R.id.done_button_container}; 81 } 82 } 83