Merge "Fix 3374446: Allow multiple shift keys in Keyboard." into honeycomb

This commit is contained in:
Jim Miller
2011-01-20 18:51:12 -08:00
committed by Android (Google) Code Review
3 changed files with 73 additions and 61 deletions

View File

@@ -97,11 +97,11 @@ public class Keyboard {
private boolean mShifted;
/** Key instance for the shift key, if present */
private Key mShiftKey;
private Key[] mShiftKeys = { null, null };
/** Key index for the shift key, if present */
private int mShiftKeyIndex = -1;
private int[] mShiftKeyIndices = {-1, -1};
/** Current key width, while loading the keyboard */
private int mKeyWidth;
@@ -656,8 +656,10 @@ public class Keyboard {
}
public boolean setShifted(boolean shiftState) {
if (mShiftKey != null) {
mShiftKey.on = shiftState;
for (Key shiftKey : mShiftKeys) {
if (shiftKey != null) {
shiftKey.on = shiftState;
}
}
if (mShifted != shiftState) {
mShifted = shiftState;
@@ -670,8 +672,15 @@ public class Keyboard {
return mShifted;
}
/**
* @hide
*/
public int[] getShiftKeyIndices() {
return mShiftKeyIndices;
}
public int getShiftKeyIndex() {
return mShiftKeyIndex;
return mShiftKeyIndices[0];
}
private void computeNearestNeighbors() {
@@ -760,8 +769,14 @@ public class Keyboard {
key = createKeyFromXml(res, currentRow, x, y, parser);
mKeys.add(key);
if (key.codes[0] == KEYCODE_SHIFT) {
mShiftKey = key;
mShiftKeyIndex = mKeys.size()-1;
// Find available shift key slot and put this shift key in it
for (int i = 0; i < mShiftKeys.length; i++) {
if (mShiftKeys[i] == null) {
mShiftKeys[i] = key;
mShiftKeyIndices[i] = mKeys.size()-1;
break;
}
}
mModifierKeys.add(key);
} else if (key.codes[0] == KEYCODE_ALT) {
mModifierKeys.add(key);

View File

@@ -20,16 +20,9 @@ import java.util.Locale;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.Paint.Align;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.util.Log;
import com.android.internal.R;
/**
@@ -40,7 +33,6 @@ import com.android.internal.R;
* keypad with alpha characters hints.
*/
public class PasswordEntryKeyboard extends Keyboard {
private static final String TAG = "PasswordEntryKeyboard";
private static final int SHIFT_OFF = 0;
private static final int SHIFT_ON = 1;
private static final int SHIFT_LOCKED = 2;
@@ -48,17 +40,14 @@ public class PasswordEntryKeyboard extends Keyboard {
private Drawable mShiftIcon;
private Drawable mShiftLockIcon;
private Drawable mShiftLockPreviewIcon;
private Drawable mOldShiftIcon;
private Drawable mOldShiftPreviewIcon;
private Drawable mSpaceIcon;
private Key mShiftKey;
// These two arrays must be the same length
private Drawable[] mOldShiftIcons = { null, null };
private Key[] mShiftKeys = { null, null };
private Key mEnterKey;
private Key mF1Key;
private Key mSpaceKey;
private Locale mLocale;
private Resources mRes;
private int mExtensionResId;
private int mShiftState = SHIFT_OFF;
static int sSpacebarVerticalCorrection;
@@ -84,14 +73,8 @@ public class PasswordEntryKeyboard extends Keyboard {
private void init(Context context) {
final Resources res = context.getResources();
mRes = res;
mShiftIcon = res.getDrawable(R.drawable.sym_keyboard_shift);
mShiftLockIcon = res.getDrawable(R.drawable.sym_keyboard_shift_locked);
mShiftLockPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_shift_locked);
mShiftLockPreviewIcon.setBounds(0, 0,
mShiftLockPreviewIcon.getIntrinsicWidth(),
mShiftLockPreviewIcon.getIntrinsicHeight());
mSpaceIcon = res.getDrawable(R.drawable.sym_keyboard_space);
sSpacebarVerticalCorrection = res.getDimensionPixelOffset(
R.dimen.password_keyboard_spacebar_vertical_correction);
}
@@ -157,14 +140,16 @@ public class PasswordEntryKeyboard extends Keyboard {
*
*/
void enableShiftLock() {
int index = getShiftKeyIndex();
if (index >= 0) {
mShiftKey = getKeys().get(index);
if (mShiftKey instanceof LatinKey) {
((LatinKey)mShiftKey).enableShiftLock();
int i = 0;
for (int index : getShiftKeyIndices()) {
if (index >= 0 && i < mShiftKeys.length) {
mShiftKeys[i] = getKeys().get(index);
if (mShiftKeys[i] instanceof LatinKey) {
((LatinKey)mShiftKeys[i]).enableShiftLock();
}
mOldShiftIcons[i] = mShiftKeys[i].icon;
i++;
}
mOldShiftIcon = mShiftKey.icon;
mOldShiftPreviewIcon = mShiftKey.iconPreview;
}
}
@@ -176,17 +161,13 @@ public class PasswordEntryKeyboard extends Keyboard {
* @param shiftLocked
*/
void setShiftLocked(boolean shiftLocked) {
if (mShiftKey != null) {
if (shiftLocked) {
mShiftKey.on = true;
mShiftKey.icon = mShiftLockIcon;
mShiftState = SHIFT_LOCKED;
} else {
mShiftKey.on = false;
mShiftKey.icon = mShiftLockIcon;
mShiftState = SHIFT_ON;
for (Key shiftKey : mShiftKeys) {
if (shiftKey != null) {
shiftKey.on = shiftLocked;
shiftKey.icon = mShiftLockIcon;
}
}
mShiftState = shiftLocked ? SHIFT_LOCKED : SHIFT_ON;
}
/**
@@ -199,20 +180,25 @@ public class PasswordEntryKeyboard extends Keyboard {
@Override
public boolean setShifted(boolean shiftState) {
boolean shiftChanged = false;
if (mShiftKey != null) {
if (shiftState == false) {
shiftChanged = mShiftState != SHIFT_OFF;
mShiftState = SHIFT_OFF;
mShiftKey.on = false;
mShiftKey.icon = mOldShiftIcon;
} else if (mShiftState == SHIFT_OFF) {
shiftChanged = mShiftState == SHIFT_OFF;
mShiftState = SHIFT_ON;
mShiftKey.on = false;
mShiftKey.icon = mShiftIcon;
if (shiftState == false) {
shiftChanged = mShiftState != SHIFT_OFF;
mShiftState = SHIFT_OFF;
} else if (mShiftState == SHIFT_OFF) {
shiftChanged = mShiftState == SHIFT_OFF;
mShiftState = SHIFT_ON;
}
for (int i = 0; i < mShiftKeys.length; i++) {
if (mShiftKeys[i] != null) {
if (shiftState == false) {
mShiftKeys[i].on = false;
mShiftKeys[i].icon = mOldShiftIcons[i];
} else if (mShiftState == SHIFT_OFF) {
mShiftKeys[i].on = false;
mShiftKeys[i].icon = mShiftIcon;
}
} else {
// return super.setShifted(shiftState);
}
} else {
return super.setShifted(shiftState);
}
return shiftChanged;
}
@@ -223,7 +209,7 @@ public class PasswordEntryKeyboard extends Keyboard {
*/
@Override
public boolean isShifted() {
if (mShiftKey != null) {
if (mShiftKeys[0] != null) {
return mShiftState != SHIFT_OFF;
} else {
return super.isShifted();

View File

@@ -36,4 +36,15 @@ public class PasswordEntryKeyboardView extends KeyboardView {
super(context, attrs, defStyle);
}
@Override
public boolean setShifted(boolean shifted) {
boolean result = super.setShifted(shifted);
// invalidate both shift keys
int[] indices = getKeyboard().getShiftKeyIndices();
for (int index : indices) {
invalidateKey(index);
}
return result;
}
}