2011-12-16 03:57:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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
|
2011-12-16 03:57:27 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-12-16 03:57:27 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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.
|
2011-12-16 03:57:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
2014-10-23 09:37:32 +00:00
|
|
|
import static com.android.inputmethod.latin.common.Constants.ImeOption.NO_FLOATING_GESTURE_PREVIEW;
|
|
|
|
import static com.android.inputmethod.latin.common.Constants.ImeOption.NO_MICROPHONE;
|
|
|
|
import static com.android.inputmethod.latin.common.Constants.ImeOption.NO_MICROPHONE_COMPAT;
|
2014-06-05 16:41:42 +00:00
|
|
|
|
2011-12-16 05:13:08 +00:00
|
|
|
import android.text.InputType;
|
|
|
|
import android.util.Log;
|
2011-12-16 03:57:27 +00:00
|
|
|
import android.view.inputmethod.EditorInfo;
|
|
|
|
|
2014-10-28 12:31:09 +00:00
|
|
|
import com.android.inputmethod.latin.common.StringUtils;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.InputTypeUtils;
|
|
|
|
|
2014-02-18 02:08:30 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
2011-12-16 03:57:27 +00:00
|
|
|
/**
|
|
|
|
* Class to hold attributes of the input field.
|
|
|
|
*/
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class InputAttributes {
|
2011-12-16 03:57:27 +00:00
|
|
|
private final String TAG = InputAttributes.class.getSimpleName();
|
|
|
|
|
2013-12-20 06:00:44 +00:00
|
|
|
final public String mTargetApplicationPackageName;
|
2011-12-16 05:13:08 +00:00
|
|
|
final public boolean mInputTypeNoAutoCorrect;
|
2014-02-17 02:48:30 +00:00
|
|
|
final public boolean mIsPasswordField;
|
2014-06-05 09:04:11 +00:00
|
|
|
final public boolean mShouldShowSuggestions;
|
2011-12-16 05:13:08 +00:00
|
|
|
final public boolean mApplicationSpecifiedCompletionOn;
|
2012-11-13 06:10:07 +00:00
|
|
|
final public boolean mShouldInsertSpacesAutomatically;
|
2014-06-18 23:35:51 +00:00
|
|
|
final public boolean mShouldShowVoiceInputKey;
|
2014-08-28 23:56:04 +00:00
|
|
|
/**
|
|
|
|
* Whether the floating gesture preview should be disabled. If true, this should override the
|
|
|
|
* corresponding keyboard settings preference, always suppressing the floating preview text.
|
|
|
|
* {@link com.android.inputmethod.latin.settings.SettingsValues#mGestureFloatingPreviewTextEnabled}
|
|
|
|
*/
|
|
|
|
final public boolean mDisableGestureFloatingPreviewText;
|
2014-09-12 08:28:21 +00:00
|
|
|
final public boolean mIsGeneralTextInput;
|
2012-08-15 08:57:38 +00:00
|
|
|
final private int mInputType;
|
2014-06-05 16:41:42 +00:00
|
|
|
final private EditorInfo mEditorInfo;
|
|
|
|
final private String mPackageNameForPrivateImeOptions;
|
2011-12-16 05:13:08 +00:00
|
|
|
|
2014-06-05 16:41:42 +00:00
|
|
|
public InputAttributes(final EditorInfo editorInfo, final boolean isFullscreenMode,
|
|
|
|
final String packageNameForPrivateImeOptions) {
|
|
|
|
mEditorInfo = editorInfo;
|
|
|
|
mPackageNameForPrivateImeOptions = packageNameForPrivateImeOptions;
|
2013-12-20 06:00:44 +00:00
|
|
|
mTargetApplicationPackageName = null != editorInfo ? editorInfo.packageName : null;
|
2011-12-20 05:14:47 +00:00
|
|
|
final int inputType = null != editorInfo ? editorInfo.inputType : 0;
|
|
|
|
final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
|
2012-08-15 08:57:38 +00:00
|
|
|
mInputType = inputType;
|
2014-05-20 01:21:57 +00:00
|
|
|
mIsPasswordField = InputTypeUtils.isPasswordInputType(inputType)
|
|
|
|
|| InputTypeUtils.isVisiblePasswordInputType(inputType);
|
2011-12-20 05:14:47 +00:00
|
|
|
if (inputClass != InputType.TYPE_CLASS_TEXT) {
|
|
|
|
// If we are not looking at a TYPE_CLASS_TEXT field, the following strange
|
|
|
|
// cases may arise, so we do a couple sanity checks for them. If it's a
|
|
|
|
// TYPE_CLASS_TEXT field, these special cases cannot happen, by construction
|
|
|
|
// of the flags.
|
|
|
|
if (null == editorInfo) {
|
|
|
|
Log.w(TAG, "No editor info for this field. Bug?");
|
|
|
|
} else if (InputType.TYPE_NULL == inputType) {
|
2011-12-16 05:13:08 +00:00
|
|
|
// TODO: We should honor TYPE_NULL specification.
|
|
|
|
Log.i(TAG, "InputType.TYPE_NULL is specified");
|
2011-12-20 05:14:47 +00:00
|
|
|
} else if (inputClass == 0) {
|
2011-12-16 05:21:50 +00:00
|
|
|
// TODO: is this check still necessary?
|
2011-12-16 05:13:08 +00:00
|
|
|
Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x"
|
2013-12-13 08:09:16 +00:00
|
|
|
+ " imeOptions=0x%08x", inputType, editorInfo.imeOptions));
|
2011-12-16 05:13:08 +00:00
|
|
|
}
|
2014-06-05 09:04:11 +00:00
|
|
|
mShouldShowSuggestions = false;
|
2011-12-20 05:14:47 +00:00
|
|
|
mInputTypeNoAutoCorrect = false;
|
|
|
|
mApplicationSpecifiedCompletionOn = false;
|
2012-11-13 06:10:07 +00:00
|
|
|
mShouldInsertSpacesAutomatically = false;
|
2014-06-18 23:35:51 +00:00
|
|
|
mShouldShowVoiceInputKey = false;
|
2014-08-28 23:56:04 +00:00
|
|
|
mDisableGestureFloatingPreviewText = false;
|
2014-09-12 08:28:21 +00:00
|
|
|
mIsGeneralTextInput = false;
|
2014-02-18 02:08:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// inputClass == InputType.TYPE_CLASS_TEXT
|
|
|
|
final int variation = inputType & InputType.TYPE_MASK_VARIATION;
|
|
|
|
final boolean flagNoSuggestions =
|
|
|
|
0 != (inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
|
|
|
|
final boolean flagMultiLine =
|
|
|
|
0 != (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE);
|
|
|
|
final boolean flagAutoCorrect =
|
|
|
|
0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
|
|
|
|
final boolean flagAutoComplete =
|
|
|
|
0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
|
2011-12-16 05:13:08 +00:00
|
|
|
|
2014-02-18 02:08:30 +00:00
|
|
|
// TODO: Have a helper method in InputTypeUtils
|
|
|
|
// Make sure that passwords are not displayed in {@link SuggestionStripView}.
|
2014-06-05 09:04:11 +00:00
|
|
|
final boolean shouldSuppressSuggestions = mIsPasswordField
|
2014-02-18 02:08:30 +00:00
|
|
|
|| InputTypeUtils.isEmailVariation(variation)
|
|
|
|
|| InputType.TYPE_TEXT_VARIATION_URI == variation
|
|
|
|
|| InputType.TYPE_TEXT_VARIATION_FILTER == variation
|
|
|
|
|| flagNoSuggestions
|
|
|
|
|| flagAutoComplete;
|
2014-06-05 09:04:11 +00:00
|
|
|
mShouldShowSuggestions = !shouldSuppressSuggestions;
|
2011-12-16 05:13:08 +00:00
|
|
|
|
2014-02-18 02:08:30 +00:00
|
|
|
mShouldInsertSpacesAutomatically = InputTypeUtils.isAutoSpaceFriendlyType(inputType);
|
|
|
|
|
2014-06-18 23:35:51 +00:00
|
|
|
final boolean noMicrophone = mIsPasswordField
|
2014-09-18 05:08:21 +00:00
|
|
|
|| InputTypeUtils.isEmailVariation(variation)
|
2014-06-18 23:35:51 +00:00
|
|
|
|| InputType.TYPE_TEXT_VARIATION_URI == variation
|
|
|
|
|| hasNoMicrophoneKeyOption();
|
|
|
|
mShouldShowVoiceInputKey = !noMicrophone;
|
|
|
|
|
2014-08-28 23:56:04 +00:00
|
|
|
mDisableGestureFloatingPreviewText = InputAttributes.inPrivateImeOptions(
|
|
|
|
mPackageNameForPrivateImeOptions, NO_FLOATING_GESTURE_PREVIEW, editorInfo);
|
|
|
|
|
2014-02-18 02:08:30 +00:00
|
|
|
// If it's a browser edit field and auto correct is not ON explicitly, then
|
|
|
|
// disable auto correction, but keep suggestions on.
|
|
|
|
// If NO_SUGGESTIONS is set, don't do prediction.
|
|
|
|
// If it's not multiline and the autoCorrect flag is not set, then don't correct
|
|
|
|
mInputTypeNoAutoCorrect =
|
|
|
|
(variation == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT && !flagAutoCorrect)
|
|
|
|
|| flagNoSuggestions
|
|
|
|
|| (!flagAutoCorrect && !flagMultiLine);
|
|
|
|
|
|
|
|
mApplicationSpecifiedCompletionOn = flagAutoComplete && isFullscreenMode;
|
2014-09-12 08:28:21 +00:00
|
|
|
|
|
|
|
// If we come here, inputClass is always TYPE_CLASS_TEXT
|
|
|
|
mIsGeneralTextInput = InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS != variation
|
|
|
|
&& InputType.TYPE_TEXT_VARIATION_PASSWORD != variation
|
|
|
|
&& InputType.TYPE_TEXT_VARIATION_PHONETIC != variation
|
|
|
|
&& InputType.TYPE_TEXT_VARIATION_URI != variation
|
|
|
|
&& InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD != variation
|
|
|
|
&& InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS != variation
|
|
|
|
&& InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD != variation;
|
2011-12-16 03:57:27 +00:00
|
|
|
}
|
2011-12-16 05:28:50 +00:00
|
|
|
|
2013-09-27 04:03:06 +00:00
|
|
|
public boolean isTypeNull() {
|
|
|
|
return InputType.TYPE_NULL == mInputType;
|
|
|
|
}
|
|
|
|
|
2012-08-15 08:57:38 +00:00
|
|
|
public boolean isSameInputType(final EditorInfo editorInfo) {
|
|
|
|
return editorInfo.inputType == mInputType;
|
|
|
|
}
|
|
|
|
|
2014-06-18 23:35:51 +00:00
|
|
|
private boolean hasNoMicrophoneKeyOption() {
|
2014-06-05 16:41:42 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
final boolean deprecatedNoMicrophone = InputAttributes.inPrivateImeOptions(
|
|
|
|
null, NO_MICROPHONE_COMPAT, mEditorInfo);
|
|
|
|
final boolean noMicrophone = InputAttributes.inPrivateImeOptions(
|
|
|
|
mPackageNameForPrivateImeOptions, NO_MICROPHONE, mEditorInfo);
|
|
|
|
return noMicrophone || deprecatedNoMicrophone;
|
|
|
|
}
|
|
|
|
|
2012-03-19 05:47:38 +00:00
|
|
|
@SuppressWarnings("unused")
|
2012-02-23 00:16:32 +00:00
|
|
|
private void dumpFlags(final int inputType) {
|
|
|
|
final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
|
2014-02-18 02:08:30 +00:00
|
|
|
final String inputClassString = toInputClassString(inputClass);
|
|
|
|
final String variationString = toVariationString(
|
|
|
|
inputClass, inputType & InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
|
|
|
|
final String flagsString = toFlagsString(inputType & InputType.TYPE_MASK_FLAGS);
|
|
|
|
Log.i(TAG, "Input class: " + inputClassString);
|
|
|
|
Log.i(TAG, "Variation: " + variationString);
|
|
|
|
Log.i(TAG, "Flags: " + flagsString);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String toInputClassString(final int inputClass) {
|
|
|
|
switch (inputClass) {
|
|
|
|
case InputType.TYPE_CLASS_TEXT:
|
|
|
|
return "TYPE_CLASS_TEXT";
|
|
|
|
case InputType.TYPE_CLASS_PHONE:
|
|
|
|
return "TYPE_CLASS_PHONE";
|
|
|
|
case InputType.TYPE_CLASS_NUMBER:
|
|
|
|
return "TYPE_CLASS_NUMBER";
|
|
|
|
case InputType.TYPE_CLASS_DATETIME:
|
|
|
|
return "TYPE_CLASS_DATETIME";
|
|
|
|
default:
|
|
|
|
return String.format("unknownInputClass<0x%08x>", inputClass);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String toVariationString(final int inputClass, final int variation) {
|
|
|
|
switch (inputClass) {
|
|
|
|
case InputType.TYPE_CLASS_TEXT:
|
|
|
|
return toTextVariationString(variation);
|
|
|
|
case InputType.TYPE_CLASS_NUMBER:
|
|
|
|
return toNumberVariationString(variation);
|
|
|
|
case InputType.TYPE_CLASS_DATETIME:
|
|
|
|
return toDatetimeVariationString(variation);
|
|
|
|
default:
|
|
|
|
return "";
|
2012-11-19 10:30:47 +00:00
|
|
|
}
|
2014-02-18 02:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private static String toTextVariationString(final int variation) {
|
|
|
|
switch (variation) {
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS:
|
|
|
|
return " TYPE_TEXT_VARIATION_EMAIL_ADDRESS";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT:
|
|
|
|
return "TYPE_TEXT_VARIATION_EMAIL_SUBJECT";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_FILTER:
|
|
|
|
return "TYPE_TEXT_VARIATION_FILTER";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE:
|
|
|
|
return "TYPE_TEXT_VARIATION_LONG_MESSAGE";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_NORMAL:
|
|
|
|
return "TYPE_TEXT_VARIATION_NORMAL";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_PASSWORD:
|
|
|
|
return "TYPE_TEXT_VARIATION_PASSWORD";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_PERSON_NAME:
|
|
|
|
return "TYPE_TEXT_VARIATION_PERSON_NAME";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_PHONETIC:
|
|
|
|
return "TYPE_TEXT_VARIATION_PHONETIC";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS:
|
|
|
|
return "TYPE_TEXT_VARIATION_POSTAL_ADDRESS";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE:
|
|
|
|
return "TYPE_TEXT_VARIATION_SHORT_MESSAGE";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_URI:
|
|
|
|
return "TYPE_TEXT_VARIATION_URI";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD:
|
|
|
|
return "TYPE_TEXT_VARIATION_VISIBLE_PASSWORD";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT:
|
|
|
|
return "TYPE_TEXT_VARIATION_WEB_EDIT_TEXT";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS:
|
|
|
|
return "TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS";
|
|
|
|
case InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD:
|
|
|
|
return "TYPE_TEXT_VARIATION_WEB_PASSWORD";
|
|
|
|
default:
|
|
|
|
return String.format("unknownVariation<0x%08x>", variation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String toNumberVariationString(final int variation) {
|
|
|
|
switch (variation) {
|
|
|
|
case InputType.TYPE_NUMBER_VARIATION_NORMAL:
|
|
|
|
return "TYPE_NUMBER_VARIATION_NORMAL";
|
|
|
|
case InputType.TYPE_NUMBER_VARIATION_PASSWORD:
|
|
|
|
return "TYPE_NUMBER_VARIATION_PASSWORD";
|
|
|
|
default:
|
|
|
|
return String.format("unknownVariation<0x%08x>", variation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String toDatetimeVariationString(final int variation) {
|
|
|
|
switch (variation) {
|
|
|
|
case InputType.TYPE_DATETIME_VARIATION_NORMAL:
|
|
|
|
return "TYPE_DATETIME_VARIATION_NORMAL";
|
|
|
|
case InputType.TYPE_DATETIME_VARIATION_DATE:
|
|
|
|
return "TYPE_DATETIME_VARIATION_DATE";
|
|
|
|
case InputType.TYPE_DATETIME_VARIATION_TIME:
|
|
|
|
return "TYPE_DATETIME_VARIATION_TIME";
|
|
|
|
default:
|
|
|
|
return String.format("unknownVariation<0x%08x>", variation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static String toFlagsString(final int flags) {
|
2014-05-23 11:18:17 +00:00
|
|
|
final ArrayList<String> flagsArray = new ArrayList<>();
|
2014-02-18 02:08:30 +00:00
|
|
|
if (0 != (flags & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS))
|
|
|
|
flagsArray.add("TYPE_TEXT_FLAG_NO_SUGGESTIONS");
|
|
|
|
if (0 != (flags & InputType.TYPE_TEXT_FLAG_MULTI_LINE))
|
|
|
|
flagsArray.add("TYPE_TEXT_FLAG_MULTI_LINE");
|
|
|
|
if (0 != (flags & InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE))
|
|
|
|
flagsArray.add("TYPE_TEXT_FLAG_IME_MULTI_LINE");
|
|
|
|
if (0 != (flags & InputType.TYPE_TEXT_FLAG_CAP_WORDS))
|
|
|
|
flagsArray.add("TYPE_TEXT_FLAG_CAP_WORDS");
|
|
|
|
if (0 != (flags & InputType.TYPE_TEXT_FLAG_CAP_SENTENCES))
|
|
|
|
flagsArray.add("TYPE_TEXT_FLAG_CAP_SENTENCES");
|
|
|
|
if (0 != (flags & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS))
|
|
|
|
flagsArray.add("TYPE_TEXT_FLAG_CAP_CHARACTERS");
|
|
|
|
if (0 != (flags & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT))
|
|
|
|
flagsArray.add("TYPE_TEXT_FLAG_AUTO_CORRECT");
|
|
|
|
if (0 != (flags & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE))
|
|
|
|
flagsArray.add("TYPE_TEXT_FLAG_AUTO_COMPLETE");
|
|
|
|
return flagsArray.isEmpty() ? "" : Arrays.toString(flagsArray.toArray());
|
2012-02-23 00:16:32 +00:00
|
|
|
}
|
|
|
|
|
2011-12-16 05:28:50 +00:00
|
|
|
// Pretty print
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2014-02-17 16:10:17 +00:00
|
|
|
return String.format(
|
|
|
|
"%s: inputType=0x%08x%s%s%s%s%s targetApp=%s\n", getClass().getSimpleName(),
|
|
|
|
mInputType,
|
|
|
|
(mInputTypeNoAutoCorrect ? " noAutoCorrect" : ""),
|
|
|
|
(mIsPasswordField ? " password" : ""),
|
2014-06-05 09:04:11 +00:00
|
|
|
(mShouldShowSuggestions ? " shouldShowSuggestions" : ""),
|
2014-02-17 16:10:17 +00:00
|
|
|
(mApplicationSpecifiedCompletionOn ? " appSpecified" : ""),
|
|
|
|
(mShouldInsertSpacesAutomatically ? " insertSpaces" : ""),
|
|
|
|
mTargetApplicationPackageName);
|
2011-12-16 05:28:50 +00:00
|
|
|
}
|
2012-04-19 07:39:25 +00:00
|
|
|
|
2014-02-17 16:10:17 +00:00
|
|
|
public static boolean inPrivateImeOptions(final String packageName, final String key,
|
|
|
|
final EditorInfo editorInfo) {
|
2012-04-19 07:39:25 +00:00
|
|
|
if (editorInfo == null) return false;
|
2013-12-13 08:09:16 +00:00
|
|
|
final String findingKey = (packageName != null) ? packageName + "." + key : key;
|
2013-05-28 10:12:12 +00:00
|
|
|
return StringUtils.containsInCommaSplittableText(findingKey, editorInfo.privateImeOptions);
|
2012-04-19 07:39:25 +00:00
|
|
|
}
|
2011-12-16 03:57:27 +00:00
|
|
|
}
|