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