diff --git a/res/values/evolution_strings.xml b/res/values/evolution_strings.xml
index 664a18c1569..83c492a06c7 100644
--- a/res/values/evolution_strings.xml
+++ b/res/values/evolution_strings.xml
@@ -275,9 +275,10 @@
Alarms
steps
-
- Always on display schedule
+
+ Extra dim schedule
Disabled
+ Always on display schedule
Sunset
Sunrise
Turns on from sunset till a time
diff --git a/res/xml/extra_dim_schedule.xml b/res/xml/extra_dim_schedule.xml
new file mode 100644
index 00000000000..4554dfd60bc
--- /dev/null
+++ b/res/xml/extra_dim_schedule.xml
@@ -0,0 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/com/android/settings/accessibility/ExtraDimScheduleFragment.java b/src/com/android/settings/accessibility/ExtraDimScheduleFragment.java
new file mode 100644
index 00000000000..ee9181c35c9
--- /dev/null
+++ b/src/com/android/settings/accessibility/ExtraDimScheduleFragment.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2021 Yet Another AOSP Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.settings.accessibility;
+
+import static com.android.internal.util.evolution.AutoSettingConsts.MODE_DISABLED;
+import static com.android.internal.util.evolution.AutoSettingConsts.MODE_NIGHT;
+import static com.android.internal.util.evolution.AutoSettingConsts.MODE_TIME;
+import static com.android.internal.util.evolution.AutoSettingConsts.MODE_MIXED_SUNSET;
+import static com.android.internal.util.evolution.AutoSettingConsts.MODE_MIXED_SUNRISE;
+
+import android.app.TimePickerDialog;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.os.Bundle;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.text.format.DateFormat;
+import android.widget.TimePicker;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.R;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.search.SearchIndexable;
+
+import org.evolution.settings.preferences.SecureSettingListPreference;
+
+import java.time.format.DateTimeFormatter;
+import java.time.LocalTime;
+
+@SearchIndexable
+public class ExtraDimScheduleFragment extends DashboardFragment implements
+ Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
+
+ private static final String TAG = "ExtraDimScheduleFragment";
+ private static final String MODE_KEY = "extra_dim_auto_mode";
+ private static final String SINCE_PREF_KEY = "extra_dim_auto_since";
+ private static final String TILL_PREF_KEY = "extra_dim_auto_till";
+
+ private SecureSettingListPreference mModePref;
+ private Preference mSincePref;
+ private Preference mTillPref;
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.extra_dim_schedule;
+ }
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ PreferenceScreen screen = getPreferenceScreen();
+ ContentResolver resolver = getActivity().getContentResolver();
+
+ mSincePref = findPreference(SINCE_PREF_KEY);
+ mSincePref.setOnPreferenceClickListener(this);
+ mTillPref = findPreference(TILL_PREF_KEY);
+ mTillPref.setOnPreferenceClickListener(this);
+
+ int mode = Settings.Secure.getIntForUser(resolver,
+ MODE_KEY, MODE_DISABLED, UserHandle.USER_CURRENT);
+ mModePref = findPreference(MODE_KEY);
+ mModePref.setValue(String.valueOf(mode));
+ mModePref.setSummary(mModePref.getEntry());
+ mModePref.setOnPreferenceChangeListener(this);
+
+ updateTimeEnablement(mode);
+ updateTimeSummary(mode);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object objValue) {
+ int value = Integer.parseInt((String) objValue);
+ int index = mModePref.findIndexOfValue((String) objValue);
+ mModePref.setSummary(mModePref.getEntries()[index]);
+ Settings.Secure.putIntForUser(getActivity().getContentResolver(),
+ MODE_KEY, value, UserHandle.USER_CURRENT);
+ updateTimeEnablement(value);
+ updateTimeSummary(value);
+ return true;
+ }
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ String[] times = getCustomTimeSetting();
+ boolean isSince = preference == mSincePref;
+ int hour, minute;
+ TimePickerDialog.OnTimeSetListener listener = (view, hourOfDay, minute1) -> {
+ updateTimeSetting(isSince, hourOfDay, minute1);
+ };
+ if (isSince) {
+ String[] sinceValues = times[0].split(":", 0);
+ hour = Integer.parseInt(sinceValues[0]);
+ minute = Integer.parseInt(sinceValues[1]);
+ } else {
+ String[] tillValues = times[1].split(":", 0);
+ hour = Integer.parseInt(tillValues[0]);
+ minute = Integer.parseInt(tillValues[1]);
+ }
+ TimePickerDialog dialog = new TimePickerDialog(getContext(), listener,
+ hour, minute, DateFormat.is24HourFormat(getContext()));
+ dialog.show();
+ return true;
+ }
+
+ private String[] getCustomTimeSetting() {
+ String value = Settings.Secure.getStringForUser(getActivity().getContentResolver(),
+ Settings.Secure.EXTRA_DIM_AUTO_TIME, UserHandle.USER_CURRENT);
+ if (value == null || value.equals("")) value = "20:00,07:00";
+ return value.split(",", 0);
+ }
+
+ private void updateTimeEnablement(int mode) {
+ mSincePref.setEnabled(mode == MODE_TIME || mode == MODE_MIXED_SUNRISE);
+ mTillPref.setEnabled(mode == MODE_TIME || mode == MODE_MIXED_SUNSET);
+ }
+
+ private void updateTimeSummary(int mode) {
+ updateTimeSummary(getCustomTimeSetting(), mode);
+ }
+
+ private void updateTimeSummary(String[] times, int mode) {
+ if (mode == MODE_DISABLED) {
+ mSincePref.setSummary("-");
+ mTillPref.setSummary("-");
+ return;
+ }
+
+ if (mode == MODE_NIGHT) {
+ mSincePref.setSummary(R.string.always_on_display_schedule_sunset);
+ mTillPref.setSummary(R.string.always_on_display_schedule_sunrise);
+ return;
+ }
+
+ String outputFormat = DateFormat.is24HourFormat(getContext()) ? "HH:mm" : "hh:mm a";
+ DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormat);
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
+ LocalTime sinceDT = LocalTime.parse(times[0], formatter);
+ LocalTime tillDT = LocalTime.parse(times[1], formatter);
+
+ if (mode == MODE_MIXED_SUNSET) {
+ mSincePref.setSummary(R.string.always_on_display_schedule_sunset);
+ mTillPref.setSummary(tillDT.format(outputFormatter));
+ } else if (mode == MODE_MIXED_SUNRISE) {
+ mTillPref.setSummary(R.string.always_on_display_schedule_sunrise);
+ mSincePref.setSummary(sinceDT.format(outputFormatter));
+ } else {
+ mSincePref.setSummary(sinceDT.format(outputFormatter));
+ mTillPref.setSummary(tillDT.format(outputFormatter));
+ }
+ }
+
+ private void updateTimeSetting(boolean since, int hour, int minute) {
+ String[] times = getCustomTimeSetting();
+ String nHour = "";
+ String nMinute = "";
+ if (hour < 10) nHour += "0";
+ if (minute < 10) nMinute += "0";
+ nHour += String.valueOf(hour);
+ nMinute += String.valueOf(minute);
+ times[since ? 0 : 1] = nHour + ":" + nMinute;
+ Settings.Secure.putStringForUser(getActivity().getContentResolver(),
+ Settings.Secure.EXTRA_DIM_AUTO_TIME,
+ times[0] + "," + times[1], UserHandle.USER_CURRENT);
+ updateTimeSummary(times, Integer.parseInt(mModePref.getValue()));
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsProto.MetricsEvent.EVOLVER;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider(R.xml.extra_dim_schedule);
+}
diff --git a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
index dc63828da3e..40c86973015 100644
--- a/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java
@@ -18,6 +18,11 @@ package com.android.settings.accessibility;
import static com.android.internal.accessibility.AccessibilityShortcutController.REDUCE_BRIGHT_COLORS_COMPONENT_NAME;
import static com.android.internal.accessibility.AccessibilityShortcutController.REDUCE_BRIGHT_COLORS_TILE_SERVICE_COMPONENT_NAME;
+import static com.android.internal.util.evolution.AutoSettingConsts.MODE_DISABLED;
+import static com.android.internal.util.evolution.AutoSettingConsts.MODE_NIGHT;
+import static com.android.internal.util.evolution.AutoSettingConsts.MODE_TIME;
+import static com.android.internal.util.evolution.AutoSettingConsts.MODE_MIXED_SUNSET;
+import static com.android.internal.util.evolution.AutoSettingConsts.MODE_MIXED_SUNRISE;
import static com.android.settings.accessibility.AccessibilityStatsLogUtils.logAccessibilityServiceEnabled;
import android.app.settings.SettingsEnums;
@@ -27,12 +32,14 @@ import android.content.Context;
import android.hardware.display.ColorDisplayManager;
import android.net.Uri;
import android.os.Bundle;
+import android.os.UserHandle;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.TwoStatePreference;
@@ -59,10 +66,12 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
static final String KEY_SWITCH = "rbc_switch";
private static final String REDUCE_BRIGHT_COLORS_ACTIVATED_KEY =
Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED;
+ private static final String KEY_SCHEDULE = "extra_dim_schedule";
private ReduceBrightColorsIntensityPreferenceController mRbcIntensityPreferenceController;
private ReduceBrightColorsPersistencePreferenceController mRbcPersistencePreferenceController;
private ColorDisplayManager mColorDisplayManager;
+ private Preference mSchedulePref;
@Override
protected void registerKeysToObserverCallback(
@@ -96,8 +105,16 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
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);
+
+ mSchedulePref = new Preference(getPrefContext());
+ mSchedulePref.setKey(KEY_SCHEDULE);
+ mSchedulePref.setTitle(getText(R.string.extra_dim_schedule_title));
+ mSchedulePref.setFragment("com.android.settings.accessibility.ExtraDimScheduleFragment");
+
+ getPreferenceScreen().addPreference(mTopIntroPreference);
updateGeneralCategoryOrder();
updateFooterPreference();
+ updateSchedulePreference();
return view;
}
@@ -111,6 +128,7 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
getPreferenceScreen().removePreference(persist);
persist.setOrder(mShortcutPreference.getOrder() - 1);
generalCategory.addPreference(persist);
+ generalCategory.addPreference(mSchedulePref);
}
private void updateFooterPreference() {
@@ -119,10 +137,29 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
mFooterPreferenceController.displayPreference(getPreferenceScreen());
}
+ private void updateSchedulePreference() {
+ if (mSchedulePref == null) return;
+ int mode = Settings.Secure.getIntForUser(getActivity().getContentResolver(),
+ Settings.Secure.EXTRA_DIM_AUTO_MODE, 0, UserHandle.USER_CURRENT);
+ switch (mode) {
+ default:
+ case MODE_DISABLED:
+ mSchedulePref.setSummary(R.string.string_disabled);
+ break;
+ case MODE_NIGHT:
+ mSchedulePref.setSummary(R.string.night_display_auto_mode_twilight);
+ break;
+ case MODE_TIME:
+ mSchedulePref.setSummary(R.string.night_display_auto_mode_custom);
+ break;
+ }
+ }
+
@Override
public void onResume() {
super.onResume();
updateSwitchBarToggleSwitch();
+ updateSchedulePreference();
}
@Override