1 /* 2 * Copyright (C) 2023 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.shortcuts; 18 19 import android.content.Context; 20 import android.view.accessibility.Flags; 21 22 import androidx.preference.Preference; 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.internal.accessibility.common.ShortcutConstants; 26 import com.android.settings.R; 27 import com.android.settings.accessibility.AccessibilityUtil; 28 29 /** 30 * A controller handles displaying the volume keys shortcut option preference and 31 * configuring the shortcut. 32 */ 33 public class VolumeKeysShortcutOptionController extends ShortcutOptionPreferenceController { 34 VolumeKeysShortcutOptionController( Context context, String preferenceKey)35 public VolumeKeysShortcutOptionController( 36 Context context, String preferenceKey) { 37 super(context, preferenceKey); 38 } 39 40 @ShortcutConstants.UserShortcutType 41 @Override getShortcutType()42 protected int getShortcutType() { 43 return ShortcutConstants.UserShortcutType.HARDWARE; 44 } 45 46 @Override displayPreference(PreferenceScreen screen)47 public void displayPreference(PreferenceScreen screen) { 48 super.displayPreference(screen); 49 final Preference preference = screen.findPreference(getPreferenceKey()); 50 if (preference instanceof ShortcutOptionPreference shortcutOptionPreference) { 51 shortcutOptionPreference.setTitle( 52 R.string.accessibility_shortcut_edit_dialog_title_hardware); 53 shortcutOptionPreference.setSummary( 54 R.string.accessibility_shortcut_edit_dialog_summary_hardware); 55 shortcutOptionPreference.setIntroImageResId( 56 R.drawable.accessibility_shortcut_type_volume_keys); 57 } 58 } 59 60 @Override isShortcutAvailable()61 protected boolean isShortcutAvailable() { 62 return true; 63 } 64 65 @Override enableShortcutForTargets(boolean enable)66 protected void enableShortcutForTargets(boolean enable) { 67 super.enableShortcutForTargets(enable); 68 if (Flags.a11yQsShortcut()) { 69 return; 70 } 71 72 if (enable) { 73 AccessibilityUtil.skipVolumeShortcutDialogTimeoutRestriction(mContext); 74 } 75 } 76 } 77