Call ColorDisplayManager for Extra Dim/RBC state
- Move junit test into unit test folder - Settings resources ids are different from the junit test ids so we need to find the correct resource id - ColorDisplayManager will not update in time before the controller is checked, and it can't be mocked since it's a final class Bug: 170970675 Test: manual, atest ReduceBrightColorsPreferenceControllerTest Change-Id: I57bfdd8294c5b6e147b4e11ae97b6b56f6121343
This commit is contained in:
@@ -42,6 +42,7 @@ public class ReduceBrightColorsPreferenceController extends TogglePreferenceCont
|
||||
private ContentObserver mSettingsContentObserver;
|
||||
private PrimarySwitchPreference mPreference;
|
||||
private final Context mContext;
|
||||
private final ColorDisplayManager mColorDisplayManager;
|
||||
|
||||
public ReduceBrightColorsPreferenceController(Context context,
|
||||
String preferenceKey) {
|
||||
@@ -56,21 +57,17 @@ public class ReduceBrightColorsPreferenceController extends TogglePreferenceCont
|
||||
}
|
||||
}
|
||||
};
|
||||
mColorDisplayManager = mContext.getSystemService(ColorDisplayManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.Secure.getIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED,
|
||||
0,
|
||||
UserHandle.USER_CURRENT) == 1;
|
||||
return mColorDisplayManager.isReduceBrightColorsActivated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED, isChecked ? 1 : 0,
|
||||
UserHandle.USER_CURRENT);
|
||||
return mColorDisplayManager.setReduceBrightColorsActivated(isChecked);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -16,9 +16,6 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.hardware.display.ColorDisplayManager;
|
||||
@@ -56,6 +53,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
|
||||
private SettingsContentObserver mSettingsContentObserver;
|
||||
private ReduceBrightColorsIntensityPreferenceController mRbcIntensityPreferenceController;
|
||||
private ReduceBrightColorsPersistencePreferenceController mRbcPersistencePreferenceController;
|
||||
private ColorDisplayManager mColorDisplayManager;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
@@ -79,7 +77,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
|
||||
updateSwitchBarToggleSwitch();
|
||||
}
|
||||
};
|
||||
|
||||
mColorDisplayManager = getContext().getSystemService(ColorDisplayManager.class);
|
||||
final View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
// Parent sets the title when creating the view, so set it after calling super
|
||||
mToggleServiceSwitchPreference.setTitle(R.string.reduce_bright_colors_switch_title);
|
||||
@@ -137,8 +135,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
|
||||
@Override
|
||||
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
|
||||
AccessibilityStatsLogUtils.logAccessibilityServiceEnabled(mComponentName, enabled);
|
||||
Settings.Secure.putInt(getContentResolver(),
|
||||
REDUCE_BRIGHT_COLORS_ACTIVATED_KEY, enabled ? ON : OFF);
|
||||
mColorDisplayManager.setReduceBrightColorsActivated(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -161,8 +158,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
|
||||
|
||||
@Override
|
||||
protected void updateSwitchBarToggleSwitch() {
|
||||
final boolean checked = Settings.Secure.getInt(getContentResolver(),
|
||||
REDUCE_BRIGHT_COLORS_ACTIVATED_KEY, OFF) == ON;
|
||||
final boolean checked = mColorDisplayManager.isReduceBrightColorsActivated();
|
||||
mRbcIntensityPreferenceController.updateState(getPreferenceScreen()
|
||||
.findPreference(KEY_INTENSITY));
|
||||
mRbcPersistencePreferenceController.updateState(getPreferenceScreen()
|
||||
|
Reference in New Issue
Block a user