diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 9beec69031c..e8e45e3e881 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -727,6 +727,10 @@
+
+
+
+
@@ -752,23 +756,6 @@
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index cc4b1c440d0..c8dad37afa6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7223,24 +7223,23 @@
Allow visual signals
-
- Restrict notifications
+
+ When Do Not Disturb is turned on
+
Notifications
-
- When Do Not Disturb is turned on
- Mute notifications
+ Show notifications silently
- Show notifications but mute sounds & vibrations
+ Notifications will be muted
- When new notifications arrive your phone won\u2019t make a sound or vibration
+ When notifications arrive, your phone won\u2019t make a sound or vibrate.
- Hide & mute notifications
+ Hide notifications
- Notifications will not appear at all
+ You won\u2019t see new or existing notifications
- You won\u2019t see new or existing notifications when Do Not Disturb is on. However, notifications needed for basic phone activity and status will still appear.
+ Your phone won\u2019t show new or existing notifications, and won\u2019t make a sound or vibrate. Notifications won\u2019t appear when you swipe down from the top of your screen.\n\nKeep in mind, critical notifications for phone activity and status will still appear.
Custom
@@ -7360,6 +7359,35 @@
- %d rules can turn on automatically
+
+ Behavior
+
+ Exceptions
+
+ Schedule
+
+
+ Sound & vibration
+
+ When Do Not Disturb is on, sound and vibration will be muted, except for the items you allow above.
+
+ Mute all except
+
+ Muted
+
+ Not muted
+
+ Muted, but allow %1$s
+
+ Muted, but allow %1$s and %2$s
+
+ Muted, but allow %1$s, %2$s, and %3$s
+
+
+ Messages, events & reminders
+
+ When Do Not Disturb is on, messages, reminders, and events will muted, except for the items you allow above. You can adjust messages settings to allow your friends, family, or other contacts to reach you.
+
Update
@@ -7891,14 +7919,17 @@
Calls
+
+ When Do Not Disturb is on, incoming calls are blocked. You can adjust settings to allow your friends, family, or other contacts to reach you.
+
Messages
- All messages
+ Messages
- Selected messages
+ Some messages
From anyone
@@ -7909,6 +7940,15 @@
From starred contacts only
+
+ From starred contacts and repeat callers
+
+
+ From contacts and repeat callers
+
+
+ From repeat callers only
+
None
@@ -7928,14 +7968,23 @@
Events
- All callers
+ anyone
- Selected callers
+ contacts
+
+
+ starred contacts
Repeat callers
+
+ From %1$s only
+
+
+ From %1$s and %2$s
+
If the same person calls a second time within a %d minute period
@@ -9346,7 +9395,7 @@
All
- Support & tips
+ Tips & support
%1$s dp
diff --git a/res/xml/night_display_settings.xml b/res/xml/night_display_settings.xml
index 9442a0d54f5..7b00ea02567 100644
--- a/res/xml/night_display_settings.xml
+++ b/res/xml/night_display_settings.xml
@@ -15,31 +15,44 @@
-->
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:title="@string/night_display_title"
+ android:key="night_display_title"
+ settings:keywords="@string/keywords_display_night_display">
+ android:key="night_display_auto_mode"
+ android:title="@string/night_display_auto_mode_title"
+ android:summary="%s"
+ settings:controller="com.android.settings.display.NightDisplayAutoModePreferenceController" />
+ android:key="night_display_start_time"
+ android:title="@string/night_display_start_time_title"
+ settings:controller="com.android.settings.display.NightDisplayCustomStartTimePreferenceController" />
-
-
+ android:key="night_display_end_time"
+ android:title="@string/night_display_end_time_title"
+ settings:controller="com.android.settings.display.NightDisplayCustomEndTimePreferenceController" />
+ android:key="night_display_temperature"
+ android:title="@string/night_display_temperature_title"
+ settings:keywords="@string/keywords_display_night_display"
+ settings:controller="com.android.settings.display.NightDisplayIntensityPreferenceController" />
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/xml/zen_mode_behavior_settings.xml b/res/xml/zen_mode_behavior_settings.xml
deleted file mode 100644
index 8426d9154c2..00000000000
--- a/res/xml/zen_mode_behavior_settings.xml
+++ /dev/null
@@ -1,70 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/res/xml/zen_mode_calls_settings.xml b/res/xml/zen_mode_calls_settings.xml
new file mode 100644
index 00000000000..d9e47f30538
--- /dev/null
+++ b/res/xml/zen_mode_calls_settings.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/xml/zen_mode_msg_event_reminder_settings.xml b/res/xml/zen_mode_msg_event_reminder_settings.xml
new file mode 100644
index 00000000000..866f333d3a2
--- /dev/null
+++ b/res/xml/zen_mode_msg_event_reminder_settings.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/xml/zen_mode_restrict_notifications_settings.xml b/res/xml/zen_mode_restrict_notifications_settings.xml
index d5243f62943..e024ab9d974 100644
--- a/res/xml/zen_mode_restrict_notifications_settings.xml
+++ b/res/xml/zen_mode_restrict_notifications_settings.xml
@@ -18,11 +18,11 @@
+ android:title="@string/zen_mode_restrict_notifications_title">
+ android:title="@string/zen_mode_settings_category">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ android:title="@string/zen_category_behavior">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/xml/zen_mode_sound_vibration_settings.xml b/res/xml/zen_mode_sound_vibration_settings.xml
new file mode 100644
index 00000000000..50128b9a340
--- /dev/null
+++ b/res/xml/zen_mode_sound_vibration_settings.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/com/android/settings/core/SliderPreferenceController.java b/src/com/android/settings/core/SliderPreferenceController.java
index 0baa86874de..a6e3a5b2ba1 100644
--- a/src/com/android/settings/core/SliderPreferenceController.java
+++ b/src/com/android/settings/core/SliderPreferenceController.java
@@ -16,7 +16,6 @@ package com.android.settings.core;
import android.content.Context;
import android.support.v7.preference.Preference;
-import android.support.v7.preference.SeekBarPreference;
import com.android.settings.slices.SliceData;
@@ -34,7 +33,13 @@ public abstract class SliderPreferenceController extends BasePreferenceControlle
@Override
public void updateState(Preference preference) {
- ((SeekBarPreference) preference).setValue(getSliderPosition());
+ if (preference instanceof com.android.settings.widget.SeekBarPreference) {
+ ((com.android.settings.widget.SeekBarPreference) preference)
+ .setProgress(getSliderPosition());
+ } else if (preference instanceof android.support.v7.preference.SeekBarPreference) {
+ ((android.support.v7.preference.SeekBarPreference) preference)
+ .setValue(getSliderPosition());
+ }
}
/**
diff --git a/src/com/android/settings/core/TogglePreferenceController.java b/src/com/android/settings/core/TogglePreferenceController.java
index 16cb18b7443..ffe7fd3e5e2 100644
--- a/src/com/android/settings/core/TogglePreferenceController.java
+++ b/src/com/android/settings/core/TogglePreferenceController.java
@@ -42,8 +42,8 @@ public abstract class TogglePreferenceController extends BasePreferenceControlle
/**
* Set the Setting to {@param isChecked}
*
- * @param isChecked Is {@true} when the setting should be enabled.
- * @return {@true} if the underlying setting is updated.
+ * @param isChecked Is {@code true} when the setting should be enabled.
+ * @return {@code true} if the underlying setting is updated.
*/
public abstract boolean setChecked(boolean isChecked);
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index aa9d7b54879..a8cb61cd848 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -106,9 +106,10 @@ import com.android.settings.notification.NotificationStation;
import com.android.settings.notification.SoundSettings;
import com.android.settings.notification.ZenAccessSettings;
import com.android.settings.notification.ZenModeAutomationSettings;
-import com.android.settings.notification.ZenModeBehaviorSettings;
+import com.android.settings.notification.ZenModeMsgEventReminderSettings;
import com.android.settings.notification.ZenModeBlockedEffectsSettings;
import com.android.settings.notification.ZenModeEventRuleSettings;
+import com.android.settings.notification.ZenModeRestrictNotificationsSettings;
import com.android.settings.notification.ZenModeScheduleRuleSettings;
import com.android.settings.notification.ZenModeSettings;
import com.android.settings.password.ChooseLockPassword;
@@ -220,7 +221,6 @@ public class SettingsGateway {
ApnSettings.class.getName(),
ApnEditor.class.getName(),
WifiCallingSettings.class.getName(),
- ZenModeBehaviorSettings.class.getName(),
ZenModeScheduleRuleSettings.class.getName(),
ZenModeEventRuleSettings.class.getName(),
ZenModeBlockedEffectsSettings.class.getName(),
diff --git a/src/com/android/settings/display/NightDisplayActivationPreferenceController.java b/src/com/android/settings/display/NightDisplayActivationPreferenceController.java
new file mode 100644
index 00000000000..9634739854a
--- /dev/null
+++ b/src/com/android/settings/display/NightDisplayActivationPreferenceController.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2018 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;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import com.android.internal.app.ColorDisplayController;
+import com.android.settings.R;
+import com.android.settings.applications.LayoutPreference;
+import com.android.settings.core.TogglePreferenceController;
+
+public class NightDisplayActivationPreferenceController extends TogglePreferenceController {
+
+ private ColorDisplayController mController;
+ private NightDisplayTimeFormatter mTimeFormatter;
+ private Button mTurnOffButton;
+ private Button mTurnOnButton;
+
+ private final OnClickListener mListener = new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mController.setActivated(!mController.isActivated());
+ updateStateInternal();
+ }
+ };
+
+ public NightDisplayActivationPreferenceController(Context context, String key) {
+ super(context, key);
+ mController = new ColorDisplayController(context);
+ mTimeFormatter = new NightDisplayTimeFormatter(context);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return ColorDisplayController.isAvailable(mContext) ? AVAILABLE : DISABLED_UNSUPPORTED;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ final LayoutPreference preference = (LayoutPreference) screen.findPreference(
+ getPreferenceKey());
+ mTurnOnButton = preference.findViewById(R.id.night_display_turn_on_button);
+ mTurnOnButton.setOnClickListener(mListener);
+ mTurnOffButton = preference.findViewById(R.id.night_display_turn_off_button);
+ mTurnOffButton.setOnClickListener(mListener);
+ }
+
+ @Override
+ public final void updateState(Preference preference) {
+ updateStateInternal();
+ }
+
+ /** FOR SLICES */
+
+ @Override
+ public boolean isChecked() {
+ return mController.isActivated();
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ return mController.setActivated(isChecked);
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return mTimeFormatter.getAutoModeTimeSummary(mContext, mController);
+ }
+
+ private void updateStateInternal() {
+ if (mTurnOnButton == null || mTurnOffButton == null) {
+ return;
+ }
+
+ final boolean isActivated = mController.isActivated();
+ final int autoMode = mController.getAutoMode();
+
+ String buttonText;
+ if (autoMode == ColorDisplayController.AUTO_MODE_CUSTOM) {
+ buttonText = mContext.getString(isActivated
+ ? R.string.night_display_activation_off_custom
+ : R.string.night_display_activation_on_custom,
+ mTimeFormatter.getFormattedTimeString(isActivated
+ ? mController.getCustomStartTime()
+ : mController.getCustomEndTime()));
+ } else if (autoMode == ColorDisplayController.AUTO_MODE_TWILIGHT) {
+ buttonText = mContext.getString(isActivated
+ ? R.string.night_display_activation_off_twilight
+ : R.string.night_display_activation_on_twilight);
+ } else {
+ buttonText = mContext.getString(isActivated
+ ? R.string.night_display_activation_off_manual
+ : R.string.night_display_activation_on_manual);
+ }
+
+ if (isActivated) {
+ mTurnOnButton.setVisibility(View.GONE);
+ mTurnOffButton.setVisibility(View.VISIBLE);
+ mTurnOffButton.setText(buttonText);
+ } else {
+ mTurnOnButton.setVisibility(View.VISIBLE);
+ mTurnOffButton.setVisibility(View.GONE);
+ mTurnOnButton.setText(buttonText);
+ }
+ }
+}
diff --git a/src/com/android/settings/display/NightDisplayAutoModePreferenceController.java b/src/com/android/settings/display/NightDisplayAutoModePreferenceController.java
new file mode 100644
index 00000000000..e7b7de2cc1e
--- /dev/null
+++ b/src/com/android/settings/display/NightDisplayAutoModePreferenceController.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2018 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;
+
+import android.content.Context;
+import android.support.v7.preference.DropDownPreference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import com.android.internal.app.ColorDisplayController;
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+
+public class NightDisplayAutoModePreferenceController extends BasePreferenceController
+ implements Preference.OnPreferenceChangeListener {
+
+ private DropDownPreference mPreference;
+ private ColorDisplayController mController;
+
+ public NightDisplayAutoModePreferenceController(Context context, String key) {
+ super(context, key);
+ mController = new ColorDisplayController(context);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return ColorDisplayController.isAvailable(mContext) ? AVAILABLE : DISABLED_UNSUPPORTED;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ mPreference = (DropDownPreference) screen.findPreference(getPreferenceKey());
+
+ mPreference.setEntries(new CharSequence[]{
+ mContext.getString(R.string.night_display_auto_mode_never),
+ mContext.getString(R.string.night_display_auto_mode_custom),
+ mContext.getString(R.string.night_display_auto_mode_twilight)
+ });
+ mPreference.setEntryValues(new CharSequence[]{
+ String.valueOf(ColorDisplayController.AUTO_MODE_DISABLED),
+ String.valueOf(ColorDisplayController.AUTO_MODE_CUSTOM),
+ String.valueOf(ColorDisplayController.AUTO_MODE_TWILIGHT)
+ });
+ }
+
+ @Override
+ public final void updateState(Preference preference) {
+ mPreference.setValue(String.valueOf(mController.getAutoMode()));
+ }
+
+ @Override
+ public final boolean onPreferenceChange(Preference preference, Object newValue) {
+ return mController.setAutoMode(Integer.parseInt((String) newValue));
+ }
+}
diff --git a/src/com/android/settings/display/NightDisplayCustomEndTimePreferenceController.java b/src/com/android/settings/display/NightDisplayCustomEndTimePreferenceController.java
new file mode 100644
index 00000000000..524e7dbc4f4
--- /dev/null
+++ b/src/com/android/settings/display/NightDisplayCustomEndTimePreferenceController.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 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;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import com.android.internal.app.ColorDisplayController;
+import com.android.settings.core.BasePreferenceController;
+
+public class NightDisplayCustomEndTimePreferenceController extends BasePreferenceController {
+
+ private ColorDisplayController mController;
+ private NightDisplayTimeFormatter mTimeFormatter;
+
+ public NightDisplayCustomEndTimePreferenceController(Context context, String key) {
+ super(context, key);
+
+ mController = new ColorDisplayController(context);
+ mTimeFormatter = new NightDisplayTimeFormatter(context);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return ColorDisplayController.isAvailable(mContext) ? AVAILABLE : DISABLED_UNSUPPORTED;
+ }
+
+ @Override
+ public final void updateState(Preference preference) {
+ preference.setVisible(mController.getAutoMode() == ColorDisplayController.AUTO_MODE_CUSTOM);
+ preference.setSummary(mTimeFormatter.getFormattedTimeString(
+ mController.getCustomEndTime()));
+ }
+}
diff --git a/src/com/android/settings/display/NightDisplayCustomStartTimePreferenceController.java b/src/com/android/settings/display/NightDisplayCustomStartTimePreferenceController.java
new file mode 100644
index 00000000000..4dda8f47dc7
--- /dev/null
+++ b/src/com/android/settings/display/NightDisplayCustomStartTimePreferenceController.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 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;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import com.android.internal.app.ColorDisplayController;
+import com.android.settings.core.BasePreferenceController;
+
+public class NightDisplayCustomStartTimePreferenceController extends BasePreferenceController {
+
+ private ColorDisplayController mController;
+ private NightDisplayTimeFormatter mTimeFormatter;
+
+ public NightDisplayCustomStartTimePreferenceController(Context context, String key) {
+ super(context, key);
+
+ mController = new ColorDisplayController(context);
+ mTimeFormatter = new NightDisplayTimeFormatter(context);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return ColorDisplayController.isAvailable(mContext) ? AVAILABLE : DISABLED_UNSUPPORTED;
+ }
+
+ @Override
+ public final void updateState(Preference preference) {
+ preference.setVisible(mController.getAutoMode() == ColorDisplayController.AUTO_MODE_CUSTOM);
+ preference.setSummary(mTimeFormatter.getFormattedTimeString(
+ mController.getCustomStartTime()));
+ }
+}
diff --git a/src/com/android/settings/display/NightDisplayFooterPreferenceController.java b/src/com/android/settings/display/NightDisplayFooterPreferenceController.java
new file mode 100644
index 00000000000..228d27126ea
--- /dev/null
+++ b/src/com/android/settings/display/NightDisplayFooterPreferenceController.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2018 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;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import com.android.internal.app.ColorDisplayController;
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.widget.FooterPreference;
+
+public class NightDisplayFooterPreferenceController extends BasePreferenceController {
+
+ public NightDisplayFooterPreferenceController(Context context) {
+ super(context, FooterPreference.KEY_FOOTER);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return ColorDisplayController.isAvailable(mContext) ? AVAILABLE : DISABLED_UNSUPPORTED;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ preference.setTitle(R.string.night_display_text);
+ }
+}
diff --git a/src/com/android/settings/display/NightDisplayIntensityPreferenceController.java b/src/com/android/settings/display/NightDisplayIntensityPreferenceController.java
new file mode 100644
index 00000000000..b039644ce55
--- /dev/null
+++ b/src/com/android/settings/display/NightDisplayIntensityPreferenceController.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2018 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;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import com.android.internal.app.ColorDisplayController;
+import com.android.settings.core.SliderPreferenceController;
+import com.android.settings.widget.SeekBarPreference;
+
+public class NightDisplayIntensityPreferenceController extends SliderPreferenceController {
+
+ private ColorDisplayController mController;
+
+ public NightDisplayIntensityPreferenceController(Context context, String key) {
+ super(context, key);
+ mController = new ColorDisplayController(context);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (!ColorDisplayController.isAvailable(mContext)) {
+ return DISABLED_UNSUPPORTED;
+ } else if (!mController.isActivated()) {
+ return DISABLED_DEPENDENT_SETTING;
+ }
+ return AVAILABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ final SeekBarPreference preference = (SeekBarPreference) screen.findPreference(
+ getPreferenceKey());
+ preference.setContinuousUpdates(true);
+ preference.setMax(getMaxSteps());
+ }
+
+ @Override
+ public final void updateState(Preference preference) {
+ super.updateState(preference);
+ preference.setEnabled(mController.isActivated());
+ }
+
+ @Override
+ public int getSliderPosition() {
+ return convertTemperature(mController.getColorTemperature());
+ }
+
+ @Override
+ public boolean setSliderPosition(int position) {
+ return mController.setColorTemperature(convertTemperature(position));
+ }
+
+ @Override
+ public int getMaxSteps() {
+ return convertTemperature(mController.getMinimumColorTemperature());
+ }
+
+ /**
+ * Inverts and range-adjusts a raw value from the SeekBar (i.e. [0, maxTemp-minTemp]), or
+ * converts an inverted and range-adjusted value to the raw SeekBar value, depending on the
+ * adjustment status of the input.
+ */
+ private int convertTemperature(int temperature) {
+ return mController.getMaximumColorTemperature() - temperature;
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/display/NightDisplayPreference.java b/src/com/android/settings/display/NightDisplayPreference.java
index ea39f75ceda..e463292e558 100644
--- a/src/com/android/settings/display/NightDisplayPreference.java
+++ b/src/com/android/settings/display/NightDisplayPreference.java
@@ -19,25 +19,20 @@ import android.support.v14.preference.SwitchPreference;
import android.util.AttributeSet;
import com.android.internal.app.ColorDisplayController;
-import com.android.settings.R;
-import java.text.DateFormat;
import java.time.LocalTime;
-import java.util.Calendar;
-import java.util.TimeZone;
public class NightDisplayPreference extends SwitchPreference
implements ColorDisplayController.Callback {
private ColorDisplayController mController;
- private DateFormat mTimeFormatter;
+ private NightDisplayTimeFormatter mTimeFormatter;
public NightDisplayPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mController = new ColorDisplayController(context);
- mTimeFormatter = android.text.format.DateFormat.getTimeFormat(context);
- mTimeFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
+ mTimeFormatter = new NightDisplayTimeFormatter(context);
}
@Override
@@ -59,53 +54,6 @@ public class NightDisplayPreference extends SwitchPreference
mController.setListener(null);
}
- private String getFormattedTimeString(LocalTime localTime) {
- final Calendar c = Calendar.getInstance();
- c.setTimeZone(mTimeFormatter.getTimeZone());
- c.set(Calendar.HOUR_OF_DAY, localTime.getHour());
- c.set(Calendar.MINUTE, localTime.getMinute());
- c.set(Calendar.SECOND, 0);
- c.set(Calendar.MILLISECOND, 0);
- return mTimeFormatter.format(c.getTime());
- }
-
- private void updateSummary() {
- final Context context = getContext();
-
- final boolean isActivated = mController.isActivated();
- final int autoMode = mController.getAutoMode();
-
- final String autoModeSummary;
- switch (autoMode) {
- default:
- case ColorDisplayController.AUTO_MODE_DISABLED:
- autoModeSummary = context.getString(isActivated
- ? R.string.night_display_summary_on_auto_mode_never
- : R.string.night_display_summary_off_auto_mode_never);
- break;
- case ColorDisplayController.AUTO_MODE_CUSTOM:
- if (isActivated) {
- autoModeSummary = context.getString(
- R.string.night_display_summary_on_auto_mode_custom,
- getFormattedTimeString(mController.getCustomEndTime()));
- } else {
- autoModeSummary = context.getString(
- R.string.night_display_summary_off_auto_mode_custom,
- getFormattedTimeString(mController.getCustomStartTime()));
- }
- break;
- case ColorDisplayController.AUTO_MODE_TWILIGHT:
- autoModeSummary = context.getString(isActivated
- ? R.string.night_display_summary_on_auto_mode_twilight
- : R.string.night_display_summary_off_auto_mode_twilight);
- break;
- }
-
- final int summaryFormatResId = isActivated ? R.string.night_display_summary_on
- : R.string.night_display_summary_off;
- setSummary(context.getString(summaryFormatResId, autoModeSummary));
- }
-
@Override
public void onActivated(boolean activated) {
updateSummary();
@@ -125,4 +73,8 @@ public class NightDisplayPreference extends SwitchPreference
public void onCustomEndTimeChanged(LocalTime endTime) {
updateSummary();
}
+
+ private void updateSummary() {
+ setSummary(mTimeFormatter.getAutoModeTimeSummary(getContext(), mController));
+ }
}
diff --git a/src/com/android/settings/display/NightDisplaySettings.java b/src/com/android/settings/display/NightDisplaySettings.java
index 4e0ebcd0f6d..e9bcde59f46 100644
--- a/src/com/android/settings/display/NightDisplaySettings.java
+++ b/src/com/android/settings/display/NightDisplaySettings.java
@@ -21,51 +21,32 @@ import android.app.TimePickerDialog;
import android.content.Context;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
-import android.support.v7.preference.DropDownPreference;
import android.support.v7.preference.Preference;
-import android.support.v7.preference.TwoStatePreference;
import com.android.internal.app.ColorDisplayController;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
-import com.android.settings.widget.SeekBarPreference;
-import com.android.settings.SettingsPreferenceFragment;
import com.android.settingslib.core.AbstractPreferenceController;
-import java.text.DateFormat;
import java.time.LocalTime;
import java.util.ArrayList;
-import java.util.Calendar;
import java.util.List;
-import java.util.TimeZone;
/**
* Settings screen for Night display.
- * TODO (b/69912911) Upgrade to Dashboard fragment
*/
-public class NightDisplaySettings extends SettingsPreferenceFragment
- implements ColorDisplayController.Callback, Preference.OnPreferenceChangeListener,
- Indexable {
+public class NightDisplaySettings extends DashboardFragment
+ implements ColorDisplayController.Callback, Indexable {
- private static final String KEY_NIGHT_DISPLAY_AUTO_MODE = "night_display_auto_mode";
- private static final String KEY_NIGHT_DISPLAY_START_TIME = "night_display_start_time";
- private static final String KEY_NIGHT_DISPLAY_END_TIME = "night_display_end_time";
- private static final String KEY_NIGHT_DISPLAY_ACTIVATED = "night_display_activated";
- private static final String KEY_NIGHT_DISPLAY_TEMPERATURE = "night_display_temperature";
+ private static final String TAG = "NightDisplaySettings";
private static final int DIALOG_START_TIME = 0;
private static final int DIALOG_END_TIME = 1;
private ColorDisplayController mController;
- private DateFormat mTimeFormatter;
-
- private DropDownPreference mAutoModePreference;
- private Preference mStartTimePreference;
- private Preference mEndTimePreference;
- private TwoStatePreference mActivatedPreference;
- private SeekBarPreference mTemperaturePreference;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -73,45 +54,6 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
final Context context = getContext();
mController = new ColorDisplayController(context);
-
- mTimeFormatter = android.text.format.DateFormat.getTimeFormat(context);
- mTimeFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
-
- mTemperaturePreference.setMax(convertTemperature(mController.getMinimumColorTemperature()));
- mTemperaturePreference.setContinuousUpdates(true);
- }
-
- @Override
- public int getHelpResource() {
- return R.string.help_url_night_display;
- }
-
- @Override
- public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- super.onCreatePreferences(savedInstanceState, rootKey);
-
- // Load the preferences from xml.
- addPreferencesFromResource(R.xml.night_display_settings);
- mFooterPreferenceMixin.createFooterPreference().setTitle(R.string.night_display_text);
- mAutoModePreference = (DropDownPreference) findPreference(KEY_NIGHT_DISPLAY_AUTO_MODE);
- mStartTimePreference = findPreference(KEY_NIGHT_DISPLAY_START_TIME);
- mEndTimePreference = findPreference(KEY_NIGHT_DISPLAY_END_TIME);
- mActivatedPreference = (TwoStatePreference) findPreference(KEY_NIGHT_DISPLAY_ACTIVATED);
- mTemperaturePreference = (SeekBarPreference) findPreference(KEY_NIGHT_DISPLAY_TEMPERATURE);
-
- mAutoModePreference.setEntries(new CharSequence[]{
- getString(R.string.night_display_auto_mode_never),
- getString(R.string.night_display_auto_mode_custom),
- getString(R.string.night_display_auto_mode_twilight)
- });
- mAutoModePreference.setEntryValues(new CharSequence[]{
- String.valueOf(ColorDisplayController.AUTO_MODE_DISABLED),
- String.valueOf(ColorDisplayController.AUTO_MODE_CUSTOM),
- String.valueOf(ColorDisplayController.AUTO_MODE_TWILIGHT)
- });
- mAutoModePreference.setOnPreferenceChangeListener(this);
- mActivatedPreference.setOnPreferenceChangeListener(this);
- mTemperaturePreference.setOnPreferenceChangeListener(this);
}
@Override
@@ -120,14 +62,6 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
// Listen for changes only while visible.
mController.setListener(this);
-
- // Update the current state since it have changed while not visible.
- onActivated(mController.isActivated());
- onAutoModeChanged(mController.getAutoMode());
- onCustomStartTimeChanged(mController.getCustomStartTime());
- onCustomEndTimeChanged(mController.getCustomEndTime());
- onColorTemperatureChanged(mController.getColorTemperature());
- onDisplayColorModeChanged(mController.getColorMode());
}
@Override
@@ -140,12 +74,12 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
@Override
public boolean onPreferenceTreeClick(Preference preference) {
- if (preference == mStartTimePreference) {
- showDialog(DIALOG_START_TIME);
- return true;
- } else if (preference == mEndTimePreference) {
+ if ("night_display_end_time".equals(preference.getKey())) {
showDialog(DIALOG_END_TIME);
return true;
+ } else if ("night_display_start_time".equals(preference.getKey())) {
+ showDialog(DIALOG_START_TIME);
+ return true;
}
return super.onPreferenceTreeClick(preference);
}
@@ -188,63 +122,37 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
@Override
public void onActivated(boolean activated) {
- mActivatedPreference.setChecked(activated);
- mTemperaturePreference.setEnabled(activated);
+ // Update activated and temperature preferences.
+ updatePreferenceStates();
}
@Override
public void onAutoModeChanged(int autoMode) {
- mAutoModePreference.setValue(String.valueOf(autoMode));
-
- final boolean showCustomSchedule = autoMode == ColorDisplayController.AUTO_MODE_CUSTOM;
- mStartTimePreference.setVisible(showCustomSchedule);
- mEndTimePreference.setVisible(showCustomSchedule);
+ // Update auto mode, start time, and end time preferences.
+ updatePreferenceStates();
}
@Override
public void onColorTemperatureChanged(int colorTemperature) {
- mTemperaturePreference.setProgress(convertTemperature(colorTemperature));
- }
-
- private String getFormattedTimeString(LocalTime localTime) {
- final Calendar c = Calendar.getInstance();
- c.setTimeZone(mTimeFormatter.getTimeZone());
- c.set(Calendar.HOUR_OF_DAY, localTime.getHour());
- c.set(Calendar.MINUTE, localTime.getMinute());
- c.set(Calendar.SECOND, 0);
- c.set(Calendar.MILLISECOND, 0);
- return mTimeFormatter.format(c.getTime());
- }
-
- /**
- * Inverts and range-adjusts a raw value from the SeekBar (i.e. [0, maxTemp-minTemp]), or
- * converts an inverted and range-adjusted value to the raw SeekBar value, depending on the
- * adjustment status of the input.
- */
- private int convertTemperature(int temperature) {
- return mController.getMaximumColorTemperature() - temperature;
+ // Update temperature preference.
+ updatePreferenceStates();
}
@Override
public void onCustomStartTimeChanged(LocalTime startTime) {
- mStartTimePreference.setSummary(getFormattedTimeString(startTime));
+ // Update start time preference.
+ updatePreferenceStates();
}
@Override
public void onCustomEndTimeChanged(LocalTime endTime) {
- mEndTimePreference.setSummary(getFormattedTimeString(endTime));
+ // Update end time preference.
+ updatePreferenceStates();
}
@Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (preference == mAutoModePreference) {
- return mController.setAutoMode(Integer.parseInt((String) newValue));
- } else if (preference == mActivatedPreference) {
- return mController.setActivated((Boolean) newValue);
- } else if (preference == mTemperaturePreference) {
- return mController.setColorTemperature(convertTemperature((Integer) newValue));
- }
- return false;
+ protected int getPreferenceScreenResId() {
+ return R.xml.night_display_settings;
}
@Override
@@ -252,13 +160,33 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
return MetricsEvent.NIGHT_DISPLAY_SETTINGS;
}
+ @Override
+ public int getHelpResource() {
+ return R.string.help_url_night_display;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected List createPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context);
+ }
+
+ private static List buildPreferenceControllers(Context context) {
+ final List controllers = new ArrayList<>(1);
+ controllers.add(new NightDisplayFooterPreferenceController(context));
+ return controllers;
+ }
+
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
public List getXmlResourcesToIndex(Context context,
boolean enabled) {
final ArrayList result = new ArrayList<>();
-
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.night_display_settings;
result.add(sir);
@@ -269,5 +197,11 @@ public class NightDisplaySettings extends SettingsPreferenceFragment
protected boolean isPageSearchEnabled(Context context) {
return ColorDisplayController.isAvailable(context);
}
+
+ @Override
+ public List createPreferenceControllers(
+ Context context) {
+ return buildPreferenceControllers(context);
+ }
};
}
diff --git a/src/com/android/settings/display/NightDisplayTimeFormatter.java b/src/com/android/settings/display/NightDisplayTimeFormatter.java
new file mode 100644
index 00000000000..48a1994cee3
--- /dev/null
+++ b/src/com/android/settings/display/NightDisplayTimeFormatter.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2018 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;
+
+import android.content.Context;
+
+import com.android.internal.app.ColorDisplayController;
+import com.android.settings.R;
+
+import java.text.DateFormat;
+import java.time.LocalTime;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+public class NightDisplayTimeFormatter {
+
+ private DateFormat mTimeFormatter;
+
+ NightDisplayTimeFormatter(Context context) {
+ mTimeFormatter = android.text.format.DateFormat.getTimeFormat(context);
+ mTimeFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
+ }
+
+ public String getFormattedTimeString(LocalTime localTime) {
+ final Calendar c = Calendar.getInstance();
+ c.setTimeZone(mTimeFormatter.getTimeZone());
+ c.set(Calendar.HOUR_OF_DAY, localTime.getHour());
+ c.set(Calendar.MINUTE, localTime.getMinute());
+ c.set(Calendar.SECOND, 0);
+ c.set(Calendar.MILLISECOND, 0);
+ return mTimeFormatter.format(c.getTime());
+ }
+
+ public String getAutoModeTimeSummary(Context context, ColorDisplayController controller) {
+ final int summaryFormatResId = controller.isActivated() ? R.string.night_display_summary_on
+ : R.string.night_display_summary_off;
+ return context.getString(summaryFormatResId, getAutoModeSummary(context, controller));
+ }
+
+ private String getAutoModeSummary(Context context, ColorDisplayController controller) {
+ final boolean isActivated = controller.isActivated();
+ final int autoMode = controller.getAutoMode();
+ if (autoMode == ColorDisplayController.AUTO_MODE_CUSTOM) {
+ if (isActivated) {
+ return context.getString(R.string.night_display_summary_on_auto_mode_custom,
+ getFormattedTimeString(controller.getCustomEndTime()));
+ } else {
+ return context.getString(R.string.night_display_summary_off_auto_mode_custom,
+ getFormattedTimeString(controller.getCustomStartTime()));
+ }
+ } else if (autoMode == ColorDisplayController.AUTO_MODE_TWILIGHT) {
+ return context.getString(isActivated
+ ? R.string.night_display_summary_on_auto_mode_twilight
+ : R.string.night_display_summary_off_auto_mode_twilight);
+ } else {
+ return context.getString(isActivated
+ ? R.string.night_display_summary_on_auto_mode_never
+ : R.string.night_display_summary_off_auto_mode_never);
+ }
+ }
+}
diff --git a/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceController.java
similarity index 84%
rename from src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java
rename to src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceController.java
index cf6218c2deb..79aa0cba6c4 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceController.java
@@ -22,13 +22,13 @@ import android.support.v7.preference.Preference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
-public class ZenModeBehaviorPreferenceController extends
+public class ZenModeBehaviorCallsPreferenceController extends
AbstractZenModePreferenceController implements PreferenceControllerMixin {
- protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_behavior_settings";
+ protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_calls_settings";
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
- public ZenModeBehaviorPreferenceController(Context context, Lifecycle lifecycle) {
+ public ZenModeBehaviorCallsPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
}
@@ -47,7 +47,6 @@ public class ZenModeBehaviorPreferenceController extends
public void updateState(Preference preference) {
super.updateState(preference);
- preference.setSummary(mSummaryBuilder.getBehaviorSettingSummary(getPolicy(),
- getZenMode()));
+ preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy()));
}
}
diff --git a/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceController.java
index a1c2b017f17..7f8760b0627 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceController.java
@@ -16,13 +16,12 @@
package com.android.settings.notification;
-import android.content.Context;
import android.content.ComponentName;
+import android.content.Context;
import android.net.Uri;
import android.provider.Settings;
import android.service.notification.ZenModeConfig;
import android.support.v7.preference.Preference;
-import android.util.Slog;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -30,14 +29,17 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeBehaviorFooterPreferenceController extends AbstractZenModePreferenceController {
protected static final String KEY = "footer_preference";
+ private final int mTitleRes;
- public ZenModeBehaviorFooterPreferenceController(Context context, Lifecycle lifecycle) {
+ public ZenModeBehaviorFooterPreferenceController(Context context, Lifecycle lifecycle,
+ int titleRes) {
super(context, KEY, lifecycle);
+ mTitleRes = titleRes;
}
@Override
public boolean isAvailable() {
- return isDeprecatedZenMode(getZenMode());
+ return true;
}
@Override
@@ -48,45 +50,45 @@ public class ZenModeBehaviorFooterPreferenceController extends AbstractZenModePr
@Override
public void updateState(Preference preference) {
super.updateState(preference);
-
- boolean isAvailable = isAvailable();
- preference.setVisible(isAvailable);
- if (isAvailable) {
- preference.setTitle(getFooterText());
- }
-
+ preference.setTitle(getFooterText());
}
protected String getFooterText() {
- ZenModeConfig config = getZenModeConfig();
+ if (isDeprecatedZenMode(getZenMode())) {
+ ZenModeConfig config = getZenModeConfig();
- // DND turned on by manual rule with deprecated zen mode
- if (config.manualRule != null &&
- isDeprecatedZenMode(config.manualRule.zenMode)) {
- final Uri id = config.manualRule.conditionId;
- if (config.manualRule.enabler != null) {
- // app triggered manual rule
- String appOwner = mZenModeConfigWrapper.getOwnerCaption(config.manualRule.enabler);
- if (!appOwner.isEmpty()) {
- return mContext.getString(R.string.zen_mode_app_set_behavior, appOwner);
- }
- } else {
- return mContext.getString(R.string.zen_mode_qs_set_behavior);
- }
- }
-
- // DND turned on by an automatic rule with deprecated zen mode
- for (ZenModeConfig.ZenRule automaticRule : config.automaticRules.values()) {
- if (automaticRule.isAutomaticActive() && isDeprecatedZenMode(automaticRule.zenMode)) {
- ComponentName component = automaticRule.component;
- if (component != null) {
- return mContext.getString(R.string.zen_mode_app_set_behavior,
- component.getPackageName());
+ // DND turned on by manual rule with deprecated zen mode
+ if (config.manualRule != null &&
+ isDeprecatedZenMode(config.manualRule.zenMode)) {
+ final Uri id = config.manualRule.conditionId;
+ if (config.manualRule.enabler != null) {
+ // app triggered manual rule
+ String appOwner = mZenModeConfigWrapper.getOwnerCaption(
+ config.manualRule.enabler);
+ if (!appOwner.isEmpty()) {
+ return mContext.getString(R.string.zen_mode_app_set_behavior, appOwner);
+ }
+ } else {
+ return mContext.getString(R.string.zen_mode_qs_set_behavior);
}
}
- }
- return mContext.getString(R.string.zen_mode_unknown_app_set_behavior);
+ // DND turned on by an automatic rule with deprecated zen mode
+ for (ZenModeConfig.ZenRule automaticRule : config.automaticRules.values()) {
+ if (automaticRule.isAutomaticActive() && isDeprecatedZenMode(
+ automaticRule.zenMode)) {
+ ComponentName component = automaticRule.component;
+ if (component != null) {
+ return mContext.getString(R.string.zen_mode_app_set_behavior,
+ component.getPackageName());
+ }
+ }
+ }
+
+ return mContext.getString(R.string.zen_mode_unknown_app_set_behavior);
+ } else {
+ return mContext.getString(mTitleRes);
+ }
}
private boolean isDeprecatedZenMode(int zenMode) {
diff --git a/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceController.java
new file mode 100644
index 00000000000..852769630e9
--- /dev/null
+++ b/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceController.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2017 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.notification;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+public class ZenModeBehaviorMsgEventReminderPreferenceController extends
+ AbstractZenModePreferenceController implements PreferenceControllerMixin {
+
+ protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_msg_event_reminder_settings";
+ private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
+
+ public ZenModeBehaviorMsgEventReminderPreferenceController(Context context,
+ Lifecycle lifecycle) {
+ super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
+ mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_BEHAVIOR_SETTINGS;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+
+ preference.setSummary(mSummaryBuilder.getMsgEventReminderSettingSummary(getPolicy()));
+ }
+}
diff --git a/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceController.java b/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceController.java
new file mode 100644
index 00000000000..07f12295473
--- /dev/null
+++ b/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceController.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2018 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.notification;
+
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+public class ZenModeBehaviorSoundPreferenceController extends
+ AbstractZenModePreferenceController implements PreferenceControllerMixin {
+
+ protected static final String KEY_BEHAVIOR_SETTINGS = "zen_sound_vibration_settings";
+ private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
+
+ public ZenModeBehaviorSoundPreferenceController(Context context, Lifecycle lifecycle) {
+ super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
+ mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_BEHAVIOR_SETTINGS;
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+
+ preference.setSummary(mSummaryBuilder.getSoundSettingSummary(getPolicy()));
+ }
+}
diff --git a/src/com/android/settings/notification/ZenModeCallsSettings.java b/src/com/android/settings/notification/ZenModeCallsSettings.java
new file mode 100644
index 00000000000..20396b5fb5c
--- /dev/null
+++ b/src/com/android/settings/notification/ZenModeCallsSettings.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2018 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.notification;
+
+import android.content.Context;
+import android.provider.SearchIndexableResource;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ZenModeCallsSettings extends ZenModeSettingsBase implements Indexable {
+
+ @Override
+ protected List createPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context, getLifecycle());
+ }
+
+ private static List buildPreferenceControllers(Context context,
+ Lifecycle lifecycle) {
+ List controllers = new ArrayList<>();
+ controllers.add(new ZenModeCallsPreferenceController(context, lifecycle));
+ // TODO: is a controller needed for a pref that just launches an external activity?
+ // or can the contacts app insert this setting themselves?
+ controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle,
+ context.getResources().getInteger(com.android.internal.R.integer
+ .config_zen_repeat_callers_threshold)));
+ controllers.add(new ZenModeBehaviorFooterPreferenceController(
+ context, lifecycle, R.string.zen_mode_calls_footer));
+ return controllers;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.zen_mode_calls_settings;
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsEvent.NOTIFICATION_ZEN_MODE_PRIORITY;
+ }
+
+ /**
+ * For Search.
+ */
+ public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+
+ @Override
+ public List getXmlResourcesToIndex(Context context,
+ boolean enabled) {
+ final ArrayList result = new ArrayList<>();
+
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.zen_mode_calls_settings;
+ result.add(sir);
+ return result;
+ }
+
+ @Override
+ public List getNonIndexableKeys(Context context) {
+ final List keys = super.getNonIndexableKeys(context);
+ return keys;
+ }
+
+ @Override
+ public List createPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context, null);
+ }
+ };
+}
diff --git a/src/com/android/settings/notification/ZenModeBehaviorSettings.java b/src/com/android/settings/notification/ZenModeMsgEventReminderSettings.java
similarity index 78%
rename from src/com/android/settings/notification/ZenModeBehaviorSettings.java
rename to src/com/android/settings/notification/ZenModeMsgEventReminderSettings.java
index 31542c35ed4..c2508e35286 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorSettings.java
+++ b/src/com/android/settings/notification/ZenModeMsgEventReminderSettings.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * Copyright (C) 2018 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.
@@ -29,7 +29,7 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
import java.util.List;
-public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Indexable {
+public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase implements Indexable {
@Override
protected List createPreferenceControllers(Context context) {
@@ -39,23 +39,17 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
private static List buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
List controllers = new ArrayList<>();
- controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle));
- controllers.add(new ZenModeMediaPreferenceController(context, lifecycle));
- controllers.add(new ZenModeSystemPreferenceController(context, lifecycle));
controllers.add(new ZenModeEventsPreferenceController(context, lifecycle));
controllers.add(new ZenModeRemindersPreferenceController(context, lifecycle));
controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle));
- controllers.add(new ZenModeCallsPreferenceController(context, lifecycle));
- controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle,
- context.getResources().getInteger(com.android.internal.R.integer
- .config_zen_repeat_callers_threshold)));
- controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle,
+ R.string.zen_msg_event_reminder_footer));
return controllers;
}
@Override
protected int getPreferenceScreenResId() {
- return R.xml.zen_mode_behavior_settings;
+ return R.xml.zen_mode_msg_event_reminder_settings;
}
@Override
@@ -75,7 +69,7 @@ public class ZenModeBehaviorSettings extends ZenModeSettingsBase implements Inde
final ArrayList result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.zen_mode_behavior_settings;
+ sir.xmlResId = R.xml.zen_mode_msg_event_reminder_settings;
result.add(sir);
return result;
}
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index bdc24e3c530..ec0f6192d94 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -16,6 +16,15 @@
package com.android.settings.notification;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_CALLS;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_EVENTS;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_REMINDERS;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS;
+import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_SYSTEM;
+
import android.app.AutomaticZenRule;
import android.app.FragmentManager;
import android.app.NotificationManager;
@@ -25,7 +34,6 @@ import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.service.notification.ZenModeConfig;
import android.support.annotation.VisibleForTesting;
-import android.support.v7.preference.CheckBoxPreference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
@@ -39,17 +47,12 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.function.Predicate;
public class ZenModeSettings extends ZenModeSettingsBase {
- private static final String KEY_SOUND = "zen_effect_sound";
@Override
public void onResume() {
super.onResume();
- CheckBoxPreference soundPreference =
- (CheckBoxPreference) getPreferenceScreen().findPreference(KEY_SOUND);
- if (soundPreference != null) {
- soundPreference.setChecked(true);
- }
}
@Override
@@ -75,7 +78,9 @@ public class ZenModeSettings extends ZenModeSettingsBase {
private static List buildPreferenceControllers(Context context,
Lifecycle lifecycle, FragmentManager fragmentManager) {
List controllers = new ArrayList<>();
- controllers.add(new ZenModeBehaviorPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeBehaviorMsgEventReminderPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeBehaviorSoundPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeBehaviorCallsPreferenceController(context, lifecycle));
controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle));
controllers.add(new ZenModeDurationPreferenceController(context, lifecycle,
fragmentManager));
@@ -95,19 +100,63 @@ public class ZenModeSettings extends ZenModeSettingsBase {
// these should match NotificationManager.Policy#ALL_PRIORITY_CATEGORIES
private static final int[] ALL_PRIORITY_CATEGORIES = {
- Policy.PRIORITY_CATEGORY_ALARMS,
- Policy.PRIORITY_CATEGORY_MEDIA,
- Policy.PRIORITY_CATEGORY_SYSTEM,
- Policy.PRIORITY_CATEGORY_REMINDERS,
- Policy.PRIORITY_CATEGORY_EVENTS,
- Policy.PRIORITY_CATEGORY_MESSAGES,
- Policy.PRIORITY_CATEGORY_CALLS,
- Policy.PRIORITY_CATEGORY_REPEAT_CALLERS,
+ PRIORITY_CATEGORY_ALARMS,
+ PRIORITY_CATEGORY_MEDIA,
+ PRIORITY_CATEGORY_SYSTEM,
+ PRIORITY_CATEGORY_MESSAGES,
+ PRIORITY_CATEGORY_EVENTS,
+ PRIORITY_CATEGORY_REMINDERS,
+ PRIORITY_CATEGORY_CALLS,
+ PRIORITY_CATEGORY_REPEAT_CALLERS,
};
- String getBehaviorSettingSummary(Policy policy, int zenMode) {
- List enabledCategories = getEnabledCategories(policy);
+ String getSoundSettingSummary(Policy policy) {
+ List enabledCategories = getEnabledCategories(policy,
+ category -> PRIORITY_CATEGORY_ALARMS == category
+ || PRIORITY_CATEGORY_MEDIA == category
+ || PRIORITY_CATEGORY_SYSTEM == category);
+ int numCategories = enabledCategories.size();
+ if (numCategories == 0) {
+ return mContext.getString(R.string.zen_sound_all_muted);
+ } else if (numCategories == 1) {
+ return mContext.getString(R.string.zen_sound_one_allowed,
+ enabledCategories.get(0).toLowerCase());
+ } else if (numCategories == 2) {
+ return mContext.getString(R.string.zen_sound_two_allowed,
+ enabledCategories.get(0).toLowerCase(),
+ enabledCategories.get(1).toLowerCase());
+ } else if (numCategories == 3) {
+ return mContext.getString(R.string.zen_sound_three_allowed,
+ enabledCategories.get(0).toLowerCase(),
+ enabledCategories.get(1).toLowerCase(),
+ enabledCategories.get(2).toLowerCase());
+ } else {
+ return mContext.getString(R.string.zen_sound_none_muted);
+ }
+ }
+ String getCallsSettingSummary(Policy policy) {
+ List enabledCategories = getEnabledCategories(policy,
+ category -> PRIORITY_CATEGORY_CALLS == category
+ || PRIORITY_CATEGORY_REPEAT_CALLERS == category);
+ int numCategories = enabledCategories.size();
+ if (numCategories == 0) {
+ return mContext.getString(R.string.zen_mode_no_exceptions);
+ } else if (numCategories == 1) {
+ return mContext.getString(R.string.zen_mode_calls_summary_one,
+ enabledCategories.get(0).toLowerCase());
+ } else {
+ return mContext.getString(R.string.zen_mode_calls_summary_two,
+ enabledCategories.get(0).toLowerCase(),
+ enabledCategories.get(1).toLowerCase());
+ }
+ }
+
+ String getMsgEventReminderSettingSummary(Policy policy) {
+ List enabledCategories = getEnabledCategories(policy,
+ category -> PRIORITY_CATEGORY_EVENTS == category
+ || PRIORITY_CATEGORY_REMINDERS == category
+ || PRIORITY_CATEGORY_MESSAGES == category);
int numCategories = enabledCategories.size();
if (numCategories == 0) {
return mContext.getString(R.string.zen_mode_no_exceptions);
@@ -193,22 +242,19 @@ public class ZenModeSettings extends ZenModeSettingsBase {
return count;
}
- private List getEnabledCategories(Policy policy) {
+ private List getEnabledCategories(Policy policy,
+ Predicate filteredCategories) {
List enabledCategories = new ArrayList<>();
for (int category : ALL_PRIORITY_CATEGORIES) {
- if (isCategoryEnabled(policy, category)) {
- if (category == Policy.PRIORITY_CATEGORY_ALARMS) {
+ if (filteredCategories.test(category) && isCategoryEnabled(policy, category)) {
+ if (category == PRIORITY_CATEGORY_ALARMS) {
enabledCategories.add(mContext.getString(R.string.zen_mode_alarms));
- } else if (category == Policy.PRIORITY_CATEGORY_MEDIA) {
+ } else if (category == PRIORITY_CATEGORY_MEDIA) {
enabledCategories.add(mContext.getString(
R.string.zen_mode_media));
- } else if (category == Policy.PRIORITY_CATEGORY_SYSTEM) {
+ } else if (category == PRIORITY_CATEGORY_SYSTEM) {
enabledCategories.add(mContext.getString(
R.string.zen_mode_system));
- } else if (category == Policy.PRIORITY_CATEGORY_REMINDERS) {
- enabledCategories.add(mContext.getString(R.string.zen_mode_reminders));
- } else if (category == Policy.PRIORITY_CATEGORY_EVENTS) {
- enabledCategories.add(mContext.getString(R.string.zen_mode_events));
} else if (category == Policy.PRIORITY_CATEGORY_MESSAGES) {
if (policy.priorityMessageSenders == Policy.PRIORITY_SENDERS_ANY) {
enabledCategories.add(mContext.getString(
@@ -217,13 +263,20 @@ public class ZenModeSettings extends ZenModeSettingsBase {
enabledCategories.add(mContext.getString(
R.string.zen_mode_selected_messages));
}
+ } else if (category == Policy.PRIORITY_CATEGORY_EVENTS) {
+ enabledCategories.add(mContext.getString(R.string.zen_mode_events));
+ } else if (category == Policy.PRIORITY_CATEGORY_REMINDERS) {
+ enabledCategories.add(mContext.getString(R.string.zen_mode_reminders));
} else if (category == Policy.PRIORITY_CATEGORY_CALLS) {
if (policy.priorityCallSenders == Policy.PRIORITY_SENDERS_ANY) {
enabledCategories.add(mContext.getString(
R.string.zen_mode_all_callers));
+ } else if (policy.priorityCallSenders == Policy.PRIORITY_SENDERS_CONTACTS){
+ enabledCategories.add(mContext.getString(
+ R.string.zen_mode_contacts_callers));
} else {
enabledCategories.add(mContext.getString(
- R.string.zen_mode_selected_callers));
+ R.string.zen_mode_starred_callers));
}
} else if (category == Policy.PRIORITY_CATEGORY_REPEAT_CALLERS) {
if (!enabledCategories.contains(mContext.getString(
@@ -240,10 +293,6 @@ public class ZenModeSettings extends ZenModeSettingsBase {
private boolean isCategoryEnabled(Policy policy, int categoryType) {
return (policy.priorityCategories & categoryType) != 0;
}
-
- private boolean isEffectSuppressed(Policy policy, int effect) {
- return (policy.suppressedVisualEffects & effect) != 0;
- }
}
/**
diff --git a/src/com/android/settings/notification/ZenModeSoundVibrationSettings.java b/src/com/android/settings/notification/ZenModeSoundVibrationSettings.java
new file mode 100644
index 00000000000..d100e12798d
--- /dev/null
+++ b/src/com/android/settings/notification/ZenModeSoundVibrationSettings.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2018 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.notification;
+
+import android.content.Context;
+import android.provider.SearchIndexableResource;
+
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ZenModeSoundVibrationSettings extends ZenModeSettingsBase implements Indexable {
+
+ @Override
+ protected List createPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context, getLifecycle());
+ }
+
+ private static List buildPreferenceControllers(Context context,
+ Lifecycle lifecycle) {
+ List controllers = new ArrayList<>();
+ controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeMediaPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeSystemPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle,
+ R.string.zen_sound_footer));
+ return controllers;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.zen_mode_sound_vibration_settings;
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsEvent.NOTIFICATION_ZEN_MODE_PRIORITY;
+ }
+
+ /**
+ * For Search.
+ */
+ public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+
+ @Override
+ public List getXmlResourcesToIndex(Context context,
+ boolean enabled) {
+ final ArrayList result = new ArrayList<>();
+
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.zen_mode_sound_vibration_settings;
+ result.add(sir);
+ return result;
+ }
+
+ @Override
+ public List getNonIndexableKeys(Context context) {
+ final List keys = super.getNonIndexableKeys(context);
+ return keys;
+ }
+
+ @Override
+ public List createPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context, null);
+ }
+ };
+}
diff --git a/src/com/android/settings/search/SearchIndexableResourcesImpl.java b/src/com/android/settings/search/SearchIndexableResourcesImpl.java
index d5e4eb9983c..0001c7dae29 100644
--- a/src/com/android/settings/search/SearchIndexableResourcesImpl.java
+++ b/src/com/android/settings/search/SearchIndexableResourcesImpl.java
@@ -75,10 +75,12 @@ import com.android.settings.nfc.PaymentSettings;
import com.android.settings.notification.ConfigureNotificationSettings;
import com.android.settings.notification.SoundSettings;
import com.android.settings.notification.ZenModeAutomationSettings;
-import com.android.settings.notification.ZenModeBehaviorSettings;
+import com.android.settings.notification.ZenModeCallsSettings;
+import com.android.settings.notification.ZenModeMsgEventReminderSettings;
import com.android.settings.notification.ZenModeBlockedEffectsSettings;
import com.android.settings.notification.ZenModeRestrictNotificationsSettings;
import com.android.settings.notification.ZenModeSettings;
+import com.android.settings.notification.ZenModeSoundVibrationSettings;
import com.android.settings.print.PrintSettingsFragment;
import com.android.settings.security.EncryptionAndCredential;
import com.android.settings.security.LockscreenDashboardFragment;
@@ -178,7 +180,9 @@ public class SearchIndexableResourcesImpl implements SearchIndexableResources {
addIndex(LockscreenDashboardFragment.class);
addIndex(UsbDetailsFragment.class);
addIndex(WifiDisplaySettings.class);
- addIndex(ZenModeBehaviorSettings.class);
+ addIndex(ZenModeMsgEventReminderSettings.class);
+ addIndex(ZenModeCallsSettings.class);
+ addIndex(ZenModeSoundVibrationSettings.class);
addIndex(ZenModeBlockedEffectsSettings.class);
addIndex(ZenModeAutomationSettings.class);
addIndex(ZenModeRestrictNotificationsSettings.class);
diff --git a/tests/robotests/src/com/android/settings/core/SettingsSliderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/core/SettingsSliderPreferenceControllerTest.java
new file mode 100644
index 00000000000..8553f114d5b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/core/SettingsSliderPreferenceControllerTest.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2018 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.core;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import com.android.settings.widget.SeekBarPreference;
+
+import com.android.settings.slices.SliceData;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class SettingsSliderPreferenceControllerTest {
+
+ private FakeSliderPreferenceController mSliderController;
+
+ private SeekBarPreference mPreference;
+
+ @Before
+ public void setUp() {
+ mPreference = new SeekBarPreference(RuntimeEnvironment.application);
+ mSliderController = new FakeSliderPreferenceController(RuntimeEnvironment.application,
+ "key");
+
+ mPreference.setContinuousUpdates(true);
+ mPreference.setMax(mSliderController.getMaxSteps());
+ }
+
+ @Test
+ public void onPreferenceChange_updatesPosition() {
+ final int newValue = 28;
+
+ mSliderController.onPreferenceChange(mPreference, newValue);
+
+ assertThat(mSliderController.getSliderPosition()).isEqualTo(newValue);
+ }
+
+ @Test
+ public void updateState_setsPreferenceToCurrentValue() {
+ final int newValue = 28;
+ mSliderController.setSliderPosition(newValue);
+
+ mSliderController.updateState(mPreference);
+
+ assertThat(mPreference.getProgress()).isEqualTo(newValue);
+ }
+
+ @Test
+ public void testSliceType_returnsSliceType() {
+ assertThat(mSliderController.getSliceType()).isEqualTo(
+ SliceData.SliceType.SLIDER);
+ }
+
+ private class FakeSliderPreferenceController extends SliderPreferenceController {
+
+ private final int MAX_STEPS = 2112;
+ private int mPosition;
+
+ public FakeSliderPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ public int getSliderPosition() {
+ return mPosition;
+ }
+
+ @Override
+ public boolean setSliderPosition(int position) {
+ mPosition = position;
+ return true;
+ }
+
+ @Override
+ public int getMaxSteps() {
+ return MAX_STEPS;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/core/SliderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/core/SliderPreferenceControllerTest.java
index f9f656ed9d2..2d598c5f5cd 100644
--- a/tests/robotests/src/com/android/settings/core/SliderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/core/SliderPreferenceControllerTest.java
@@ -30,10 +30,10 @@ import org.robolectric.RuntimeEnvironment;
@RunWith(SettingsRobolectricTestRunner.class)
public class SliderPreferenceControllerTest {
- FakeSlider mSliderController;
+ private FakeSlider mSliderController;
- Context mContext;
- SeekBarPreference mPreference;
+ private Context mContext;
+ private SeekBarPreference mPreference;
@Before
public void setUp() {
diff --git a/tests/robotests/src/com/android/settings/display/NightDisplayActivationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/NightDisplayActivationPreferenceControllerTest.java
new file mode 100644
index 00000000000..88adc51c4a2
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/NightDisplayActivationPreferenceControllerTest.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2018 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;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.provider.Settings.Secure;
+import android.support.v7.preference.PreferenceScreen;
+
+import android.view.View;
+import com.android.settings.R;
+import com.android.settings.applications.LayoutPreference;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = SettingsShadowResources.class)
+public class NightDisplayActivationPreferenceControllerTest {
+
+ @Mock
+ private PreferenceScreen mScreen;
+ private LayoutPreference mPreference;
+ private Context mContext;
+ private NightDisplayActivationPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mPreference = new LayoutPreference(mContext, R.layout.night_display_activation_button);
+ when(mScreen.findPreference(anyString())).thenReturn(mPreference);
+ mController = new NightDisplayActivationPreferenceController(mContext,
+ "night_display_activation");
+ mController.displayPreference(mScreen);
+ }
+
+ @Test
+ public void isAvailable_configuredAvailable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_nightDisplayAvailable, true);
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_configuredUnavailable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_nightDisplayAvailable, false);
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void onClick_activates() {
+ Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 0);
+
+ final View view = mPreference.findViewById(R.id.night_display_turn_on_button);
+ assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
+ view.performClick();
+
+ assertThat(Secure.getInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, -1))
+ .isEqualTo(1);
+ }
+
+ @Test
+ public void onClick_deactivates() {
+ Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 1);
+
+ final View view = mPreference.findViewById(R.id.night_display_turn_on_button);
+ assertThat(view.getVisibility()).isEqualTo(View.VISIBLE);
+ view.performClick();
+
+ assertThat(Secure.getInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, -1))
+ .isEqualTo(0);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/display/NightDisplayAutoModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/NightDisplayAutoModePreferenceControllerTest.java
new file mode 100644
index 00000000000..20b03809209
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/NightDisplayAutoModePreferenceControllerTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2018 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;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.provider.Settings.Secure;
+import com.android.internal.app.ColorDisplayController;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = SettingsShadowResources.class)
+public class NightDisplayAutoModePreferenceControllerTest {
+
+ private Context mContext;
+ private NightDisplayAutoModePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mController = new NightDisplayAutoModePreferenceController(mContext,
+ "night_display_auto_mode");
+ }
+
+ @Test
+ public void isAvailable_configuredAvailable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_nightDisplayAvailable, true);
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_configuredUnavailable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_nightDisplayAvailable, false);
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void onPreferenceChange_changesAutoMode() {
+ mController.onPreferenceChange(null,
+ String.valueOf(ColorDisplayController.AUTO_MODE_TWILIGHT));
+ assertThat(Secure.getInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE, -1))
+ .isEqualTo(ColorDisplayController.AUTO_MODE_TWILIGHT);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/display/NightDisplayCustomEndTimePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/NightDisplayCustomEndTimePreferenceControllerTest.java
new file mode 100644
index 00000000000..ed6618b1a60
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/NightDisplayCustomEndTimePreferenceControllerTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2018 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;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = SettingsShadowResources.class)
+public class NightDisplayCustomEndTimePreferenceControllerTest {
+
+ private NightDisplayCustomEndTimePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mController = new NightDisplayCustomEndTimePreferenceController(
+ RuntimeEnvironment.application, "night_display_end_time");
+ }
+
+ @Test
+ public void isAvailable_configuredAvailable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_nightDisplayAvailable, true);
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_configuredUnavailable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_nightDisplayAvailable, false);
+ assertThat(mController.isAvailable()).isFalse();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/display/NightDisplayCustomStartTimePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/NightDisplayCustomStartTimePreferenceControllerTest.java
new file mode 100644
index 00000000000..c41300079da
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/NightDisplayCustomStartTimePreferenceControllerTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2018 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;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = SettingsShadowResources.class)
+public class NightDisplayCustomStartTimePreferenceControllerTest {
+
+ private NightDisplayCustomStartTimePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mController = new NightDisplayCustomStartTimePreferenceController(
+ RuntimeEnvironment.application, "night_display_start_time");
+ }
+
+ @Test
+ public void isAvailable_configuredAvailable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_nightDisplayAvailable, true);
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_configuredUnavailable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_nightDisplayAvailable, false);
+ assertThat(mController.isAvailable()).isFalse();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/display/NightDisplayFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/NightDisplayFooterPreferenceControllerTest.java
new file mode 100644
index 00000000000..8168c203a5a
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/NightDisplayFooterPreferenceControllerTest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2018 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;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = SettingsShadowResources.class)
+public class NightDisplayFooterPreferenceControllerTest {
+
+ private NightDisplayFooterPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mController = new NightDisplayFooterPreferenceController(RuntimeEnvironment.application);
+ }
+
+ @Test
+ public void isAvailable_configuredAvailable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_nightDisplayAvailable, true);
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_configuredUnavailable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_nightDisplayAvailable, false);
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/display/NightDisplayIntensityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/NightDisplayIntensityPreferenceControllerTest.java
new file mode 100644
index 00000000000..1a69b6b84e6
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/display/NightDisplayIntensityPreferenceControllerTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2018 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;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.provider.Settings.Secure;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowResources;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = SettingsShadowResources.class)
+public class NightDisplayIntensityPreferenceControllerTest {
+
+ private Context mContext;
+ private NightDisplayIntensityPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mController = new NightDisplayIntensityPreferenceController(mContext,
+ "night_display_temperature");
+ }
+
+ @Test
+ public void isAvailable_configuredAvailable_isActivated_available() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_nightDisplayAvailable, true);
+ Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 1);
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_configuredAvailable_isNotActivated_available() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_nightDisplayAvailable, true);
+ Secure.putInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_ACTIVATED, 0);
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_configuredUnavailable_unavailable() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.bool.config_nightDisplayAvailable, false);
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void onPreferenceChange_changesTemperature() {
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.integer.config_nightDisplayColorTemperatureMin, 2950);
+ SettingsShadowResources.overrideResource(
+ com.android.internal.R.integer.config_nightDisplayColorTemperatureMax, 3050);
+ // A slider-adjusted "20" here would be 1/5 from the left / least-intense, i.e. 3030.
+ mController.onPreferenceChange(null, 20);
+
+ assertThat(Secure.getInt(mContext.getContentResolver(),
+ Secure.NIGHT_DISPLAY_COLOR_TEMPERATURE, -1))
+ .isEqualTo(3030);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceControllerTest.java
new file mode 100644
index 00000000000..70e79198fa2
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorCallsPreferenceControllerTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2018 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.notification;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationManager;
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public final class ZenModeBehaviorCallsPreferenceControllerTest {
+
+ private ZenModeBehaviorCallsPreferenceController mController;
+ @Mock
+ private NotificationManager mNotificationManager;
+ @Mock
+ private NotificationManager.Policy mPolicy;
+
+ private Context mContext;
+ @Mock
+ private ZenModeBackend mBackend;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
+
+ mContext = RuntimeEnvironment.application;
+ when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
+
+ mController = new ZenModeBehaviorCallsPreferenceController(
+ mContext, mock(Lifecycle.class));
+ ReflectionHelpers.setField(mController, "mBackend", mBackend);
+ }
+
+ @Test
+ public void testIsAvailable() {
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testHasSummary() {
+ Preference pref = mock(Preference.class);
+ mController.updateState(pref);
+ verify(pref).setSummary(any());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceControllerTest.java
index 2de559e0124..502059838c2 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorFooterPreferenceControllerTest.java
@@ -41,6 +41,7 @@ import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.util.ArrayMap;
+import com.android.settings.R;
import com.android.settings.notification.AbstractZenModePreferenceController.ZenModeConfigWrapper;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -77,6 +78,7 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
private Context mContext;
private ContentResolver mContentResolver;
+ private int mTitleResId = R.string.zen_sound_title;
@Before
public void setup() {
@@ -88,8 +90,8 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mNotificationManager.getZenModeConfig()).thenReturn(mZenModeConfig);
- mController =
- new ZenModeBehaviorFooterPreferenceController(mContext, mock(Lifecycle.class));
+ mController = new ZenModeBehaviorFooterPreferenceController(
+ mContext, mock(Lifecycle.class), mTitleResId);
ReflectionHelpers.setField(mController, "mZenModeConfigWrapper", mConfigWrapper);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
@@ -112,13 +114,13 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
@Test
public void priorityOnly_footerIsAvailable() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
- assertFalse(mController.isAvailable());
+ assertTrue(mController.isAvailable());
}
@Test
- public void zenModeOff_footerIsNotAvailable() {
+ public void zenModeOff_footerIsAvailable() {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
- assertFalse(mController.isAvailable());
+ assertTrue(mController.isAvailable());
}
@Test
@@ -126,7 +128,7 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_OFF);
mController.updateState(mockPref);
- verify(mockPref, never()).setTitle(any(String.class));
+ verify(mockPref).setTitle(mContext.getString(mTitleResId));
}
@Test
@@ -134,7 +136,7 @@ public class ZenModeBehaviorFooterPreferenceControllerTest {
Settings.Global.putInt(mContentResolver, ZEN_MODE, ZEN_MODE_IMPORTANT_INTERRUPTIONS);
mController.updateState(mockPref);
- verify(mockPref, never()).setTitle(any(String.class));
+ verify(mockPref).setTitle(mContext.getString(mTitleResId));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceControllerTest.java
new file mode 100644
index 00000000000..afd9f715931
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorMsgEventReminderPreferenceControllerTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2018 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.notification;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationManager;
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public final class ZenModeBehaviorMsgEventReminderPreferenceControllerTest {
+
+ private ZenModeBehaviorMsgEventReminderPreferenceController mController;
+ @Mock
+ private NotificationManager mNotificationManager;
+ @Mock
+ private NotificationManager.Policy mPolicy;
+
+ private Context mContext;
+ @Mock
+ private ZenModeBackend mBackend;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
+
+ mContext = RuntimeEnvironment.application;
+ when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
+
+ mController = new ZenModeBehaviorMsgEventReminderPreferenceController(
+ mContext, mock(Lifecycle.class));
+ ReflectionHelpers.setField(mController, "mBackend", mBackend);
+ }
+
+ @Test
+ public void testIsAvailable() {
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testHasSummary() {
+ Preference pref = mock(Preference.class);
+ mController.updateState(pref);
+ verify(pref).setSummary(any());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceControllerTest.java
new file mode 100644
index 00000000000..a56127113a8
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeBehaviorSoundPreferenceControllerTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2018 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.notification;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationManager;
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public final class ZenModeBehaviorSoundPreferenceControllerTest {
+
+ private ZenModeBehaviorSoundPreferenceController mController;
+ @Mock
+ private NotificationManager mNotificationManager;
+ @Mock
+ private NotificationManager.Policy mPolicy;
+
+ private Context mContext;
+ @Mock
+ private ZenModeBackend mBackend;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ ShadowApplication shadowApplication = ShadowApplication.getInstance();
+ shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
+
+ mContext = RuntimeEnvironment.application;
+ when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
+
+ mController = new ZenModeBehaviorSoundPreferenceController(
+ mContext, mock(Lifecycle.class));
+ ReflectionHelpers.setField(mController, "mBackend", mBackend);
+ }
+
+ @Test
+ public void testIsAvailable() {
+ assertTrue(mController.isAvailable());
+ }
+
+ @Test
+ public void testHasSummary() {
+ Preference pref = mock(Preference.class);
+ mController.updateState(pref);
+ verify(pref).setSummary(any());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
index b26989d3475..5b2782fb6b7 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeSettingsTest.java
@@ -20,9 +20,9 @@ import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import android.app.NotificationManager;
+import android.app.NotificationManager.Policy;
import android.content.Context;
import android.provider.SearchIndexableResource;
-import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -46,54 +46,140 @@ public class ZenModeSettingsTest {
mBuilder = new ZenModeSettings.SummaryBuilder(mContext);
}
- @Test
- public void testGetBehaviorSettingSummary_noSoundsCanBypass() {
- NotificationManager.Policy policy = new NotificationManager.Policy(0, 0, 0);
- final String result = mBuilder.getBehaviorSettingSummary(policy,
- Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
-
- String totalSilence = mContext.getString(R.string.zen_mode_no_exceptions);
- assertEquals(totalSilence, result);
- }
-
- @Test
- public void testGetBehaviorSettingSummary_alarmsAndMedia() {
- NotificationManager.Policy policy = new NotificationManager.Policy(
- NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS
- | NotificationManager.Policy.PRIORITY_CATEGORY_MEDIA,
- 0, 0);
- final String result = mBuilder.getBehaviorSettingSummary(policy,
- Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS);
-
- String alarmsAndMedia = mContext.getString(R.string.join_two_items,
- mContext.getString(R.string.zen_mode_alarms),
- mContext.getString(R.string.zen_mode_media).toLowerCase());
- assertEquals(alarmsAndMedia, result);
- }
-
@Test
public void testBlockedEffectsSummary_none() {
- NotificationManager.Policy policy = new NotificationManager.Policy(0, 0, 0, 0);
+ Policy policy = new Policy(0, 0, 0, 0);
assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_muted),
mBuilder.getBlockedEffectsSummary(policy));
}
@Test
public void testBlockedEffectsSummary_some() {
- NotificationManager.Policy policy = new NotificationManager.Policy(
- 0, 0, 0, NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK);
+ Policy policy = new Policy(0, 0, 0, NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK);
assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_custom),
mBuilder.getBlockedEffectsSummary(policy));
}
@Test
public void testBlockedEffectsSummary_all() {
- NotificationManager.Policy policy = new NotificationManager.Policy(
- 0, 0, 0, 511);
+ Policy policy = new Policy(0, 0, 0, 511);
assertEquals(mContext.getString(R.string.zen_mode_restrict_notifications_summary_hidden),
mBuilder.getBlockedEffectsSummary(policy));
}
+ @Test
+ public void testGetMsgEventReminderSettingSummary_none() {
+ Policy policy = new Policy(0, 0, 0, 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("None");
+ }
+
+ @Test
+ public void testGetMsgEventReminderSettingSummary_single() {
+ Policy policy = new Policy(
+ Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_EVENTS, 0 , 0 , 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Events");
+ }
+
+ @Test
+ public void testGetMsgEventReminderSettingSummary_someMsgs() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0,
+ Policy.PRIORITY_SENDERS_CONTACTS , 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Some messages");
+
+ policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0,
+ Policy.PRIORITY_SENDERS_STARRED , 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Some messages");
+ }
+
+ @Test
+ public void testGetMsgEventReminderSettingSummary_msgs() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MESSAGES, 0, 0, 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy)).isEqualTo("Messages");
+ }
+
+ @Test
+ public void testGetMsgEventReminderSettingSummary_someMsgsAndOther() {
+ Policy policy = new Policy(
+ Policy.PRIORITY_CATEGORY_MESSAGES | Policy.PRIORITY_CATEGORY_REMINDERS,
+ 0, Policy.PRIORITY_SENDERS_CONTACTS , 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy))
+ .isEqualTo("Some messages and reminders");
+ }
+
+ @Test
+ public void testGetMsgEventReminderSettingSummary_someMsgsAndAllOthers() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_EVENTS
+ | Policy.PRIORITY_CATEGORY_MESSAGES | Policy.PRIORITY_CATEGORY_REMINDERS,
+ 0, Policy.PRIORITY_SENDERS_CONTACTS , 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy))
+ .isEqualTo("Some messages, events, and reminders");
+ }
+
+ @Test
+ public void testGetMsgEventReminderSettingSummary_noMsgsAndOther() {
+ Policy policy = new Policy(
+ Policy.PRIORITY_CATEGORY_EVENTS | Policy.PRIORITY_CATEGORY_REMINDERS,
+ 0,0, 0);
+ assertThat(mBuilder.getMsgEventReminderSettingSummary(policy))
+ .isEqualTo("Events and reminders");
+ }
+
+ @Test
+ public void testGetCallsSettingSummary_none() {
+ Policy policy = new Policy(0, 0, 0, 0);
+ assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("None");
+ }
+
+ @Test
+ public void testGetCallsSettingSummary_contacts() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_CALLS,
+ Policy.PRIORITY_SENDERS_CONTACTS, 0, 0);
+ assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From contacts only");
+ }
+
+ @Test
+ public void testGetCallsSettingSummary_repeatCallers() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_REPEAT_CALLERS, 0, 0, 0);
+ assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From repeat callers only");
+ }
+
+ @Test
+ public void testGetCallsSettingSummary_starredRepeatCallers() {
+ Policy policy = new Policy(
+ Policy.PRIORITY_CATEGORY_REPEAT_CALLERS | Policy.PRIORITY_CATEGORY_CALLS,
+ Policy.PRIORITY_SENDERS_STARRED, 0, 0);
+ assertThat(mBuilder.getCallsSettingSummary(policy))
+ .isEqualTo("From starred contacts and repeat callers");
+ }
+
+ @Test
+ public void testGetSoundSettingSummary_allOff() {
+ Policy policy = new Policy(0, 0, 0, 0);
+ assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted");
+ }
+
+ @Test
+ public void testGetSoundSettingSummary_allOn() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_SYSTEM
+ | Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
+ assertThat(mBuilder.getSoundSettingSummary(policy))
+ .isEqualTo("Muted, but allow alarms, media, and touch sounds");
+ }
+
+ @Test
+ public void testGetSoundSettingSummary_allOffButOne() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
+ assertThat(mBuilder.getSoundSettingSummary(policy)).isEqualTo("Muted, but allow media");
+ }
+
+ @Test
+ public void testGetSoundSettingSummary_allOffButTwo() {
+ Policy policy = new Policy(Policy.PRIORITY_CATEGORY_SYSTEM
+ | Policy.PRIORITY_CATEGORY_MEDIA, 0, 0, 0);
+ assertThat(mBuilder.getSoundSettingSummary(policy))
+ .isEqualTo("Muted, but allow media and touch sounds");
+ }
+
@Test
public void searchProvider_shouldIndexDefaultXml() {
final List sir = ZenModeSettings.SEARCH_INDEX_DATA_PROVIDER