am 644c8b7c: Initialize input attributes in the InputAttribute class

* commit '644c8b7c96627199c13297082e4566adae159bf3':
  Initialize input attributes in the InputAttribute class
main
Jean Chalard 2011-12-16 03:38:42 -08:00 committed by Android Git Automerger
commit e4f09a8e08
2 changed files with 85 additions and 86 deletions

View File

@ -16,20 +16,97 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import android.text.InputType;
import android.util.Log;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.compat.InputTypeCompatUtils;
/** /**
* Class to hold attributes of the input field. * Class to hold attributes of the input field.
*/ */
public class InputAttributes { public class InputAttributes {
private final String TAG = InputAttributes.class.getSimpleName(); private final String TAG = InputAttributes.class.getSimpleName();
// TODO: make these final final public boolean mInsertSpaceOnPickSuggestionManually;
public boolean mInsertSpaceOnPickSuggestionManually; final public boolean mInputTypeNoAutoCorrect;
public boolean mInputTypeNoAutoCorrect; final public boolean mIsSettingsSuggestionStripOn;
public boolean mIsSettingsSuggestionStripOn; final public boolean mApplicationSpecifiedCompletionOn;
public boolean mApplicationSpecifiedCompletionOn;
public InputAttributes(final EditorInfo editorInfo) { public InputAttributes(final EditorInfo editorInfo, final boolean isFullscreenMode) {
final boolean insertSpaceOnPickSuggestionManually;
final boolean inputTypeNoAutoCorrect;
final boolean isSettingsSuggestionStripOn;
final boolean applicationSpecifiedCompletionOn;
if (editorInfo == null || editorInfo.inputType == InputType.TYPE_CLASS_TEXT) {
insertSpaceOnPickSuggestionManually = false;
isSettingsSuggestionStripOn = false;
inputTypeNoAutoCorrect = false;
applicationSpecifiedCompletionOn = false;
} else {
final int inputType = editorInfo.inputType;
if (inputType == InputType.TYPE_NULL) {
// TODO: We should honor TYPE_NULL specification.
Log.i(TAG, "InputType.TYPE_NULL is specified");
}
final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
final int variation = inputType & InputType.TYPE_MASK_VARIATION;
if (inputClass == 0) {
Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x"
+ " imeOptions=0x%08x",
inputType, editorInfo.imeOptions));
}
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) {
isSettingsSuggestionStripOn = false;
} else {
isSettingsSuggestionStripOn = true;
}
if (InputTypeCompatUtils.isEmailVariation(variation)
|| variation == InputType.TYPE_TEXT_VARIATION_PERSON_NAME) {
// The point in turning this off is that we don't want to insert a space after
// a name when filling a form: we can't delete trailing spaces when changing fields
insertSpaceOnPickSuggestionManually = false;
} else {
insertSpaceOnPickSuggestionManually = true;
}
// 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)) {
inputTypeNoAutoCorrect = true;
} else {
inputTypeNoAutoCorrect = false;
}
applicationSpecifiedCompletionOn = flagAutoComplete && isFullscreenMode;
}
mInsertSpaceOnPickSuggestionManually = insertSpaceOnPickSuggestionManually;
mInputTypeNoAutoCorrect = inputTypeNoAutoCorrect;
mIsSettingsSuggestionStripOn = isSettingsSuggestionStripOn;
mApplicationSpecifiedCompletionOn = applicationSpecifiedCompletionOn;
} }
} }

View File

@ -511,7 +511,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
loadSettings(); loadSettings();
// TODO: remove the following when it's not needed by updateCorrectionMode() any more // TODO: remove the following when it's not needed by updateCorrectionMode() any more
mInputAttributes = new InputAttributes(null); mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */);
Utils.GCUtils.getInstance().reset(); Utils.GCUtils.getInstance().reset();
boolean tryGC = true; boolean tryGC = true;
for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) { for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
@ -797,85 +797,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
private void initializeInputAttributes(final EditorInfo editorInfo) { private void initializeInputAttributes(final EditorInfo editorInfo) {
mInputAttributes = new InputAttributes(editorInfo); mInputAttributes = new InputAttributes(editorInfo, isFullscreenMode());
final boolean insertSpaceOnPickSuggestionManually;
final boolean inputTypeNoAutoCorrect;
final boolean isSettingsSuggestionStripOn;
final boolean applicationSpecifiedCompletionOn;
if (editorInfo == null || editorInfo.inputType != InputType.TYPE_CLASS_TEXT) {
if (editorInfo.inputType == InputType.TYPE_NULL) {
// TODO: We should honor TYPE_NULL specification.
Log.i(TAG, "InputType.TYPE_NULL is specified");
}
insertSpaceOnPickSuggestionManually = false;
isSettingsSuggestionStripOn = false;
inputTypeNoAutoCorrect = false;
applicationSpecifiedCompletionOn = false;
} else {
final int inputType = editorInfo.inputType;
final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
final int variation = inputType & InputType.TYPE_MASK_VARIATION;
if (inputClass == 0) {
Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x"
+ " imeOptions=0x%08x",
inputType, editorInfo.imeOptions));
}
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) {
isSettingsSuggestionStripOn = false;
} else {
isSettingsSuggestionStripOn = true;
}
if (InputTypeCompatUtils.isEmailVariation(variation)
|| variation == InputType.TYPE_TEXT_VARIATION_PERSON_NAME) {
// The point in turning this off is that we don't want to insert a space after
// a name when filling a form: we can't delete trailing spaces when changing fields
insertSpaceOnPickSuggestionManually = false;
} else {
insertSpaceOnPickSuggestionManually = true;
}
// 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)) {
inputTypeNoAutoCorrect = true;
} else {
inputTypeNoAutoCorrect = false;
}
if (flagAutoComplete) {
applicationSpecifiedCompletionOn = isFullscreenMode();
} else {
applicationSpecifiedCompletionOn = false;
}
}
mInputAttributes.mInsertSpaceOnPickSuggestionManually = insertSpaceOnPickSuggestionManually;
mInputAttributes.mInputTypeNoAutoCorrect = inputTypeNoAutoCorrect;
mInputAttributes.mIsSettingsSuggestionStripOn = isSettingsSuggestionStripOn;
mInputAttributes.mApplicationSpecifiedCompletionOn = applicationSpecifiedCompletionOn;
} }
@Override @Override