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 android.content.Context;
20 import android.os.UserHandle;
21 import android.provider.Settings;
22 
23 import androidx.annotation.NonNull;
24 import androidx.annotation.VisibleForTesting;
25 import androidx.preference.Preference;
26 import androidx.preference.PreferenceDataStore;
27 import androidx.preference.PreferenceScreen;
28 
29 import com.android.settings.core.BasePreferenceController;
30 
31 public class PointerFillStylePreferenceController extends BasePreferenceController {
32 
33     @VisibleForTesting
34     static final String KEY_POINTER_FILL_STYLE = "pointer_fill_style";
35 
PointerFillStylePreferenceController(@onNull Context context)36     public PointerFillStylePreferenceController(@NonNull Context context) {
37         super(context, KEY_POINTER_FILL_STYLE);
38     }
39 
40     @AvailabilityStatus
getAvailabilityStatus()41     public int getAvailabilityStatus() {
42         return android.view.flags.Flags.enableVectorCursorA11ySettings() ? AVAILABLE
43                 : CONDITIONALLY_UNAVAILABLE;
44     }
45 
46     @Override
displayPreference(PreferenceScreen screen)47     public void displayPreference(PreferenceScreen screen) {
48         super.displayPreference(screen);
49         Preference pointerFillStylePreference = screen.findPreference(KEY_POINTER_FILL_STYLE);
50         if (pointerFillStylePreference == null) {
51             return;
52         }
53         pointerFillStylePreference.setPreferenceDataStore(new PreferenceDataStore() {
54             @Override
55             public void putInt(@NonNull String key, int value) {
56                 Settings.System.putIntForUser(mContext.getContentResolver(), key, value,
57                         UserHandle.USER_CURRENT);
58             }
59 
60             @Override
61             public int getInt(@NonNull String key, int defValue) {
62                 return Settings.System.getIntForUser(mContext.getContentResolver(), key, defValue,
63                         UserHandle.USER_CURRENT);
64             }
65         });
66     }
67 }
68