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

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

Merge "Added footers to zen mode settings"

parents 82789a1f b7b74226
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:gravity="bottom"
    android:paddingTop="4dp"
    android:paddingStart="72dp"
    android:paddingEnd="72dp"
    android:layout_width="match_parent"
+13 −7
Original line number Diff line number Diff line
@@ -6775,19 +6775,16 @@
    <string name="zen_mode_button_turn_off">TURN OFF NOW</string>
    <!-- [CHAR LIMIT=110] Zen mode settings footer: Footer showing end time of DND -->
    <string name="zen_mode_settings_dnd_manual_end_time_next_day">Do Not Disturb is on until <xliff:g id="formatted_time" example="7:00 AM">%s</xliff:g></string>
    <string name="zen_mode_settings_dnd_manual_end_time">Do Not Disturb is on until <xliff:g id="formatted_time" example="7:00 AM">%s</xliff:g></string>
    <!-- [CHAR LIMIT=110] Zen mode settings footer: Footer showing length of DND -->
    <string name="zen_mode_settings_dnd_manual_indefinite">Do Not Disturb will stay on until you turn it off.</string>
    <string name="zen_mode_settings_dnd_manual_indefinite">Do Not Disturb will stay on until you turn it off</string>
    <!-- [CHAR LIMIT=110] Zen mode settings footer: Footer showing how DND was triggered by an automatic DND rule -->
    <string name="zen_mode_settings_dnd_automatic_rule">Do Not Disturb was automatically turned on by a rule <xliff:g id="rule_name" example="Weeknights">%s</xliff:g></string>
    <string name="zen_mode_settings_dnd_automatic_rule">Do Not Disturb was automatically turned on by a rule (<xliff:g id="rule_name" example="Weeknights">%s</xliff:g>)</string>
    <!-- [CHAR LIMIT=110] Zen mode settings footer: Footer how DND was triggered by an app -->
    <string name="zen_mode_settings_dnd_automatic_rule_app">Do Not Disturb was automatically turned on by an app <xliff:g id="app_name" example="Pixel Services">%s</xliff:g></string>
    <!-- [CHAR LIMIT=110] Zen mode settings footer: Footer how DND was triggered by multiple rules and/or apps -->
    <string name="zen_mode_settings_dnd_automatic_rule_multiple">Do Not Disturb was automatically turned on by a rule or app</string>
    <string name="zen_mode_settings_dnd_automatic_rule_app">Do Not Disturb was automatically turned on by an app (<xliff:g id="app_name" example="Android Services">%s</xliff:g>)</string>
    <!-- Work Sounds: Work sound settings section header.  [CHAR LIMIT=50] -->
    <string name="sound_work_settings">Work profile sounds</string>
@@ -7205,6 +7202,15 @@
    <!-- [CHAR LIMIT=40] Zen mode settings: Configure external rule -->
    <string name="zen_mode_configure_rule">Configure rule</string>
    <!-- [CHAR LIMIT=NONE] Zen mode behavior settings footer: footer describing why the user cannot change the current do not disturb behavior settings -->
    <string name="zen_mode_app_set_behavior">These settings can\'t be changed right now. An app (<xliff:g id="app_name" example="Android Services">%1$s</xliff:g>) has automatically turned on Do Not Disturb with custom behavior."</string>
    <!-- [CHAR LIMIT=NONE] Zen mode behavior settings footer: footer describing why the user cannot change the current do not disturb behavior settings -->
    <string name="zen_mode_unknown_app_set_behavior">These settings can\'t be changed right now. An app has automatically turned on Do Not Disturb with custom behavior."</string>
    <!-- [CHAR LIMIT=NONE] Zen mode behavior settings footer: footer describing why the user cannot change the current do not disturb behavior settings -->
    <string name="zen_mode_qs_set_behavior">These settings can\'t be changed right now. Do Not Disturb was manually turned on with custom behavior."</string>
    <!-- [CHAR LIMIT=40] Zen mode settings: Schedule rule type name -->
    <string name="zen_schedule_rule_type_name">Time</string>
