Merge "Add zen onboarding screen" into pi-dev

This commit is contained in:
TreeHugger Robot
2018-04-10 14:35:44 +00:00
committed by Android (Google) Code Review
5 changed files with 523 additions and 0 deletions

View File

@@ -742,12 +742,30 @@
android:exported="true"
android:taskAffinity="com.android.settings"
android:parentActivityName="Settings">
<intent-filter android:priority="1">
<action android:name="android.settings.ZEN_MODE_BLOCKED_EFFECTS_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.notification.ZenModeBlockedEffectsSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
<activity
android:name=".notification.ZenOnboardingActivity"
android:label="@string/zen_onboarding_dnd_visual_disturbances_header"
android:icon="@drawable/ic_settings_notifications"
android:theme="@style/Theme.Settings.NoActionBar"
android:exported="true"
android:taskAffinity="com.android.settings"
android:parentActivityName="Settings">
<intent-filter android:priority="1">
<action android:name="android.settings.ZEN_MODE_ONBOARDING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="Settings$ZenModeBehaviorSettingsActivity"
android:label="@string/zen_mode_behavior_settings_title"

View File

@@ -0,0 +1,167 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp">
<ImageView
android:id="@+id/header_icon"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/ic_zen"
android:tint="?android:attr/colorAccent"/>
<TextView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/header_icon"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:text="@string/zen_onboarding_dnd_visual_disturbances_header"
android:textAppearance="@android:style/TextAppearance.Material.Headline" />
<TextView
android:id="@+id/feature_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:layout_centerHorizontal="true"
android:textAlignment="center"
android:layout_marginTop="14dp"
android:textAppearance="?android:attr/textAppearanceListItem"
android:text="@string/zen_onboarding_dnd_visual_disturbances_description" />
<LinearLayout
android:id="@+id/screen_off"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/feature_description"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:orientation="horizontal">
<CheckBox
android:id="@+id/screen_off_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="8dp"
android:onClick="logClick" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/screen_off_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/zen_onboarding_screen_off_title"
android:textAppearance="?android:attr/textAppearanceListItem" />
<TextView
android:id="@+id/screen_off_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/zen_onboarding_screen_off_summary" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/screen_on"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/screen_off"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<CheckBox
android:id="@+id/screen_on_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingHorizontal="8dp"
android:onClick="logClick" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/screen_on_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/zen_onboarding_screen_off_title"
android:textAppearance="?android:attr/textAppearanceListItem" />
<TextView
android:id="@+id/screen_on_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/zen_onboarding_screen_on_summary" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="@+id/further_customize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/screen_on"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textAppearance="?android:attr/textAppearanceListItem"
android:text="@string/zen_onboarding_more_options" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/further_customize"
android:layout_marginTop="35dp"
android:id="@+id/buttons">
<TextView
android:id="@+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_weight="1"
android:layout_centerInParent="true"
android:text="@string/zen_onboarding_settings"
android:textAppearance="?android:attr/textAppearanceListItem"
android:textColor="?android:attr/colorControlActivated"
android:onClick="launchSettings" />
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_weight="1"
android:layout_centerInParent="true"
android:text="@string/zen_onboarding_ok"
style="@style/ActionPrimaryButton"
android:onClick="save" />
</RelativeLayout>
</RelativeLayout>

View File

@@ -7325,6 +7325,16 @@
<item quantity="other"><xliff:g id="on_count" example="3">%d</xliff:g> rules can turn on automatically</item>
</plurals>
<string name="zen_onboarding_ok">Ok</string>
<string name="zen_onboarding_settings">Settings</string>
<string name="zen_onboarding_more_options">You can further customize this in Settings.</string>
<string name="zen_onboarding_screen_on_title">Block when the screen is on</string>
<string name="zen_onboarding_screen_off_title">Block when the screen is off</string>
<string name="zen_onboarding_dnd_visual_disturbances_description">Do Not Disturb can do more than block unwanted sounds - it can block visuals too. This may be helpful if you\'re trying to sleep, focus, or limit time spent on your phone.</string>
<string name="zen_onboarding_dnd_visual_disturbances_header">Block sounds and visuals</string>
<string name="zen_onboarding_screen_off_summary">Don\'t turn on the screen or show notifications in the ambient display</string>
<string name="zen_onboarding_screen_on_summary">Don\'t show notifications at all, except for basic phone activity and status</string>
<!-- Work Sounds: Work sound settings section header. [CHAR LIMIT=50] -->
<string name="sound_work_settings">Work profile sounds</string>

View File

