Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0ae266c6 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add dark theme custom type into the dark theme settings page"

parents 3774ff68 3859251b
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -110,6 +110,18 @@
        <item>@string/dark_ui_auto_mode_auto</item>
    </string-array>

    <!-- Dark theme scheduling preferences  [CHAR LIMIT=NONE] -->
    <string-array name="dark_ui_scheduler_with_bedtime_preference_titles">
        <!-- 0: None -->
        <item>@string/dark_ui_auto_mode_never</item>
        <!-- 1: Custom -->
        <item>@string/dark_ui_auto_mode_custom</item>
        <!-- 2: Auto -->
        <item>@string/dark_ui_auto_mode_auto</item>
        <!-- 3: Bedtime -->
        <item>@string/dark_ui_auto_mode_custom_bedtime</item>
    </string-array>

    <!-- Security settings.  The delay after screen is turned off until device locks.
         These are shown in a list dialog. -->
    <string-array name="lock_after_timeout_entries">
+11 −0
Original line number Diff line number Diff line
@@ -3077,6 +3077,8 @@
    <string name="dark_ui_auto_mode_auto">Turns on from sunset to sunrise</string>
    <!-- Dark UI screen, setting option value for Dark theme to turn on/off automatically according to a user defined schedule. [CHAR LIMIT=32] -->
    <string name="dark_ui_auto_mode_custom">Turns on at custom time</string>
    <!-- Dark UI screen, setting option value for Dark theme to turn on/off automatically according to a user bedtime schedule. [CHAR LIMIT=40] -->
    <string name="dark_ui_auto_mode_custom_bedtime">Turns on at bedtime</string>
    <!-- Dark UI screen, setting option name controlling the current activation status. [CHAR LIMIT=30] -->
    <string name="dark_ui_status_title">Status</string>
    <!-- Display settings screen, summary of Dark UI when off and will *never* turn on automatically. [CHAR LIMIT=NONE] -->
@@ -3085,18 +3087,27 @@
    <string name="dark_ui_summary_off_auto_mode_auto">Will turn on automatically at sunset</string>
        <!-- Display settings screen, summary format of night display when off and will turn on automatically at a user defined time. [CHAR LIMIT=NONE] -->
    <string name="dark_ui_summary_off_auto_mode_custom">Will turn on automatically at <xliff:g name="time" example="6 AM">%1$s</xliff:g></string>
    <!-- Display settings screen, summary of Dark UI when off and will turn on automatically at bedtime. [CHAR LIMIT=NONE] -->
    <string name="dark_ui_summary_off_auto_mode_custom_bedtime">Will turn on automatically at bedtime</string>
    <!-- Display settings screen, summary of Dark UI when on and will *never* turn off automatically. [CHAR LIMIT=NONE] -->
    <string name="dark_ui_summary_on_auto_mode_never">Will never turn off automatically</string>
    <!-- Display settings screen, summary of Dark UI when on and will turn off automatically at sunrise. [CHAR LIMIT=NONE] -->
    <string name="dark_ui_summary_on_auto_mode_auto">Will turn off automatically at sunrise</string>
    <!-- Display settings screen, summary format of night display when on and will turn off automatically at a user defined time. [CHAR LIMIT=NONE] -->
    <string name="dark_ui_summary_on_auto_mode_custom">Will turn off automatically at <xliff:g name="time" example="10 PM">%1$s</xliff:g></string>
    <!-- Display settings screen, summary of Dark UI when on and will turn off automatically after bedtime. [CHAR LIMIT=NONE] -->
    <string name="dark_ui_summary_on_auto_mode_custom_bedtime">Will turn off automatically after bedtime</string>
    <!-- Display settings screen, activation button action for custom schedule [CHAR LIMIT=40] -->
    <string name="dark_ui_activation_on_custom">Turn on until <xliff:g name="time" example="6 AM">%1$s</xliff:g></string>
    <!-- Display settings screen, deactivation button action for custom schedule [CHAR LIMIT=40] -->
    <string name="dark_ui_activation_off_custom">Turn off until <xliff:g name="time" example="10 PM">%1$s</xliff:g></string>
    <!-- Dark theme screen, description of Dark theme feature. [CHAR LIMIT=NONE] -->
    <string name="dark_ui_text">Dark theme uses a black background to help keep battery alive longer on some screens. Dark theme schedules wait to turn on until your screen is off.</string>
    <!-- Dark UI screen footer summary text shown when the when Dark theme turns on/off automatically according to a user bedtime schedule. [CHAR LIMIT=NONE] -->
    <string name="dark_ui_bedtime_footer_summary">Dark theme is currently following your Bedtime mode schedule</string>
    <!-- Dark UI screen footer action text shown when the when Dark theme turns on/off automatically according to a user bedtime schedule. [CHAR LIMIT=NONE] -->
    <string name="dark_ui_bedtime_footer_action">Bedtime mode settings</string>
    <!-- Sound & display settings screen, setting option name to change screen timeout -->
    <string name="screen_timeout">Screen timeout</string>
