Call into ColorDisplayManager for RBC slider range
Test: atest ReduceBrightColorsIntensityPreferenceControllerTest Bug: b/179805222 Change-Id: I0927f41fad27e6b9b54c374e2c6a7cc6e0c5240d
This commit is contained in:
@@ -29,8 +29,11 @@ import com.android.settings.widget.SeekBarPreference;
|
||||
/** PreferenceController for feature intensity. */
|
||||
public class ReduceBrightColorsIntensityPreferenceController extends SliderPreferenceController {
|
||||
|
||||
private final ColorDisplayManager mColorDisplayManager;
|
||||
|
||||
public ReduceBrightColorsIntensityPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mColorDisplayManager = context.getSystemService(ColorDisplayManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,31 +62,26 @@ public class ReduceBrightColorsIntensityPreferenceController extends SliderPrefe
|
||||
@Override
|
||||
public final void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
preference.setEnabled(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 0) == 1);
|
||||
preference.setEnabled(mColorDisplayManager.isReduceBrightColorsActivated());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliderPosition() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, 0);
|
||||
return mColorDisplayManager.getReduceBrightColorsStrength();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setSliderPosition(int position) {
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, position);
|
||||
return mColorDisplayManager.setReduceBrightColorsStrength(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMax() {
|
||||
// TODO(b/170970675): Call into CDS to get config max intensity
|
||||
return 100;
|
||||
return ColorDisplayManager.getMaximumReduceBrightColorsStrength(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMin() {
|
||||
// TODO(b/170970675): Call into CDS to get config min intensity
|
||||
return 0;
|
||||
return ColorDisplayManager.getMinimumReduceBrightColorsStrength(mContext);
|
||||
}
|
||||
}
|
||||
|
@@ -24,11 +24,14 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.hardware.display.ColorDisplayManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -79,8 +82,19 @@ public class ReduceBrightColorsIntensityPreferenceControllerTest {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, 1);
|
||||
mPreferenceController.onPreferenceChange(/* preference= */ null, 20);
|
||||
assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_LEVEL, 0))
|
||||
assertThat(
|
||||
mContext.getSystemService(
|
||||
ColorDisplayManager.class).getReduceBrightColorsStrength())
|
||||
.isEqualTo(20);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rangeOfSlider_staysWithinValidRange() {
|
||||
when(mResources.getInteger(
|
||||
R.integer.config_reduceBrightColorsStrengthMax)).thenReturn(90);
|
||||
when(mResources.getInteger(
|
||||
R.integer.config_reduceBrightColorsStrengthMin)).thenReturn(10);
|
||||
assertThat(mPreferenceController.getMax() - mPreferenceController.getMin())
|
||||
.isEqualTo(80);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user