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