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