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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,15 +188,24 @@ public class ReduceBrightColorsIntensityPreferenceControllerTest {
|
||||
.isEqualTo(80);
|
||||
}
|
||||
|
||||
// Slider range should represent percentage.
|
||||
@Test
|
||||
public void rangeOfSlider_staysWithinValidRange() {
|
||||
when(mResources.getInteger(
|
||||
R.integer.config_reduceBrightColorsStrengthMax)).thenReturn(90);
|
||||
when(mResources.getInteger(
|
||||
R.integer.config_reduceBrightColorsStrengthMin)).thenReturn(15);
|
||||
assertThat(mPreferenceController.getMax()).isEqualTo(85);
|
||||
assertThat(mPreferenceController.getMin()).isEqualTo(10);
|
||||
public void rangeOfSlider_isPercentage() {
|
||||
assertThat(mPreferenceController.getMax()).isEqualTo(100);
|
||||
assertThat(mPreferenceController.getMin()).isEqualTo(0);
|
||||
assertThat(mPreferenceController.getMax() - mPreferenceController.getMin())
|
||||
.isEqualTo(75);
|
||||
.isEqualTo(100);
|
||||
}
|
||||
|
||||
// Slider should be of range 100 - 0.
|
||||
@Test
|
||||
public void rangeOfSlider_isInverted() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
|
||||
mPreferenceController.onPreferenceChange(/* preference= */ null, 2);
|
||||
assertThat(
|
||||
Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, 0))
|
||||
.isEqualTo(98);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user