Added InputTypeCompatUtils

Also Moved utilities related to InputType to InputTypeCompatUtils

Change-Id: Iab8ff5389f624f2abe627ece2acb156b0e1285ef
This commit is contained in:
satok 2011-03-24 23:28:29 -07:00
parent b2707856ab
commit e9957752bc
4 changed files with 108 additions and 36 deletions

View File

@ -0,0 +1,95 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.android.inputmethod.compat;
import android.text.InputType;
import java.lang.reflect.Field;
public class InputTypeCompatUtils {
private static final Field FIELD_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS =
CompatUtils.getField(InputType.class, "TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS");
private static final Field FIELD_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD = CompatUtils
.getField(InputType.class, "TYPE_TEXT_VARIATION_WEB_PASSWORD");
private static final Field FIELD_InputType_TYPE_NUMBER_VARIATION_PASSWORD = CompatUtils
.getField(InputType.class, "TYPE_NUMBER_VARIATION_PASSWORD");
private static final Integer OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS =
(Integer) CompatUtils.getFieldValue(null, null,
FIELD_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS);
private static final Integer OBJ_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD =
(Integer) CompatUtils.getFieldValue(null, null,
FIELD_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD);
private static final Integer OBJ_InputType_TYPE_NUMBER_VARIATION_PASSWORD =
(Integer) CompatUtils.getFieldValue(null, null,
FIELD_InputType_TYPE_NUMBER_VARIATION_PASSWORD);
private static final int WEB_TEXT_PASSWORD_INPUT_TYPE;
private static final int NUMBER_PASSWORD_INPUT_TYPE;
private static final int TEXT_PASSWORD_INPUT_TYPE =
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
private static final int TEXT_VISIBLE_PASSWORD_INPUT_TYPE =
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
static {
WEB_TEXT_PASSWORD_INPUT_TYPE =
OBJ_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD != null
? InputType.TYPE_CLASS_TEXT | OBJ_InputType_TYPE_TEXT_VARIATION_WEB_PASSWORD
: 0;
NUMBER_PASSWORD_INPUT_TYPE =
OBJ_InputType_TYPE_NUMBER_VARIATION_PASSWORD != null
? InputType.TYPE_CLASS_NUMBER | OBJ_InputType_TYPE_NUMBER_VARIATION_PASSWORD
: 0;
}
private static boolean isWebPasswordInputType(int inputType) {
return WEB_TEXT_PASSWORD_INPUT_TYPE != 0
&& inputType == WEB_TEXT_PASSWORD_INPUT_TYPE;
}
private static boolean isNumberPasswordInputType(int inputType) {
return NUMBER_PASSWORD_INPUT_TYPE != 0
&& inputType == NUMBER_PASSWORD_INPUT_TYPE;
}
private static boolean isTextPasswordInputType(int inputType) {
return inputType == TEXT_PASSWORD_INPUT_TYPE;
}
private static boolean isWebEmailAddressVariation(int variation) {
return OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS != null
&& variation == OBJ_InputType_TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
}
public static boolean isEmailVariation(int variation) {
return variation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|| isWebEmailAddressVariation(variation);
}
// Please refer to TextView.isPasswordInputType
public static boolean isPasswordInputType(int inputType) {
final int maskedInputType =
inputType & (InputType.TYPE_MASK_CLASS | InputType.TYPE_MASK_VARIATION);
return isTextPasswordInputType(maskedInputType) || isWebPasswordInputType(maskedInputType)
|| isNumberPasswordInputType(maskedInputType);
}
// Please refer to TextView.isVisiblePasswordInputType
public static boolean isVisiblePasswordInputType(int inputType) {
final int maskedInputType =
inputType & (InputType.TYPE_MASK_CLASS | InputType.TYPE_MASK_VARIATION);
return maskedInputType == TEXT_VISIBLE_PASSWORD_INPUT_TYPE;
}
}

View File

