From 6d9bcd5e1317722207116ab6a3ddfcb152005701 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 27 Jul 2011 17:20:06 -0700 Subject: [PATCH] Remove enableShiftLock attribute from KeyboardId This change is a follow up of Ia72de236. Bug: 4311428 Change-Id: I0ad0f1fb93545ceb40df8dffe377240b020c2602 --- .../com/android/inputmethod/keyboard/Key.java | 16 +++--- .../inputmethod/keyboard/Keyboard.java | 51 ++++++++++--------- .../inputmethod/keyboard/KeyboardId.java | 19 +++---- .../keyboard/KeyboardSwitcher.java | 21 +------- .../keyboard/internal/KeyboardParser.java | 2 - .../inputmethod/latin/SuggestTestsBase.java | 2 +- 6 files changed, 46 insertions(+), 65 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 0ee8d7174..68868f12e 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -325,6 +325,13 @@ public class Key { keyAttr, R.styleable.Keyboard_Key_keyIcon, KeyboardIconsSet.ICON_UNDEFINED)); Keyboard.setDefaultBounds(mIcon); + final int shiftedIconId = style.getInt(keyAttr, R.styleable.Keyboard_Key_keyIconShifted, + KeyboardIconsSet.ICON_UNDEFINED); + if (shiftedIconId != KeyboardIconsSet.ICON_UNDEFINED) { + final Drawable shiftedIcon = iconsSet.getIcon(shiftedIconId); + Keyboard.setDefaultBounds(shiftedIcon); + mKeyboard.addShiftedIcon(this, shiftedIcon); + } mHintLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyHintLabel); mLabel = style.getText(keyAttr, R.styleable.Keyboard_Key_keyLabel); @@ -342,12 +349,9 @@ public class Key { } else { mCode = Keyboard.CODE_DUMMY; } - - final Drawable shiftedIcon = iconsSet.getIcon(style.getInt( - keyAttr, R.styleable.Keyboard_Key_keyIconShifted, - KeyboardIconsSet.ICON_UNDEFINED)); - if (shiftedIcon != null) - mKeyboard.getShiftedIcons().put(this, shiftedIcon); + if (mCode == Keyboard.CODE_SHIFT) { + mKeyboard.addShiftKey(this); + } } finally { keyAttr.recycle(); } diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 19847c5ec..f160f65f0 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -34,7 +34,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; /** * Loads an XML description of a keyboard and stores the attributes of the keys. A keyboard @@ -116,8 +115,8 @@ public class Keyboard { /** List of shift keys in this keyboard and its icons and state */ private final List mShiftKeys = new ArrayList(); private final HashMap mShiftedIcons = new HashMap(); - private final HashMap mNormalShiftIcons = new HashMap(); - private final HashSet mShiftLockEnabled = new HashSet(); + private final HashMap mUnshiftedIcons = new HashMap(); + private final HashSet mShiftLockKeys = new HashSet(); private final KeyboardShiftState mShiftState = new KeyboardShiftState(); /** Total height of the keyboard, including the padding and keys */ @@ -284,30 +283,35 @@ public class Keyboard { mMaxPopupColumn = column; } - public List getShiftKeys() { - return mShiftKeys; - } - - public Map getShiftedIcons() { - return mShiftedIcons; - } - - public void enableShiftLock() { - for (final Key key : getShiftKeys()) { - mShiftLockEnabled.add(key); - mNormalShiftIcons.put(key, key.getIcon()); + public void addShiftKey(Key key) { + if (key == null) return; + mShiftKeys.add(key); + if (key.mSticky) { + mShiftLockKeys.add(key); } } - public boolean isShiftLockEnabled(Key key) { - return mShiftLockEnabled.contains(key); + public void addShiftedIcon(Key key, Drawable icon) { + if (key == null) return; + mUnshiftedIcons.put(key, key.getIcon()); + mShiftedIcons.put(key, icon); + } + + public boolean hasShiftLockKey() { + return !mShiftLockKeys.isEmpty(); } public boolean setShiftLocked(boolean newShiftLockState) { - final Map shiftedIcons = getShiftedIcons(); - for (final Key key : getShiftKeys()) { + for (final Key key : mShiftLockKeys) { + // To represent "shift locked" state. The highlight is handled by background image that + // might be a StateListDrawable. key.setHighlightOn(newShiftLockState); - key.setIcon(newShiftLockState ? shiftedIcons.get(key) : mNormalShiftIcons.get(key)); + // To represent "shifted" state. The key might have a shifted icon. + if (newShiftLockState && mShiftedIcons.containsKey(key)) { + key.setIcon(mShiftedIcons.get(key)); + } else { + key.setIcon(mUnshiftedIcons.get(key)); + } } mShiftState.setShiftLocked(newShiftLockState); return true; @@ -318,12 +322,11 @@ public class Keyboard { } public boolean setShifted(boolean newShiftState) { - final Map shiftedIcons = getShiftedIcons(); - for (final Key key : getShiftKeys()) { + for (final Key key : mShiftKeys) { if (!newShiftState && !mShiftState.isShiftLocked()) { - key.setIcon(mNormalShiftIcons.get(key)); + key.setIcon(mUnshiftedIcons.get(key)); } else if (newShiftState && !mShiftState.isShiftedOrShiftLocked()) { - key.setIcon(shiftedIcons.get(key)); + key.setIcon(mShiftedIcons.get(key)); } } return mShiftState.setShifted(newShiftState); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index 3f30165aa..3ed0dbe62 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java @@ -58,7 +58,6 @@ public class KeyboardId { public final boolean mVoiceKeyEnabled; public final boolean mHasVoiceKey; public final int mImeAction; - public final boolean mEnableShiftLock; public final String mXmlName; public final EditorInfo mAttribute; @@ -67,8 +66,7 @@ public class KeyboardId { public KeyboardId(String xmlName, int xmlId, Locale locale, int orientation, int width, int mode, EditorInfo attribute, boolean hasSettingsKey, int f2KeyMode, - boolean clobberSettingsKey, boolean voiceKeyEnabled, boolean hasVoiceKey, - boolean enableShiftLock) { + boolean clobberSettingsKey, boolean voiceKeyEnabled, boolean hasVoiceKey) { final int inputType = (attribute != null) ? attribute.inputType : 0; final int imeOptions = (attribute != null) ? attribute.imeOptions : 0; this.mLocale = locale; @@ -91,7 +89,6 @@ public class KeyboardId { // {@link EditorInfo#IME_FLAG_NO_ENTER_ACTION}. this.mImeAction = imeOptions & ( EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION); - this.mEnableShiftLock = enableShiftLock; this.mXmlName = xmlName; this.mAttribute = attribute; @@ -110,21 +107,19 @@ public class KeyboardId { voiceKeyEnabled, hasVoiceKey, mImeAction, - enableShiftLock, }); } public KeyboardId cloneAsMiniKeyboard() { return new KeyboardId("mini popup keyboard", MINI_KEYBOARD_ID_MARKER, mLocale, mOrientation, - mWidth, mMode, mAttribute, false, F2KEY_MODE_NONE, false, false, false, false); + mWidth, mMode, mAttribute, false, F2KEY_MODE_NONE, false, false, false); } public KeyboardId cloneWithNewGeometry(int orientation, int width) { if (mWidth == width) return this; return new KeyboardId(mXmlName, mXmlId, mLocale, orientation, width, mMode, mAttribute, - mHasSettingsKey, mF2KeyMode, mClobberSettingsKey, mVoiceKeyEnabled, mHasVoiceKey, - mEnableShiftLock); + mHasSettingsKey, mF2KeyMode, mClobberSettingsKey, mVoiceKeyEnabled, mHasVoiceKey); } public int getXmlId() { @@ -173,8 +168,7 @@ public class KeyboardId { && other.mClobberSettingsKey == this.mClobberSettingsKey && other.mVoiceKeyEnabled == this.mVoiceKeyEnabled && other.mHasVoiceKey == this.mHasVoiceKey - && other.mImeAction == this.mImeAction - && other.mEnableShiftLock == this.mEnableShiftLock; + && other.mImeAction == this.mImeAction; } @Override @@ -184,7 +178,7 @@ public class KeyboardId { @Override public String toString() { - return String.format("[%s.xml %s %s%d %s %s %s%s%s%s%s%s%s%s]", + return String.format("[%s.xml %s %s%d %s %s %s%s%s%s%s%s%s]", mXmlName, mLocale, (mOrientation == 1 ? "port" : "land"), mWidth, @@ -196,8 +190,7 @@ public class KeyboardId { (mPasswordInput ? " passwordInput" : ""), (mHasSettingsKey ? " hasSettingsKey" : ""), (mVoiceKeyEnabled ? " voiceKeyEnabled" : ""), - (mHasVoiceKey ? " hasVoiceKey" : ""), - (mEnableShiftLock ? " enableShiftLock" : "") + (mHasVoiceKey ? " hasVoiceKey" : "") ); } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 552a3cd30..e7e707ca1 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -204,11 +204,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mSubtypeSwitcher.getInputLocale()); keyboard = new LatinKeyboard(mThemeContext, id, id.mWidth); - - if (id.mEnableShiftLock) { - keyboard.enableShiftLock(); - } - mKeyboardCache.put(id, new SoftReference(keyboard)); if (DEBUG_CACHE) Log.d(TAG, "keyboard cache size=" + mKeyboardCache.size() + ": " @@ -241,16 +236,13 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha final int mode = Utils.getKeyboardMode(attribute); final boolean hasVoiceKey = voiceKeyEnabled && (isSymbols != voiceKeyOnMain); final int xmlId; - final boolean enableShiftLock; switch (mode) { case KeyboardId.MODE_PHONE: xmlId = (isSymbols && isShift) ? R.xml.kbd_phone_shift : R.xml.kbd_phone; - enableShiftLock = true; break; case KeyboardId.MODE_NUMBER: xmlId = R.xml.kbd_number; - enableShiftLock = false; break; default: if (isSymbols) { @@ -258,7 +250,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } else { xmlId = R.xml.kbd_qwerty; } - enableShiftLock = true; break; } @@ -275,7 +266,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha return new KeyboardId( res.getResourceEntryName(xmlId), xmlId, locale, orientation, mWindowWidth, mode, attribute, hasSettingsKey, f2KeyMode, clobberSettingsKey, voiceKeyEnabled, - hasVoiceKey, enableShiftLock); + hasVoiceKey); } public int getKeyboardMode() { @@ -571,7 +562,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha // Symbol keyboard may have an ALT key that has a caps lock style indicator (a.k.a. // sticky shift key). To show or dismiss the indicator, we need to call setShiftLocked() // that takes care of the current keyboard having such ALT key or not. - keyboard.setShiftLocked(hasStickyShiftKey(keyboard)); + keyboard.setShiftLocked(keyboard.hasShiftLockKey()); } else { keyboard = getKeyboard(mSymbolsKeyboardId); // Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the @@ -581,14 +572,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha setKeyboard(keyboard); } - private static boolean hasStickyShiftKey(Keyboard keyboard) { - for (final Key shiftKey : keyboard.getShiftKeys()) { - if (shiftKey.mSticky) - return true; - } - return false; - } - public boolean isInMomentarySwitchState() { return mSwitchState == SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL || mSwitchState == SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE; diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java index 8eae2bb42..6a83b3d99 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParser.java @@ -338,8 +338,6 @@ public class KeyboardParser { Arrays.toString(key.mPopupCharacters))); checkEndTag(TAG_KEY, parser); keys.add(key); - if (key.mCode == Keyboard.CODE_SHIFT) - mKeyboard.getShiftKeys().add(key); endKey(key); } } diff --git a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java index 8aadee42e..7d61d00f0 100644 --- a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java @@ -42,7 +42,7 @@ public class SuggestTestsBase extends AndroidTestCase { return new KeyboardId(locale.toString() + " keyboard", com.android.inputmethod.latin.R.xml.kbd_qwerty, locale, Configuration.ORIENTATION_LANDSCAPE, displayWidth, KeyboardId.MODE_TEXT, - new EditorInfo(), false, KeyboardId.F2KEY_MODE_NONE, false, false, false, false); + new EditorInfo(), false, KeyboardId.F2KEY_MODE_NONE, false, false, false); } protected InputStream openTestRawResource(int resIdInTest) {