aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardView.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinKeyboardView.java245
1 files changed, 48 insertions, 197 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
index e57abd2c5..71ca8b81a 100644
--- a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
@@ -16,8 +16,6 @@
package com.android.inputmethod.latin;
-import java.util.List;
-
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
@@ -27,14 +25,14 @@ import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.util.AttributeSet;
-import android.view.LayoutInflater;
import android.view.MotionEvent;
-import android.widget.PopupWindow;
+
+import java.util.List;
public class LatinKeyboardView extends LatinKeyboardBaseView {
static final int KEYCODE_OPTIONS = -100;
- static final int KEYCODE_SHIFT_LONGPRESS = -101;
+ static final int KEYCODE_OPTIONS_LONGPRESS = -101;
static final int KEYCODE_VOICE = -102;
static final int KEYCODE_F1 = -103;
static final int KEYCODE_NEXT_LANGUAGE = -104;
@@ -42,21 +40,11 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
private Keyboard mPhoneKeyboard;
- /** Whether the extension of this keyboard is visible */
- private boolean mExtensionVisible;
- /** The view that is shown as an extension of this keyboard view */
- private LatinKeyboardView mExtension;
- /** The popup window that contains the extension of this keyboard */
- private PopupWindow mExtensionPopup;
- /** Whether this view is an extension of another keyboard */
- private boolean mIsExtensionType;
- private boolean mFirstEvent;
/** Whether we've started dropping move events because we found a big jump */
private boolean mDroppingEvents;
- /**
- * Whether multi-touch disambiguation needs to be disabled for any reason. There are 2 reasons
- * for this to happen - (1) if a real multi-touch event has occured and (2) we've opened an
- * extension keyboard.
+ /**
+ * Whether multi-touch disambiguation needs to be disabled if a real multi-touch event has
+ * occured
*/
private boolean mDisableDisambiguation;
/** The distance threshold at which we start treating the touch session as a multi-touch */
@@ -64,7 +52,8 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
/** The y coordinate of the last row */
private int mLastRowY;
- private int mExtensionLayoutResId = 0;
+ // This is local working variable for onLongPress().
+ private int[] mKeyCodes = new int[1];
public LatinKeyboardView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -78,10 +67,6 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
mPhoneKeyboard = phoneKeyboard;
}
- public void setExtentionLayoutResId (int id) {
- mExtensionLayoutResId = id;
- }
-
@Override
public void setKeyboard(Keyboard k) {
super.setKeyboard(k);
@@ -93,23 +78,37 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
setKeyboardLocal(k);
}
+ private static boolean hasOneDigitAlternate(Key key) {
+ final CharSequence alternates = key.popupCharacters;
+ if (alternates == null)
+ return false;
+ final String altChars = alternates.toString();
+ if (altChars.codePointCount(0, altChars.length()) != 1)
+ return false;
+ final int altCode = altChars.codePointAt(0);
+ return altCode >= '0' && altCode <= '9';
+ }
+
@Override
protected boolean onLongPress(Key key) {
- if (key.codes[0] == Keyboard.KEYCODE_MODE_CHANGE) {
- getOnKeyboardActionListener().onKey(KEYCODE_OPTIONS, null,
+ int primaryCode = key.codes[0];
+ if (primaryCode == KEYCODE_OPTIONS) {
+ getOnKeyboardActionListener().onKey(KEYCODE_OPTIONS_LONGPRESS, null,
LatinKeyboardBaseView.NOT_A_TOUCH_COORDINATE,
LatinKeyboardBaseView.NOT_A_TOUCH_COORDINATE);
return true;
- } else if (key.codes[0] == Keyboard.KEYCODE_SHIFT) {
- getOnKeyboardActionListener().onKey(KEYCODE_SHIFT_LONGPRESS, null,
+ } else if (primaryCode == '0' && getKeyboard() == mPhoneKeyboard) {
+ // Long pressing on 0 in phone number keypad gives you a '+'.
+ getOnKeyboardActionListener().onKey(
+ '+', null,
LatinKeyboardBaseView.NOT_A_TOUCH_COORDINATE,
LatinKeyboardBaseView.NOT_A_TOUCH_COORDINATE);
- invalidateAllKeys();
return true;
- } else if (key.codes[0] == '0' && getKeyboard() == mPhoneKeyboard) {
- // Long pressing on 0 in phone number keypad gives you a '+'.
- getOnKeyboardActionListener().onKey(
- '+', null, LatinKeyboardBaseView.NOT_A_TOUCH_COORDINATE,
+ } else if (hasOneDigitAlternate(key)) {
+ mKeyCodes[0] = primaryCode = key.popupCharacters.charAt(0);
+ // when there is only one alternate character, send it as key action.
+ getOnKeyboardActionListener().onKey(primaryCode, mKeyCodes,
+ LatinKeyboardBaseView.NOT_A_TOUCH_COORDINATE,
LatinKeyboardBaseView.NOT_A_TOUCH_COORDINATE);
return true;
} else {
@@ -145,10 +144,10 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
* that could be due to a multi-touch being treated as a move by the firmware or hardware.
* Once a sudden jump is detected, all subsequent move events are discarded
* until an UP is received.<P>
- * When a sudden jump is detected, an UP event is simulated at the last position and when
+ * When a sudden jump is detected, an UP event is simulated at the last position and when
* the sudden moves subside, a DOWN event is simulated for the second key.
* @param me the motion event
- * @return true if the event was consumed, so that it doesn't continue to be handled by
+ * @return true if the event was consumed, so that it doesn't continue to be handled by
* KeyboardView.
*/
private boolean handleSuddenJump(MotionEvent me) {
@@ -226,11 +225,10 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
invalidate();
}
- // If an extension keyboard is visible or this is an extension keyboard, don't look
- // for sudden jumps. Otherwise, if there was a sudden jump, return without processing the
- // actual motion event.
- if (!mExtensionVisible && !mIsExtensionType
- && handleSuddenJump(me)) return true;
+ // If there was a sudden jump, return without processing the actual motion event.
+ if (handleSuddenJump(me))
+ return true;
+
// Reset any bounding box controls in the keyboard
if (me.getAction() == MotionEvent.ACTION_DOWN) {
keyboard.keyReleased();
@@ -248,154 +246,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
}
}
- // If we don't have an extension keyboard, don't go any further.
- if (keyboard.getExtension() == 0) {
- return super.onTouchEvent(me);
- }
- // If the motion event is above the keyboard and it's not an UP event coming
- // even before the first MOVE event into the extension area
- if (me.getY() < 0 && (mExtensionVisible || me.getAction() != MotionEvent.ACTION_UP)) {
- 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;
- }
- // Stop processing multi-touch errors
- mDisableDisambiguation = 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 void setExtensionType(boolean isExtensionType) {
- mIsExtensionType = isExtensionType;
- }
-
- private boolean openExtension() {
- // If the current keyboard is not visible, don't show the popup
- if (!isShown()) {
- return false;
- }
- if (((LatinKeyboard) 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 = (LatinKeyboardView) li.inflate(mExtensionLayoutResId == 0 ?
- R.layout.input_trans : mExtensionLayoutResId, null);
- mExtension.setExtensionType(true);
- mExtension.setOnKeyboardActionListener(
- new ExtensionKeyboardListener(getOnKeyboardActionListener()));
- mExtension.setPopupParent(this);
- mExtension.setPopupOffset(0, -windowLocation[1]);
- Keyboard keyboard;
- mExtension.setKeyboard(keyboard = new LatinKeyboard(getContext(),
- ((LatinKeyboard) getKeyboard()).getExtension()));
- mExtensionPopup.setContentView(mExtension);
- mExtensionPopup.setWidth(getWidth());
- mExtensionPopup.setHeight(keyboard.getHeight());
- mExtensionPopup.setAnimationStyle(-1);
- 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.closing();
- mExtension.setVisibility(INVISIBLE);
- mExtensionVisible = false;
- }
-
- private static class ExtensionKeyboardListener implements OnKeyboardActionListener {
- private OnKeyboardActionListener mTarget;
- ExtensionKeyboardListener(OnKeyboardActionListener target) {
- mTarget = target;
- }
- public void onKey(int primaryCode, int[] keyCodes, int x, int y) {
- mTarget.onKey(primaryCode, keyCodes, x, y);
- }
- public void onPress(int primaryCode) {
- mTarget.onPress(primaryCode);
- }
- public void onRelease(int primaryCode) {
- mTarget.onRelease(primaryCode);
- }
- public void onText(CharSequence text) {
- mTarget.onText(text);
- }
- public void swipeDown() {
- // Don't pass through
- }
- public void swipeLeft() {
- // Don't pass through
- }
- public void swipeRight() {
- // Don't pass through
- }
- public void swipeUp() {
- // Don't pass through
- }
+ return super.onTouchEvent(me);
}
/**************************** INSTRUMENTATION *******************************/
@@ -404,9 +255,9 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
static final boolean DEBUG_LINE = false;
private static final int MSG_TOUCH_DOWN = 1;
private static final int MSG_TOUCH_UP = 2;
-
+
Handler mHandler2;
-
+
private String mStringToPlay;
private int mStringIndex;
private boolean mDownDelivered;
@@ -426,7 +277,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
removeMessages(MSG_TOUCH_DOWN);
removeMessages(MSG_TOUCH_UP);
if (mPlaying == false) return;
-
+
switch (msg.what) {
case MSG_TOUCH_DOWN:
if (mStringIndex >= mStringToPlay.length()) {
@@ -434,7 +285,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
return;
}
char c = mStringToPlay.charAt(mStringIndex);
- while (c > 255 || mAsciiKeys[(int) c] == null) {
+ while (c > 255 || mAsciiKeys[c] == null) {
mStringIndex++;
if (mStringIndex >= mStringToPlay.length()) {
mPlaying = false;
@@ -444,8 +295,8 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
}
int x = mAsciiKeys[c].x + 10;
int y = mAsciiKeys[c].y + 26;
- MotionEvent me = MotionEvent.obtain(SystemClock.uptimeMillis(),
- SystemClock.uptimeMillis(),
+ MotionEvent me = MotionEvent.obtain(SystemClock.uptimeMillis(),
+ SystemClock.uptimeMillis(),
MotionEvent.ACTION_DOWN, x, y, 0);
LatinKeyboardView.this.dispatchTouchEvent(me);
me.recycle();
@@ -458,9 +309,9 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
int x2 = mAsciiKeys[cUp].x + 10;
int y2 = mAsciiKeys[cUp].y + 26;
mStringIndex++;
-
- MotionEvent me2 = MotionEvent.obtain(SystemClock.uptimeMillis(),
- SystemClock.uptimeMillis(),
+
+ MotionEvent me2 = MotionEvent.obtain(SystemClock.uptimeMillis(),
+ SystemClock.uptimeMillis(),
MotionEvent.ACTION_UP, x2, y2, 0);
LatinKeyboardView.this.dispatchTouchEvent(me2);
me2.recycle();
@@ -481,7 +332,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
// Get the keys on this keyboard
for (int i = 0; i < keys.size(); i++) {
int code = keys.get(i).codes[0];
- if (code >= 0 && code <= 255) {
+ if (code >= 0 && code <= 255) {
mAsciiKeys[code] = keys.get(i);
}
}