2011-12-16 03:57:27 +00:00
|
|
|
/*
|
|
|
|
* 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.latin;
|
|
|
|
|
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;
|
|
|
|
|
2011-12-16 05:13:08 +00:00
|
|
|
import com.android.inputmethod.compat.InputTypeCompatUtils;
|
|
|
|
|
2011-12-16 03:57:27 +00:00
|
|
|
/**
|
|
|
|
* Class to hold attributes of the input field.
|
|
|
|
*/
|
|
|
|
public class InputAttributes {
|
|
|
|
private final String TAG = InputAttributes.class.getSimpleName();
|
|
|
|
|
2011-12-16 05:13:08 +00:00
|
|
|
final public boolean mInputTypeNoAutoCorrect;
|
|
|
|
final public boolean mIsSettingsSuggestionStripOn;
|
|
|
|
final public boolean mApplicationSpecifiedCompletionOn;
|
|
|
|
|
|
|
|
public InputAttributes(final EditorInfo editorInfo, final boolean isFullscreenMode) {
|
2011-12-20 05:14:47 +00:00
|
|
|
final int inputType = null != editorInfo ? editorInfo.inputType : 0;
|
|
|
|
final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
|
|
|
|
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"
|
|
|
|
+ " imeOptions=0x%08x",
|
|
|
|
inputType, editorInfo.imeOptions));
|
|
|
|
}
|
2011-12-20 05:14:47 +00:00
|
|
|
mIsSettingsSuggestionStripOn = false;
|
|
|
|
mInputTypeNoAutoCorrect = false;
|
|
|
|
mApplicationSpecifiedCompletionOn = false;
|
|
|
|
} else {
|
|
|
|
final int variation = inputType & InputType.TYPE_MASK_VARIATION;
|
2011-12-16 05:13:08 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
// Make sure that passwords are not displayed in {@link SuggestionsView}.
|
|
|
|
if (InputTypeCompatUtils.isPasswordInputType(inputType)
|
|
|
|
|| InputTypeCompatUtils.isVisiblePasswordInputType(inputType)
|
|
|
|
|| InputTypeCompatUtils.isEmailVariation(variation)
|
|
|
|
|| InputType.TYPE_TEXT_VARIATION_URI == variation
|
|
|
|
|| InputType.TYPE_TEXT_VARIATION_FILTER == variation
|
|
|
|
|| flagNoSuggestions
|
|
|
|
|| flagAutoComplete) {
|
2011-12-16 05:21:50 +00:00
|
|
|
mIsSettingsSuggestionStripOn = false;
|
2011-12-16 05:13:08 +00:00
|
|
|
} else {
|
2011-12-16 05:21:50 +00:00
|
|
|
mIsSettingsSuggestionStripOn = true;
|
2011-12-16 05:13:08 +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
|
|
|
|
if ((variation == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT
|
|
|
|
&& !flagAutoCorrect)
|
|
|
|
|| flagNoSuggestions
|
|
|
|
|| (!flagAutoCorrect && !flagMultiLine)) {
|
2011-12-16 05:21:50 +00:00
|
|
|
mInputTypeNoAutoCorrect = true;
|
2011-12-16 05:13:08 +00:00
|
|
|
} else {
|
2011-12-16 05:21:50 +00:00
|
|
|
mInputTypeNoAutoCorrect = false;
|
2011-12-16 05:13:08 +00:00
|
|
|
}
|
|
|
|
|
2011-12-16 05:21:50 +00:00
|
|
|
mApplicationSpecifiedCompletionOn = flagAutoComplete && isFullscreenMode;
|
2011-12-16 05:13:08 +00:00
|
|
|
}
|
2011-12-16 03:57:27 +00:00
|
|
|
}
|
2011-12-16 05:28:50 +00:00
|
|
|
|
2012-02-23 00:16:32 +00:00
|
|
|
private void dumpFlags(final int inputType) {
|
|
|
|
Log.i(TAG, "Input class:");
|
|
|
|
final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
|
|
|
|
if (inputClass == InputType.TYPE_CLASS_TEXT)
|
|
|
|
Log.i(TAG, " TYPE_CLASS_TEXT");
|
|
|
|
if (inputClass == InputType.TYPE_CLASS_PHONE)
|
|
|
|
Log.i(TAG, " TYPE_CLASS_PHONE");
|
|
|
|
if (inputClass == InputType.TYPE_CLASS_NUMBER)
|
|
|
|
Log.i(TAG, " TYPE_CLASS_NUMBER");
|
|
|
|
if (inputClass == InputType.TYPE_CLASS_DATETIME)
|
|
|
|
Log.i(TAG, " TYPE_CLASS_DATETIME");
|
|
|
|
Log.i(TAG, "Variation:");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_EMAIL_ADDRESS");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_EMAIL_SUBJECT");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_FILTER))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_FILTER");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_LONG_MESSAGE");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_NORMAL))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_NORMAL");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_PASSWORD))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_PASSWORD");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_PERSON_NAME))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_PERSON_NAME");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_PHONETIC))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_PHONETIC");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_POSTAL_ADDRESS");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_SHORT_MESSAGE");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_URI))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_URI");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_VISIBLE_PASSWORD");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_WEB_EDIT_TEXT");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_VARIATION_WEB_PASSWORD");
|
|
|
|
Log.i(TAG, "Flags:");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_FLAG_NO_SUGGESTIONS");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_FLAG_MULTI_LINE");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_FLAG_IME_MULTI_LINE");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_CAP_WORDS))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_FLAG_CAP_WORDS");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_CAP_SENTENCES))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_FLAG_CAP_SENTENCES");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_FLAG_CAP_CHARACTERS");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_FLAG_AUTO_CORRECT");
|
|
|
|
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE))
|
|
|
|
Log.i(TAG, " TYPE_TEXT_FLAG_AUTO_COMPLETE");
|
|
|
|
}
|
|
|
|
|
2011-12-16 05:28:50 +00:00
|
|
|
// Pretty print
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2012-02-02 08:18:03 +00:00
|
|
|
return "\n mInputTypeNoAutoCorrect = " + mInputTypeNoAutoCorrect
|
2011-12-16 05:28:50 +00:00
|
|
|
+ "\n mIsSettingsSuggestionStripOn = " + mIsSettingsSuggestionStripOn
|
|
|
|
+ "\n mApplicationSpecifiedCompletionOn = " + mApplicationSpecifiedCompletionOn;
|
|
|
|
}
|
2011-12-16 03:57:27 +00:00
|
|
|
}
|