From 6614ac9f7b506c688abd2d6f09a0f2ae8b22fa68 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Sat, 2 Oct 2010 15:50:06 +0900 Subject: [PATCH] Modify BaseKeyboard to be able to handle multiple shift keys Change-Id: Ie840ae113ee6bd5b629a90959d7f955a5ceba95a --- .../inputmethod/latin/BaseKeyboard.java | 32 +++++++------------ .../inputmethod/latin/LatinKeyboard.java | 17 +++------- 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/BaseKeyboard.java b/java/src/com/android/inputmethod/latin/BaseKeyboard.java index f1a08cb4a..6f32f9c1a 100644 --- a/java/src/com/android/inputmethod/latin/BaseKeyboard.java +++ b/java/src/com/android/inputmethod/latin/BaseKeyboard.java @@ -89,11 +89,8 @@ public class BaseKeyboard { /** Is the keyboard in the shifted state */ private boolean mShifted; - /** Key instance for the shift key, if present */ - private Key mShiftKey; - - /** Key index for the shift key, if present */ - private int mShiftKeyIndex = -1; + /** List of shift keys in this keyboard */ + private final List mShiftKeys = new ArrayList(); /** Total height of the keyboard, including the padding and keys */ private int mTotalHeight; @@ -105,19 +102,19 @@ public class BaseKeyboard { private int mTotalWidth; /** List of keys in this keyboard */ - private List mKeys; + private final List mKeys = new ArrayList(); /** List of modifier keys such as Shift & Alt, if any */ - private List mModifierKeys; + private final List mModifierKeys = new ArrayList(); /** Width of the screen available to fit the keyboard */ - private int mDisplayWidth; + private final int mDisplayWidth; /** Height of the screen */ - private int mDisplayHeight; + private final int mDisplayHeight; /** Keyboard mode, or zero, if none. */ - private int mKeyboardMode; + private final int mKeyboardMode; // Variables for pre-computing nearest keys. @@ -488,8 +485,6 @@ public class BaseKeyboard { mDefaultWidth = mDisplayWidth / 10; mDefaultVerticalGap = 0; mDefaultHeight = mDefaultWidth; - mKeys = new ArrayList(); - mModifierKeys = new ArrayList(); mKeyboardMode = modeId; loadKeyboard(context, context.getResources().getXml(xmlLayoutResId)); } @@ -511,8 +506,6 @@ public class BaseKeyboard { mDefaultWidth = mDisplayWidth / 10; mDefaultVerticalGap = 0; mDefaultHeight = mDefaultWidth; - mKeys = new ArrayList(); - mModifierKeys = new ArrayList(); mKeyboardMode = modeId; loadKeyboard(context, context.getResources().getXml(xmlLayoutResId)); } @@ -622,8 +615,8 @@ public class BaseKeyboard { } public boolean setShifted(boolean shiftState) { - if (mShiftKey != null) { - mShiftKey.on = shiftState; + for (final Key key : mShiftKeys) { + key.on = shiftState; } if (mShifted != shiftState) { mShifted = shiftState; @@ -636,8 +629,8 @@ public class BaseKeyboard { return mShifted; } - public int getShiftKeyIndex() { - return mShiftKeyIndex; + public List getShiftKeys() { + return mShiftKeys; } private void computeNearestNeighbors() { @@ -725,8 +718,7 @@ public class BaseKeyboard { key = createKeyFromXml(res, currentRow, x, y, parser); mKeys.add(key); if (key.codes[0] == KEYCODE_SHIFT) { - mShiftKey = key; - mShiftKeyIndex = mKeys.size()-1; + mShiftKeys.add(key); mModifierKeys.add(key); } else if (key.codes[0] == KEYCODE_ALT) { mModifierKeys.add(key); diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java index 9c252e6c6..53ccf3629 100644 --- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -35,7 +35,6 @@ import android.util.Log; import android.view.ViewConfiguration; import android.view.inputmethod.EditorInfo; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -59,7 +58,6 @@ public class LatinKeyboard extends BaseKeyboard { private Drawable m123MicPreviewIcon; private final Drawable mButtonArrowLeftIcon; private final Drawable mButtonArrowRightIcon; - private ArrayList mShiftKeys; private Key mEnterKey; private Key mF1Key; private Key mSpaceKey; @@ -161,8 +159,6 @@ public class LatinKeyboard extends BaseKeyboard { private void initializeMemberVariablesAsNeeded() { if (mNumberHintKeys == null) mNumberHintKeys = new Key[NUMBER_HINT_COUNT]; - if (mShiftKeys == null) - mShiftKeys = new ArrayList(); } @Override @@ -184,9 +180,6 @@ public class LatinKeyboard extends BaseKeyboard { case LatinIME.KEYCODE_SPACE: mSpaceKey = key; break; - case KEYCODE_SHIFT: - mShiftKeys.add(key); - break; case KEYCODE_MODE_CHANGE: m123Key = key; m123Label = key.label; @@ -267,7 +260,7 @@ public class LatinKeyboard extends BaseKeyboard { } public void enableShiftLock() { - for (final Key key : mShiftKeys) { + for (final Key key : getShiftKeys()) { if (key instanceof LatinKey) { ((LatinKey)key).enableShiftLock(); } @@ -276,7 +269,7 @@ public class LatinKeyboard extends BaseKeyboard { } public void setShiftLocked(boolean shiftLocked) { - for (final Key key : mShiftKeys) { + for (final Key key : getShiftKeys()) { key.on = shiftLocked; key.icon = mShiftLockIcon; } @@ -290,8 +283,8 @@ public class LatinKeyboard extends BaseKeyboard { @Override public boolean setShifted(boolean shiftState) { boolean shiftChanged = false; - if (mShiftKeys.size() > 0) { - for (final Key key : mShiftKeys) { + if (getShiftKeys().size() > 0) { + for (final Key key : getShiftKeys()) { if (shiftState == false) { key.on = false; key.icon = mOldShiftIcons.get(key); @@ -314,7 +307,7 @@ public class LatinKeyboard extends BaseKeyboard { @Override public boolean isShifted() { - if (mShiftKeys.size() > 0) { + if (getShiftKeys().size() > 0) { return mShiftState != SHIFT_OFF; } else { return super.isShifted();