Home | History | Annotate | Download | only in sidepanel
      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.ui.sidepanel;
     18 
     19 import android.content.Context;
     20 import com.android.tv.R;
     21 import com.android.tv.data.DisplayMode;
     22 import com.android.tv.ui.TvViewUiManager;
     23 import java.util.ArrayList;
     24 import java.util.List;
     25 
     26 public class DisplayModeFragment extends SideFragment {
     27     private static final String TRACKER_LABEL = "display mode";
     28     private TvViewUiManager mTvViewUiManager;
     29 
     30     @Override
     31     protected String getTitle() {
     32         return getString(R.string.side_panel_title_display_mode);
     33     }
     34 
     35     @Override
     36     public String getTrackerLabel() {
     37         return TRACKER_LABEL;
     38     }
     39 
     40     @Override
     41     protected List<Item> getItemList() {
     42         List<Item> items = new ArrayList<>();
     43         for (int i = 0; i < DisplayMode.SIZE_OF_RATIO_TYPES; ++i) {
     44             items.add(new DisplayModeRadioItem(i));
     45         }
     46         return items;
     47     }
     48 
     49     @Override
     50     public void onAttach(Context context) {
     51         super.onAttach(context);
     52         mTvViewUiManager = getMainActivity().getTvViewUiManager();
     53     }
     54 
     55     @Override
     56     public void onResume() {
     57         super.onResume();
     58         setSelectedPosition(mTvViewUiManager.getDisplayMode());
     59     }
     60 
     61     @Override
     62     public void onDetach() {
     63         super.onDetach();
     64         mTvViewUiManager.restoreDisplayMode(true);
     65     }
     66 
     67     private class DisplayModeRadioItem extends RadioButtonItem {
     68         private final int mDisplayMode;
     69 
     70         private DisplayModeRadioItem(int displayMode) {
     71             super(DisplayMode.getLabel(displayMode, getActivity()));
     72             mDisplayMode = displayMode;
     73         }
     74 
     75         @Override
     76         protected void onUpdate() {
     77             super.onUpdate();
     78             setEnabled(mTvViewUiManager.isDisplayModeAvailable(mDisplayMode));
     79             setChecked(mDisplayMode == mTvViewUiManager.getDisplayMode());
     80         }
     81 
     82         @Override
     83         protected void onSelected() {
     84             super.onSelected();
     85             mTvViewUiManager.setDisplayMode(mDisplayMode, true, true);
     86             closeFragment();
     87         }
     88 
     89         @Override
     90         protected void onFocused() {
     91             super.onFocused();
     92             mTvViewUiManager.setDisplayMode(mDisplayMode, false, true);
     93         }
     94     }
     95 }
     96