Home | History | Annotate | Download | only in latin
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
      5  * use this file except in compliance with the License. You may obtain a copy of
      6  * the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     13  * License for the specific language governing permissions and limitations under
     14  * the License.
     15  */
     16 
     17 package com.android.inputmethod.latin;
     18 
     19 import android.text.InputType;
     20 
     21 public class InputTypeUtils implements InputType {
     22     private static final int WEB_TEXT_PASSWORD_INPUT_TYPE =
     23             TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_PASSWORD;
     24     private static final int WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE =
     25             TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
     26     private static final int NUMBER_PASSWORD_INPUT_TYPE =
     27             TYPE_CLASS_NUMBER | TYPE_NUMBER_VARIATION_PASSWORD;
     28     private static final int TEXT_PASSWORD_INPUT_TYPE =
     29             TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_PASSWORD;
     30     private static final int TEXT_VISIBLE_PASSWORD_INPUT_TYPE =
     31             TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
     32 
     33     private InputTypeUtils() {
     34         // This utility class is not publicly instantiable.
     35     }
     36 
     37     private static boolean isWebEditTextInputType(int inputType) {
     38         return inputType == (TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_WEB_EDIT_TEXT);
     39     }
     40 
     41     private static boolean isWebPasswordInputType(int inputType) {
     42         return WEB_TEXT_PASSWORD_INPUT_TYPE != 0
     43                 && inputType == WEB_TEXT_PASSWORD_INPUT_TYPE;
     44     }
     45 
     46     private static boolean isWebEmailAddressInputType(int inputType) {
     47         return WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE != 0
     48                 && inputType == WEB_TEXT_EMAIL_ADDRESS_INPUT_TYPE;
     49     }
     50 
     51     private static boolean isNumberPasswordInputType(int inputType) {
     52         return NUMBER_PASSWORD_INPUT_TYPE != 0
     53                 && inputType == NUMBER_PASSWORD_INPUT_TYPE;
     54     }
     55 
     56     private static boolean isTextPasswordInputType(int inputType) {
     57         return inputType == TEXT_PASSWORD_INPUT_TYPE;
     58     }
     59 
     60     private static boolean isWebEmailAddressVariation(int variation) {
     61         return variation == TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
     62     }
     63 
     64     public static boolean isEmailVariation(int variation) {
     65         return variation == TYPE_TEXT_VARIATION_EMAIL_ADDRESS
     66                 || isWebEmailAddressVariation(variation);
     67     }
     68 
     69     public static boolean isWebInputType(int inputType) {
     70         final int maskedInputType =
     71                 inputType & (TYPE_MASK_CLASS | TYPE_MASK_VARIATION);
     72         return isWebEditTextInputType(maskedInputType) || isWebPasswordInputType(maskedInputType)
     73                 || isWebEmailAddressInputType(maskedInputType);
     74     }
     75 
     76     // Please refer to TextView.isPasswordInputType
     77     public static boolean isPasswordInputType(int inputType) {
     78         final int maskedInputType =
     79                 inputType & (TYPE_MASK_CLASS | TYPE_MASK_VARIATION);
     80         return isTextPasswordInputType(maskedInputType) || isWebPasswordInputType(maskedInputType)
     81                 || isNumberPasswordInputType(maskedInputType);
     82     }
     83 
     84     // Please refer to TextView.isVisiblePasswordInputType
     85     public static boolean isVisiblePasswordInputType(int inputType) {
     86         final int maskedInputType =
     87                 inputType & (TYPE_MASK_CLASS | TYPE_MASK_VARIATION);
     88         return maskedInputType == TEXT_VISIBLE_PASSWORD_INPUT_TYPE;
     89     }
     90 }
     91