Merge "Zen automatic rule page ui changes"
This commit is contained in:
committed by
Android (Google) Code Review
commit
182a0fc91b
@@ -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>
|
||||
|
||||
|
@@ -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"
|
||||
|
@@ -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"
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.notification;
|
||||
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.support.v7.preference.Preference;
|
||||
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 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
|
||||
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 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
|
||||
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 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
|
||||
.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 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ import android.app.AutomaticZenRule;
|
||||
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 @@ public class ZenAutomaticRuleSwitchPreferenceController extends
|
||||
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 @@ public class ZenAutomaticRuleSwitchPreferenceController extends
|
||||
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
|
||||
|
@@ -173,8 +173,8 @@ public class ZenModeBackend {
|
||||
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));
|
||||
}
|
||||
|
||||
|
@@ -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.net.Uri;
|
||||
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 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
|
||||
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 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
|
||||
}
|
||||
|
||||
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 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
|
||||
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 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -63,12 +63,14 @@ public class EntityHeaderController {
|
||||
|
||||
@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 @@ public class EntityHeaderController {
|
||||
|
||||
private boolean mIsInstantApp;
|
||||
|
||||
private View.OnClickListener mEditRuleNameOnClickListener;
|
||||
|
||||
/**
|
||||
* Creates a new instance of the controller.
|
||||
*
|
||||
@@ -212,6 +216,11 @@ public class EntityHeaderController {
|
||||
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 @@ public class EntityHeaderController {
|
||||
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);
|
||||
|
@@ -164,6 +164,57 @@ public class EntityHeaderControllerTest {
|
||||
verify(mFragment).startActivity(any(Intent.class));
|
||||
}
|
||||
|
||||
@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
|
||||
|
Reference in New Issue
Block a user