@ -16,8 +16,8 @@
package com.android.inputmethod.keyboard; package com.android.inputmethod.keyboard;
import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Utils;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
@ -62,8 +62,8 @@ public class KeyboardId {
this.mMode = mode; this.mMode = mode;
this.mXmlId = xmlId; this.mXmlId = xmlId;
this.mColorScheme = colorScheme; this.mColorScheme = colorScheme;
this.mPasswordInput = Utils.isPasswordInputType(inputType) this.mPasswordInput = InputTypeCompatUtils.isPasswordInputType(inputType)
|| Utils.isVisiblePasswordInputType(inputType); || InputTypeCompatUtils.isVisiblePasswordInputType(inputType);
this.mHasSettingsKey = hasSettingsKey; this.mHasSettingsKey = hasSettingsKey;
this.mVoiceKeyEnabled = voiceKeyEnabled; this.mVoiceKeyEnabled = voiceKeyEnabled;
this.mHasVoiceKey = hasVoiceKey; this.mHasVoiceKey = hasVoiceKey;

View File

@ -21,8 +21,9 @@ import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.compat.InputConnectionCompatUtils; import com.android.inputmethod.compat.InputConnectionCompatUtils;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; import com.android.inputmethod.compat.InputMethodServiceCompatWrapper;
import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.compat.VibratorCompatWrapper; import com.android.inputmethod.compat.VibratorCompatWrapper;
import com.android.inputmethod.deprecated.VoiceProxy;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardSwitcher;
@ -561,8 +562,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// know now whether this is a password text field, because we need to know now whether we // know now whether this is a password text field, because we need to know now whether we
// want to enable the voice button. // want to enable the voice button.
final VoiceProxy voiceIme = mVoiceProxy; final VoiceProxy voiceIme = mVoiceProxy;
voiceIme.resetVoiceStates(Utils.isPasswordInputType(attribute.inputType) voiceIme.resetVoiceStates(InputTypeCompatUtils.isPasswordInputType(attribute.inputType)
|| Utils.isVisiblePasswordInputType(attribute.inputType)); || InputTypeCompatUtils.isVisiblePasswordInputType(attribute.inputType));
initializeInputAttributes(attribute); initializeInputAttributes(attribute);
@ -616,17 +617,17 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if ((inputType & InputType.TYPE_MASK_CLASS) == InputType.TYPE_CLASS_TEXT) { if ((inputType & InputType.TYPE_MASK_CLASS) == InputType.TYPE_CLASS_TEXT) {
mIsSettingsSuggestionStripOn = true; mIsSettingsSuggestionStripOn = true;
// Make sure that passwords are not displayed in candidate view // Make sure that passwords are not displayed in candidate view
if (Utils.isPasswordInputType(inputType) if (InputTypeCompatUtils.isPasswordInputType(inputType)
|| Utils.isVisiblePasswordInputType(inputType)) { || InputTypeCompatUtils.isVisiblePasswordInputType(inputType)) {
mIsSettingsSuggestionStripOn = false; mIsSettingsSuggestionStripOn = false;
} }
if (Utils.isEmailVariation(variation) if (InputTypeCompatUtils.isEmailVariation(variation)
|| variation == InputType.TYPE_TEXT_VARIATION_PERSON_NAME) { || variation == InputType.TYPE_TEXT_VARIATION_PERSON_NAME) {
mAutoSpace = false; mAutoSpace = false;
} else { } else {
mAutoSpace = true; mAutoSpace = true;
} }
if (Utils.isEmailVariation(variation)) { if (InputTypeCompatUtils.isEmailVariation(variation)) {
mIsSettingsSuggestionStripOn = false; mIsSettingsSuggestionStripOn = false;
} else if (variation == InputType.TYPE_TEXT_VARIATION_URI) { } else if (variation == InputType.TYPE_TEXT_VARIATION_URI) {
mIsSettingsSuggestionStripOn = false; mIsSettingsSuggestionStripOn = false;

View File

@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
import com.android.inputmethod.compat.InputMethodInfoCompatWrapper; import com.android.inputmethod.compat.InputMethodInfoCompatWrapper;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.InputTypeCompatUtils;
import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardId;
import android.content.res.Resources; import android.content.res.Resources;
@ -485,7 +486,7 @@ public class Utils {
case InputType.TYPE_CLASS_PHONE: case InputType.TYPE_CLASS_PHONE:
return KeyboardId.MODE_PHONE; return KeyboardId.MODE_PHONE;
case InputType.TYPE_CLASS_TEXT: case InputType.TYPE_CLASS_TEXT:
if (Utils.isEmailVariation(variation)) { if (InputTypeCompatUtils.isEmailVariation(variation)) {
return KeyboardId.MODE_EMAIL; return KeyboardId.MODE_EMAIL;
} else if (variation == InputType.TYPE_TEXT_VARIATION_URI) { } else if (variation == InputType.TYPE_TEXT_VARIATION_URI) {
return KeyboardId.MODE_URL; return KeyboardId.MODE_URL;
@ -503,31 +504,6 @@ public class Utils {
} }
} }
public static boolean isEmailVariation(int variation) {
return variation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
|| variation == InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS;
}
// Please refer to TextView.isPasswordInputType
public static boolean isPasswordInputType(int inputType) {
final int variation =
inputType & (InputType.TYPE_MASK_CLASS | InputType.TYPE_MASK_VARIATION);
return (variation
== (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD))
|| (variation
== (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD))
|| (variation
== (InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD));
}
// Please refer to TextView.isVisiblePasswordInputType
public static boolean isVisiblePasswordInputType(int inputType) {
final int variation =
inputType & (InputType.TYPE_MASK_CLASS | InputType.TYPE_MASK_VARIATION);
return variation
== (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
}
public static boolean containsInCsv(String key, String csv) { public static boolean containsInCsv(String key, String csv) {
if (csv == null) if (csv == null)
return false; return false;