Fix label of switch to symbols key when symbols has shortcut key

This change fixes the labels of switch to symbols key and switch back
from more symbols key when symbols layout has shortcut key.

Change-Id: I3fbbef2d929486d0f0542f4d89cb086d9f5bad82
This commit is contained in:
Tadashi G. Takaoka 2012-12-10 19:46:23 -08:00
parent ac3720ce6d
commit 8eaf75aa7b
7 changed files with 91 additions and 94 deletions

View File

@ -389,6 +389,7 @@
<attr name="passwordInput" format="boolean" />
<attr name="clobberSettingsKey" format="boolean" />
<attr name="shortcutKeyEnabled" format="boolean" />
<attr name="shortcutKeyOnSymbols" format="boolean" />
<attr name="hasShortcutKey" format="boolean" />
<attr name="languageSwitchKeyEnabled" format="boolean" />
<attr name="isMultiLine" format="boolean" />

View File

@ -154,31 +154,30 @@
</default>
</switch>
<key-style
latin:styleName="toSymbolKeyStyle"
latin:code="!code/key_switch_alpha_symbol"
latin:keyLabel="!text/label_to_symbol_key"
latin:styleName="baseForLayoutSwitchKeyStyle"
latin:keyLabelFlags="preserveCase"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
<key-style
latin:styleName="toSymbolKeyStyle"
latin:code="!code/key_switch_alpha_symbol"
latin:keyLabel="!text/label_to_symbol_key"
latin:parentStyle="baseForLayoutSwitchKeyStyle" />
<key-style
latin:styleName="toAlphaKeyStyle"
latin:code="!code/key_switch_alpha_symbol"
latin:keyLabel="!text/label_to_alpha_key"
latin:keyLabelFlags="preserveCase"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
latin:parentStyle="baseForLayoutSwitchKeyStyle" />
<key-style
latin:styleName="toMoreSymbolKeyStyle"
latin:code="!code/key_shift"
latin:keyLabel="!text/label_to_more_symbol_for_tablet_key"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
latin:parentStyle="baseForLayoutSwitchKeyStyle" />
<key-style
latin:styleName="backFromMoreSymbolKeyStyle"
latin:code="!code/key_shift"
latin:keyLabel="!text/label_to_symbol_key"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
latin:parentStyle="baseForLayoutSwitchKeyStyle" />
<key-style
latin:styleName="comKeyStyle"
latin:keyLabel="!text/keylabel_for_popular_domain"

View File

@ -144,33 +144,30 @@
</default>
</switch>
<key-style
latin:styleName="toSymbolKeyStyle"
latin:code="!code/key_switch_alpha_symbol"
latin:keyLabel="!text/label_to_symbol_key"
latin:styleName="baseForLayoutSwitchKeyStyle"
latin:keyLabelFlags="fontNormal|preserveCase"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
<key-style
latin:styleName="toSymbolKeyStyle"
latin:code="!code/key_switch_alpha_symbol"
latin:keyLabel="!text/label_to_symbol_key"
latin:parentStyle="baseForLayoutSwitchKeyStyle" />
<key-style
latin:styleName="toAlphaKeyStyle"
latin:code="!code/key_switch_alpha_symbol"
latin:keyLabel="!text/label_to_alpha_key"
latin:keyLabelFlags="fontNormal|preserveCase"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
latin:parentStyle="baseForLayoutSwitchKeyStyle" />
<key-style
latin:styleName="toMoreSymbolKeyStyle"
latin:code="!code/key_shift"
latin:keyLabel="!text/label_to_more_symbol_for_tablet_key"
latin:keyLabelFlags="fontNormal"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
latin:parentStyle="baseForLayoutSwitchKeyStyle" />
<key-style
latin:styleName="backFromMoreSymbolKeyStyle"
latin:code="!code/key_shift"
latin:keyLabel="!text/label_to_symbol_key"
latin:keyLabelFlags="fontNormal"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
latin:parentStyle="baseForLayoutSwitchKeyStyle" />
<key-style
latin:styleName="comKeyStyle"
latin:keyLabel="!text/keylabel_for_popular_domain"

View File

@ -134,52 +134,50 @@
latin:code="!code/key_tab"
latin:keyIcon="!icon/tab_key"
latin:keyIconPreview="!icon/tab_key_preview" />
<key-style
latin:styleName="baseForLayoutSwitchKeyStyle"
latin:keyLabelFlags="preserveCase"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
<switch>
<!-- When this qwerty keyboard has no shortcut keys but shortcut key is enabled, then symbol
keyboard will have a shortcut key. That means we should use label_to_symbol_key label
and shortcut_for_label icon. -->
<case
latin:shortcutKeyEnabled="true"
latin:hasShortcutKey="false"
latin:shortcutKeyOnSymbols="true"
>
<key-style
latin:styleName="toSymbolKeyStyle"
latin:code="!code/key_switch_alpha_symbol"
latin:styleName="baseForToSymbolKeyStyle"
latin:keyIcon="!icon/shortcut_for_label"
latin:keyLabel="!text/label_to_symbol_with_microphone_key"
latin:keyLabelFlags="withIconRight|preserveCase"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
latin:parentStyle="baseForLayoutSwitchKeyStyle" />
</case>
<default>
<key-style
latin:styleName="toSymbolKeyStyle"
latin:code="!code/key_switch_alpha_symbol"
latin:styleName="baseForToSymbolKeyStyle"
latin:keyLabel="!text/label_to_symbol_key"
latin:keyLabelFlags="preserveCase"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
latin:parentStyle="baseForLayoutSwitchKeyStyle" />
</default>
</switch>
<key-style
latin:styleName="toSymbolKeyStyle"
latin:code="!code/key_switch_alpha_symbol"
latin:parentStyle="baseForToSymbolKeyStyle" />
<key-style
latin:styleName="toAlphaKeyStyle"
latin:code="!code/key_switch_alpha_symbol"
latin:keyLabel="!text/label_to_alpha_key"
latin:keyLabelFlags="preserveCase"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
latin:parentStyle="baseForLayoutSwitchKeyStyle" />
<key-style
latin:styleName="toMoreSymbolKeyStyle"
latin:code="!code/key_shift"
latin:keyLabel="!text/label_to_more_symbol_key"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
latin:parentStyle="baseForLayoutSwitchKeyStyle" />
<key-style
latin:styleName="backFromMoreSymbolKeyStyle"
latin:code="!code/key_shift"
latin:keyLabel="!text/label_to_symbol_key"
latin:keyActionFlags="noKeyPreview"
latin:backgroundType="functional" />
latin:parentStyle="baseForToSymbolKeyStyle" />
<key-style
latin:styleName="punctuationKeyStyle"
latin:keyLabel="."

View File

@ -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);
}

View File

@ -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;

View File

@ -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,