Fix 2373088: Cleanup and minor fixes to PasswordKeyboard*.

This commit is contained in:
Jim Miller
2010-02-09 19:05:02 -08:00
parent d2e6af66ce
commit 280b6023cb
12 changed files with 180 additions and 388 deletions

View File

@@ -216,61 +216,6 @@ public class PasswordEntryKeyboard extends Keyboard {
}
}
/**
* Sets keyboard extension. Keyboard extension is shown when input is detected above keyboard
* while keyboard has focus.
*
* @param resId
*/
public void setExtension(int resId) {
mExtensionResId = resId;
}
/**
* Get current extesion resource id.
*
* @return resource id, 0 if not set.
*/
public int getExtension() {
return mExtensionResId;
}
private void updateSpaceBarForLocale() {
if (mLocale != null) {
// Create the graphic for spacebar
Bitmap buffer = Bitmap.createBitmap(mSpaceKey.width, mSpaceIcon.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(buffer);
canvas.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
Paint paint = new Paint();
paint.setAntiAlias(true);
// TODO: Make the text size a customizable attribute
paint.setTextSize(22);
paint.setTextAlign(Align.CENTER);
// Draw a drop shadow for the text
paint.setShadowLayer(1f, 0, 0, 0xFF000000);
paint.setColor(0x80C0C0C0);
canvas.drawText(mLocale.getDisplayLanguage(mLocale),
buffer.getWidth() / 2, - paint.ascent() + 2, paint);
int x = (buffer.getWidth() - mSpaceIcon.getIntrinsicWidth()) / 2;
int y = buffer.getHeight() - mSpaceIcon.getIntrinsicHeight();
mSpaceIcon.setBounds(x, y,
x + mSpaceIcon.getIntrinsicWidth(), y + mSpaceIcon.getIntrinsicHeight());
mSpaceIcon.draw(canvas);
mSpaceKey.icon = new BitmapDrawable(mRes, buffer);
mSpaceKey.repeatable = false;
} else {
mSpaceKey.icon = mRes.getDrawable(R.drawable.sym_keyboard_space);
mSpaceKey.repeatable = true;
}
}
public void setLanguage(Locale locale) {
if (mLocale != null && mLocale.equals(locale)) return;
mLocale = locale;
updateSpaceBarForLocale();
}
static class LatinKey extends Keyboard.Key {
private boolean mShiftLockEnabled;
private boolean mEnabled = true;

View File

@@ -22,15 +22,11 @@ import android.inputmethodservice.KeyboardView;
import android.inputmethodservice.KeyboardView.OnKeyboardActionListener;
import android.os.Handler;
import android.os.SystemClock;
import android.text.Editable;
import android.text.Selection;
import android.util.Log;
import android.provider.Settings;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewRoot;
import android.view.inputmethod.InputConnection;
import android.widget.EditText;
import com.android.internal.R;
public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
@@ -40,7 +36,6 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
private static final int KEYBOARD_STATE_NORMAL = 0;
private static final int KEYBOARD_STATE_SHIFTED = 1;
private static final int KEYBOARD_STATE_CAPSLOCK = 2;
private static final String TAG = "PasswordEntryKeyboardHelper";
private int mKeyboardMode = KEYBOARD_MODE_ALPHA;
private int mKeyboardState = KEYBOARD_STATE_NORMAL;
private PasswordEntryKeyboard mQwertyKeyboard;
@@ -90,10 +85,15 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
case KEYBOARD_MODE_ALPHA:
mKeyboardView.setKeyboard(mQwertyKeyboard);
mKeyboardState = KEYBOARD_STATE_NORMAL;
final boolean visiblePassword = Settings.System.getInt(
mContext.getContentResolver(),
Settings.System.TEXT_SHOW_PASSWORD, 1) != 0;
mKeyboardView.setPreviewEnabled(visiblePassword);
break;
case KEYBOARD_MODE_NUMERIC:
mKeyboardView.setKeyboard(mNumericKeyboard);
mKeyboardState = KEYBOARD_STATE_NORMAL;
mKeyboardView.setPreviewEnabled(false); // never show popup for numeric keypad
break;
}
mKeyboardMode = mode;
@@ -122,7 +122,6 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
}
public void onKey(int primaryCode, int[] keyCodes) {
Log.v(TAG, "Key code = " + Integer.toHexString(primaryCode));
if (primaryCode == Keyboard.KEYCODE_DELETE) {
handleBackspace();
} else if (primaryCode == Keyboard.KEYCODE_SHIFT) {
@@ -201,7 +200,7 @@ public class PasswordEntryKeyboardHelper implements OnKeyboardActionListener {
}
public void onPress(int primaryCode) {
// TODO: vibration support.
}
public void onRelease(int primaryCode) {

View File

@@ -17,27 +17,17 @@
package com.android.internal.widget;
import android.content.Context;
import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.widget.PopupWindow;
import com.android.internal.R;
public class PasswordEntryKeyboardView extends KeyboardView {
public static final int KEYCODE_OPTIONS = -100;
static final int KEYCODE_OPTIONS = -100;
static final int KEYCODE_SHIFT_LONGPRESS = -101;
static final int KEYCODE_VOICE = -102;
static final int KEYCODE_F1 = -103;
static final int KEYCODE_NEXT_LANGUAGE = -104;
private boolean mExtensionVisible;
private PasswordEntryKeyboardView mExtension;
private PopupWindow mExtensionPopup;
private boolean mFirstEvent;
public PasswordEntryKeyboardView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@@ -46,107 +36,4 @@ public class PasswordEntryKeyboardView extends KeyboardView {
super(context, attrs, defStyle);
}
@Override
public boolean onTouchEvent(MotionEvent me) {
if (((PasswordEntryKeyboard) getKeyboard()).getExtension() == 0) {
return super.onTouchEvent(me);
}
if (me.getY() < 0) {
if (mExtensionVisible) {
int action = me.getAction();
if (mFirstEvent) action = MotionEvent.ACTION_DOWN;
mFirstEvent = false;
MotionEvent translated = MotionEvent.obtain(me.getEventTime(), me.getEventTime(),
action,
me.getX(), me.getY() + mExtension.getHeight(), me.getMetaState());
boolean result = mExtension.onTouchEvent(translated);
translated.recycle();
if (me.getAction() == MotionEvent.ACTION_UP
|| me.getAction() == MotionEvent.ACTION_CANCEL) {
closeExtension();
}
return result;
} else {
if (openExtension()) {
MotionEvent cancel = MotionEvent.obtain(me.getDownTime(), me.getEventTime(),
MotionEvent.ACTION_CANCEL, me.getX() - 100, me.getY() - 100, 0);
super.onTouchEvent(cancel);
cancel.recycle();
if (mExtension.getHeight() > 0) {
MotionEvent translated = MotionEvent.obtain(me.getEventTime(),
me.getEventTime(),
MotionEvent.ACTION_DOWN,
me.getX(), me.getY() + mExtension.getHeight(),
me.getMetaState());
mExtension.onTouchEvent(translated);
translated.recycle();
} else {
mFirstEvent = true;
}
}
return true;
}
} else if (mExtensionVisible) {
closeExtension();
// Send a down event into the main keyboard first
MotionEvent down = MotionEvent.obtain(me.getEventTime(), me.getEventTime(),
MotionEvent.ACTION_DOWN, me.getX(), me.getY(), me.getMetaState());
super.onTouchEvent(down);
down.recycle();
// Send the actual event
return super.onTouchEvent(me);
} else {
return super.onTouchEvent(me);
}
}
private boolean openExtension() {
if (((PasswordEntryKeyboard) getKeyboard()).getExtension() == 0) return false;
makePopupWindow();
mExtensionVisible = true;
return true;
}
private void makePopupWindow() {
if (mExtensionPopup == null) {
int[] windowLocation = new int[2];
mExtensionPopup = new PopupWindow(getContext());
mExtensionPopup.setBackgroundDrawable(null);
LayoutInflater li = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
mExtension = (PasswordEntryKeyboardView) li.inflate(
R.layout.password_keyboard_input, null);
mExtension.setOnKeyboardActionListener(getOnKeyboardActionListener());
mExtension.setPopupParent(this);
mExtension.setPopupOffset(0, -windowLocation[1]);
Keyboard keyboard;
mExtension.setKeyboard(keyboard = new PasswordEntryKeyboard(getContext(),
((PasswordEntryKeyboard) getKeyboard()).getExtension()));
mExtensionPopup.setContentView(mExtension);
mExtensionPopup.setWidth(getWidth());
mExtensionPopup.setHeight(keyboard.getHeight());
getLocationInWindow(windowLocation);
// TODO: Fix the "- 30".
mExtension.setPopupOffset(0, -windowLocation[1] - 30);
mExtensionPopup.showAtLocation(this, 0, 0, -keyboard.getHeight()
+ windowLocation[1]);
} else {
mExtension.setVisibility(VISIBLE);
}
}
@Override
public void closing() {
super.closing();
if (mExtensionPopup != null && mExtensionPopup.isShowing()) {
mExtensionPopup.dismiss();
mExtensionPopup = null;
}
}
private void closeExtension() {
mExtension.setVisibility(INVISIBLE);
mExtension.closing();
mExtensionVisible = false;
}
}