Settings: Add zen rule name warning text.
Bug: 21307309
Change-Id: Id08e3bdebb9a87dc474f2551f17268d655c8b4ea
diff --git a/res/layout/zen_rule_name.xml b/res/layout/zen_rule_name.xml
index 31a5df8..39262ab 100755
--- a/res/layout/zen_rule_name.xml
+++ b/res/layout/zen_rule_name.xml
@@ -32,13 +32,23 @@
</EditText>
+ <TextView
+ android:id="@+id/rule_name_warning"
+ android:visibility="invisible"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:layout_marginLeft="26dp"
+ android:layout_marginRight="26dp"
+ android:textColor="@color/zen_rule_name_warning"
+ android:text="@string/zen_mode_rule_name_warning" />
+
<RadioGroup
android:id="@+id/rule_types"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="22dp"
android:layout_marginRight="22dp"
- android:layout_marginTop="16dp"
android:orientation="vertical"
android:checkedButton="@+id/rule_type_schedule" >
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 3bcf1ae..a1859ca 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -50,6 +50,8 @@
<color name="setup_wizard_wifi_color_dark">#89ffffff</color>
<color name="setup_wizard_wifi_color_light">#89000000</color>
+ <color name="system_warning_color">#fff4511e</color><!-- deep orange 600 -->
+
<color name="lock_pattern_background">#00000000</color>
<color name="lock_pattern_view_regular_color">#ff37474f</color>
<color name="lock_pattern_view_error_color">@color/warning</color>
@@ -57,7 +59,7 @@
<color name="lock_pattern_view_regular_color_dark">#ffffff</color>
<color name="unlock_pattern_view_regular_color">@android:color/white</color>
- <color name="unlock_pattern_view_error_color">#fff4511e</color>
+ <color name="unlock_pattern_view_error_color">@color/system_warning_color</color>
<color name="fingerprint_title_area_bg">#ff009688</color>
<color name="fingerprint_title_color">#ffffffff</color>
@@ -96,4 +98,6 @@
<color name="memory_max_use">#ff009587</color>
<color name="memory_remaining">#ffced7db</color>
+ <color name="zen_rule_name_warning">@color/system_warning_color</color>
+
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9569b5c..58169f8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6102,6 +6102,9 @@
<!-- [CHAR LIMIT=40] Zen mode settings: Rule name hint text -->
<string name="zen_mode_rule_name_hint">Enter rule name</string>
+ <!-- [CHAR LIMIT=100] Zen mode settings: Warning text for invalid zen rule names -->
+ <string name="zen_mode_rule_name_warning">Rule name already in use</string>
+
<!-- [CHAR LIMIT=40] Zen mode settings: Add rule menu option name -->
<string name="zen_mode_add_rule">Add rule</string>
diff --git a/src/com/android/settings/notification/ZenRuleNameDialog.java b/src/com/android/settings/notification/ZenRuleNameDialog.java
index 1279ee6..c06038e 100644
--- a/src/com/android/settings/notification/ZenRuleNameDialog.java
+++ b/src/com/android/settings/notification/ZenRuleNameDialog.java
@@ -22,6 +22,7 @@
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.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 @@
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<String> mExistingNames;
private final ServiceListing mServiceListing;
@@ -59,11 +64,16 @@
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 @@
@Override
public void afterTextChanged(Editable s) {
- updatePositiveButton();
+ updatePositiveButtonAndWarning();
}
});
mExistingNames = new ArraySet<String>(existingNames.size());
@@ -125,7 +135,7 @@
public void show() {
mDialog.show();
- updatePositiveButton();
+ updatePositiveButtonAndWarning();
}
private void bindType(int id, RuleInfo ri) {
@@ -152,12 +162,15 @@
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() {