1 /* 2 * Copyright (C) 2021 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.accessibility; 18 19 import static com.android.tv.settings.library.ManagerUtil.STATE_ACCESSIBILITY_SERVICE; 20 21 import android.os.Bundle; 22 23 import androidx.annotation.Keep; 24 import androidx.preference.PreferenceManager; 25 26 import com.android.tv.settings.R; 27 import com.android.tv.settings.compat.HasKeys; 28 import com.android.tv.settings.compat.PreferenceControllerFragmentCompat; 29 import com.android.tv.settings.compat.RenderUtil; 30 import com.android.tv.settings.compat.TsPreferenceCategory; 31 import com.android.tv.settings.compat.TsRestrictedSwitchPreference; 32 import com.android.tv.settings.library.PreferenceCompat; 33 34 /** 35 * Fragment for controlling accessibility service 36 */ 37 @Keep 38 public class AccessibilityServiceFragmentCompat extends 39 PreferenceControllerFragmentCompat { 40 private static final String KEY_SCREEN = "screen"; 41 private static final String KEY_ENABLE = "enable"; 42 43 @Override getStateIdentifier()44 public int getStateIdentifier() { 45 return STATE_ACCESSIBILITY_SERVICE; 46 } 47 48 @Override onCreatePreferences(Bundle savedInstanceState, String rootKey)49 public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { 50 getPreferenceManager() 51 .setPreferenceComparisonCallback( 52 new PreferenceManager.SimplePreferenceComparisonCallback()); 53 setPreferencesFromResource(R.xml.accessibility_service_compat, null); 54 } 55 56 @Override updatePref(PreferenceCompat prefCompat)57 public HasKeys updatePref(PreferenceCompat prefCompat) { 58 HasKeys preference = super.updatePref(prefCompat); 59 if (preference == null) { 60 return null; 61 } 62 switch (prefCompat.getKey()[0]) { 63 case KEY_SCREEN: 64 final TsPreferenceCategory screen = findPreference(KEY_SCREEN); 65 RenderUtil.updatePreferenceGroup(screen, prefCompat.getChildPrefCompats()); 66 // Set OnPreferenceChangeListener to the ENABLE switch after them created. 67 TsRestrictedSwitchPreference enable = findPreference(KEY_ENABLE); 68 enable.setOnPreferenceChangeListener(this); 69 break; 70 default: 71 // no-op 72 } 73 return preference; 74 } 75 } 76