1 /* 2 * Copyright 2024 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.inputmethod; 18 19 import static android.view.PointerIcon.POINTER_ICON_VECTOR_STYLE_FILL_BLACK; 20 21 import android.app.settings.SettingsEnums; 22 import android.content.Context; 23 import android.os.UserHandle; 24 import android.provider.Settings; 25 26 import androidx.annotation.NonNull; 27 import androidx.annotation.VisibleForTesting; 28 import androidx.lifecycle.Lifecycle; 29 import androidx.lifecycle.LifecycleEventObserver; 30 import androidx.lifecycle.LifecycleOwner; 31 import androidx.preference.Preference; 32 import androidx.preference.PreferenceDataStore; 33 import androidx.preference.PreferenceScreen; 34 35 import com.android.settings.core.BasePreferenceController; 36 import com.android.settings.overlay.FeatureFactory; 37 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; 38 39 public class PointerFillStylePreferenceController extends BasePreferenceController 40 implements LifecycleEventObserver { 41 42 private MetricsFeatureProvider mMetricsFeatureProvider; 43 44 @VisibleForTesting 45 static final String KEY_POINTER_FILL_STYLE = "pointer_fill_style"; 46 PointerFillStylePreferenceController(@onNull Context context)47 public PointerFillStylePreferenceController(@NonNull Context context) { 48 super(context, KEY_POINTER_FILL_STYLE); 49 50 mMetricsFeatureProvider = 51 FeatureFactory.getFeatureFactory().getMetricsFeatureProvider(); 52 } 53 54 @AvailabilityStatus getAvailabilityStatus()55 public int getAvailabilityStatus() { 56 return android.view.flags.Flags.enableVectorCursorA11ySettings() ? AVAILABLE 57 : CONDITIONALLY_UNAVAILABLE; 58 } 59 60 @Override displayPreference(PreferenceScreen screen)61 public void displayPreference(PreferenceScreen screen) { 62 super.displayPreference(screen); 63 Preference pointerFillStylePreference = screen.findPreference(KEY_POINTER_FILL_STYLE); 64 if (pointerFillStylePreference == null) { 65 return; 66 } 67 pointerFillStylePreference.setPreferenceDataStore(new PreferenceDataStore() { 68 @Override 69 public void putInt(@NonNull String key, int value) { 70 Settings.System.putIntForUser(mContext.getContentResolver(), key, value, 71 UserHandle.USER_CURRENT); 72 } 73 74 @Override 75 public int getInt(@NonNull String key, int defValue) { 76 return Settings.System.getIntForUser(mContext.getContentResolver(), key, defValue, 77 UserHandle.USER_CURRENT); 78 } 79 }); 80 } 81 82 @Override onStateChanged(@onNull LifecycleOwner lifecycleOwner, @NonNull Lifecycle.Event event)83 public void onStateChanged(@NonNull LifecycleOwner lifecycleOwner, 84 @NonNull Lifecycle.Event event) { 85 if (event == Lifecycle.Event.ON_PAUSE) { 86 int currentValue = 87 Settings.System.getIntForUser(mContext.getContentResolver(), 88 Settings.System.POINTER_FILL_STYLE, 89 POINTER_ICON_VECTOR_STYLE_FILL_BLACK, UserHandle.USER_CURRENT); 90 mMetricsFeatureProvider.action(mContext, 91 SettingsEnums.ACTION_POINTER_ICON_FILL_STYLE_CHANGED, currentValue); 92 } 93 } 94 } 95