Loading res/values/arrays.xml +10 −0 Original line number Diff line number Diff line Loading @@ -1067,6 +1067,16 @@ <item>while_docked</item> </string-array> <string-array name="low_light_display_behavior_entries" translatable="false"> <item>@string/low_light_display_behavior_screen_off</item> <item>@string/low_light_display_behavior_low_light_clock_dream</item> </string-array> <string-array name="low_light_display_behavior_values" translatable="false"> <item>low_light_display_behavior_screen_off</item> <item>low_light_display_behavior_low_light_clock_dream</item> </string-array> <string-array name="zen_mode_contacts_calls_entries" translatable="false"> <item>@string/zen_mode_from_anyone</item> <item>@string/zen_mode_from_contacts</item> Loading res/values/strings.xml +21 −0 Original line number Diff line number Diff line Loading @@ -3329,11 +3329,32 @@ <string name="screensaver_settings_summary_off">Off</string> <!-- Dream settings screen, action label, when to dream [CHAR LIMIT=20] --> <string name="screensaver_settings_when_to_dream">When to show</string> <!-- Dream settings screen, action label, what to show in low light [CHAR LIMIT=30] --> <string name="screensaver_settings_low_light_mode">Low light mode</string> <!-- [CHAR LIMIT=40] Display settings screen, setting option name to change whether the device wakes up when a lift gesture is detected. --> <string name="lift_to_wake_title">Lift to wake</string> <!-- Title of toggle preference in screensaver "when to start" screen to restrict to starting only when charging wirelessly [CHAR LIMIT=NONE] --> <string name="screensaver_restrict_to_wireless_charging_title">Restrict to wireless charging</string> <!-- Title for the main switch to enable or disable the low light display behavior. [CHAR LIMIT=NONE] --> <string name="low_light_display_behavior_main_switch_title">Use Low Light mode</string> <!-- Category title for the settings to control what to show when in low light. [CHAR LIMIT=NONE] --> <string name="low_light_display_behavior_subtitle">Choose what to show in Low Light mode</string> <!-- Low light display behavior: turn the screen off [CHAR LIMIT=50] --> <string name="low_light_display_behavior_screen_off">Screen off</string> <!-- Low light display behavior: show the low light clock [CHAR LIMIT=50] --> <string name="low_light_display_behavior_low_light_clock_dream">Low light clock</string> <!-- Summary for low light display behavior summary when low light display is enabled [CHAR LIMIT=50] --> <string name="low_light_display_behavior_summary_on"> On / <xliff:g id="low_light_mode" example="Screen off">%1$s</xliff:g> </string> <!-- Summary for low light display behavior summary when low light display is disabled [CHAR LIMIT=20] --> <string name="low_light_display_behavior_summary_off">Off</string> <!-- Low light display behavior: full summary for turn the screen off [CHAR LIMIT=NONE] --> <string name="low_light_display_behavior_screen_off_full_summary">Screen will turn off when your environment is dark</string> <!-- Low light display behavior: full summary for show the low light clock [CHAR LIMIT=NONE] --> <string name="low_light_display_behavior_low_light_clock_dream_full_summary">Low Light Clock will show when your environment is dark</string> <!-- [CHAR LIMIT=30] Title of the preference that opens the Ambient display settings screen. --> <string name="ambient_display_screen_title">Ambient display</string> res/xml/dream_fragment_overview.xml +7 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,13 @@ android:summary="@string/dream_complications_toggle_summary" settings:controller="com.android.settings.dream.DreamComplicationPreferenceController"/> <com.android.settingslib.PrimarySwitchPreference android:key="low_light_mode" android:order="350" android:title="@string/screensaver_settings_low_light_mode" android:fragment="com.android.settings.dream.LowLightModePicker" settings:controller="com.android.settings.dream.LowLightModePreferenceController" /> <SwitchPreferenceCompat android:key="dream_home_controls_toggle" android:order="400" Loading res/xml/low_light_mode_settings.xml 0 → 100644 +20 −0 Original line number Diff line number Diff line <!-- ~ Copyright (C) 2025 The Android Open Source 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/screensaver_settings_low_light_mode"> </PreferenceScreen> src/com/android/settings/dream/LowLightModePicker.java 0 → 100644 +196 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source 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.dream; import android.content.Context; import android.graphics.drawable.Drawable; import android.provider.Settings; import androidx.annotation.Nullable; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceScreen; import com.android.internal.util.ArrayUtils; import com.android.settings.R; import com.android.settings.widget.RadioButtonPickerFragment; import com.android.settingslib.dream.DreamBackend; import com.android.settingslib.widget.CandidateInfo; import com.android.settingslib.widget.MainSwitchPreference; import java.util.ArrayList; import java.util.List; public class LowLightModePicker extends RadioButtonPickerFragment implements Preference.OnPreferenceChangeListener { static final String LOW_LIGHT_DISPLAY_BEHAVIOR_NONE = "low_light_display_behavior_none"; static final String LOW_LIGHT_DISPLAY_BEHAVIOR_SCREEN_OFF = "low_light_display_behavior_screen_off"; static final String LOW_LIGHT_DISPLAY_BEHAVIOR_LOW_LIGHT_CLOCK_DREAM = "low_light_display_behavior_low_light_clock_dream"; static final String LOW_LIGHT_DISPLAY_BEHAVIOR_NO_DREAM = "low_light_display_behavior_no_dream"; private Context mContext; private DreamBackend mBackend; @Nullable private MainSwitchPreference mMainSwitch; @Settings.Secure.LowLightDisplayBehavior static int getSettingFromPrefKey(String key) { switch (key) { case LOW_LIGHT_DISPLAY_BEHAVIOR_SCREEN_OFF: return Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_SCREEN_OFF; case LOW_LIGHT_DISPLAY_BEHAVIOR_LOW_LIGHT_CLOCK_DREAM: return Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_LOW_LIGHT_CLOCK_DREAM; case LOW_LIGHT_DISPLAY_BEHAVIOR_NO_DREAM: return Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_NO_DREAM; case LOW_LIGHT_DISPLAY_BEHAVIOR_NONE: default: return Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_NONE; } } static String getKeyFromSetting(@Settings.Secure.LowLightDisplayBehavior int setting) { switch (setting) { case Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_SCREEN_OFF: return LOW_LIGHT_DISPLAY_BEHAVIOR_SCREEN_OFF; case Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_LOW_LIGHT_CLOCK_DREAM: return LOW_LIGHT_DISPLAY_BEHAVIOR_LOW_LIGHT_CLOCK_DREAM; case Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_NO_DREAM: return LOW_LIGHT_DISPLAY_BEHAVIOR_NO_DREAM; case Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_NONE: default: return LOW_LIGHT_DISPLAY_BEHAVIOR_NONE; } } @Override public void onAttach(Context context) { super.onAttach(context); mContext = context; mBackend = DreamBackend.getInstance(context); } @Override public int getMetricsCategory() { return 0; } @Override protected int getPreferenceScreenResId() { return R.xml.low_light_mode_settings; } @Override protected String getDefaultKey() { return getKeyFromSetting(mBackend.getLowLightDisplayBehavior()); } @Override protected boolean setDefaultKey(String key) { mBackend.setLowLightDisplayBehavior(getSettingFromPrefKey(key)); return true; } @Override protected void addStaticPreferences(PreferenceScreen screen) { mMainSwitch = new MainSwitchPreference(mContext); mMainSwitch.setTitle(R.string.low_light_display_behavior_main_switch_title); mMainSwitch.setChecked(mBackend.getLowLightDisplayBehaviorEnabled()); mMainSwitch.setOnPreferenceChangeListener(this); screen.addPreference(mMainSwitch); final Preference category = new PreferenceCategory(mContext); category.setTitle(R.string.low_light_display_behavior_subtitle); screen.addPreference(category); } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference == mMainSwitch) { mBackend.setLowLightDisplayBehaviorEnabled((boolean) newValue); updateCandidates(); return true; } return false; } @Override protected void onSelectionPerformed(boolean success) { super.onSelectionPerformed(success); getActivity().finish(); } private String[] entries() { return getResources().getStringArray(R.array.low_light_display_behavior_entries); } private String[] keys() { return getResources().getStringArray(R.array.low_light_display_behavior_values); } @Override protected List<? extends CandidateInfo> getCandidates() { final String[] entries = entries(); final String[] values = keys(); final List<LowLightModeCandidateInfo> candidates = new ArrayList<>(); if (ArrayUtils.isEmpty(entries)) return candidates; if (ArrayUtils.size(values) != ArrayUtils.size(entries)) { throw new IllegalArgumentException("Entries and values must be of the same length."); } final boolean enabled = mBackend.getLowLightDisplayBehaviorEnabled(); for (int i = 0; i < entries.length; i++) { candidates.add(new LowLightModeCandidateInfo(entries[i], values[i], enabled)); } return candidates; } private static final class LowLightModeCandidateInfo extends CandidateInfo { private final String mName; private final String mKey; LowLightModeCandidateInfo(String title, String value, boolean enabled) { super(enabled); mName = title; mKey = value; } @Override public CharSequence loadLabel() { return mName; } @Nullable @Override public Drawable loadIcon() { return null; } @Override public String getKey() { return mKey; } } } Loading
res/values/arrays.xml +10 −0 Original line number Diff line number Diff line Loading @@ -1067,6 +1067,16 @@ <item>while_docked</item> </string-array> <string-array name="low_light_display_behavior_entries" translatable="false"> <item>@string/low_light_display_behavior_screen_off</item> <item>@string/low_light_display_behavior_low_light_clock_dream</item> </string-array> <string-array name="low_light_display_behavior_values" translatable="false"> <item>low_light_display_behavior_screen_off</item> <item>low_light_display_behavior_low_light_clock_dream</item> </string-array> <string-array name="zen_mode_contacts_calls_entries" translatable="false"> <item>@string/zen_mode_from_anyone</item> <item>@string/zen_mode_from_contacts</item> Loading
res/values/strings.xml +21 −0 Original line number Diff line number Diff line Loading @@ -3329,11 +3329,32 @@ <string name="screensaver_settings_summary_off">Off</string> <!-- Dream settings screen, action label, when to dream [CHAR LIMIT=20] --> <string name="screensaver_settings_when_to_dream">When to show</string> <!-- Dream settings screen, action label, what to show in low light [CHAR LIMIT=30] --> <string name="screensaver_settings_low_light_mode">Low light mode</string> <!-- [CHAR LIMIT=40] Display settings screen, setting option name to change whether the device wakes up when a lift gesture is detected. --> <string name="lift_to_wake_title">Lift to wake</string> <!-- Title of toggle preference in screensaver "when to start" screen to restrict to starting only when charging wirelessly [CHAR LIMIT=NONE] --> <string name="screensaver_restrict_to_wireless_charging_title">Restrict to wireless charging</string> <!-- Title for the main switch to enable or disable the low light display behavior. [CHAR LIMIT=NONE] --> <string name="low_light_display_behavior_main_switch_title">Use Low Light mode</string> <!-- Category title for the settings to control what to show when in low light. [CHAR LIMIT=NONE] --> <string name="low_light_display_behavior_subtitle">Choose what to show in Low Light mode</string> <!-- Low light display behavior: turn the screen off [CHAR LIMIT=50] --> <string name="low_light_display_behavior_screen_off">Screen off</string> <!-- Low light display behavior: show the low light clock [CHAR LIMIT=50] --> <string name="low_light_display_behavior_low_light_clock_dream">Low light clock</string> <!-- Summary for low light display behavior summary when low light display is enabled [CHAR LIMIT=50] --> <string name="low_light_display_behavior_summary_on"> On / <xliff:g id="low_light_mode" example="Screen off">%1$s</xliff:g> </string> <!-- Summary for low light display behavior summary when low light display is disabled [CHAR LIMIT=20] --> <string name="low_light_display_behavior_summary_off">Off</string> <!-- Low light display behavior: full summary for turn the screen off [CHAR LIMIT=NONE] --> <string name="low_light_display_behavior_screen_off_full_summary">Screen will turn off when your environment is dark</string> <!-- Low light display behavior: full summary for show the low light clock [CHAR LIMIT=NONE] --> <string name="low_light_display_behavior_low_light_clock_dream_full_summary">Low Light Clock will show when your environment is dark</string> <!-- [CHAR LIMIT=30] Title of the preference that opens the Ambient display settings screen. --> <string name="ambient_display_screen_title">Ambient display</string>
res/xml/dream_fragment_overview.xml +7 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,13 @@ android:summary="@string/dream_complications_toggle_summary" settings:controller="com.android.settings.dream.DreamComplicationPreferenceController"/> <com.android.settingslib.PrimarySwitchPreference android:key="low_light_mode" android:order="350" android:title="@string/screensaver_settings_low_light_mode" android:fragment="com.android.settings.dream.LowLightModePicker" settings:controller="com.android.settings.dream.LowLightModePreferenceController" /> <SwitchPreferenceCompat android:key="dream_home_controls_toggle" android:order="400" Loading
res/xml/low_light_mode_settings.xml 0 → 100644 +20 −0 Original line number Diff line number Diff line <!-- ~ Copyright (C) 2025 The Android Open Source 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. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/screensaver_settings_low_light_mode"> </PreferenceScreen>
src/com/android/settings/dream/LowLightModePicker.java 0 → 100644 +196 −0 Original line number Diff line number Diff line /* * Copyright (C) 2025 The Android Open Source 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.dream; import android.content.Context; import android.graphics.drawable.Drawable; import android.provider.Settings; import androidx.annotation.Nullable; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceScreen; import com.android.internal.util.ArrayUtils; import com.android.settings.R; import com.android.settings.widget.RadioButtonPickerFragment; import com.android.settingslib.dream.DreamBackend; import com.android.settingslib.widget.CandidateInfo; import com.android.settingslib.widget.MainSwitchPreference; import java.util.ArrayList; import java.util.List; public class LowLightModePicker extends RadioButtonPickerFragment implements Preference.OnPreferenceChangeListener { static final String LOW_LIGHT_DISPLAY_BEHAVIOR_NONE = "low_light_display_behavior_none"; static final String LOW_LIGHT_DISPLAY_BEHAVIOR_SCREEN_OFF = "low_light_display_behavior_screen_off"; static final String LOW_LIGHT_DISPLAY_BEHAVIOR_LOW_LIGHT_CLOCK_DREAM = "low_light_display_behavior_low_light_clock_dream"; static final String LOW_LIGHT_DISPLAY_BEHAVIOR_NO_DREAM = "low_light_display_behavior_no_dream"; private Context mContext; private DreamBackend mBackend; @Nullable private MainSwitchPreference mMainSwitch; @Settings.Secure.LowLightDisplayBehavior static int getSettingFromPrefKey(String key) { switch (key) { case LOW_LIGHT_DISPLAY_BEHAVIOR_SCREEN_OFF: return Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_SCREEN_OFF; case LOW_LIGHT_DISPLAY_BEHAVIOR_LOW_LIGHT_CLOCK_DREAM: return Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_LOW_LIGHT_CLOCK_DREAM; case LOW_LIGHT_DISPLAY_BEHAVIOR_NO_DREAM: return Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_NO_DREAM; case LOW_LIGHT_DISPLAY_BEHAVIOR_NONE: default: return Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_NONE; } } static String getKeyFromSetting(@Settings.Secure.LowLightDisplayBehavior int setting) { switch (setting) { case Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_SCREEN_OFF: return LOW_LIGHT_DISPLAY_BEHAVIOR_SCREEN_OFF; case Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_LOW_LIGHT_CLOCK_DREAM: return LOW_LIGHT_DISPLAY_BEHAVIOR_LOW_LIGHT_CLOCK_DREAM; case Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_NO_DREAM: return LOW_LIGHT_DISPLAY_BEHAVIOR_NO_DREAM; case Settings.Secure.LOW_LIGHT_DISPLAY_BEHAVIOR_NONE: default: return LOW_LIGHT_DISPLAY_BEHAVIOR_NONE; } } @Override public void onAttach(Context context) { super.onAttach(context); mContext = context; mBackend = DreamBackend.getInstance(context); } @Override public int getMetricsCategory() { return 0; } @Override protected int getPreferenceScreenResId() { return R.xml.low_light_mode_settings; } @Override protected String getDefaultKey() { return getKeyFromSetting(mBackend.getLowLightDisplayBehavior()); } @Override protected boolean setDefaultKey(String key) { mBackend.setLowLightDisplayBehavior(getSettingFromPrefKey(key)); return true; } @Override protected void addStaticPreferences(PreferenceScreen screen) { mMainSwitch = new MainSwitchPreference(mContext); mMainSwitch.setTitle(R.string.low_light_display_behavior_main_switch_title); mMainSwitch.setChecked(mBackend.getLowLightDisplayBehaviorEnabled()); mMainSwitch.setOnPreferenceChangeListener(this); screen.addPreference(mMainSwitch); final Preference category = new PreferenceCategory(mContext); category.setTitle(R.string.low_light_display_behavior_subtitle); screen.addPreference(category); } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (preference == mMainSwitch) { mBackend.setLowLightDisplayBehaviorEnabled((boolean) newValue); updateCandidates(); return true; } return false; } @Override protected void onSelectionPerformed(boolean success) { super.onSelectionPerformed(success); getActivity().finish(); } private String[] entries() { return getResources().getStringArray(R.array.low_light_display_behavior_entries); } private String[] keys() { return getResources().getStringArray(R.array.low_light_display_behavior_values); } @Override protected List<? extends CandidateInfo> getCandidates() { final String[] entries = entries(); final String[] values = keys(); final List<LowLightModeCandidateInfo> candidates = new ArrayList<>(); if (ArrayUtils.isEmpty(entries)) return candidates; if (ArrayUtils.size(values) != ArrayUtils.size(entries)) { throw new IllegalArgumentException("Entries and values must be of the same length."); } final boolean enabled = mBackend.getLowLightDisplayBehaviorEnabled(); for (int i = 0; i < entries.length; i++) { candidates.add(new LowLightModeCandidateInfo(entries[i], values[i], enabled)); } return candidates; } private static final class LowLightModeCandidateInfo extends CandidateInfo { private final String mName; private final String mKey; LowLightModeCandidateInfo(String title, String value, boolean enabled) { super(enabled); mName = title; mKey = value; } @Override public CharSequence loadLabel() { return mName; } @Nullable @Override public Drawable loadIcon() { return null; } @Override public String getKey() { return mKey; } } }