@@ -0,0 +1,106 @@
/*
* 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.app.Activity;
import android.app.NotificationManager;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import android.view.View;
import android.widget.CheckBox;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
public class ZenOnboardingActivity extends Activity {
private NotificationManager mNm;
private MetricsLogger mMetrics;
CheckBox mScreenOn;
CheckBox mScreenOff;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setNotificationManager(getSystemService(NotificationManager.class));
setMetricsLogger(new MetricsLogger());
setupUI();
}
@VisibleForTesting
protected void setupUI() {
setContentView(R.layout.zen_onboarding);
mScreenOn = findViewById(R.id.screen_on_option);
mScreenOff = findViewById(R.id.screen_off_option);
mScreenOn.setChecked(true);
mScreenOff.setChecked(true);
mMetrics.visible(MetricsEvent.SETTINGS_ZEN_ONBOARDING);
}
@VisibleForTesting
protected void setNotificationManager(NotificationManager nm) {
mNm = nm;
}
@VisibleForTesting
protected void setMetricsLogger(MetricsLogger ml) {
mMetrics = ml;
}
public void logClick(View view) {
CheckBox checkbox = (CheckBox) view;
switch (checkbox.getId()) {
case R.id.screen_on_option:
mMetrics.action(MetricsEvent.ACTION_ZEN_ONBOARDING_SCREEN_ON, checkbox.isChecked());
break;
case R.id.screen_off_option:
mMetrics.action(MetricsEvent.ACTION_ZEN_ONBOARDING_SCREEN_OFF,
checkbox.isChecked());
break;
}
}
public void launchSettings(View button) {
mMetrics.action(MetricsEvent.ACTION_ZEN_ONBOARDING_SETTINGS);
Intent settings = new Intent(Settings.ZEN_MODE_BLOCKED_EFFECTS_SETTINGS);
settings.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(settings);
}
public void save(View button) {
mMetrics.action(MetricsEvent.ACTION_ZEN_ONBOARDING_OK);
NotificationManager.Policy policy = mNm.getNotificationPolicy();
int currentEffects = policy.suppressedVisualEffects;
currentEffects = NotificationManager.Policy.toggleScreenOnEffectsSuppressed(
currentEffects, mScreenOn != null && mScreenOn.isChecked());
currentEffects = NotificationManager.Policy.toggleScreenOffEffectsSuppressed(
currentEffects, mScreenOff != null && mScreenOff.isChecked());
NotificationManager.Policy newPolicy = new NotificationManager.Policy(
policy.priorityCategories, policy.priorityCallSenders,
policy.priorityMessageSenders, currentEffects);
mNm.setNotificationPolicy(newPolicy);
finishAndRemoveTask();
}
}

View File

@@ -0,0 +1,222 @@
/*
* 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 android.app.NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS;
import static android.app.NotificationManager.Policy.PRIORITY_SENDERS_ANY;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_OFF;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_SCREEN_ON;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationManager;
import android.app.NotificationManager.Policy;
import android.content.Context;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
@RunWith(SettingsRobolectricTestRunner.class)
public class ZenOnboardingActivityTest {
@Mock
MetricsLogger mMetricsLogger;
@Mock
NotificationManager mNm;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
ZenOnboardingActivity mActivity;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mActivity = Robolectric.buildActivity(ZenOnboardingActivity.class)
.create()
.get();
mActivity.setNotificationManager(mNm);
mActivity.setMetricsLogger(mMetricsLogger);
mActivity.setupUI();
}
@Test
public void loadUiRecordsEvent() {
verify(mMetricsLogger).visible(MetricsEvent.SETTINGS_ZEN_ONBOARDING);
}
@Test
public void toggleCheckBoxRecordsEvents_screenOn() {
mActivity.findViewById(R.id.screen_on_option).performClick();
verify(mMetricsLogger).action(MetricsEvent.ACTION_ZEN_ONBOARDING_SCREEN_ON, false);
mActivity.findViewById(R.id.screen_on_option).performClick();
verify(mMetricsLogger).action(MetricsEvent.ACTION_ZEN_ONBOARDING_SCREEN_ON, true);
}
@Test
public void toggleCheckBoxRecordsEvents_screenOff() {
mActivity.findViewById(R.id.screen_off_option).performClick();
verify(mMetricsLogger).action(MetricsEvent.ACTION_ZEN_ONBOARDING_SCREEN_OFF, false);
mActivity.findViewById(R.id.screen_off_option).performClick();
verify(mMetricsLogger).action(MetricsEvent.ACTION_ZEN_ONBOARDING_SCREEN_OFF, true);
}
@Test
public void save_screenOn() {
Policy policy = new Policy(
PRIORITY_CATEGORY_ALARMS, 0, 0,
SUPPRESSED_EFFECT_SCREEN_ON
| SUPPRESSED_EFFECT_SCREEN_OFF
| SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_PEEK
| SUPPRESSED_EFFECT_STATUS_BAR
| SUPPRESSED_EFFECT_BADGE
| SUPPRESSED_EFFECT_AMBIENT
| SUPPRESSED_EFFECT_NOTIFICATION_LIST);
when(mNm.getNotificationPolicy()).thenReturn(policy);
mActivity.findViewById(R.id.screen_off_option).performClick();
mActivity.save(null);
verify(mMetricsLogger).action(MetricsEvent.ACTION_ZEN_ONBOARDING_OK);
ArgumentCaptor<Policy> captor = ArgumentCaptor.forClass(Policy.class);
verify(mNm).setNotificationPolicy(captor.capture());
Policy actual = captor.getValue();
assertThat(actual.priorityCategories).isEqualTo(PRIORITY_CATEGORY_ALARMS);
assertThat(actual.suppressedVisualEffects).isEqualTo(
SUPPRESSED_EFFECT_SCREEN_ON | SUPPRESSED_EFFECT_NOTIFICATION_LIST
| SUPPRESSED_EFFECT_BADGE | SUPPRESSED_EFFECT_STATUS_BAR
| SUPPRESSED_EFFECT_PEEK);
}
@Test
public void save_screenOff() {
Policy policy = new Policy(
PRIORITY_CATEGORY_ALARMS, PRIORITY_SENDERS_ANY, 0,
SUPPRESSED_EFFECT_SCREEN_ON
| SUPPRESSED_EFFECT_SCREEN_OFF
| SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_PEEK
| SUPPRESSED_EFFECT_STATUS_BAR
| SUPPRESSED_EFFECT_BADGE
| SUPPRESSED_EFFECT_AMBIENT
| SUPPRESSED_EFFECT_NOTIFICATION_LIST);
when(mNm.getNotificationPolicy()).thenReturn(policy);
mActivity.findViewById(R.id.screen_on_option).performClick();
mActivity.save(null);
verify(mMetricsLogger).action(MetricsEvent.ACTION_ZEN_ONBOARDING_OK);
ArgumentCaptor<Policy> captor = ArgumentCaptor.forClass(Policy.class);
verify(mNm).setNotificationPolicy(captor.capture());
Policy actual = captor.getValue();
assertThat(actual.priorityCallSenders).isEqualTo(PRIORITY_SENDERS_ANY);
assertThat(actual.suppressedVisualEffects).isEqualTo(
SUPPRESSED_EFFECT_SCREEN_OFF | SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_LIGHTS | SUPPRESSED_EFFECT_AMBIENT);
}
@Test
public void save_none() {
Policy policy = new Policy(0, 0, 0,
SUPPRESSED_EFFECT_SCREEN_ON
| SUPPRESSED_EFFECT_SCREEN_OFF
| SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_PEEK
| SUPPRESSED_EFFECT_STATUS_BAR
| SUPPRESSED_EFFECT_BADGE
| SUPPRESSED_EFFECT_AMBIENT
| SUPPRESSED_EFFECT_NOTIFICATION_LIST);
when(mNm.getNotificationPolicy()).thenReturn(policy);
mActivity.findViewById(R.id.screen_on_option).performClick();
mActivity.findViewById(R.id.screen_off_option).performClick();
mActivity.save(null);
verify(mMetricsLogger).action(MetricsEvent.ACTION_ZEN_ONBOARDING_OK);
ArgumentCaptor<Policy> captor = ArgumentCaptor.forClass(Policy.class);
verify(mNm).setNotificationPolicy(captor.capture());
Policy actual = captor.getValue();
assertThat(actual.suppressedVisualEffects).isEqualTo(0);
}
@Test
public void save_all() {
Policy policy = new Policy(0, 0, 0, 0);
when(mNm.getNotificationPolicy()).thenReturn(policy);
mActivity.save(null);
verify(mMetricsLogger).action(MetricsEvent.ACTION_ZEN_ONBOARDING_OK);
ArgumentCaptor<Policy> captor = ArgumentCaptor.forClass(Policy.class);
verify(mNm).setNotificationPolicy(captor.capture());
Policy actual = captor.getValue();
assertThat(actual.suppressedVisualEffects).isEqualTo(
SUPPRESSED_EFFECT_SCREEN_ON
| SUPPRESSED_EFFECT_SCREEN_OFF
| SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
| SUPPRESSED_EFFECT_LIGHTS
| SUPPRESSED_EFFECT_PEEK
| SUPPRESSED_EFFECT_STATUS_BAR
| SUPPRESSED_EFFECT_BADGE
| SUPPRESSED_EFFECT_AMBIENT
| SUPPRESSED_EFFECT_NOTIFICATION_LIST);
}
}