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 static com.android.internal.accessibility.AccessibilityShortcutController.MAGNIFICATION_CONTROLLER_NAME;
20 
21 import android.content.Context;
22 
23 import com.android.settings.accessibility.ExpandablePreference;
24 
25 import java.util.Set;
26 
27 /**
28  * A preference controller that controls an expandable preference that wraps
29  * the advanced shortcut options.
30  */
31 public class AdvancedShortcutsPreferenceController extends ShortcutOptionPreferenceController
32         implements ExpandablePreference {
33 
34     private boolean mIsExpanded = false;
35 
AdvancedShortcutsPreferenceController(Context context, String preferenceKey)36     public AdvancedShortcutsPreferenceController(Context context, String preferenceKey) {
37         super(context, preferenceKey);
38     }
39 
40     @Override
isChecked()41     protected boolean isChecked() {
42         return false;
43     }
44 
45     @Override
enableShortcutForTargets(boolean enable)46     protected void enableShortcutForTargets(boolean enable) {
47         // do nothing
48     }
49 
50     @Override
getAvailabilityStatus()51     public int getAvailabilityStatus() {
52         if (!isExpanded() && isShortcutAvailable()) {
53             // "Advanced" is available when the user hasn't clicked on it
54             return AVAILABLE_UNSEARCHABLE;
55         }
56         return CONDITIONALLY_UNAVAILABLE;
57     }
58 
59     @Override
setExpanded(boolean expanded)60     public void setExpanded(boolean expanded) {
61         mIsExpanded = expanded;
62     }
63 
64     @Override
isExpanded()65     public boolean isExpanded() {
66         return mIsExpanded;
67     }
68 
69     @Override
isShortcutAvailable()70     protected boolean isShortcutAvailable() {
71         // Only Magnification has advanced shortcut options.
72         Set<String> shortcutTargets = getShortcutTargets();
73         return shortcutTargets.size() == 1
74                 && shortcutTargets.contains(MAGNIFICATION_CONTROLLER_NAME);
75     }
76 }
77