Modify BaseKeyboard to be able to handle multiple shift keys

Change-Id: Ie840ae113ee6bd5b629a90959d7f955a5ceba95a
main
Tadashi G. Takaoka 2010-10-02 15:50:06 +09:00
parent 4fc510a789
commit 6614ac9f7b
2 changed files with 17 additions and 32 deletions

View File

@ -89,11 +89,8 @@ public class BaseKeyboard {
/** Is the keyboard in the shifted state */ /** Is the keyboard in the shifted state */
private boolean mShifted; private boolean mShifted;
/** Key instance for the shift key, if present */ /** List of shift keys in this keyboard */
private Key mShiftKey; private final List<Key> mShiftKeys = new ArrayList<Key>();
/** Key index for the shift key, if present */
private int mShiftKeyIndex = -1;
/** Total height of the keyboard, including the padding and keys */ /** Total height of the keyboard, including the padding and keys */
private int mTotalHeight; private int mTotalHeight;
@ -105,19 +102,19 @@ public class BaseKeyboard {
private int mTotalWidth; private int mTotalWidth;
/** List of keys in this keyboard */ /** List of keys in this keyboard */
private List<Key> mKeys; private final List<Key> mKeys = new ArrayList<Key>();
/** List of modifier keys such as Shift & Alt, if any */ /** List of modifier keys such as Shift & Alt, if any */
private List<Key> mModifierKeys; private final List<Key> mModifierKeys = new ArrayList<Key>();
/** Width of the screen available to fit the keyboard */ /** Width of the screen available to fit the keyboard */
private int mDisplayWidth; private final int mDisplayWidth;
/** Height of the screen */ /** Height of the screen */
private int mDisplayHeight; private final int mDisplayHeight;
/** Keyboard mode, or zero, if none. */ /** Keyboard mode, or zero, if none. */
private int mKeyboardMode; private final int mKeyboardMode;
// Variables for pre-computing nearest keys. // Variables for pre-computing nearest keys.
@ -488,8 +485,6 @@ public class BaseKeyboard {
mDefaultWidth = mDisplayWidth / 10; mDefaultWidth = mDisplayWidth / 10;
mDefaultVerticalGap = 0; mDefaultVerticalGap = 0;
mDefaultHeight = mDefaultWidth; mDefaultHeight = mDefaultWidth;
mKeys = new ArrayList<Key>();
mModifierKeys = new ArrayList<Key>();
mKeyboardMode = modeId; mKeyboardMode = modeId;
loadKeyboard(context, context.getResources().getXml(xmlLayoutResId)); loadKeyboard(context, context.getResources().getXml(xmlLayoutResId));
} }
@ -511,8 +506,6 @@ public class BaseKeyboard {
mDefaultWidth = mDisplayWidth / 10; mDefaultWidth = mDisplayWidth / 10;
mDefaultVerticalGap = 0; mDefaultVerticalGap = 0;
mDefaultHeight = mDefaultWidth; mDefaultHeight = mDefaultWidth;
mKeys = new ArrayList<Key>();
mModifierKeys = new ArrayList<Key>();
mKeyboardMode = modeId; mKeyboardMode = modeId;
loadKeyboard(context, context.getResources().getXml(xmlLayoutResId)); loadKeyboard(context, context.getResources().getXml(xmlLayoutResId));
} }
@ -622,8 +615,8 @@ public class BaseKeyboard {
} }
public boolean setShifted(boolean shiftState) { public boolean setShifted(boolean shiftState) {
if (mShiftKey != null) { for (final Key key : mShiftKeys) {
mShiftKey.on = shiftState; key.on = shiftState;
} }
if (mShifted != shiftState) { if (mShifted != shiftState) {
mShifted = shiftState; mShifted = shiftState;
@ -636,8 +629,8 @@ public class BaseKeyboard {
return mShifted; return mShifted;
} }
public int getShiftKeyIndex() { public List<Key> getShiftKeys() {
return mShiftKeyIndex; return mShiftKeys;
} }
private void computeNearestNeighbors() { private void computeNearestNeighbors() {
@ -725,8 +718,7 @@ public class BaseKeyboard {
key = createKeyFromXml(res, currentRow, x, y, parser); key = createKeyFromXml(res, currentRow, x, y, parser);
mKeys.add(key); mKeys.add(key);
if (key.codes[0] == KEYCODE_SHIFT) { if (key.codes[0] == KEYCODE_SHIFT) {
mShiftKey = key; mShiftKeys.add(key);
mShiftKeyIndex = mKeys.size()-1;
mModifierKeys.add(key); mModifierKeys.add(key);
} else if (key.codes[0] == KEYCODE_ALT) { } else if (key.codes[0] == KEYCODE_ALT) {
mModifierKeys.add(key); mModifierKeys.add(key);

View File

@ -35,7 +35,6 @@ import android.util.Log;
import android.view.ViewConfiguration; import android.view.ViewConfiguration;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -59,7 +58,6 @@ public class LatinKeyboard extends BaseKeyboard {
private Drawable m123MicPreviewIcon; private Drawable m123MicPreviewIcon;
private final Drawable mButtonArrowLeftIcon; private final Drawable mButtonArrowLeftIcon;
private final Drawable mButtonArrowRightIcon; private final Drawable mButtonArrowRightIcon;
private ArrayList<Key> mShiftKeys;
private Key mEnterKey; private Key mEnterKey;
private Key mF1Key; private Key mF1Key;
private Key mSpaceKey; private Key mSpaceKey;
@ -161,8 +159,6 @@ public class LatinKeyboard extends BaseKeyboard {
private void initializeMemberVariablesAsNeeded() { private void initializeMemberVariablesAsNeeded() {
if (mNumberHintKeys == null) if (mNumberHintKeys == null)
mNumberHintKeys = new Key[NUMBER_HINT_COUNT]; mNumberHintKeys = new Key[NUMBER_HINT_COUNT];
if (mShiftKeys == null)
mShiftKeys = new ArrayList<Key>();
} }
@Override @Override
@ -184,9 +180,6 @@ public class LatinKeyboard extends BaseKeyboard {
case LatinIME.KEYCODE_SPACE: case LatinIME.KEYCODE_SPACE:
mSpaceKey = key; mSpaceKey = key;
break; break;
case KEYCODE_SHIFT:
mShiftKeys.add(key);
break;
case KEYCODE_MODE_CHANGE: case KEYCODE_MODE_CHANGE:
m123Key = key; m123Key = key;
m123Label = key.label; m123Label = key.label;
@ -267,7 +260,7 @@ public class LatinKeyboard extends BaseKeyboard {
} }
public void enableShiftLock() { public void enableShiftLock() {
for (final Key key : mShiftKeys) { for (final Key key : getShiftKeys()) {
if (key instanceof LatinKey) { if (key instanceof LatinKey) {
((LatinKey)key).enableShiftLock(); ((LatinKey)key).enableShiftLock();
} }
@ -276,7 +269,7 @@ public class LatinKeyboard extends BaseKeyboard {
} }
public void setShiftLocked(boolean shiftLocked) { public void setShiftLocked(boolean shiftLocked) {
for (final Key key : mShiftKeys) { for (final Key key : getShiftKeys()) {
key.on = shiftLocked; key.on = shiftLocked;
key.icon = mShiftLockIcon; key.icon = mShiftLockIcon;
} }
@ -290,8 +283,8 @@ public class LatinKeyboard extends BaseKeyboard {
@Override @Override
public boolean setShifted(boolean shiftState) { public boolean setShifted(boolean shiftState) {
boolean shiftChanged = false; boolean shiftChanged = false;
if (mShiftKeys.size() > 0) { if (getShiftKeys().size() > 0) {
for (final Key key : mShiftKeys) { for (final Key key : getShiftKeys()) {
if (shiftState == false) { if (shiftState == false) {
key.on = false; key.on = false;
key.icon = mOldShiftIcons.get(key); key.icon = mOldShiftIcons.get(key);
@ -314,7 +307,7 @@ public class LatinKeyboard extends BaseKeyboard {
@Override @Override
public boolean isShifted() { public boolean isShifted() {
if (mShiftKeys.size() > 0) { if (getShiftKeys().size() > 0) {
return mShiftState != SHIFT_OFF; return mShiftState != SHIFT_OFF;
} else { } else {
return super.isShifted(); return super.isShifted();