1 /* 2 * Copyright (C) 2019 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.settings.help; 18 19 import static android.content.Context.ACCESSIBILITY_SERVICE; 20 21 import static com.android.tv.settings.overlay.FlavorUtils.FLAVOR_CLASSIC; 22 import static com.android.tv.settings.overlay.FlavorUtils.FLAVOR_TWO_PANEL; 23 import static com.android.tv.settings.overlay.FlavorUtils.FLAVOR_VENDOR; 24 import static com.android.tv.settings.overlay.FlavorUtils.FLAVOR_X; 25 import static com.android.tv.settings.util.InstrumentationUtils.logEntrySelected; 26 27 import android.app.tvsettings.TvSettingsEnums; 28 import android.content.pm.ResolveInfo; 29 import android.os.Bundle; 30 import android.view.accessibility.AccessibilityManager; 31 32 import androidx.annotation.Keep; 33 import androidx.leanback.widget.VerticalGridView; 34 import androidx.preference.Preference; 35 36 import com.android.tv.settings.MainFragment; 37 import com.android.tv.settings.R; 38 import com.android.tv.settings.SettingsPreferenceFragment; 39 import com.android.tv.settings.overlay.FlavorUtils; 40 41 /** 42 * The "Help & feedback" screen in TV settings. 43 */ 44 @Keep 45 public class HelpFragment extends SettingsPreferenceFragment { 46 47 private static final String KEY_SEND_FEEDBACK = "feedback"; 48 private static final String KEY_HELP = "help_center"; 49 getPreferenceScreenResId()50 private int getPreferenceScreenResId() { 51 switch (FlavorUtils.getFlavor(getContext())) { 52 case FLAVOR_CLASSIC: 53 case FLAVOR_TWO_PANEL: 54 return R.xml.help_and_feedback; 55 case FLAVOR_X: 56 case FLAVOR_VENDOR: 57 return R.xml.help_and_feedback_x; 58 default: 59 return R.xml.help_and_feedback; 60 } 61 } 62 63 @Override onCreatePreferences(Bundle savedInstanceState, String rootKey)64 public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { 65 setPreferencesFromResource(getPreferenceScreenResId(), null); 66 67 final Preference sendFeedbackPref = findPreference(KEY_SEND_FEEDBACK); 68 if (sendFeedbackPref != null) { 69 sendFeedbackPref.setVisible(!FlavorUtils.getFeatureFactory(getContext()) 70 .getBasicModeFeatureProvider().isBasicMode(getContext())); 71 } 72 73 final Preference helpPref = findPreference(KEY_HELP); 74 if (helpPref != null) { 75 final ResolveInfo info = MainFragment.systemIntentIsHandled(getActivity(), 76 helpPref.getIntent()); 77 helpPref.setVisible(info != null); 78 } 79 } 80 81 @Override onPreferenceTreeClick(Preference preference)82 public boolean onPreferenceTreeClick(Preference preference) { 83 AccessibilityManager am = 84 (AccessibilityManager) getContext().getSystemService(ACCESSIBILITY_SERVICE); 85 boolean isAccessibilityEnabled = am.isEnabled(); 86 VerticalGridView listView = (VerticalGridView) getListView(); 87 if (!listView.getChildAt(listView.getSelectedPosition()).isAccessibilityFocused() 88 && isAccessibilityEnabled) { 89 return true; 90 } 91 switch (preference.getKey()) { 92 case KEY_SEND_FEEDBACK: 93 logEntrySelected(TvSettingsEnums.FEEDBACK_SEND); 94 return super.onPreferenceTreeClick(preference); 95 case KEY_HELP: 96 FlavorUtils.getFeatureFactory(getActivity()).getSupportFeatureProvider() 97 .startSupport(getActivity()); 98 return true; 99 default: 100 return super.onPreferenceTreeClick(preference); 101 } 102 } 103 104 @Override getPageId()105 protected int getPageId() { 106 return TvSettingsEnums.FEEDBACK; 107 } 108 } 109