1 /* 2 * Copyright (C) 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 package com.android.settings.accessibility; 17 18 import android.content.ContentResolver; 19 import android.content.Context; 20 import android.provider.Settings; 21 22 import androidx.preference.PreferenceScreen; 23 24 import com.android.server.accessibility.Flags; 25 import com.android.settings.core.SliderPreferenceController; 26 import com.android.settings.widget.SeekBarPreference; 27 28 /** 29 * The controller of the seekbar preference for the saturation level of color correction. 30 */ 31 public class DaltonizerSaturationSeekbarPreferenceController extends SliderPreferenceController { 32 33 private static final int DEFAULT_SATURATION_LEVEL = 7; 34 private static final int SATURATION_MAX = 10; 35 private static final int SATURATION_MIN = 0; 36 37 private int mSliderPosition; 38 private final ContentResolver mContentResolver; 39 DaltonizerSaturationSeekbarPreferenceController(Context context, String preferenceKey)40 public DaltonizerSaturationSeekbarPreferenceController(Context context, 41 String preferenceKey) { 42 super(context, preferenceKey); 43 mContentResolver = context.getContentResolver(); 44 mSliderPosition = Settings.Secure.getInt( 45 mContentResolver, 46 Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_SATURATION_LEVEL, 47 DEFAULT_SATURATION_LEVEL); 48 setSliderPosition(mSliderPosition); 49 // TODO: Observer color correction on/off and enable/disable based on secure settings. 50 } 51 52 @Override displayPreference(PreferenceScreen screen)53 public void displayPreference(PreferenceScreen screen) { 54 super.displayPreference(screen); 55 SeekBarPreference preference = screen.findPreference(getPreferenceKey()); 56 preference.setMax(getMax()); 57 preference.setMin(getMin()); 58 preference.setProgress(mSliderPosition); 59 preference.setContinuousUpdates(true); 60 } 61 62 @Override getAvailabilityStatus()63 public int getAvailabilityStatus() { 64 if (Flags.enableColorCorrectionSaturation()) { 65 return AVAILABLE; 66 } 67 return CONDITIONALLY_UNAVAILABLE; 68 } 69 70 @Override getSliderPosition()71 public int getSliderPosition() { 72 return mSliderPosition; 73 } 74 75 @Override setSliderPosition(int position)76 public boolean setSliderPosition(int position) { 77 if (position < getMin() || position > getMax()) { 78 return false; 79 } 80 mSliderPosition = position; 81 Settings.Secure.putInt( 82 mContentResolver, 83 Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_SATURATION_LEVEL, 84 mSliderPosition); 85 return true; 86 } 87 88 @Override getMax()89 public int getMax() { 90 return SATURATION_MAX; 91 } 92 93 @Override getMin()94 public int getMin() { 95 return SATURATION_MIN; 96 } 97 } 98