diff --git a/res/layout/zen_rule_name.xml b/res/layout/zen_rule_name.xml
index 31a5df89bcc..39262ab2438 100755
--- a/res/layout/zen_rule_name.xml
+++ b/res/layout/zen_rule_name.xml
@@ -32,13 +32,23 @@
+
+
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 3bcf1ae987c..a1859caf496 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -50,6 +50,8 @@
#89ffffff
#89000000
+ #fff4511e
+
#00000000
#ff37474f
@color/warning
@@ -57,7 +59,7 @@
#ffffff
@android:color/white
- #fff4511e
+ @color/system_warning_color
#ff009688
#ffffffff
@@ -96,4 +98,6 @@
#ff009587
#ffced7db
+ @color/system_warning_color
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ca04c71fe6a..fc61b897cc4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6104,6 +6104,9 @@
Enter rule name
+
+ Rule name already in use
+
Add rule
diff --git a/src/com/android/settings/notification/ZenRuleNameDialog.java b/src/com/android/settings/notification/ZenRuleNameDialog.java
index 1279ee6c179..c06038ed465 100644
--- a/src/com/android/settings/notification/ZenRuleNameDialog.java
+++ b/src/com/android/settings/notification/ZenRuleNameDialog.java
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.content.pm.ServiceInfo;
+import android.content.res.ColorStateList;
import android.net.Uri;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenModeConfig.EventInfo;
@@ -31,6 +32,7 @@ import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.ArraySet;
import android.util.Log;
+import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
@@ -47,7 +49,10 @@ public abstract class ZenRuleNameDialog {
private final AlertDialog mDialog;
private final EditText mEditText;
+ private final View mWarning;
private final RadioGroup mTypes;
+ private final ColorStateList mWarningTint;
+ private final ColorStateList mOriginalTint;
private final String mOriginalRuleName;
private final ArraySet mExistingNames;
private final ServiceListing mServiceListing;
@@ -59,11 +64,16 @@ public abstract class ZenRuleNameDialog {
mServiceListing = serviceListing;
mIsNew = ruleName == null;
mOriginalRuleName = ruleName;
+ mWarningTint = ColorStateList.valueOf(context.getColor(R.color.zen_rule_name_warning));
final View v = LayoutInflater.from(context).inflate(R.layout.zen_rule_name, null, false);
mEditText = (EditText) v.findViewById(R.id.rule_name);
+ mWarning = v.findViewById(R.id.rule_name_warning);
if (!mIsNew) {
mEditText.setText(ruleName);
}
+ TypedValue outValue = new TypedValue();
+ context.getTheme().resolveAttribute(android.R.attr.colorAccent, outValue, true);
+ mOriginalTint = ColorStateList.valueOf(outValue.data);
mEditText.setSelectAllOnFocus(true);
mTypes = (RadioGroup) v.findViewById(R.id.rule_types);
if (mServiceListing != null) {
@@ -112,7 +122,7 @@ public abstract class ZenRuleNameDialog {
@Override
public void afterTextChanged(Editable s) {
- updatePositiveButton();
+ updatePositiveButtonAndWarning();
}
});
mExistingNames = new ArraySet(existingNames.size());
@@ -125,7 +135,7 @@ public abstract class ZenRuleNameDialog {
public void show() {
mDialog.show();
- updatePositiveButton();
+ updatePositiveButtonAndWarning();
}
private void bindType(int id, RuleInfo ri) {
@@ -152,12 +162,15 @@ public abstract class ZenRuleNameDialog {
return mEditText.getText() == null ? null : mEditText.getText().toString().trim();
}
- private void updatePositiveButton() {
+ private void updatePositiveButtonAndWarning() {
final String name = trimmedText();
final boolean validName = !TextUtils.isEmpty(name)
&& (name.equalsIgnoreCase(mOriginalRuleName)
|| !mExistingNames.contains(name.toLowerCase()));
mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(validName);
+ final boolean showWarning = !TextUtils.isEmpty(name) && !validName;
+ mWarning.setVisibility(showWarning ? View.VISIBLE : View.INVISIBLE);
+ mEditText.setBackgroundTintList(showWarning ? mWarningTint : mOriginalTint);
}
private static RuleInfo defaultNewSchedule() {