Refactor InputAttributes a bit

Change-Id: I43d65be6de64ba86f83e8528a138e20c4fa1e3ed
main
Tadashi G. Takaoka 2014-02-18 11:08:30 +09:00
parent f0f4e9fc16
commit 06fbfc4951
1 changed files with 156 additions and 118 deletions

View File

@ -20,9 +20,13 @@ import android.text.InputType;
import android.util.Log; import android.util.Log;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.InputTypeUtils; import com.android.inputmethod.latin.utils.InputTypeUtils;
import com.android.inputmethod.latin.utils.StringUtils; import com.android.inputmethod.latin.utils.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
/** /**
* Class to hold attributes of the input field. * Class to hold attributes of the input field.
*/ */
@ -62,7 +66,9 @@ public final class InputAttributes {
mInputTypeNoAutoCorrect = false; mInputTypeNoAutoCorrect = false;
mApplicationSpecifiedCompletionOn = false; mApplicationSpecifiedCompletionOn = false;
mShouldInsertSpacesAutomatically = false; mShouldInsertSpacesAutomatically = false;
} else { return;
}
// inputClass == InputType.TYPE_CLASS_TEXT
final int variation = inputType & InputType.TYPE_MASK_VARIATION; final int variation = inputType & InputType.TYPE_MASK_VARIATION;
final boolean flagNoSuggestions = final boolean flagNoSuggestions =
0 != (inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); 0 != (inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
@ -77,16 +83,13 @@ public final class InputAttributes {
|| InputTypeUtils.isVisiblePasswordInputType(inputType); || InputTypeUtils.isVisiblePasswordInputType(inputType);
// TODO: Have a helper method in InputTypeUtils // TODO: Have a helper method in InputTypeUtils
// Make sure that passwords are not displayed in {@link SuggestionStripView}. // Make sure that passwords are not displayed in {@link SuggestionStripView}.
if (mIsPasswordField final boolean noSuggestionStrip = mIsPasswordField
|| InputTypeUtils.isEmailVariation(variation) || InputTypeUtils.isEmailVariation(variation)
|| InputType.TYPE_TEXT_VARIATION_URI == variation || InputType.TYPE_TEXT_VARIATION_URI == variation
|| InputType.TYPE_TEXT_VARIATION_FILTER == variation || InputType.TYPE_TEXT_VARIATION_FILTER == variation
|| flagNoSuggestions || flagNoSuggestions
|| flagAutoComplete) { || flagAutoComplete;
mIsSettingsSuggestionStripOn = false; mIsSettingsSuggestionStripOn = !noSuggestionStrip;
} else {
mIsSettingsSuggestionStripOn = true;
}
mShouldInsertSpacesAutomatically = InputTypeUtils.isAutoSpaceFriendlyType(inputType); mShouldInsertSpacesAutomatically = InputTypeUtils.isAutoSpaceFriendlyType(inputType);
@ -94,18 +97,13 @@ public final class InputAttributes {
// disable auto correction, but keep suggestions on. // disable auto correction, but keep suggestions on.
// If NO_SUGGESTIONS is set, don't do prediction. // 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 it's not multiline and the autoCorrect flag is not set, then don't correct
if ((variation == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT mInputTypeNoAutoCorrect =
&& !flagAutoCorrect) (variation == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT && !flagAutoCorrect)
|| flagNoSuggestions || flagNoSuggestions
|| (!flagAutoCorrect && !flagMultiLine)) { || (!flagAutoCorrect && !flagMultiLine);
mInputTypeNoAutoCorrect = true;
} else {
mInputTypeNoAutoCorrect = false;
}
mApplicationSpecifiedCompletionOn = flagAutoComplete && isFullscreenMode; mApplicationSpecifiedCompletionOn = flagAutoComplete && isFullscreenMode;
} }
}
public boolean isTypeNull() { public boolean isTypeNull() {
return InputType.TYPE_NULL == mInputType; return InputType.TYPE_NULL == mInputType;
@ -117,84 +115,124 @@ public final class InputAttributes {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private void dumpFlags(final int inputType) { private void dumpFlags(final int inputType) {
Log.i(TAG, "Input class:");
final int inputClass = inputType & InputType.TYPE_MASK_CLASS; final int inputClass = inputType & InputType.TYPE_MASK_CLASS;
if (inputClass == InputType.TYPE_CLASS_TEXT) final String inputClassString = toInputClassString(inputClass);
Log.i(TAG, " TYPE_CLASS_TEXT"); final String variationString = toVariationString(
if (inputClass == InputType.TYPE_CLASS_PHONE) inputClass, inputType & InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
Log.i(TAG, " TYPE_CLASS_PHONE"); final String flagsString = toFlagsString(inputType & InputType.TYPE_MASK_FLAGS);
if (inputClass == InputType.TYPE_CLASS_NUMBER) Log.i(TAG, "Input class: " + inputClassString);
Log.i(TAG, " TYPE_CLASS_NUMBER"); Log.i(TAG, "Variation: " + variationString);
if (inputClass == InputType.TYPE_CLASS_DATETIME) Log.i(TAG, "Flags: " + flagsString);
Log.i(TAG, " TYPE_CLASS_DATETIME");
Log.i(TAG, "Variation:");
switch (InputType.TYPE_MASK_VARIATION & inputType) {
case InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS:
Log.i(TAG, " TYPE_TEXT_VARIATION_EMAIL_ADDRESS");
break;
case InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT:
Log.i(TAG, " TYPE_TEXT_VARIATION_EMAIL_SUBJECT");
break;
case InputType.TYPE_TEXT_VARIATION_FILTER:
Log.i(TAG, " TYPE_TEXT_VARIATION_FILTER");
break;
case InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE:
Log.i(TAG, " TYPE_TEXT_VARIATION_LONG_MESSAGE");
break;
case InputType.TYPE_TEXT_VARIATION_NORMAL:
Log.i(TAG, " TYPE_TEXT_VARIATION_NORMAL");
break;
case InputType.TYPE_TEXT_VARIATION_PASSWORD:
Log.i(TAG, " TYPE_TEXT_VARIATION_PASSWORD");
break;
case InputType.TYPE_TEXT_VARIATION_PERSON_NAME:
Log.i(TAG, " TYPE_TEXT_VARIATION_PERSON_NAME");
break;
case InputType.TYPE_TEXT_VARIATION_PHONETIC:
Log.i(TAG, " TYPE_TEXT_VARIATION_PHONETIC");
break;
case InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS:
Log.i(TAG, " TYPE_TEXT_VARIATION_POSTAL_ADDRESS");
break;
case InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE:
Log.i(TAG, " TYPE_TEXT_VARIATION_SHORT_MESSAGE");
break;
case InputType.TYPE_TEXT_VARIATION_URI:
Log.i(TAG, " TYPE_TEXT_VARIATION_URI");
break;
case InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD:
Log.i(TAG, " TYPE_TEXT_VARIATION_VISIBLE_PASSWORD");
break;
case InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT:
Log.i(TAG, " TYPE_TEXT_VARIATION_WEB_EDIT_TEXT");
break;
case InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS:
Log.i(TAG, " TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS");
break;
case InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD:
Log.i(TAG, " TYPE_TEXT_VARIATION_WEB_PASSWORD");
break;
default:
Log.i(TAG, " Unknown variation");
break;
} }
Log.i(TAG, "Flags:");
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS)) private static String toInputClassString(final int inputClass) {
Log.i(TAG, " TYPE_TEXT_FLAG_NO_SUGGESTIONS"); switch (inputClass) {
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE)) case InputType.TYPE_CLASS_TEXT:
Log.i(TAG, " TYPE_TEXT_FLAG_MULTI_LINE"); return "TYPE_CLASS_TEXT";
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE)) case InputType.TYPE_CLASS_PHONE:
Log.i(TAG, " TYPE_TEXT_FLAG_IME_MULTI_LINE"); return "TYPE_CLASS_PHONE";
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_CAP_WORDS)) case InputType.TYPE_CLASS_NUMBER:
Log.i(TAG, " TYPE_TEXT_FLAG_CAP_WORDS"); return "TYPE_CLASS_NUMBER";
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_CAP_SENTENCES)) case InputType.TYPE_CLASS_DATETIME:
Log.i(TAG, " TYPE_TEXT_FLAG_CAP_SENTENCES"); return "TYPE_CLASS_DATETIME";
if (0 != (inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS)) default:
Log.i(TAG, " TYPE_TEXT_FLAG_CAP_CHARACTERS"); return String.format("unknownInputClass<0x%08x>", inputClass);
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"); 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 "";
}
}
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) {
final ArrayList<String> flagsArray = CollectionUtils.newArrayList();
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());
} }
// Pretty print // Pretty print