Add labels to intensity slider and flip labels

Labels are Dimmer and Brighter. As the slider value is lowered,
the dimming intensity is increased

Slider min = 100 - intensity max
Slider max = 100 - intensity min

Ex: If intensity max = 80, the slider min with be 20. If the user
moves the position to the minimum end we'll send 80 to Color DisplayManager

Test: atest ReduceBrightColorsIntensityPreferenceControllerTest,
manual
Bug: 190722076

Change-Id: Ib05ba38805b8fa1f68c144a3929027899df70abf
This commit is contained in:
Sally
2021-06-14 22:10:27 +00:00
parent 9f7564c1b6
commit d98ee531c1
4 changed files with 24 additions and 9 deletions

View File

@@ -5586,6 +5586,10 @@
</string>
<!-- Title for setting the brightness intensity of the display using Reduce Brightness. [CHAR LIMIT=NONE] -->
<string name="reduce_bright_colors_intensity_preference_title">Intensity</string>
<!-- Start label for slider that reduces the brightness intensity of the display using Extra Dim. [CHAR LIMIT=NONE] -->
<string name="reduce_bright_colors_intensity_start_label">Dimmer</string>
<!-- End label for slider that reduces the brightness intensity of the display using Extra Dim. [CHAR LIMIT=NONE] -->
<string name="reduce_bright_colors_intensity_end_label">Brighter</string>
<!-- Title for setting whether the Reduce Brightness activation state persists across reboots. [CHAR LIMIT=NONE] -->
<string name="reduce_bright_colors_persist_preference_title">Keep on after device restarts</string>

View File

@@ -17,13 +17,18 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:persistent="false"
android:title="@string/reduce_bright_colors_preference_title">
<com.android.settings.widget.SeekBarPreference
<com.android.settings.widget.LabeledSeekBarPreference
android:key="rbc_intensity"
android:persistent="false"
android:title="@string/reduce_bright_colors_intensity_preference_title"/>
android:title="@string/reduce_bright_colors_intensity_preference_title"
settings:textStart="@string/reduce_bright_colors_intensity_start_label"
settings:textEnd="@string/reduce_bright_colors_intensity_end_label"
settings:tickMark="@android:color/transparent"
/>
<SwitchPreference
android:key="rbc_persist"

View File

@@ -28,6 +28,7 @@ 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) {
@@ -66,21 +67,24 @@ public class ReduceBrightColorsIntensityPreferenceController extends SliderPrefe
@Override
public int getSliderPosition() {
return mColorDisplayManager.getReduceBrightColorsStrength();
return INVERSE_PERCENTAGE_BASE - mColorDisplayManager.getReduceBrightColorsStrength();
}
@Override
public boolean setSliderPosition(int position) {
return mColorDisplayManager.setReduceBrightColorsStrength(position);
return mColorDisplayManager.setReduceBrightColorsStrength(
INVERSE_PERCENTAGE_BASE - position);
}
@Override
public int getMax() {
return ColorDisplayManager.getMaximumReduceBrightColorsStrength(mContext);
return INVERSE_PERCENTAGE_BASE
- ColorDisplayManager.getMinimumReduceBrightColorsStrength(mContext);
}
@Override
public int getMin() {
return ColorDisplayManager.getMinimumReduceBrightColorsStrength(mContext);
return INVERSE_PERCENTAGE_BASE
- ColorDisplayManager.getMaximumReduceBrightColorsStrength(mContext);
}
}

View File

@@ -84,7 +84,7 @@ public class ReduceBrightColorsIntensityPreferenceControllerTest {
assertThat(
Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, 0))
.isEqualTo(20);
.isEqualTo(80);
}
@Test
@@ -92,8 +92,10 @@ public class ReduceBrightColorsIntensityPreferenceControllerTest {
when(mResources.getInteger(
R.integer.config_reduceBrightColorsStrengthMax)).thenReturn(90);
when(mResources.getInteger(
R.integer.config_reduceBrightColorsStrengthMin)).thenReturn(10);
R.integer.config_reduceBrightColorsStrengthMin)).thenReturn(15);
assertThat(mPreferenceController.getMax()).isEqualTo(85);
assertThat(mPreferenceController.getMin()).isEqualTo(10);
assertThat(mPreferenceController.getMax() - mPreferenceController.getMin())
.isEqualTo(80);
.isEqualTo(75);
}
}