diff options
author | Jim Miller <jaggies@google.com> | 2011-01-19 22:01:25 -0800 |
---|---|---|
committer | Jim Miller <jaggies@google.com> | 2011-01-20 18:20:12 -0800 |
commit | 6465f7753783a614948fb3ffbd8c072345b4eea1 (patch) | |
tree | 20e2267a4993d8d28ba6836e0058aac0bde0b64d /core/java/com/android/internal/widget/PasswordEntryKeyboard.java | |
parent | 9c91c7e27fbfff5abc34e19779a9477239ab9b10 (diff) | |
download | frameworks_base-6465f7753783a614948fb3ffbd8c072345b4eea1.zip frameworks_base-6465f7753783a614948fb3ffbd8c072345b4eea1.tar.gz frameworks_base-6465f7753783a614948fb3ffbd8c072345b4eea1.tar.bz2 |
Fix 3374446: Allow multiple shift keys in Keyboard.
This fixes a bug introduced in 3c6dd8f9 because we now
have two shift keys. The code now tracks a global state
and looks for up to two shift keys.
Update after review and added code to handle extra
invalidate required by additional shift key.
Change-Id: Ic1728dd0ceec089089cd1beca1b0b30565d6e658
Diffstat (limited to 'core/java/com/android/internal/widget/PasswordEntryKeyboard.java')
-rw-r--r-- | core/java/com/android/internal/widget/PasswordEntryKeyboard.java | 90 |
1 files changed, 38 insertions, 52 deletions
diff --git a/core/java/com/android/internal/widget/PasswordEntryKeyboard.java b/core/java/com/android/internal/widget/PasswordEntryKeyboard.java index facda36..3c01c69 100644 --- a/core/java/com/android/internal/widget/PasswordEntryKeyboard.java +++ b/core/java/com/android/internal/widget/PasswordEntryKeyboard.java @@ -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(); |