aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java188
1 files changed, 94 insertions, 94 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java
index 30042d8a1..ba901eddb 100644
--- a/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java
+++ b/java/src/com/android/inputmethod/latin/LatinKeyboardBaseView.java
@@ -62,8 +62,7 @@ import java.util.Map;
* @attr ref R.styleable#LatinKeyboardBaseView_verticalCorrection
* @attr ref R.styleable#LatinKeyboardBaseView_popupLayout
*/
-public class LatinKeyboardBaseView extends View implements View.OnClickListener,
- PointerTracker.UIProxy {
+public class LatinKeyboardBaseView extends View implements PointerTracker.UIProxy {
private static final String TAG = "LatinKeyboardBaseView";
private static final boolean DEBUG = false;
@@ -165,7 +164,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
private float mShadowRadius;
private Drawable mKeyBackground;
private float mBackgroundDimAmount;
- private int mVerticalCorrection;
+ private float mVerticalCorrection;
private int mPreviewOffset;
private int mPreviewHeight;
private int mPopupLayout;
@@ -185,17 +184,18 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
private boolean mShowTouchPoints = true;
private int mPopupPreviewX;
private int mPopupPreviewY;
+ private int mPopupPreviewOffsetX;
+ private int mPopupPreviewOffsetY;
private int mWindowY;
// Popup mini keyboard
- private PopupWindow mPopupKeyboard;
- private View mMiniKeyboardContainer;
+ private PopupWindow mMiniKeyboardPopup;
private LatinKeyboardBaseView mMiniKeyboard;
- private boolean mMiniKeyboardOnScreen;
- private View mPopupParent;
- private int mMiniKeyboardOffsetX;
- private int mMiniKeyboardOffsetY;
+ private View mMiniKeyboardParent;
private Map<Key,View> mMiniKeyboardCache;
+ private int mMiniKeyboardOriginX;
+ private int mMiniKeyboardOriginY;
+ private long mMiniKeyboardPopupTime;
private int[] mWindowOffset;
/** Listener for {@link OnKeyboardActionListener}. */
@@ -254,9 +254,11 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
startKeyRepeatTimer(REPEAT_INTERVAL, msg.arg1, tracker);
break;
}
- case MSG_LONGPRESS_KEY:
- openPopupIfRequired(msg.arg1);
+ case MSG_LONGPRESS_KEY: {
+ final PointerTracker tracker = (PointerTracker)msg.obj;
+ openPopupIfRequired(msg.arg1, tracker);
break;
+ }
}
}
@@ -299,9 +301,9 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
return mInKeyRepeat;
}
- public void startLongPressTimer(int keyIndex, long delay) {
+ public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker) {
removeMessages(MSG_LONGPRESS_KEY);
- sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, keyIndex, 0), delay);
+ sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, keyIndex, 0, tracker), delay);
}
public void cancelLongPressTimer() {
@@ -443,10 +445,10 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
mShowPreview = false;
}
mPreviewPopup.setTouchable(false);
- mPopupParent = this;
+ mMiniKeyboardParent = this;
- mPopupKeyboard = new PopupWindow(context);
- mPopupKeyboard.setBackgroundDrawable(null);
+ mMiniKeyboardPopup = new PopupWindow(context);
+ mMiniKeyboardPopup.setBackgroundDrawable(null);
mPaint = new Paint();
mPaint.setAntiAlias(true);
@@ -539,7 +541,8 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
mHandler.cancelPopupPreview();
mKeyboard = keyboard;
LatinImeLogger.onSetKeyboard(keyboard);
- mKeys = mKeyDetector.setKeyboard(keyboard);
+ mKeys = mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(),
+ -getPaddingTop() + mVerticalCorrection);
for (PointerTracker tracker : mPointerTrackers) {
tracker.setKeyboard(mKeys, mDebounceHysteresis);
}
@@ -611,16 +614,13 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
return mSymbolColorScheme;
}
- public void setVerticalCorrection(int verticalOffset) {
- }
-
public void setPopupParent(View v) {
- mPopupParent = v;
+ mMiniKeyboardParent = v;
}
public void setPopupOffset(int x, int y) {
- mMiniKeyboardOffsetX = x;
- mMiniKeyboardOffsetY = y;
+ mPopupPreviewOffsetX = x;
+ mPopupPreviewOffsetY = y;
if (mPreviewPopup.isShowing()) {
mPreviewPopup.dismiss();
}
@@ -643,14 +643,6 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
return mKeyDetector.isProximityCorrectionEnabled();
}
- /**
- * Popup keyboard close button clicked.
- * @hide
- */
- public void onClick(View v) {
- dismissPopupKeyboard();
- }
-
protected CharSequence adjustCase(CharSequence label) {
if (mKeyboard.isShifted() && label != null && label.length() < 3
&& Character.isLowerCase(label.charAt(0))) {
@@ -805,7 +797,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
}
mInvalidatedKey = null;
// Overlay a dark rectangle to dim the keyboard
- if (mMiniKeyboardOnScreen) {
+ if (mMiniKeyboard != null) {
paint.setColor((int) (mBackgroundDimAmount * 0xFF) << 24);
canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
}
@@ -896,8 +888,8 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
if (mOffsetInWindow == null) {
mOffsetInWindow = new int[2];
getLocationInWindow(mOffsetInWindow);
- mOffsetInWindow[0] += mMiniKeyboardOffsetX; // Offset may be zero
- mOffsetInWindow[1] += mMiniKeyboardOffsetY; // Offset may be zero
+ mOffsetInWindow[0] += mPopupPreviewOffsetX; // Offset may be zero
+ mOffsetInWindow[1] += mPopupPreviewOffsetY; // Offset may be zero
int[] mWindowLocation = new int[2];
getLocationOnScreen(mWindowLocation);
mWindowY = mWindowLocation[1];
@@ -926,7 +918,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
} else {
previewPopup.setWidth(popupWidth);
previewPopup.setHeight(popupHeight);
- previewPopup.showAtLocation(mPopupParent, Gravity.NO_GRAVITY,
+ previewPopup.showAtLocation(mMiniKeyboardParent, Gravity.NO_GRAVITY,
mPopupPreviewX, mPopupPreviewY);
}
mPreviewText.setVisibility(VISIBLE);
@@ -962,18 +954,18 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
key.x + key.width + getPaddingLeft(), key.y + key.height + getPaddingTop());
}
- private boolean openPopupIfRequired(int keyIndex) {
+ private boolean openPopupIfRequired(int keyIndex, PointerTracker tracker) {
// Check if we have a popup layout specified first.
if (mPopupLayout == 0) {
return false;
}
- if (keyIndex < 0 || keyIndex >= mKeys.length) {
- return false;
- }
- Key popupKey = mKeys[keyIndex];
+ Key popupKey = tracker.getKey(keyIndex);
+ if (popupKey == null)
+ return false;
boolean result = onLongPress(popupKey);
if (result) {
+ tracker.setAlreadyProcessed();
dismissKeyPreview();
}
return result;
@@ -990,15 +982,13 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
int popupKeyboardId = popupKey.popupResId;
if (popupKeyboardId != 0) {
- mMiniKeyboardContainer = mMiniKeyboardCache.get(popupKey);
- if (mMiniKeyboardContainer == null) {
+ View container = mMiniKeyboardCache.get(popupKey);
+ if (container == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
- mMiniKeyboardContainer = inflater.inflate(mPopupLayout, null);
- mMiniKeyboard = (LatinKeyboardBaseView) mMiniKeyboardContainer.findViewById(
+ container = inflater.inflate(mPopupLayout, null);
+ mMiniKeyboard = (LatinKeyboardBaseView) container.findViewById(
R.id.LatinKeyboardBaseView);
- View closeButton = mMiniKeyboardContainer.findViewById(R.id.closeButton);
- if (closeButton != null) closeButton.setOnClickListener(this);
mMiniKeyboard.setOnKeyboardActionListener(new OnKeyboardActionListener() {
public void onKey(int primaryCode, int[] keyCodes, int x, int y) {
mKeyboardActionListener.onKey(primaryCode, keyCodes, x, y);
@@ -1021,7 +1011,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
mKeyboardActionListener.onRelease(primaryCode);
}
});
- //mInputView.setSuggest(mSuggest);
+
Keyboard keyboard;
if (popupKey.popupCharacters != null) {
keyboard = new Keyboard(getContext(), popupKeyboardId,
@@ -1031,50 +1021,54 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
}
mMiniKeyboard.setKeyboard(keyboard);
mMiniKeyboard.setPopupParent(this);
- mMiniKeyboardContainer.measure(
+ container.measure(
MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.AT_MOST));
- mMiniKeyboardCache.put(popupKey, mMiniKeyboardContainer);
+ mMiniKeyboardCache.put(popupKey, container);
} else {
- mMiniKeyboard = (LatinKeyboardBaseView) mMiniKeyboardContainer.findViewById(
+ mMiniKeyboard = (LatinKeyboardBaseView) container.findViewById(
R.id.LatinKeyboardBaseView);
}
if (mWindowOffset == null) {
mWindowOffset = new int[2];
getLocationInWindow(mWindowOffset);
}
- int popupX = popupKey.x + getPaddingLeft();
+ int popupX = popupKey.x + popupKey.width + getPaddingLeft();
int popupY = popupKey.y + getPaddingTop();
- popupX = popupX + popupKey.width - mMiniKeyboardContainer.getMeasuredWidth();
- popupY = popupY - mMiniKeyboardContainer.getMeasuredHeight();
- final int x = popupX + mMiniKeyboardContainer.getPaddingRight() + mWindowOffset[0];
- final int y = popupY + mMiniKeyboardContainer.getPaddingBottom() + mWindowOffset[1];
- mMiniKeyboard.setPopupOffset(x < 0 ? 0 : x, y);
+ popupX -= container.getMeasuredWidth();
+ popupY -= container.getMeasuredHeight();
+ popupX += mWindowOffset[0];
+ popupY += mWindowOffset[1];
+ final int x = popupX + container.getPaddingRight();
+ final int y = popupY + container.getPaddingBottom();
+ mMiniKeyboardOriginX = (x < 0 ? 0 : x) + container.getPaddingLeft();
+ mMiniKeyboardOriginY = y + container.getPaddingTop();
+ mMiniKeyboard.setPopupOffset((x < 0) ? 0 : x, y);
mMiniKeyboard.setShifted(isShifted());
- mPopupKeyboard.setContentView(mMiniKeyboardContainer);
- mPopupKeyboard.setWidth(mMiniKeyboardContainer.getMeasuredWidth());
- mPopupKeyboard.setHeight(mMiniKeyboardContainer.getMeasuredHeight());
- mPopupKeyboard.showAtLocation(this, Gravity.NO_GRAVITY, x, y);
- mMiniKeyboardOnScreen = true;
- //mMiniKeyboard.onTouchEvent(getTranslatedEvent(me));
+ mMiniKeyboard.setPreviewEnabled(isPreviewEnabled());
+ mMiniKeyboardPopup.setContentView(container);
+ mMiniKeyboardPopup.setWidth(container.getMeasuredWidth());
+ mMiniKeyboardPopup.setHeight(container.getMeasuredHeight());
+ mMiniKeyboardPopup.showAtLocation(this, Gravity.NO_GRAVITY, x, y);
+
+ // Inject down event on the key to mini keyboard.
+ long eventTime = System.currentTimeMillis();
+ mMiniKeyboardPopupTime = eventTime;
+ MotionEvent downEvent = generateMiniKeyboardMotionEvent(MotionEvent.ACTION_DOWN,
+ popupKey.x + popupKey.width / 2, popupKey.y + popupKey.height / 2, eventTime);
+ mMiniKeyboard.onTouchEvent(downEvent);
+ downEvent.recycle();
+
invalidateAllKeys();
return true;
}
return false;
}
- // TODO: Should cleanup after refactoring mini-keyboard.
- public boolean isMiniKeyboardOnScreen() {
- return mMiniKeyboardOnScreen;
- }
-
- private int getTouchX(float x) {
- return (int)x - getPaddingLeft();
- }
-
- private int getTouchY(float y) {
- return (int)y + mVerticalCorrection - getPaddingTop();
+ private MotionEvent generateMiniKeyboardMotionEvent(int action, int x, int y, long eventTime) {
+ return MotionEvent.obtain(mMiniKeyboardPopupTime, eventTime, action,
+ x - mMiniKeyboardOriginX, y - mMiniKeyboardOriginY, 0);
}
private PointerTracker getPointerTracker(final int id) {
@@ -1106,7 +1100,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
mSwipeTracker.addMovement(me);
// We must disable gesture detector while mini-keyboard is on the screen.
- if (!mMiniKeyboardOnScreen && mGestureDetector.onTouchEvent(me)) {
+ if (mMiniKeyboard == null && mGestureDetector.onTouchEvent(me)) {
dismissKeyPreview();
mHandler.cancelKeyTimers();
return true;
@@ -1114,7 +1108,11 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
// Needs to be called after the gesture detector gets a turn, as it may have
// displayed the mini keyboard
- if (mMiniKeyboardOnScreen && action != MotionEvent.ACTION_CANCEL) {
+ if (mMiniKeyboard != null) {
+ MotionEvent translated = generateMiniKeyboardMotionEvent(action, (int)me.getX(),
+ (int)me.getY(), eventTime);
+ mMiniKeyboard.onTouchEvent(translated);
+ translated.recycle();
return true;
}
@@ -1131,29 +1129,29 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
if (action == MotionEvent.ACTION_MOVE) {
for (int index = 0; index < pointerCount; index++) {
- int touchX = getTouchX(me.getX(index));
- int touchY = getTouchY(me.getY(index));
+ int x = (int)me.getX(index);
+ int y = (int)me.getY(index);
int id = me.getPointerId(index);
PointerTracker tracker = getPointerTracker(id);
- tracker.onMoveEvent(touchX, touchY, eventTime);
+ tracker.onMoveEvent(x, y, eventTime);
}
} else {
int index = me.getActionIndex();
- int touchX = getTouchX(me.getX(index));
- int touchY = getTouchY(me.getY(index));
+ int x = (int)me.getX(index);
+ int y = (int)me.getY(index);
int id = me.getPointerId(index);
PointerTracker tracker = getPointerTracker(id);
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
- onDownEvent(tracker, touchX, touchY, eventTime);
+ onDownEvent(tracker, x, y, eventTime);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
- onUpEvent(tracker, touchX, touchY, eventTime);
+ onUpEvent(tracker, x, y, eventTime);
break;
case MotionEvent.ACTION_CANCEL:
- onCancelEvent(tracker, touchX, touchY, eventTime);
+ onCancelEvent(tracker, x, y, eventTime);
break;
}
}
@@ -1161,12 +1159,12 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
return true;
}
- private void onDownEvent(PointerTracker tracker, int touchX, int touchY, long eventTime) {
- tracker.onDownEvent(touchX, touchY, eventTime);
+ private void onDownEvent(PointerTracker tracker, int x, int y, long eventTime) {
+ tracker.onDownEvent(x, y, eventTime);
mPointerQueue.add(tracker);
}
- private void onUpEvent(PointerTracker tracker, int touchX, int touchY, long eventTime) {
+ private void onUpEvent(PointerTracker tracker, int x, int y, long eventTime) {
int index = mPointerQueue.lastIndexOf(tracker);
if (index >= 0) {
mPointerQueue.releasePointersOlderThan(tracker, eventTime);
@@ -1174,12 +1172,12 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
Log.w(TAG, "onUpEvent: corresponding down event not found for pointer "
+ tracker.mPointerId);
}
- tracker.onUpEvent(touchX, touchY, eventTime);
+ tracker.onUpEvent(x, y, eventTime);
mPointerQueue.remove(tracker);
}
- private void onCancelEvent(PointerTracker tracker, int touchX, int touchY, long eventTime) {
- tracker.onCancelEvent(touchX, touchY, eventTime);
+ private void onCancelEvent(PointerTracker tracker, int x, int y, long eventTime) {
+ tracker.onCancelEvent(x, y, eventTime);
mPointerQueue.remove(tracker);
}
@@ -1217,16 +1215,18 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
closing();
}
- public void dismissPopupKeyboard() {
- if (mPopupKeyboard.isShowing()) {
- mPopupKeyboard.dismiss();
- mMiniKeyboardOnScreen = false;
+ private void dismissPopupKeyboard() {
+ if (mMiniKeyboardPopup.isShowing()) {
+ mMiniKeyboardPopup.dismiss();
+ mMiniKeyboard = null;
+ mMiniKeyboardOriginX = 0;
+ mMiniKeyboardOriginY = 0;
invalidateAllKeys();
}
}
public boolean handleBack() {
- if (mPopupKeyboard.isShowing()) {
+ if (mMiniKeyboardPopup.isShowing()) {
dismissPopupKeyboard();
return true;
}