+2 −1
Original line number Diff line number Diff line
@@ -75,7 +75,8 @@
        <SwitchPreference android:key="zen_mode_screen_off"
                          android:title="@string/zen_mode_screen_off"
                          android:summary="@string/zen_mode_screen_off_summary" />

    </PreferenceCategory>

    <com.android.settingslib.widget.FooterPreference/>

</PreferenceScreen>
+4 −0
Original line number Diff line number Diff line
@@ -41,4 +41,8 @@
            android:layout="@layout/zen_mode_settings_button" />
    </PreferenceCategory>

    <PreferenceCategory>
        <com.android.settingslib.widget.FooterPreference/>
    </PreferenceCategory>

</PreferenceScreen>
+78 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

package com.android.settings.notification;

import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.AlarmManager.AlarmClockInfo;
import android.app.NotificationManager;
import android.content.ContentResolver;
import android.content.Context;
@@ -24,8 +27,11 @@ import android.net.Uri;
import android.os.Handler;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.ScheduleCalendar;
import android.service.notification.ZenModeConfig;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.core.PreferenceControllerMixin;
@@ -41,12 +47,15 @@ abstract public class AbstractZenModePreferenceController extends

    @VisibleForTesting
    protected SettingObserver mSettingObserver;

    private final String KEY;
    final private NotificationManager mNotificationManager;
    protected static ZenModeConfigWrapper mZenModeConfigWrapper;

    public AbstractZenModePreferenceController(Context context, String key,
            Lifecycle lifecycle) {
        super(context);
        mZenModeConfigWrapper = new ZenModeConfigWrapper(context);
        if (lifecycle != null) {
            lifecycle.addObserver(this);
        }
@@ -79,6 +88,10 @@ abstract public class AbstractZenModePreferenceController extends
        return mNotificationManager.getNotificationPolicy();
    }

    protected ZenModeConfig getZenModeConfig() {
        return mNotificationManager.getZenModeConfig();
    }

    protected int getZenMode() {
        return Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.ZEN_MODE, 0);
@@ -117,4 +130,69 @@ abstract public class AbstractZenModePreferenceController extends
            }
        }
    }

    /**
     * Wrapper for testing compatibility
     */
    @VisibleForTesting
    static class ZenModeConfigWrapper {
        private final Context mContext;

        public ZenModeConfigWrapper(Context context) {
            mContext = context;
        }

        protected String getOwnerCaption(String owner) {
            return ZenModeConfig.getOwnerCaption(mContext, owner);
        }

        protected boolean isTimeRule(Uri id) {
            return ZenModeConfig.isValidEventConditionId(id) ||
                    ZenModeConfig.isValidScheduleConditionId(id);
        }

        protected CharSequence getFormattedTime(long time, int userHandle) {
            return ZenModeConfig.getFormattedTime(mContext, time, isToday(time), userHandle);
        }

        private boolean isToday(long time) {
            return ZenModeConfig.isToday(time);
        }

        protected long parseManualRuleTime(Uri id) {
            return ZenModeConfig.tryParseCountdownConditionId(id);
        }

        protected long parseAutomaticRuleEndTime(Uri id) {
            if (ZenModeConfig.isValidEventConditionId(id)) {
                // cannot look up end times for events
                return Long.MAX_VALUE;
            }

            if (ZenModeConfig.isValidScheduleConditionId(id)) {
                ScheduleCalendar schedule = ZenModeConfig.toScheduleCalendar(id);
                long endTimeMs = schedule.getNextChangeTime(System.currentTimeMillis());

                // check if automatic rule will end on next alarm
                if (schedule.exitAtAlarm()) {
                    long nextAlarm = getNextAlarm(mContext);
                    schedule.maybeSetNextAlarm(System.currentTimeMillis(), nextAlarm);
                    if (schedule.shouldExitForAlarm(endTimeMs)) {
                        return nextAlarm;
                    }
                }


                return endTimeMs;
            }

            return -1;
        }
    }

    private static long getNextAlarm(Context context) {
        final AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        final AlarmClockInfo info = alarms.getNextAlarmClock(ActivityManager.getCurrentUser());
        return info != null ? info.getTriggerTime() : 0;
    }
}
Loading