Merge "Zen automatic rule page ui changes"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 04c9235..4182fd9 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6870,6 +6870,9 @@
<!-- Do not disturb: Summary for the zen mode automation option Suggestion. [CHAR LIMIT=NONE] -->
<string name="zen_mode_automation_suggestion_summary">Limit sounds & vibrations at certain times</string>
+ <!-- Do not disturb: Switch toggle to toggle whether to use an automatic dnd rule or not [CHAR LIMIT=40] -->
+ <string name="zen_mode_use_automatic_rule">Use rule</string>
+
<!-- Do not disturb: Zen mode option: Important interruptions [CHAR LIMIT=60] -->
<string name="zen_mode_option_important_interruptions">Priority only</string>
diff --git a/res/xml/zen_mode_event_rule_settings.xml b/res/xml/zen_mode_event_rule_settings.xml
index 159dbe0..ea37855 100644
--- a/res/xml/zen_mode_event_rule_settings.xml
+++ b/res/xml/zen_mode_event_rule_settings.xml
@@ -28,12 +28,6 @@
android:key="zen_automatic_rule_switch"
android:layout="@layout/styled_switch_bar" />
- <!-- Rule name -->
- <Preference
- android:key="rule_name"
- android:title="@string/zen_mode_rule_name"
- android:persistent="false" />
-
<!-- During events for -->
<DropDownPreference
android:key="calendar"
diff --git a/res/xml/zen_mode_schedule_rule_settings.xml b/res/xml/zen_mode_schedule_rule_settings.xml
index a0c52c0..e201b87 100644
--- a/res/xml/zen_mode_schedule_rule_settings.xml
+++ b/res/xml/zen_mode_schedule_rule_settings.xml
@@ -28,12 +28,6 @@
android:key="zen_automatic_rule_switch"
android:layout="@layout/styled_switch_bar" />
- <!-- Rule name -->
- <Preference
- android:key="rule_name"
- android:title="@string/zen_mode_rule_name"
- android:persistent="false" />
-
<!-- Days -->
<Preference
android:key="days"
diff --git a/src/com/android/settings/notification/ZenAutomaticRuleHeaderPreferenceController.java b/src/com/android/settings/notification/ZenAutomaticRuleHeaderPreferenceController.java
index 8494998..39cbf5d 100644
--- a/src/com/android/settings/notification/ZenAutomaticRuleHeaderPreferenceController.java
+++ b/src/com/android/settings/notification/ZenAutomaticRuleHeaderPreferenceController.java
@@ -19,6 +19,7 @@
import static com.android.settings.widget.EntityHeaderController.PREF_KEY_APP_HEADER;
import android.app.AutomaticZenRule;
+import android.app.Fragment;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@@ -28,6 +29,7 @@
import android.util.Slog;
import android.view.View;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.core.PreferenceControllerMixin;
@@ -40,6 +42,7 @@
private final String KEY = PREF_KEY_APP_HEADER;
private final PreferenceFragment mFragment;
private AutomaticZenRule mRule;
+ private String mId;
private EntityHeaderController mController;
public ZenAutomaticRuleHeaderPreferenceController(Context context, PreferenceFragment fragment,
@@ -70,6 +73,14 @@
mController = EntityHeaderController
.newInstance(mFragment.getActivity(), mFragment,
pref.findViewById(R.id.entity_header));
+
+ mController.setEditZenRuleNameListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ ZenRuleNameDialog.show(mFragment, mRule.getName(), null,
+ new RuleNameChangeListener());
+ }
+ });
}
pref = mController.setIcon(getIcon())
@@ -77,7 +88,7 @@
.setPackageName(mRule.getOwner().getPackageName())
.setUid(mContext.getUserId())
.setHasAppInfoLink(false)
- .setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
+ .setButtonActions(EntityHeaderController.ActionType.ACTION_DND_RULE_PREFERENCE,
EntityHeaderController.ActionType.ACTION_NONE)
.done(mFragment.getActivity(), mContext);
@@ -98,7 +109,20 @@
return null;
}
- protected void onResume(AutomaticZenRule rule) {
+ protected void onResume(AutomaticZenRule rule, String id) {
mRule = rule;
+ mId = id;
+ }
+
+ public class RuleNameChangeListener implements ZenRuleNameDialog.PositiveClickListener {
+ public RuleNameChangeListener() {}
+
+ @Override
+ public void onOk(String ruleName, Fragment parent) {
+ mMetricsFeatureProvider.action(mContext,
+ MetricsProto.MetricsEvent.ACTION_ZEN_MODE_RULE_NAME_CHANGE_OK);
+ mRule.setName(ruleName);
+ mBackend.setZenRule(mId, mRule);
+ }
}
}
diff --git a/src/com/android/settings/notification/ZenAutomaticRuleSwitchPreferenceController.java b/src/com/android/settings/notification/ZenAutomaticRuleSwitchPreferenceController.java
index bc3fa25..a684d3e 100644
--- a/src/com/android/settings/notification/ZenAutomaticRuleSwitchPreferenceController.java
+++ b/src/com/android/settings/notification/ZenAutomaticRuleSwitchPreferenceController.java
@@ -20,6 +20,7 @@
import android.app.Fragment;
import android.content.Context;
import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
import android.widget.Switch;
import android.widget.Toast;
@@ -37,6 +38,7 @@
private String mId;
private Toast mEnabledToast;
private int mToastTextResource;
+ private SwitchBar mSwitchBar;
public ZenAutomaticRuleSwitchPreferenceController(Context context, Fragment parent,
int toastTextResource, Lifecycle lifecycle) {
@@ -54,26 +56,34 @@
return mRule != null && mId != null;
}
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ LayoutPreference pref = (LayoutPreference) screen.findPreference(KEY);
+ mSwitchBar = pref.findViewById(R.id.switch_bar);
+
+ if (mSwitchBar != null) {
+ mSwitchBar.setSwitchBarText(R.string.zen_mode_use_automatic_rule,
+ R.string.zen_mode_use_automatic_rule);
+ try {
+ mSwitchBar.addOnSwitchChangeListener(this);
+ } catch (IllegalStateException e) {
+ // an exception is thrown if you try to add the listener twice
+ }
+ mSwitchBar.show();
+ }
+ }
+
+
public void onResume(AutomaticZenRule rule, String id) {
mRule = rule;
mId = id;
}
public void updateState(Preference preference) {
- LayoutPreference pref = (LayoutPreference) preference;
- SwitchBar bar = pref.findViewById(R.id.switch_bar);
if (mRule != null) {
- bar.setChecked(mRule.isEnabled());
+ mSwitchBar.setChecked(mRule.isEnabled());
}
- if (bar != null) {
- bar.show();
- try {
- bar.addOnSwitchChangeListener(this);
- } catch (IllegalStateException e) {
- // an exception is thrown if you try to add the listener twice
- }
- }
- bar.show();
}
@Override
diff --git a/src/com/android/settings/notification/ZenModeBackend.java b/src/com/android/settings/notification/ZenModeBackend.java
index 158f9ac..e8f103e 100644
--- a/src/com/android/settings/notification/ZenModeBackend.java
+++ b/src/com/android/settings/notification/ZenModeBackend.java
@@ -173,8 +173,8 @@
savePolicy(getNewPriorityCategories(allowSenders, category),
priorityCallSenders, priorityMessagesSenders, mPolicy.suppressedVisualEffects);
- if (ZenModeSettingsBase.DEBUG) Log.d(TAG, "onPrefChange allow=" +
- stringCategory + allowSenders + " allow" + stringCategory + "From="
+ if (ZenModeSettingsBase.DEBUG) Log.d(TAG, "onPrefChange allow" +
+ stringCategory + "=" + allowSenders + " allow" + stringCategory + "From="
+ ZenModeConfig.sourceToString(allowSendersFrom));
}
diff --git a/src/com/android/settings/notification/ZenModeRuleSettingsBase.java b/src/com/android/settings/notification/ZenModeRuleSettingsBase.java
index 0234c8e..b5ea9c4 100644
--- a/src/com/android/settings/notification/ZenModeRuleSettingsBase.java
+++ b/src/com/android/settings/notification/ZenModeRuleSettingsBase.java
@@ -17,7 +17,6 @@
package com.android.settings.notification;
import android.app.AutomaticZenRule;
-import android.app.Fragment;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
@@ -25,12 +24,10 @@
import android.os.Bundle;
import android.service.notification.ConditionProviderService;
import android.support.v7.preference.Preference;
-import android.support.v7.preference.Preference.OnPreferenceClickListener;
import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import android.widget.Toast;
-import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -39,14 +36,11 @@
protected static final String TAG = ZenModeSettingsBase.TAG;
protected static final boolean DEBUG = ZenModeSettingsBase.DEBUG;
- private static final String KEY_RULE_NAME = "rule_name";
-
protected Context mContext;
protected boolean mDisableListeners;
protected AutomaticZenRule mRule;
protected String mId;
- private Preference mRuleName;
protected ZenAutomaticRuleHeaderPreferenceController mHeader;
protected ZenAutomaticRuleSwitchPreferenceController mSwitch;
@@ -79,18 +73,7 @@
}
super.onCreate(icicle);
-
onCreateInternal();
-
- final PreferenceScreen root = getPreferenceScreen();
- mRuleName = root.findPreference(KEY_RULE_NAME);
- mRuleName.setOnPreferenceClickListener(new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- showRuleNameDialog();
- return true;
- }
- });
}
@Override
@@ -113,11 +96,11 @@
protected void updateHeader() {
final PreferenceScreen screen = getPreferenceScreen();
- mSwitch.onResume(mRule,mId);
+ mSwitch.onResume(mRule, mId);
mSwitch.displayPreference(screen);
updatePreference(mSwitch);
- mHeader.onResume(mRule);
+ mHeader.onResume(mRule, mId);
mHeader.displayPreference(screen);
updatePreference(mHeader);
}
@@ -161,46 +144,20 @@
return false;
}
- private void showRuleNameDialog() {
- ZenRuleNameDialog.show(this, mRule.getName(), null, new RuleNameChangeListener());
- }
-
private void toastAndFinish() {
Toast.makeText(mContext, R.string.zen_mode_rule_not_found_text, Toast.LENGTH_SHORT)
.show();
getActivity().finish();
}
- private void updateRuleName() {
- if (mRule != null) {
- mRuleName.setSummary(mRule.getName());
- } else {
- if (DEBUG) Log.d(TAG, "updateRuleName - mRuleName "
- + "not updated; mRuleName returned null");
- }
- }
-
private AutomaticZenRule getZenRule() {
return NotificationManager.from(mContext).getAutomaticZenRule(mId);
}
private void updateControls() {
mDisableListeners = true;
- updateRuleName();
updateControlsInternal();
updateHeader();
mDisableListeners = false;
}
-
- public class RuleNameChangeListener implements ZenRuleNameDialog.PositiveClickListener {
- public RuleNameChangeListener() {}
-
- @Override
- public void onOk(String ruleName, Fragment parent) {
- mMetricsFeatureProvider.action(mContext,
- MetricsProto.MetricsEvent.ACTION_ZEN_MODE_RULE_NAME_CHANGE_OK);
- mRule.setName(ruleName);
- mBackend.setZenRule(mId, mRule);
- }
- }
}
diff --git a/src/com/android/settings/widget/EntityHeaderController.java b/src/com/android/settings/widget/EntityHeaderController.java
index 9b2c529..8607211 100644
--- a/src/com/android/settings/widget/EntityHeaderController.java
+++ b/src/com/android/settings/widget/EntityHeaderController.java
@@ -63,12 +63,14 @@
@IntDef({ActionType.ACTION_NONE,
ActionType.ACTION_APP_PREFERENCE,
- ActionType.ACTION_NOTIF_PREFERENCE})
+ ActionType.ACTION_NOTIF_PREFERENCE,
+ ActionType.ACTION_DND_RULE_PREFERENCE,})
@Retention(RetentionPolicy.SOURCE)
public @interface ActionType {
int ACTION_NONE = 0;
int ACTION_APP_PREFERENCE = 1;
int ACTION_NOTIF_PREFERENCE = 2;
+ int ACTION_DND_RULE_PREFERENCE = 3;
}
public static final String PREF_KEY_APP_HEADER = "pref_app_header";
@@ -99,6 +101,8 @@
private boolean mIsInstantApp;
+ private View.OnClickListener mEditRuleNameOnClickListener;
+
/**
* Creates a new instance of the controller.
*
@@ -212,6 +216,11 @@
return this;
}
+ public EntityHeaderController setEditZenRuleNameListener(View.OnClickListener listener) {
+ this.mEditRuleNameOnClickListener = listener;
+ return this;
+ }
+
/**
* Done mutating entity header, rebinds everything and return a new {@link LayoutPreference}.
*/
@@ -330,6 +339,16 @@
return;
}
switch (action) {
+ case ActionType.ACTION_DND_RULE_PREFERENCE: {
+ if (mEditRuleNameOnClickListener == null) {
+ button.setVisibility(View.GONE);
+ } else {
+ button.setImageResource(R.drawable.ic_mode_edit);
+ button.setVisibility(View.VISIBLE);
+ button.setOnClickListener(mEditRuleNameOnClickListener);
+ }
+ return;
+ }
case ActionType.ACTION_NOTIF_PREFERENCE: {
if (mAppNotifPrefIntent == null) {
button.setVisibility(View.GONE);
diff --git a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
index daa42b4..06b4d55 100644
--- a/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/widget/EntityHeaderControllerTest.java
@@ -165,6 +165,57 @@
}
@Test
+ public void bindButton_hasEditRuleNameClickListener_shouldShowButton() {
+ final ResolveInfo info = new ResolveInfo();
+ info.activityInfo = new ActivityInfo();
+ info.activityInfo.packageName = "123";
+ info.activityInfo.name = "321";
+ final View view = mLayoutInflater
+ .inflate(R.layout.settings_entity_header, null /* root */);
+ when(mActivity.getApplicationContext()).thenReturn(mContext);
+
+ mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
+ mController.setEditZenRuleNameListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ // do nothing
+ }
+ });
+ mController.setButtonActions(
+ EntityHeaderController.ActionType.ACTION_DND_RULE_PREFERENCE,
+ EntityHeaderController.ActionType.ACTION_NONE);
+ mController.done(mActivity);
+
+ final ImageButton button1 = view.findViewById(android.R.id.button1);
+ assertThat(button1.getVisibility()).isEqualTo(View.VISIBLE);
+ assertThat(button1.getDrawable()).isNotNull();
+ assertThat(view.findViewById(android.R.id.button2).getVisibility())
+ .isEqualTo(View.GONE);
+ }
+
+ @Test
+ public void bindButton_noEditRuleNameClickListener_shouldNotShowButton() {
+ final ResolveInfo info = new ResolveInfo();
+ info.activityInfo = new ActivityInfo();
+ info.activityInfo.packageName = "123";
+ info.activityInfo.name = "321";
+ final View view = mLayoutInflater
+ .inflate(R.layout.settings_entity_header, null /* root */);
+ when(mActivity.getApplicationContext()).thenReturn(mContext);
+
+ mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
+ mController.setButtonActions(
+ EntityHeaderController.ActionType.ACTION_DND_RULE_PREFERENCE,
+ EntityHeaderController.ActionType.ACTION_NONE);
+ mController.done(mActivity);
+
+ assertThat(view.findViewById(android.R.id.button1).getVisibility())
+ .isEqualTo(View.GONE);
+ assertThat(view.findViewById(android.R.id.button2).getVisibility())
+ .isEqualTo(View.GONE);
+ }
+
+
+ @Test
public void bindButton_noAppPref_shouldNotShowButton() {
final View appLinks = mLayoutInflater
.inflate(R.layout.settings_entity_header, null /* root */);