am 2c4b21d7: Merge "Cleanup settings key related stuff"

* commit '2c4b21d7ca659e958d77eff660abab7104e03cca':
  Cleanup settings key related stuff
This commit is contained in:
Tadashi G. Takaoka 2011-12-15 10:08:25 -08:00 committed by Android Git Automerger
commit 6168c33aac
4 changed files with 41 additions and 49 deletions

View file

@ -51,11 +51,10 @@ public class KeyboardId {
public static final int ELEMENT_PHONE_SHIFT = 8; public static final int ELEMENT_PHONE_SHIFT = 8;
public static final int ELEMENT_NUMBER = 9; public static final int ELEMENT_NUMBER = 9;
// TODO: These constants could be private. private static final int F2KEY_MODE_NONE = 0;
public static final int F2KEY_MODE_NONE = 0; private static final int F2KEY_MODE_SETTINGS = 1;
public static final int F2KEY_MODE_SETTINGS = 1; private static final int F2KEY_MODE_SHORTCUT_IME = 2;
public static final int F2KEY_MODE_SHORTCUT_IME = 2; private static final int F2KEY_MODE_SHORTCUT_IME_OR_SETTINGS = 3;
public static final int F2KEY_MODE_SHORTCUT_IME_OR_SETTINGS = 3;
public final Locale mLocale; public final Locale mLocale;
public final int mOrientation; public final int mOrientation;
@ -66,9 +65,7 @@ public class KeyboardId {
public final int mElementState; public final int mElementState;
public final boolean mNavigateAction; public final boolean mNavigateAction;
public final boolean mPasswordInput; public final boolean mPasswordInput;
// TODO: Clean up these booleans and modes. private final boolean mSettingsKeyEnabled;
public final boolean mHasSettingsKey;
public final int mF2KeyMode;
public final boolean mClobberSettingsKey; public final boolean mClobberSettingsKey;
public final boolean mShortcutKeyEnabled; public final boolean mShortcutKeyEnabled;
public final boolean mHasShortcutKey; public final boolean mHasShortcutKey;
@ -79,9 +76,8 @@ public class KeyboardId {
private final int mHashCode; private final int mHashCode;
// TODO: The hasSettings, f2KeyMode, and clobberSettingsKey arguments could be reduced.
public KeyboardId(int xmlId, int elementState, Locale locale, int orientation, int width, public KeyboardId(int xmlId, int elementState, Locale locale, int orientation, int width,
int mode, EditorInfo editorInfo, boolean hasSettingsKey, int f2KeyMode, int mode, EditorInfo editorInfo, boolean settingsKeyEnabled,
boolean clobberSettingsKey, boolean shortcutKeyEnabled, boolean hasShortcutKey) { boolean clobberSettingsKey, boolean shortcutKeyEnabled, boolean hasShortcutKey) {
final int inputType = (editorInfo != null) ? editorInfo.inputType : 0; final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
final int imeOptions = (editorInfo != null) ? editorInfo.imeOptions : 0; final int imeOptions = (editorInfo != null) ? editorInfo.imeOptions : 0;
@ -97,8 +93,7 @@ public class KeyboardId {
// || EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions); // || EditorInfoCompatUtils.hasFlagNavigatePrevious(imeOptions);
this.mPasswordInput = InputTypeCompatUtils.isPasswordInputType(inputType) this.mPasswordInput = InputTypeCompatUtils.isPasswordInputType(inputType)
|| InputTypeCompatUtils.isVisiblePasswordInputType(inputType); || InputTypeCompatUtils.isVisiblePasswordInputType(inputType);
this.mHasSettingsKey = hasSettingsKey; this.mSettingsKeyEnabled = settingsKeyEnabled;
this.mF2KeyMode = f2KeyMode;
this.mClobberSettingsKey = clobberSettingsKey; this.mClobberSettingsKey = clobberSettingsKey;
this.mShortcutKeyEnabled = shortcutKeyEnabled; this.mShortcutKeyEnabled = shortcutKeyEnabled;
this.mHasShortcutKey = hasShortcutKey; this.mHasShortcutKey = hasShortcutKey;
@ -118,9 +113,8 @@ public class KeyboardId {
elementState, elementState,
mNavigateAction, mNavigateAction,
mPasswordInput, mPasswordInput,
hasSettingsKey, mSettingsKeyEnabled,
f2KeyMode, mClobberSettingsKey,
clobberSettingsKey,
shortcutKeyEnabled, shortcutKeyEnabled,
hasShortcutKey, hasShortcutKey,
mImeAction, mImeAction,
@ -128,9 +122,8 @@ public class KeyboardId {
} }
public KeyboardId cloneWithNewXml(int xmlId) { public KeyboardId cloneWithNewXml(int xmlId) {
return new KeyboardId(xmlId, mElementState, mLocale, return new KeyboardId(xmlId, mElementState, mLocale, mOrientation, mWidth, mMode,
mOrientation, mWidth, mMode, mEditorInfo, false, F2KEY_MODE_NONE, false, false, mEditorInfo, false, false, false, false);
false);
} }
// Remove this method. // Remove this method.
@ -154,6 +147,25 @@ public class KeyboardId {
return mElementState == ELEMENT_PHONE_SHIFT; return mElementState == ELEMENT_PHONE_SHIFT;
} }
public boolean hasSettingsKey() {
return mSettingsKeyEnabled && !mClobberSettingsKey;
}
public int f2KeyMode() {
if (mClobberSettingsKey) {
// Never shows the Settings key
return KeyboardId.F2KEY_MODE_SHORTCUT_IME;
}
if (mSettingsKeyEnabled) {
return KeyboardId.F2KEY_MODE_SETTINGS;
} else {
// It should be alright to fall back to the Settings key on 7-inch layouts
// even when the Settings key is not explicitly enabled.
return KeyboardId.F2KEY_MODE_SHORTCUT_IME_OR_SETTINGS;
}
}
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
return other instanceof KeyboardId && equals((KeyboardId) other); return other instanceof KeyboardId && equals((KeyboardId) other);
@ -168,8 +180,7 @@ public class KeyboardId {
&& other.mElementState == this.mElementState && other.mElementState == this.mElementState
&& other.mNavigateAction == this.mNavigateAction && other.mNavigateAction == this.mNavigateAction
&& other.mPasswordInput == this.mPasswordInput && other.mPasswordInput == this.mPasswordInput
&& other.mHasSettingsKey == this.mHasSettingsKey && other.mSettingsKeyEnabled == this.mSettingsKeyEnabled
&& other.mF2KeyMode == this.mF2KeyMode
&& other.mClobberSettingsKey == this.mClobberSettingsKey && other.mClobberSettingsKey == this.mClobberSettingsKey
&& other.mShortcutKeyEnabled == this.mShortcutKeyEnabled && other.mShortcutKeyEnabled == this.mShortcutKeyEnabled
&& other.mHasShortcutKey == this.mHasShortcutKey && other.mHasShortcutKey == this.mHasShortcutKey
@ -189,11 +200,11 @@ public class KeyboardId {
(mOrientation == 1 ? "port" : "land"), mWidth, (mOrientation == 1 ? "port" : "land"), mWidth,
modeName(mMode), modeName(mMode),
EditorInfoCompatUtils.imeOptionsName(mImeAction), EditorInfoCompatUtils.imeOptionsName(mImeAction),
f2KeyModeName(mF2KeyMode), f2KeyModeName(f2KeyMode()),
(mClobberSettingsKey ? " clobberSettingsKey" : ""), (mClobberSettingsKey ? " clobberSettingsKey" : ""),
(mNavigateAction ? " navigateAction" : ""), (mNavigateAction ? " navigateAction" : ""),
(mPasswordInput ? " passwordInput" : ""), (mPasswordInput ? " passwordInput" : ""),
(mHasSettingsKey ? " hasSettingsKey" : ""), (hasSettingsKey() ? " hasSettingsKey" : ""),
(mShortcutKeyEnabled ? " shortcutKeyEnabled" : ""), (mShortcutKeyEnabled ? " shortcutKeyEnabled" : ""),
(mHasShortcutKey ? " hasShortcutKey" : "") (mHasShortcutKey ? " hasShortcutKey" : "")
); );

View file

@ -72,11 +72,10 @@ public class KeyboardSet {
new HashMap<Integer, Integer>(); new HashMap<Integer, Integer>();
private final int mMode; private final int mMode;
private final boolean mSettingsKeyEnabled;
private final boolean mVoiceKeyEnabled; private final boolean mVoiceKeyEnabled;
private final boolean mNoSettingsKey;
private final boolean mHasSettingsKey;
private final int mF2KeyMode;
private final boolean mVoiceKeyOnMain; private final boolean mVoiceKeyOnMain;
private final boolean mNoSettingsKey;
private final Locale mLocale; private final Locale mLocale;
private final Configuration mConf; private final Configuration mConf;
private final DisplayMetrics mMetrics; private final DisplayMetrics mMetrics;
@ -88,7 +87,7 @@ public class KeyboardSet {
final String packageName = context.getPackageName(); final String packageName = context.getPackageName();
mMode = Utils.getKeyboardMode(mEditorInfo); mMode = Utils.getKeyboardMode(mEditorInfo);
final boolean settingsKeyEnabled = settingsValues.isSettingsKeyEnabled(); mSettingsKeyEnabled = settingsValues.isSettingsKeyEnabled();
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
final boolean noMicrophone = Utils.inPrivateImeOptions( final boolean noMicrophone = Utils.inPrivateImeOptions(
packageName, LatinIME.IME_OPTION_NO_MICROPHONE, editorInfo) packageName, LatinIME.IME_OPTION_NO_MICROPHONE, editorInfo)
@ -98,8 +97,6 @@ public class KeyboardSet {
mVoiceKeyOnMain = settingsValues.isVoiceKeyOnMain(); mVoiceKeyOnMain = settingsValues.isVoiceKeyOnMain();
mNoSettingsKey = Utils.inPrivateImeOptions( mNoSettingsKey = Utils.inPrivateImeOptions(
packageName, LatinIME.IME_OPTION_NO_SETTINGS_KEY, editorInfo); packageName, LatinIME.IME_OPTION_NO_SETTINGS_KEY, editorInfo);
mHasSettingsKey = settingsKeyEnabled && !mNoSettingsKey;
mF2KeyMode = getF2KeyMode(settingsKeyEnabled, mNoSettingsKey);
final boolean forceAscii = Utils.inPrivateImeOptions( final boolean forceAscii = Utils.inPrivateImeOptions(
packageName, LatinIME.IME_OPTION_FORCE_ASCII, editorInfo); packageName, LatinIME.IME_OPTION_FORCE_ASCII, editorInfo);
final boolean asciiCapable = subtypeSwitcher.currentSubtypeContainsExtraValueKey( final boolean asciiCapable = subtypeSwitcher.currentSubtypeContainsExtraValueKey(
@ -126,8 +123,8 @@ public class KeyboardSet {
final int xmlId = mElementKeyboards.get(elementState); final int xmlId = mElementKeyboards.get(elementState);
final boolean hasShortcutKey = mVoiceKeyEnabled && (isSymbols != mVoiceKeyOnMain); final boolean hasShortcutKey = mVoiceKeyEnabled && (isSymbols != mVoiceKeyOnMain);
return new KeyboardId(xmlId, elementState, mLocale, mConf.orientation, return new KeyboardId(xmlId, elementState, mLocale, mConf.orientation,
mMetrics.widthPixels, mMode, mEditorInfo, mHasSettingsKey, mF2KeyMode, mMetrics.widthPixels, mMode, mEditorInfo, mSettingsKeyEnabled, mNoSettingsKey,
mNoSettingsKey, mVoiceKeyEnabled, hasShortcutKey); mVoiceKeyEnabled, hasShortcutKey);
} }
private static int getElementState(int mode, boolean isSymbols, boolean isShift) { private static int getElementState(int mode, boolean isSymbols, boolean isShift) {
@ -145,22 +142,6 @@ public class KeyboardSet {
} }
} }
// TODO: Move to KeyboardId.
private static int getF2KeyMode(boolean settingsKeyEnabled, boolean noSettingsKey) {
if (noSettingsKey) {
// Never shows the Settings key
return KeyboardId.F2KEY_MODE_SHORTCUT_IME;
}
if (settingsKeyEnabled) {
return KeyboardId.F2KEY_MODE_SETTINGS;
} else {
// It should be alright to fall back to the Settings key on 7-inch layouts
// even when the Settings key is not explicitly enabled.
return KeyboardId.F2KEY_MODE_SHORTCUT_IME_OR_SETTINGS;
}
}
private void parseKeyboardSet(Resources res, int resId) throws XmlPullParserException, private void parseKeyboardSet(Resources res, int resId) throws XmlPullParserException,
IOException { IOException {
final XmlResourceParser parser = res.getXml(resId); final XmlResourceParser parser = res.getXml(resId);

View file

@ -613,9 +613,9 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
final boolean passwordInputMatched = matchBoolean(a, final boolean passwordInputMatched = matchBoolean(a,
R.styleable.Keyboard_Case_passwordInput, id.mPasswordInput); R.styleable.Keyboard_Case_passwordInput, id.mPasswordInput);
final boolean hasSettingsKeyMatched = matchBoolean(a, final boolean hasSettingsKeyMatched = matchBoolean(a,
R.styleable.Keyboard_Case_hasSettingsKey, id.mHasSettingsKey); R.styleable.Keyboard_Case_hasSettingsKey, id.hasSettingsKey());
final boolean f2KeyModeMatched = matchInteger(a, final boolean f2KeyModeMatched = matchInteger(a,
R.styleable.Keyboard_Case_f2KeyMode, id.mF2KeyMode); R.styleable.Keyboard_Case_f2KeyMode, id.f2KeyMode());
final boolean clobberSettingsKeyMatched = matchBoolean(a, final boolean clobberSettingsKeyMatched = matchBoolean(a,
R.styleable.Keyboard_Case_clobberSettingsKey, id.mClobberSettingsKey); R.styleable.Keyboard_Case_clobberSettingsKey, id.mClobberSettingsKey);
final boolean shortcutKeyEnabledMatched = matchBoolean(a, final boolean shortcutKeyEnabledMatched = matchBoolean(a,

View file

@ -52,7 +52,7 @@ public class SuggestTestsBase extends AndroidTestCase {
} }
return new KeyboardId(com.android.inputmethod.latin.R.xml.kbd_qwerty, return new KeyboardId(com.android.inputmethod.latin.R.xml.kbd_qwerty,
KeyboardId.ELEMENT_ALPHABET, locale, orientation, width, KeyboardId.MODE_TEXT, KeyboardId.ELEMENT_ALPHABET, locale, orientation, width, KeyboardId.MODE_TEXT,
new EditorInfo(), false, KeyboardId.F2KEY_MODE_NONE, false, false, false); new EditorInfo(), false, false, false, false);
} }
protected InputStream openTestRawResource(int resIdInTest) { protected InputStream openTestRawResource(int resIdInTest) {