1 /* 2 * Copyright (C) 2022 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.settings.accessibility; 18 19 import static android.provider.Settings.Secure.ENABLED_ACCESSIBILITY_AUDIO_DESCRIPTION_BY_DEFAULT; 20 21 import static com.android.settings.accessibility.AccessibilityUtil.State.OFF; 22 import static com.android.settings.accessibility.AccessibilityUtil.State.ON; 23 24 import android.content.Context; 25 import android.os.UserHandle; 26 import android.provider.Settings; 27 28 import com.android.settings.R; 29 import com.android.settings.core.TogglePreferenceController; 30 31 /** 32 * A toggle preference controller for audio description 33 */ 34 public class AudioDescriptionPreferenceController extends TogglePreferenceController { 35 36 static final String PREF_KEY = "toggle_audio_description"; 37 AudioDescriptionPreferenceController(Context context, String preferenceKey)38 public AudioDescriptionPreferenceController(Context context, String preferenceKey) { 39 super(context, preferenceKey); 40 } 41 42 @Override isChecked()43 public boolean isChecked() { 44 return Settings.Secure.getIntForUser(mContext.getContentResolver(), 45 ENABLED_ACCESSIBILITY_AUDIO_DESCRIPTION_BY_DEFAULT, 46 OFF /* default */, 47 UserHandle.USER_CURRENT) == ON; 48 } 49 50 @Override setChecked(boolean isChecked)51 public boolean setChecked(boolean isChecked) { 52 return Settings.Secure.putIntForUser(mContext.getContentResolver(), 53 ENABLED_ACCESSIBILITY_AUDIO_DESCRIPTION_BY_DEFAULT, 54 isChecked ? ON : OFF, 55 UserHandle.USER_CURRENT); 56 } 57 58 @Override getAvailabilityStatus()59 public int getAvailabilityStatus() { 60 return AVAILABLE; 61 } 62 63 @Override getSliceHighlightMenuRes()64 public int getSliceHighlightMenuRes() { 65 return R.string.menu_key_accessibility; 66 } 67 } 68