aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardId.java70
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java26
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java12
3 files changed, 55 insertions, 53 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
index 5e8a8f6bb..b41361515 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
@@ -71,34 +71,39 @@ public final class KeyboardId {
private final EditorInfo mEditorInfo;
public final boolean mClobberSettingsKey;
public final boolean mShortcutKeyEnabled;
- public final boolean mHasShortcutKey;
+ public final boolean mShortcutKeyOnSymbols;
public final boolean mLanguageSwitchKeyEnabled;
public final String mCustomActionLabel;
+ public final boolean mHasShortcutKey;
private final int mHashCode;
- public KeyboardId(int elementId, InputMethodSubtype subtype, int deviceFormFactor,
- int orientation, int width, int mode, EditorInfo editorInfo, boolean clobberSettingsKey,
- boolean shortcutKeyEnabled, boolean hasShortcutKey, boolean languageSwitchKeyEnabled) {
- mSubtype = subtype;
- mLocale = SubtypeLocale.getSubtypeLocale(subtype);
- mDeviceFormFactor = deviceFormFactor;
- mOrientation = orientation;
- mWidth = width;
- mMode = mode;
+ public KeyboardId(final int elementId, final KeyboardLayoutSet.Params params) {
+ mSubtype = params.mSubtype;
+ mLocale = SubtypeLocale.getSubtypeLocale(mSubtype);
+ mDeviceFormFactor = params.mDeviceFormFactor;
+ mOrientation = params.mOrientation;
+ mWidth = params.mWidth;
+ mMode = params.mMode;
mElementId = elementId;
- mEditorInfo = editorInfo;
- mClobberSettingsKey = clobberSettingsKey;
- mShortcutKeyEnabled = shortcutKeyEnabled;
- mHasShortcutKey = hasShortcutKey;
- mLanguageSwitchKeyEnabled = languageSwitchKeyEnabled;
- mCustomActionLabel = (editorInfo.actionLabel != null)
- ? editorInfo.actionLabel.toString() : null;
+ mEditorInfo = params.mEditorInfo;
+ mClobberSettingsKey = params.mNoSettingsKey;
+ mShortcutKeyEnabled = params.mVoiceKeyEnabled;
+ mShortcutKeyOnSymbols = mShortcutKeyEnabled && !params.mVoiceKeyOnMain;
+ mLanguageSwitchKeyEnabled = params.mLanguageSwitchKeyEnabled;
+ mCustomActionLabel = (mEditorInfo.actionLabel != null)
+ ? mEditorInfo.actionLabel.toString() : null;
+ final boolean alphabetMayHaveShortcutKey = isAlphabetKeyboard(elementId)
+ && !mShortcutKeyOnSymbols;
+ final boolean symbolsMayHaveShortcutKey = (elementId == KeyboardId.ELEMENT_SYMBOLS)
+ && mShortcutKeyOnSymbols;
+ mHasShortcutKey = mShortcutKeyEnabled
+ && (alphabetMayHaveShortcutKey || symbolsMayHaveShortcutKey);
mHashCode = computeHashCode(this);
}
- private static int computeHashCode(KeyboardId id) {
+ private static int computeHashCode(final KeyboardId id) {
return Arrays.hashCode(new Object[] {
id.mDeviceFormFactor,
id.mOrientation,
@@ -108,7 +113,7 @@ public final class KeyboardId {
id.passwordInput(),
id.mClobberSettingsKey,
id.mShortcutKeyEnabled,
- id.mHasShortcutKey,
+ id.mShortcutKeyOnSymbols,
id.mLanguageSwitchKeyEnabled,
id.isMultiLine(),
id.imeAction(),
@@ -119,7 +124,7 @@ public final class KeyboardId {
});
}
- private boolean equals(KeyboardId other) {
+ private boolean equals(final KeyboardId other) {
if (other == this)
return true;
return other.mDeviceFormFactor == mDeviceFormFactor
@@ -130,7 +135,7 @@ public final class KeyboardId {
&& other.passwordInput() == passwordInput()
&& other.mClobberSettingsKey == mClobberSettingsKey
&& other.mShortcutKeyEnabled == mShortcutKeyEnabled
- && other.mHasShortcutKey == mHasShortcutKey
+ && other.mShortcutKeyOnSymbols == mShortcutKeyOnSymbols
&& other.mLanguageSwitchKeyEnabled == mLanguageSwitchKeyEnabled
&& other.isMultiLine() == isMultiLine()
&& other.imeAction() == imeAction()
@@ -140,8 +145,12 @@ public final class KeyboardId {
&& other.mSubtype.equals(mSubtype);
}
+ private static boolean isAlphabetKeyboard(final int elementId) {
+ return elementId < ELEMENT_SYMBOLS;
+ }
+
public boolean isAlphabetKeyboard() {
- return mElementId < ELEMENT_SYMBOLS;
+ return isAlphabetKeyboard(mElementId);
}
public boolean navigateNext() {
@@ -181,7 +190,7 @@ public final class KeyboardId {
}
@Override
- public boolean equals(Object other) {
+ public boolean equals(final Object other) {
return other instanceof KeyboardId && equals((KeyboardId) other);
}
@@ -192,7 +201,7 @@ public final class KeyboardId {
@Override
public String toString() {
- return String.format("[%s %s:%s %s-%s:%d %s %s %s%s%s%s%s%s%s%s]",
+ return String.format("[%s %s:%s %s-%s:%d %s %s %s%s%s%s%s%s%s%s%s]",
elementIdToName(mElementId),
mLocale,
mSubtype.getExtraValueOf(KEYBOARD_LAYOUT_SET),
@@ -204,13 +213,14 @@ public final class KeyboardId {
(mClobberSettingsKey ? " clobberSettingsKey" : ""),
(passwordInput() ? " passwordInput" : ""),
(mShortcutKeyEnabled ? " shortcutKeyEnabled" : ""),
+ (mShortcutKeyOnSymbols ? " shortcutKeyOnSymbols" : ""),
(mHasShortcutKey ? " hasShortcutKey" : ""),
(mLanguageSwitchKeyEnabled ? " languageSwitchKeyEnabled" : ""),
(isMultiLine() ? "isMultiLine" : "")
);
}
- public static boolean equivalentEditorInfoForKeyboard(EditorInfo a, EditorInfo b) {
+ public static boolean equivalentEditorInfoForKeyboard(final EditorInfo a, final EditorInfo b) {
if (a == null && b == null) return true;
if (a == null || b == null) return false;
return a.inputType == b.inputType
@@ -218,7 +228,7 @@ public final class KeyboardId {
&& TextUtils.equals(a.privateImeOptions, b.privateImeOptions);
}
- public static String elementIdToName(int elementId) {
+ public static String elementIdToName(final int elementId) {
switch (elementId) {
case ELEMENT_ALPHABET: return "alphabet";
case ELEMENT_ALPHABET_MANUAL_SHIFTED: return "alphabetManualShifted";
@@ -234,8 +244,8 @@ public final class KeyboardId {
}
}
- public static String deviceFormFactor(int devoceFormFactor) {
- switch (devoceFormFactor) {
+ public static String deviceFormFactor(final int deviceFormFactor) {
+ switch (deviceFormFactor) {
case FORM_FACTOR_PHONE: return "phone";
case FORM_FACTOR_TABLET7: return "tablet7";
case FORM_FACTOR_TABLET10: return "tablet10";
@@ -243,7 +253,7 @@ public final class KeyboardId {
}
}
- public static String modeName(int mode) {
+ public static String modeName(final int mode) {
switch (mode) {
case MODE_TEXT: return "text";
case MODE_URL: return "url";
@@ -258,7 +268,7 @@ public final class KeyboardId {
}
}
- public static String actionName(int actionId) {
+ public static String actionName(final int actionId) {
return (actionId == IME_ACTION_CUSTOM_LABEL) ? "actionCustomLabel"
: EditorInfoCompatUtils.imeActionName(actionId);
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
index 4d5d7e14e..295047530 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java
@@ -78,6 +78,7 @@ public final class KeyboardLayoutSet {
CollectionUtils.newHashMap();
private static final KeysCache sKeysCache = new KeysCache();
+ @SuppressWarnings("serial")
public static final class KeyboardLayoutSetException extends RuntimeException {
public final KeyboardId mKeyboardId;
@@ -93,7 +94,7 @@ public final class KeyboardLayoutSet {
public ElementParams() {}
}
- private static final class Params {
+ public static final class Params {
String mKeyboardLayoutSetName;
int mMode;
EditorInfo mEditorInfo;
@@ -109,7 +110,6 @@ public final class KeyboardLayoutSet {
// Sparse array of KeyboardLayoutSet element parameters indexed by element's id.
final SparseArray<ElementParams> mKeyboardLayoutSetElementIdToParamsMap =
CollectionUtils.newSparseArray();
- public Params() {}
}
public static void clearKeyboardCache() {
@@ -149,7 +149,11 @@ public final class KeyboardLayoutSet {
elementParams = mParams.mKeyboardLayoutSetElementIdToParamsMap.get(
KeyboardId.ELEMENT_ALPHABET);
}
- final KeyboardId id = getKeyboardId(keyboardLayoutSetElementId);
+ // Note: The keyboard for each shift state, and mode are represented as an elementName
+ // attribute in a keyboard_layout_set XML file. Also each keyboard layout XML resource is
+ // specified as an elementKeyboard attribute in the file.
+ // The KeyboardId is an internal key for a Keyboard object.
+ final KeyboardId id = new KeyboardId(keyboardLayoutSetElementId, mParams);
try {
return getKeyboard(elementParams, id);
} catch (RuntimeException e) {
@@ -187,22 +191,6 @@ public final class KeyboardLayoutSet {
return keyboard;
}
- // Note: The keyboard for each locale, shift state, and mode are represented as
- // KeyboardLayoutSet element id that is a key in keyboard_set.xml. Also that file specifies
- // which XML layout should be used for each keyboard. The KeyboardId is an internal key for
- // Keyboard object.
- private KeyboardId getKeyboardId(final int keyboardLayoutSetElementId) {
- final Params params = mParams;
- final boolean isSymbols = (keyboardLayoutSetElementId == KeyboardId.ELEMENT_SYMBOLS
- || keyboardLayoutSetElementId == KeyboardId.ELEMENT_SYMBOLS_SHIFTED);
- final boolean hasShortcutKey = params.mVoiceKeyEnabled
- && (isSymbols != params.mVoiceKeyOnMain);
- return new KeyboardId(keyboardLayoutSetElementId, params.mSubtype, params.mDeviceFormFactor,
- params.mOrientation, params.mWidth, params.mMode, params.mEditorInfo,
- params.mNoSettingsKey, params.mVoiceKeyEnabled, hasShortcutKey,
- params.mLanguageSwitchKeyEnabled);
- }
-
public static final class Builder {
private final Context mContext;
private final String mPackageName;
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index 36342688e..da418f41a 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -622,6 +622,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
R.styleable.Keyboard_Case_clobberSettingsKey, id.mClobberSettingsKey);
final boolean shortcutKeyEnabledMatched = matchBoolean(a,
R.styleable.Keyboard_Case_shortcutKeyEnabled, id.mShortcutKeyEnabled);
+ final boolean shortcutKeyOnSymbolsMatched = matchBoolean(a,
+ R.styleable.Keyboard_Case_shortcutKeyOnSymbols, id.mShortcutKeyOnSymbols);
final boolean hasShortcutKeyMatched = matchBoolean(a,
R.styleable.Keyboard_Case_hasShortcutKey, id.mHasShortcutKey);
final boolean languageSwitchKeyEnabledMatched = matchBoolean(a,
@@ -640,12 +642,12 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
final boolean selected = keyboardLayoutSetElementMatched && modeMatched
&& navigateNextMatched && navigatePreviousMatched && passwordInputMatched
&& clobberSettingsKeyMatched && shortcutKeyEnabledMatched
- && hasShortcutKeyMatched && languageSwitchKeyEnabledMatched
- && isMultiLineMatched && imeActionMatched && localeCodeMatched
- && languageCodeMatched && countryCodeMatched;
+ && shortcutKeyOnSymbolsMatched && hasShortcutKeyMatched
+ && languageSwitchKeyEnabledMatched && isMultiLineMatched && imeActionMatched
+ && localeCodeMatched && languageCodeMatched && countryCodeMatched;
if (DEBUG) {
- startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE,
+ startTag("<%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s>%s", TAG_CASE,
textAttr(a.getString(
R.styleable.Keyboard_Case_keyboardLayoutSetElement),
"keyboardLayoutSetElement"),
@@ -662,6 +664,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
"passwordInput"),
booleanAttr(a, R.styleable.Keyboard_Case_shortcutKeyEnabled,
"shortcutKeyEnabled"),
+ booleanAttr(a, R.styleable.Keyboard_Case_shortcutKeyOnSymbols,
+ "shortcutKeyOnSymbols"),
booleanAttr(a, R.styleable.Keyboard_Case_hasShortcutKey,
"hasShortcutKey"),
booleanAttr(a, R.styleable.Keyboard_Case_languageSwitchKeyEnabled,