+7 −0
Original line number Diff line number Diff line
@@ -55,4 +55,11 @@
        android:title="@string/night_display_end_time_title"
        settings:searchable="false"/>

    <com.android.settingslib.widget.FooterPreference
        android:key="dark_theme_custom_bedtime_footer"
        android:title="@string/dark_ui_bedtime_footer_summary"
        android:selectable="false"
        settings:searchable="false"
        settings:controller="com.android.settings.display.darkmode.DarkModeCustomBedtimePreferenceController" />

</PreferenceScreen>
+60 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.display.darkmode;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

/** Manages Digital Wellbeing bedtime settings' intents. */
public final class BedtimeSettings {
    @VisibleForTesting
    public static final String ACTION_BEDTIME_SETTINGS = "android.settings.BEDTIME_SETTINGS";

    private final Context mContext;
    private final PackageManager mPackageManager;
    private final String mWellbeingPackage;

    public BedtimeSettings(Context context) {
        mContext = context;
        mPackageManager = context.getPackageManager();
        mWellbeingPackage = mContext.getResources().getString(
                com.android.internal.R.string.config_defaultWellbeingPackage);
    }

    /**
     * Returns the bedtime settings intent. If the bedtime settings isn't available, returns
     * {@code null}.
     */
    @Nullable
    public Intent getBedtimeSettingsIntent() {
        Intent bedtimeSettingsIntent = new Intent(ACTION_BEDTIME_SETTINGS).setPackage(
                mWellbeingPackage);
        ResolveInfo bedtimeSettingInfo = mPackageManager.resolveActivity(bedtimeSettingsIntent,
                PackageManager.MATCH_DEFAULT_ONLY);

        if (bedtimeSettingInfo != null && bedtimeSettingInfo.activityInfo.isEnabled()) {
            return bedtimeSettingsIntent;
        } else {
            return null;
        }
    }
}
+7 −3
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.settings.display.darkmode;
import android.app.UiModeManager;
import android.content.Context;
import android.content.res.Configuration;
import android.os.PowerManager;
import android.widget.Switch;

import androidx.preference.Preference;
@@ -41,13 +40,11 @@ public class DarkModeActivationPreferenceController extends BasePreferenceContro

    private final UiModeManager mUiModeManager;
    private final MetricsFeatureProvider mMetricsFeatureProvider;
    private PowerManager mPowerManager;
    private TimeFormatter mFormat;
    private MainSwitchPreference mPreference;

    public DarkModeActivationPreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);
        mPowerManager = context.getSystemService(PowerManager.class);
        mUiModeManager = context.getSystemService(UiModeManager.class);
        mFormat = new TimeFormatter(context);
        mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
@@ -76,6 +73,13 @@ public class DarkModeActivationPreferenceController extends BasePreferenceContro
                    ? R.string.dark_ui_summary_on_auto_mode_auto
                    : R.string.dark_ui_summary_off_auto_mode_auto);
        } else if (mode == UiModeManager.MODE_NIGHT_CUSTOM) {
            if (mUiModeManager.getNightModeCustomType()
                    == UiModeManager.MODE_NIGHT_CUSTOM_TYPE_BEDTIME) {
                return mContext.getString(isActivated
                        ? R.string.dark_ui_summary_on_auto_mode_custom_bedtime
                        : R.string.dark_ui_summary_off_auto_mode_custom_bedtime);
            }

            final LocalTime time = isActivated
                    ? mUiModeManager.getCustomNightModeEnd()
                    : mUiModeManager.getCustomNightModeStart();
Loading