am a5627e4e: Merge "Reset old keyboard state before switching to new keyboard" into honeycomb

* commit 'a5627e4e1f7765b4b62a87fc8843179b5519cf18':
  Reset old keyboard state before switching to new keyboard
main
Tadashi G. Takaoka 2011-01-11 22:56:11 -08:00 committed by Android Git Automerger
commit 5c60220d8e
2 changed files with 13 additions and 7 deletions

View File

@ -48,7 +48,7 @@ public class LatinKeyboard extends Keyboard {
private final Drawable mButtonArrowLeftIcon; private final Drawable mButtonArrowLeftIcon;
private final Drawable mButtonArrowRightIcon; private final Drawable mButtonArrowRightIcon;
private final int mSpaceBarTextShadowColor; private final int mSpaceBarTextShadowColor;
private int mSpaceKeyIndex = -1; private final int[] mSpaceKeyIndexArray;
private int mSpaceDragStartX; private int mSpaceDragStartX;
private int mSpaceDragLastDiff; private int mSpaceDragLastDiff;
private final Context mContext; private final Context mContext;
@ -92,7 +92,8 @@ public class LatinKeyboard extends Keyboard {
mButtonArrowRightIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_right); mButtonArrowRightIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_right);
sSpacebarVerticalCorrection = res.getDimensionPixelOffset( sSpacebarVerticalCorrection = res.getDimensionPixelOffset(
R.dimen.spacebar_vertical_correction); R.dimen.spacebar_vertical_correction);
mSpaceKeyIndex = indexOf(CODE_SPACE); // The index of space key is available only after Keyboard constructor has finished.
mSpaceKeyIndexArray = new int[] { indexOf(CODE_SPACE) };
} }
/** /**
@ -418,7 +419,7 @@ public class LatinKeyboard extends Keyboard {
@Override @Override
public int[] getNearestKeys(int x, int y) { public int[] getNearestKeys(int x, int y) {
if (mCurrentlyInSpace) { if (mCurrentlyInSpace) {
return new int[] { mSpaceKeyIndex }; return mSpaceKeyIndexArray;
} else { } else {
// Avoid dead pixels at edges of the keyboard // Avoid dead pixels at edges of the keyboard
return super.getNearestKeys(Math.max(0, Math.min(x, getMinWidth() - 1)), return super.getNearestKeys(Math.max(0, Math.min(x, getMinWidth() - 1)),

View File

@ -62,13 +62,18 @@ public class LatinKeyboardView extends KeyboardView {
} }
} }
public void setLatinKeyboard(LatinKeyboard k) { public void setLatinKeyboard(LatinKeyboard newKeyboard) {
super.setKeyboard(k); final LatinKeyboard oldKeyboard = getLatinKeyboard();
if (oldKeyboard != null) {
// Reset old keyboard state before switching to new keyboard.
oldKeyboard.keyReleased();
}
super.setKeyboard(newKeyboard);
// One-seventh of the keyboard width seems like a reasonable threshold // One-seventh of the keyboard width seems like a reasonable threshold
mJumpThresholdSquare = k.getMinWidth() / 7; mJumpThresholdSquare = newKeyboard.getMinWidth() / 7;
mJumpThresholdSquare *= mJumpThresholdSquare; mJumpThresholdSquare *= mJumpThresholdSquare;
// Assuming there are 4 rows, this is the coordinate of the last row // Assuming there are 4 rows, this is the coordinate of the last row
mLastRowY = (k.getHeight() * 3) / 4; mLastRowY = (newKeyboard.getHeight() * 3) / 4;
} }
public LatinKeyboard getLatinKeyboard() { public LatinKeyboard getLatinKeyboard() {