Make Extra Dim Setting as percentage of device

- Extra dim setting now operates in percentage of the device's
  capabilities
- ie "100" now means the maximum possible dimming on the current device,
  if restored to another device, this means the max possible dimming on
  that device as well.

Bug: 337351445
Flag: EXEMPT bugfix
Test: atest DisplayServiceTests
Test: atest ReduceBrightColorsIntensityPreferenceControllerTest
Change-Id: I98d0d7af562fdfb2b921746e0e5654bad47b440b
This commit is contained in:
Fiona Campbell
2025-01-27 15:17:27 +00:00
parent 99ff9245a6
commit fc94995307
2 changed files with 29 additions and 17 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.accessibility;
import android.content.Context;
import android.hardware.display.ColorDisplayManager;
import android.provider.Settings;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
@@ -28,7 +29,6 @@ import com.android.settings.widget.SeekBarPreference;
/** PreferenceController for feature intensity. */
public class ReduceBrightColorsIntensityPreferenceController extends SliderPreferenceController {
private static final int INVERSE_PERCENTAGE_BASE = 100;
private final ColorDisplayManager mColorDisplayManager;
public ReduceBrightColorsIntensityPreferenceController(Context context, String key) {
@@ -58,7 +58,6 @@ public class ReduceBrightColorsIntensityPreferenceController extends SliderPrefe
updateState(preference);
}
@Override
public final void updateState(Preference preference) {
super.updateState(preference);
@@ -67,24 +66,28 @@ public class ReduceBrightColorsIntensityPreferenceController extends SliderPrefe
@Override
public int getSliderPosition() {
return INVERSE_PERCENTAGE_BASE - mColorDisplayManager.getReduceBrightColorsStrength();
final int settingValue = Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL,
/* fallback= */ 0);
return getMax() - settingValue;
}
@Override
public boolean setSliderPosition(int position) {
return mColorDisplayManager.setReduceBrightColorsStrength(
INVERSE_PERCENTAGE_BASE - position);
return Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL,
getMax() - position);
}
@Override
public int getMax() {
return INVERSE_PERCENTAGE_BASE
- ColorDisplayManager.getMinimumReduceBrightColorsStrength(mContext);
return 100;
}
@Override
public int getMin() {
return INVERSE_PERCENTAGE_BASE
- ColorDisplayManager.getMaximumReduceBrightColorsStrength(mContext);
return 0;
}
}