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.text.SpannableStringBuilder; 21 22 import androidx.preference.Preference; 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.R; 26 import com.android.settings.accessibility.AccessibilityUtil; 27 import com.android.settingslib.utils.StringUtil; 28 29 /** 30 * A controller handles displaying the gesture shortcut option preference and 31 * configuring the shortcut. 32 */ 33 public class GestureShortcutOptionController extends SoftwareShortcutOptionPreferenceController { 34 GestureShortcutOptionController(Context context, String preferenceKey)35 public GestureShortcutOptionController(Context context, String preferenceKey) { 36 super(context, preferenceKey); 37 } 38 39 @Override displayPreference(PreferenceScreen screen)40 public void displayPreference(PreferenceScreen screen) { 41 super.displayPreference(screen); 42 final Preference preference = screen.findPreference(getPreferenceKey()); 43 if (preference instanceof ShortcutOptionPreference shortcutOptionPreference) { 44 shortcutOptionPreference.setTitle( 45 R.string.accessibility_shortcut_edit_dialog_title_software_by_gesture); 46 47 int resId = AccessibilityUtil.isTouchExploreEnabled(mContext) 48 ? R.drawable.accessibility_shortcut_type_gesture_touch_explore_on 49 : R.drawable.accessibility_shortcut_type_gesture; 50 shortcutOptionPreference.setIntroImageResId(resId); 51 } 52 } 53 54 @Override isShortcutAvailable()55 protected boolean isShortcutAvailable() { 56 return !isInSetupWizard() 57 && !AccessibilityUtil.isFloatingMenuEnabled(mContext) 58 && AccessibilityUtil.isGestureNavigateEnabled(mContext); 59 } 60 61 @Override getSummary()62 public CharSequence getSummary() { 63 int numFingers = AccessibilityUtil.isTouchExploreEnabled(mContext) ? 3 : 2; 64 String instruction = StringUtil.getIcuPluralsString( 65 mContext, 66 numFingers, 67 R.string.accessibility_shortcut_edit_dialog_summary_gesture); 68 69 final SpannableStringBuilder sb = new SpannableStringBuilder(); 70 sb.append(instruction); 71 if (!isInSetupWizard()) { 72 sb.append("\n\n"); 73 sb.append(getCustomizeAccessibilityButtonLink()); 74 } 75 76 return sb; 77 } 78 } 79