OSDN Git Service

Add TYPE_NUMBER_VARIATION_PASSWORD for entering a numeric password.
authorKen Wakasa <kwakasa@google.com>
Fri, 24 Dec 2010 14:42:41 +0000 (23:42 +0900)
committerKen Wakasa <kwakasa@google.com>
Fri, 24 Dec 2010 16:22:53 +0000 (01:22 +0900)
Also, bug fix in EditoInfo.makeCompatible().

bug: 3296883
Change-Id: Icc663b375cffbe1f4506d1758d624a1acca3576b

api/current.xml
core/java/android/text/InputType.java
core/java/android/view/inputmethod/EditorInfo.java
core/java/android/widget/TextView.java
core/res/res/values/attrs.xml

index 54cdbd7..2431b1d 100644 (file)
  visibility="public"
 >
 </field>
+<field name="TYPE_NUMBER_VARIATION_NORMAL"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="0"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+<field name="TYPE_NUMBER_VARIATION_PASSWORD"
+ type="int"
+ transient="false"
+ volatile="false"
+ value="16"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
 <field name="TYPE_TEXT_FLAG_AUTO_COMPLETE"
  type="int"
  transient="false"
index 7b8acd9..6d066d6 100644 (file)
@@ -257,7 +257,10 @@ public interface InputType {
     /**
      * Class for numeric text.  This class supports the following flag:
      * {@link #TYPE_NUMBER_FLAG_SIGNED} and
-     * {@link #TYPE_NUMBER_FLAG_DECIMAL}.
+     * {@link #TYPE_NUMBER_FLAG_DECIMAL}.  It also supports the following
+     * variations: {@link #TYPE_NUMBER_VARIATION_NORMAL} and
+     * {@link #TYPE_NUMBER_VARIATION_PASSWORD}.  If you do not recognize
+     * the variation, normal should be assumed.
      */
     public static final int TYPE_CLASS_NUMBER = 0x00000002;
     
@@ -274,6 +277,29 @@ public interface InputType {
     public static final int TYPE_NUMBER_FLAG_DECIMAL = 0x00002000;
     
     // ----------------------------------------------------------------------
+
+    /**
+     * Default variation of {@link #TYPE_CLASS_NUMBER}: plain normal
+     * numeric text.  This was added in
+     * {@link android.os.Build.VERSION_CODES#HONEYCOMB}.  An IME must target
+     * this API version or later to see this input type; if it doesn't, a request
+     * for this type will be dropped when passed through
+     * {@link android.view.inputmethod.EditorInfo#makeCompatible(int)
+     * EditorInfo.makeCompatible(int)}.
+     */
+    public static final int TYPE_NUMBER_VARIATION_NORMAL = 0x00000000;
+
+    /**
+     * Variation of {@link #TYPE_CLASS_NUMBER}: entering a numeric password.
+     * This was added in {@link android.os.Build.VERSION_CODES#HONEYCOMB}.  An
+     * IME must target this API version or later to see this input type; if it
+     * doesn't, a request for this type will be dropped when passed
+     * through {@link android.view.inputmethod.EditorInfo#makeCompatible(int)
+     * EditorInfo.makeCompatible(int)}.
+     */
+    public static final int TYPE_NUMBER_VARIATION_PASSWORD = 0x00000010;
+
+    // ----------------------------------------------------------------------
     // ----------------------------------------------------------------------
     // ----------------------------------------------------------------------
     
index 300e5d6..ac378fc 100644 (file)
@@ -275,7 +275,9 @@ public class EditorInfo implements InputType, Parcelable {
      * that was developed against the given target API version.  This can
      * impact the following input types:
      * {@link InputType#TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS},
-     * {@link InputType#TYPE_TEXT_VARIATION_WEB_PASSWORD}.
+     * {@link InputType#TYPE_TEXT_VARIATION_WEB_PASSWORD},
+     * {@link InputType#TYPE_NUMBER_VARIATION_NORMAL},
+     * {@link InputType#TYPE_NUMBER_VARIATION_PASSWORD}.
      *
      * <p>This is called by the framework for input method implementations;
      * you should not generally need to call it yourself.
@@ -288,11 +290,16 @@ public class EditorInfo implements InputType, Parcelable {
             switch (inputType&(TYPE_MASK_CLASS|TYPE_MASK_VARIATION)) {
                 case TYPE_CLASS_TEXT|TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS:
                     inputType = TYPE_CLASS_TEXT|TYPE_TEXT_VARIATION_EMAIL_ADDRESS
-                            | (inputType&(~TYPE_MASK_FLAGS));
+                            | (inputType&TYPE_MASK_FLAGS);
                     break;
                 case TYPE_CLASS_TEXT|TYPE_TEXT_VARIATION_WEB_PASSWORD:
                     inputType = TYPE_CLASS_TEXT|TYPE_TEXT_VARIATION_PASSWORD
-                            | (inputType&(~TYPE_MASK_FLAGS));
+                            | (inputType&TYPE_MASK_FLAGS);
+                    break;
+                case TYPE_CLASS_NUMBER|TYPE_NUMBER_VARIATION_NORMAL:
+                case TYPE_CLASS_NUMBER|TYPE_NUMBER_VARIATION_PASSWORD:
+                    inputType = TYPE_CLASS_NUMBER
+                            | (inputType&TYPE_MASK_FLAGS);
                     break;
             }
         }
index aa2e68f..a3bfe8b 100644 (file)
@@ -783,6 +783,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                 == (EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_PASSWORD);
         final boolean webPasswordInputType = variation
                 == (EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_PASSWORD);
+        final boolean numberPasswordInputType = variation
+                == (EditorInfo.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_VARIATION_PASSWORD);
 
         if (inputMethod != null) {
             Class<?> c;
@@ -900,6 +902,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                 mInputType = (mInputType & ~(EditorInfo.TYPE_MASK_VARIATION))
                         | EditorInfo.TYPE_TEXT_VARIATION_WEB_PASSWORD;
             }
+        } else if ((mInputType & EditorInfo.TYPE_MASK_CLASS) == EditorInfo.TYPE_CLASS_NUMBER) {
+            if (numberPasswordInputType) {
+                mInputType = (mInputType & ~(EditorInfo.TYPE_MASK_VARIATION))
+                        | EditorInfo.TYPE_NUMBER_VARIATION_PASSWORD;
+            }
         }
 
         if (selectallonfocus) {
@@ -946,7 +953,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
         }
         setRawTextSize(textSize);
 
-        if (password || passwordInputType || webPasswordInputType) {
+        if (password || passwordInputType || webPasswordInputType || numberPasswordInputType) {
             setTransformationMethod(PasswordTransformationMethod.getInstance());
             typefaceIndex = MONOSPACE;
         } else if ((mInputType & (EditorInfo.TYPE_MASK_CLASS | EditorInfo.TYPE_MASK_VARIATION))
@@ -3096,7 +3103,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
         return variation
                 == (EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_PASSWORD)
                 || variation
-                == (EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_PASSWORD);
+                == (EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_PASSWORD)
+                || variation
+                == (EditorInfo.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_VARIATION_PASSWORD);
     }
 
     private boolean isVisiblePasswordInputType(int inputType) {
@@ -7637,9 +7646,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
         int variation = mInputType & InputType.TYPE_MASK_VARIATION;
 
         // Text selection is not permitted in password fields
-        if (variation == InputType.TYPE_TEXT_VARIATION_PASSWORD ||
-                variation == InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD ||
-                variation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {
+        if (isPasswordInputType(mInputType) || isVisiblePasswordInputType(mInputType)) {
             return -1;
         }
 
index 36830ce..12ff047 100755 (executable)
              {@link android.text.InputType#TYPE_TEXT_VARIATION_WEB_PASSWORD}. -->
         <flag name="textWebPassword" value="0x000000e1" />
         <!-- A numeric only field.  Corresponds to
-             {@link android.text.InputType#TYPE_CLASS_NUMBER}. -->
+             {@link android.text.InputType#TYPE_CLASS_NUMBER} |
+             {@link android.text.InputType#TYPE_NUMBER_VARIATION_NORMAL}. -->
         <flag name="number" value="0x00000002" />
         <!-- Can be combined with <var>number</var> and its other options to
              allow a signed number.  Corresponds to
              {@link android.text.InputType#TYPE_CLASS_NUMBER} |
              {@link android.text.InputType#TYPE_NUMBER_FLAG_DECIMAL}. -->
         <flag name="numberDecimal" value="0x00002002" />
+        <!-- A numeric password field.  Corresponds to
+             {@link android.text.InputType#TYPE_CLASS_NUMBER} |
+             {@link android.text.InputType#TYPE_NUMBER_VARIATION_PASSWORD}. -->
+        <flag name="numberPassword" value="0x00000012" />
         <!-- For entering a phone number.  Corresponds to
              {@link android.text.InputType#TYPE_CLASS_PHONE}. -->
         <flag name="phone" value="0x00000003" />