feat(EDT): Update the preference interaction and visiblity logic
The EDT toggle will be an subsetting in the DarkTheme settings page - When the Dark Theme main toggle is on, we check the EDT setting to decide applying normal DarkTheme or EDT now. - The EDT preference is disabled when DarkTheme is off Bug: 368721320 Flag: android.view.accessibility.force_invert_color Test: atest ToggleForceInvertPreferenceControllerTest Change-Id: I97841c5b2f03c8c0fb37e0be309d15f312bfedbd
This commit is contained in:
@@ -16,11 +16,16 @@
|
|||||||
|
|
||||||
package com.android.settings.accessibility;
|
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.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.accessibility.Flags;
|
import android.view.accessibility.Flags;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
@@ -28,27 +33,28 @@ import com.android.settings.core.TogglePreferenceController;
|
|||||||
/** A toggle preference controller for force invert (force dark). */
|
/** A toggle preference controller for force invert (force dark). */
|
||||||
public class ToggleForceInvertPreferenceController extends TogglePreferenceController {
|
public class ToggleForceInvertPreferenceController extends TogglePreferenceController {
|
||||||
|
|
||||||
public static final String SETTINGS_KEY =
|
|
||||||
Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static final int ON = 1;
|
|
||||||
@VisibleForTesting
|
|
||||||
static final int OFF = 0;
|
|
||||||
|
|
||||||
public ToggleForceInvertPreferenceController(Context context, String preferenceKey) {
|
public ToggleForceInvertPreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
return Settings.Secure.getInt(mContext.getContentResolver(), SETTINGS_KEY, OFF) != OFF;
|
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, OFF) != OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setChecked(boolean isChecked) {
|
public boolean setChecked(boolean isChecked) {
|
||||||
return Settings.Secure.putInt(mContext.getContentResolver(),
|
return Settings.Secure.putInt(mContext.getContentResolver(),
|
||||||
SETTINGS_KEY, isChecked ? ON : OFF);
|
Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, isChecked ? ON : OFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(@NonNull Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
final boolean isDarkModeActivated = (mContext.getResources().getConfiguration().uiMode
|
||||||
|
& Configuration.UI_MODE_NIGHT_YES) != 0;
|
||||||
|
preference.setEnabled(isDarkModeActivated);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -23,13 +23,18 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.platform.test.annotations.RequiresFlagsDisabled;
|
import android.platform.test.annotations.RequiresFlagsDisabled;
|
||||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
@@ -69,6 +74,30 @@ public class ToggleForceInvertPreferenceControllerTest {
|
|||||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_darkModeOn_preferenceEnabled() {
|
||||||
|
Configuration config = mContext.getResources().getConfiguration();
|
||||||
|
config.uiMode = Configuration.UI_MODE_NIGHT_YES;
|
||||||
|
mContext.getResources().updateConfiguration(config, null);
|
||||||
|
|
||||||
|
Preference preference = mock(Preference.class);
|
||||||
|
mController.updateState(preference);
|
||||||
|
|
||||||
|
verify(preference).setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_darkModeOff_preferenceDisabled() {
|
||||||
|
Configuration config = mContext.getResources().getConfiguration();
|
||||||
|
config.uiMode = Configuration.UI_MODE_NIGHT_NO;
|
||||||
|
mContext.getResources().updateConfiguration(config, null);
|
||||||
|
|
||||||
|
Preference preference = mock(Preference.class);
|
||||||
|
mController.updateState(preference);
|
||||||
|
|
||||||
|
verify(preference).setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void settingOff_reflectsCorrectValue() {
|
public void settingOff_reflectsCorrectValue() {
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
|
Reference in New Issue
Block a user