Home | History | Annotate | Download | only in setup
      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 
     38     private static final String CONTENT_FRAGMENT_TAG = "content_fragment";
     39 
     40     @Override
     41     public View onCreateView(LayoutInflater inflater, ViewGroup container,
     42             Bundle savedInstanceState) {
     43         if (DEBUG) {
     44             Log.d(TAG, "onCreateView(" + inflater + ", " + container + ", " + savedInstanceState
     45                     + ")");
     46         }
     47         View view = super.onCreateView(inflater, container, savedInstanceState);
     48         if (savedInstanceState == null) {
     49             SetupGuidedStepFragment contentFragment = onCreateContentFragment();
     50             getChildFragmentManager().beginTransaction()
     51                     .replace(R.id.guided_step_fragment_container, contentFragment,
     52                             CONTENT_FRAGMENT_TAG).commit();
     53         }
     54         if (needsDoneButton()) {
     55             setOnClickAction(view.findViewById(R.id.button_done), getActionCategory(), ACTION_DONE);
     56         } else {
     57             View doneButtonContainer = view.findViewById(R.id.done_button_container);
     58             // Use content view to check layout direction while view is being created.
     59             if (getResources().getConfiguration().getLayoutDirection()
     60                     == View.LAYOUT_DIRECTION_LTR) {
     61                 ((MarginLayoutParams) doneButtonContainer.getLayoutParams()).rightMargin =
     62                         -getResources().getDimensionPixelOffset(
     63                                 R.dimen.setup_done_button_container_width);
     64             } else {
     65                 ((MarginLayoutParams) doneButtonContainer.getLayoutParams()).leftMargin =
     66                         -getResources().getDimensionPixelOffset(
     67                                 R.dimen.setup_done_button_container_width);
     68             }
     69             view.findViewById(R.id.button_done).setFocusable(false);
     70         }
     71         return view;
     72     }
     73 
     74     @Override
     75     protected int getLayoutResourceId() {
     76         return R.layout.fragment_setup_multi_pane;
     77     }
     78 
     79     abstract protected SetupGuidedStepFragment onCreateContentFragment();
     80 
     81     @Nullable
     82     protected SetupGuidedStepFragment getContentFragment() {
     83         return (SetupGuidedStepFragment) getChildFragmentManager()
     84                 .findFragmentByTag(CONTENT_FRAGMENT_TAG);
     85     }
     86 
     87     abstract protected String getActionCategory();
     88 
     89     protected boolean needsDoneButton() {
     90         return true;
     91     }
     92 
     93     @Override
     94     protected int[] getParentIdsForDelay() {
     95         return new int[] {R.id.content_fragment, R.id.guidedactions_list};
     96     }
     97 
     98     @Override
     99     public int[] getSharedElementIds() {
    100         return new int[] {R.id.action_fragment_background, R.id.done_button_container};
    101     }
    102 }
    103