summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Bjorn Bringert <bringert@android.com> 2009-09-17 10:47:35 +0100
committer Bjorn Bringert <bringert@android.com> 2009-09-18 12:09:23 +0100
commitad8da91895afa7e8a97a9d681471d51924461cff (patch)
treeb7a9472242f81e8fa52e7da542fbd638fc2802b4
parent0050ee36398c3ab6e5f1ee0038609aff8cf4f0e9 (diff)
Reset typeface when changing from visible password inputType
Before, when changing a TextView from TYPE_TEXT_VARIATION_VISIBLE_PASSWORD to a non-password input type, the typeface remained monospaced. Fixes http://b/issue?id=2126708 "TextView does not restore typeface when changing inputType from password to text" Change-Id: Iad704640f69beed10a4b3deec7c38f3eba7b91ee
-rw-r--r--core/java/android/widget/TextView.java41
1 files changed, 27 insertions, 14 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 2e3364b9e321..3c61c1c4e61e 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -2874,26 +2874,23 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* @attr ref android.R.styleable#TextView_inputType
*/
public void setInputType(int type) {
+ final boolean wasPassword = isPasswordInputType(mInputType);
+ final boolean wasVisiblePassword = isVisiblePasswordInputType(mInputType);
setInputType(type, false);
- final int variation = type&(EditorInfo.TYPE_MASK_CLASS
- |EditorInfo.TYPE_MASK_VARIATION);
- final boolean isPassword = variation
- == (EditorInfo.TYPE_CLASS_TEXT
- |EditorInfo.TYPE_TEXT_VARIATION_PASSWORD);
+ final boolean isPassword = isPasswordInputType(type);
+ final boolean isVisiblePassword = isVisiblePasswordInputType(type);
boolean forceUpdate = false;
if (isPassword) {
setTransformationMethod(PasswordTransformationMethod.getInstance());
setTypefaceByIndex(MONOSPACE, 0);
- } else if (mTransformation == PasswordTransformationMethod.getInstance()) {
- // We need to clean up if we were previously in password mode.
- if (variation != (EditorInfo.TYPE_CLASS_TEXT
- |EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD)) {
- setTypefaceByIndex(-1, -1);
- }
- forceUpdate = true;
- } else if (variation == (EditorInfo.TYPE_CLASS_TEXT
- |EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD)) {
+ } else if (isVisiblePassword) {
setTypefaceByIndex(MONOSPACE, 0);
+ } else if (wasPassword || wasVisiblePassword) {
+ // not in password mode, clean up typeface and transformation
+ setTypefaceByIndex(-1, -1);
+ if (mTransformation == PasswordTransformationMethod.getInstance()) {
+ forceUpdate = true;
+ }
}
boolean multiLine = (type&(EditorInfo.TYPE_MASK_CLASS
@@ -2913,6 +2910,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
if (imm != null) imm.restartInput(this);
}
+ private boolean isPasswordInputType(int inputType) {
+ final int variation = inputType & (EditorInfo.TYPE_MASK_CLASS
+ | EditorInfo.TYPE_MASK_VARIATION);
+ return variation
+ == (EditorInfo.TYPE_CLASS_TEXT
+ | EditorInfo.TYPE_TEXT_VARIATION_PASSWORD);
+ }
+
+ private boolean isVisiblePasswordInputType(int inputType) {
+ final int variation = inputType & (EditorInfo.TYPE_MASK_CLASS
+ | EditorInfo.TYPE_MASK_VARIATION);
+ return variation
+ == (EditorInfo.TYPE_CLASS_TEXT
+ | EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
+ }
+
/**
* Directly change the content type integer of the text view, without
* modifying any other state.