• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.app.ApplicationErrorReport;
20 import android.content.Intent;
21 import android.media.tv.TvInputInfo;
22 import android.view.View;
23 import android.widget.Toast;
24 import com.android.tv.MainActivity;
25 import com.android.tv.R;
26 import com.android.tv.TvApplication;
27 import com.android.tv.TvSingletons;
28 import com.android.tv.common.CommonPreferences;
29 import com.android.tv.common.customization.CustomizationManager;
30 import com.android.tv.common.util.PermissionUtils;
31 import com.android.tv.dialog.PinDialogFragment;
32 import com.android.tv.features.TvFeatures;
33 import com.android.tv.license.LicenseSideFragment;
34 import com.android.tv.license.Licenses;
35 import com.android.tv.util.Utils;
36 import java.util.ArrayList;
37 import java.util.List;
38 
39 /** Shows TV app settings. */
40 public class SettingsFragment extends SideFragment {
41     private static final String TRACKER_LABEL = "settings";
42 
43     @Override
getTitle()44     protected String getTitle() {
45         return getResources().getString(R.string.side_panel_title_settings);
46     }
47 
48     @Override
getTrackerLabel()49     public String getTrackerLabel() {
50         return TRACKER_LABEL;
51     }
52 
53     @Override
getItemList()54     protected List<Item> getItemList() {
55         List<Item> items = new ArrayList<>();
56         final Item customizeChannelListItem =
57                 new SubMenuItem(
58                         getString(R.string.settings_channel_source_item_customize_channels),
59                         getString(
60                                 R.string
61                                         .settings_channel_source_item_customize_channels_description),
62                         getMainActivity().getOverlayManager().getSideFragmentManager()) {
63                     @Override
64                     protected SideFragment getFragment() {
65                         return new CustomizeChannelListFragment();
66                     }
67 
68                     @Override
69                     protected void onBind(View view) {
70                         super.onBind(view);
71                         setEnabled(false);
72                     }
73 
74                     @Override
75                     protected void onUpdate() {
76                         super.onUpdate();
77                         setEnabled(getChannelDataManager().getChannelCount() != 0);
78                     }
79                 };
80         customizeChannelListItem.setEnabled(false);
81         items.add(customizeChannelListItem);
82         final MainActivity activity = getMainActivity();
83         TvSingletons singletons = TvSingletons.getSingletons(getContext());
84         boolean hasNewInput =
85                 singletons.getSetupUtils().hasNewInput(activity.getTvInputManagerHelper());
86         items.add(
87                 new ActionItem(
88                         getString(R.string.settings_channel_source_item_setup),
89                         hasNewInput
90                                 ? getString(R.string.settings_channel_source_item_setup_new_inputs)
91                                 : null) {
92                     @Override
93                     protected void onSelected() {
94                         closeFragment();
95                         activity.getOverlayManager().showSetupFragment();
96                     }
97                 });
98         if (PermissionUtils.hasModifyParentalControls(getMainActivity())) {
99             items.add(
100                     new ActionItem(
101                             getString(R.string.settings_parental_controls),
102                             getString(
103                                     activity.getParentalControlSettings()
104                                                     .isParentalControlsEnabled()
105                                             ? R.string.option_toggle_parental_controls_on
106                                             : R.string.option_toggle_parental_controls_off)) {
107                         @Override
108                         protected void onSelected() {
109                             getMainActivity()
110                                     .getOverlayManager()
111                                     .getSideFragmentManager()
112                                     .hideSidePanel(true);
113                             PinDialogFragment fragment =
114                                     PinDialogFragment.create(
115                                             PinDialogFragment.PIN_DIALOG_TYPE_ENTER_PIN);
116                             getMainActivity()
117                                     .getOverlayManager()
118                                     .showDialogFragment(
119                                             PinDialogFragment.DIALOG_TAG, fragment, true);
120                         }
121                     });
122         } else {
123             // Note: parental control is turned off, when MODIFY_PARENTAL_CONTROLS is not granted.
124             // But, we may be able to turn on channel lock feature regardless of the permission.
125             // It's TBD.
126         }
127         boolean showTrickplaySetting = false;
128         if (singletons.getBuiltInTunerManager().isPresent()) {
129             for (TvInputInfo inputInfo :
130                     singletons.getTvInputManagerHelper().getTvInputInfos(true, true)) {
131                 if (Utils.isInternalTvInput(getContext(), inputInfo.getId())) {
132                     showTrickplaySetting = true;
133                     break;
134                 }
135             }
136             if (showTrickplaySetting) {
137                 showTrickplaySetting =
138                         CustomizationManager.getTrickplayMode(getContext())
139                                 == CustomizationManager.TRICKPLAY_MODE_ENABLED;
140             }
141         }
142         if (showTrickplaySetting) {
143             items.add(
144                     new SwitchItem(
145                             getString(R.string.settings_trickplay),
146                             getString(R.string.settings_trickplay),
147                             getString(R.string.settings_trickplay_description),
148                             getResources().getInteger(R.integer.trickplay_description_max_lines)) {
149                         @Override
150                         protected void onUpdate() {
151                             super.onUpdate();
152                             boolean enabled =
153                                     CommonPreferences.getTrickplaySetting(getContext())
154                                             != CommonPreferences.TRICKPLAY_SETTING_DISABLED;
155                             setChecked(enabled);
156                         }
157 
158                         @Override
159                         protected void onSelected() {
160                             super.onSelected();
161                             @CommonPreferences.TrickplaySetting
162                             int setting =
163                                     isChecked()
164                                             ? CommonPreferences.TRICKPLAY_SETTING_ENABLED
165                                             : CommonPreferences.TRICKPLAY_SETTING_DISABLED;
166                             CommonPreferences.setTrickplaySetting(getContext(), setting);
167                         }
168                     });
169         }
170         items.add(
171                 new ActionItem(getString(R.string.settings_send_feedback)) {
172                     @Override
173                     protected void onSelected() {
174                         Intent intent = new Intent(Intent.ACTION_APP_ERROR);
175                         ApplicationErrorReport report = new ApplicationErrorReport();
176                         report.packageName = report.processName = getContext().getPackageName();
177                         report.time = System.currentTimeMillis();
178                         report.type = ApplicationErrorReport.TYPE_NONE;
179                         intent.putExtra(Intent.EXTRA_BUG_REPORT, report);
180                         startActivityForResult(intent, 0);
181                     }
182                 });
183         if (Licenses.hasLicenses(getContext())) {
184             items.add(
185                     new SubMenuItem(
186                             getString(R.string.settings_menu_licenses),
187                             getMainActivity().getOverlayManager().getSideFragmentManager()) {
188                         @Override
189                         protected SideFragment getFragment() {
190                             return new LicenseSideFragment();
191                         }
192                     });
193         }
194 
195         //Interactive Application Settings
196         if (TvFeatures.HAS_TIAF.isEnabled(getContext()))
197         {
198             items.add(
199                     new ActionItem(getString(R.string.interactive_app_settings)) {
200                         @Override
201                         protected void onSelected() {
202                             getMainActivity()
203                                     .getOverlayManager()
204                                     .getSideFragmentManager()
205                                     .show(new InteractiveAppSettingsFragment(), false);
206                         }
207                     });
208         }
209 
210         // Show version.
211         SimpleActionItem version =
212                 new SimpleActionItem(
213                         getString(R.string.settings_menu_version),
214                         ((TvApplication) activity.getApplicationContext()).getVersionName());
215         version.setClickable(false);
216         items.add(version);
217         return items;
218     }
219 
220     @Override
onResume()221     public void onResume() {
222         super.onResume();
223         if (getChannelDataManager().areAllChannelsHidden()) {
224             Toast.makeText(getActivity(), R.string.msg_all_channels_hidden, Toast.LENGTH_SHORT)
225                     .show();
226         }
227     }
228 }
229