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 */
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<Key> mShiftKeys = new ArrayList<Key>();
/** 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<Key> mKeys;
private final List<Key> mKeys = new ArrayList<Key>();
/** 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 */
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<Key>();
mModifierKeys = new ArrayList<Key>();
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<Key>();
mModifierKeys = new ArrayList<Key>();
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<Key> 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);

View File

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