• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.systemui.accessibility;
18 
19 import android.content.Context;
20 import android.provider.Settings;
21 
22 import androidx.annotation.MainThread;
23 import androidx.annotation.Nullable;
24 
25 import com.android.systemui.dagger.SysUISingleton;
26 
27 import javax.inject.Inject;
28 
29 /**
30  * Controller for tracking the current accessibility button list.
31  *
32  * @see Settings.Secure#ACCESSIBILITY_BUTTON_TARGETS
33  */
34 @MainThread
35 @SysUISingleton
36 public class AccessibilityButtonTargetsObserver extends
37         SecureSettingsContentObserver<AccessibilityButtonTargetsObserver.TargetsChangedListener> {
38 
39     /** Listener for accessibility button targets changes. */
40     public interface TargetsChangedListener {
41 
42         /**
43          * Called when accessibility button targets changes.
44          *
45          * @param targets Current content of {@link Settings.Secure#ACCESSIBILITY_BUTTON_TARGETS}
46          */
onAccessibilityButtonTargetsChanged(String targets)47         void onAccessibilityButtonTargetsChanged(String targets);
48     }
49 
50     @Inject
AccessibilityButtonTargetsObserver(Context context)51     public AccessibilityButtonTargetsObserver(Context context) {
52         super(context, Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
53     }
54 
55     @Override
onValueChanged(TargetsChangedListener listener, String value)56     void onValueChanged(TargetsChangedListener listener, String value) {
57         listener.onAccessibilityButtonTargetsChanged(value);
58     }
59 
60     /** Returns the current string from settings key
61      *  {@link Settings.Secure#ACCESSIBILITY_BUTTON_TARGETS}. */
62     @Nullable
getCurrentAccessibilityButtonTargets()63     public String getCurrentAccessibilityButtonTargets() {
64         return getSettingsValue();
65     }
66 }
67