Fix Keyboard crash when chording and long pressing key
This change just prevents crashing. The another bug#4646271 has been opened to support chording and long pressing key. Bug: 4463909 Change-Id: I50e42656fe111e6b261310c899e672b8ba001e5d
This commit is contained in:
parent
862e05a8f0
commit
1ddb4897fe
2 changed files with 10 additions and 18 deletions
|
@ -22,6 +22,7 @@ import com.android.inputmethod.latin.R;
|
|||
import com.android.inputmethod.latin.SubtypeSwitcher;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
|
@ -540,9 +541,12 @@ public class PointerTracker {
|
|||
|
||||
public void onLongPressed(PointerTrackerQueue queue) {
|
||||
mKeyAlreadyProcessed = true;
|
||||
if (queue != null)
|
||||
if (queue != null) {
|
||||
// TODO: Support chording + long-press input.
|
||||
queue.releaseAllPointersExcept(this, SystemClock.uptimeMillis(), true);
|
||||
queue.remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void onCancelEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
|
||||
if (ENABLE_ASSERTION) checkAssertion(queue);
|
||||
|
|
|
@ -37,7 +37,6 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel {
|
|||
|
||||
private int mOriginX;
|
||||
private int mOriginY;
|
||||
private int mTrackerId;
|
||||
private long mDownTime;
|
||||
|
||||
public PopupMiniKeyboardView(Context context, AttributeSet attrs) {
|
||||
|
@ -98,30 +97,19 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel {
|
|||
|
||||
mOriginX = x + container.getPaddingLeft() - mCoordinates[0];
|
||||
mOriginY = y + container.getPaddingTop() - mCoordinates[1];
|
||||
mTrackerId = tracker.mPointerId;
|
||||
mDownTime = SystemClock.uptimeMillis();
|
||||
|
||||
// Inject down event on the key to mini keyboard.
|
||||
final MotionEvent downEvent = translateMotionEvent(MotionEvent.ACTION_DOWN, pointX,
|
||||
pointY + parentKey.mHeight / 2, mDownTime);
|
||||
final MotionEvent downEvent = MotionEvent.obtain(mDownTime, mDownTime,
|
||||
MotionEvent.ACTION_DOWN, pointX - mOriginX,
|
||||
pointY + parentKey.mHeight / 2 - mOriginY, 0);
|
||||
onTouchEvent(downEvent);
|
||||
downEvent.recycle();
|
||||
}
|
||||
|
||||
private MotionEvent translateMotionEvent(int action, float x, float y, long eventTime) {
|
||||
return MotionEvent.obtain(mDownTime, eventTime, action, x - mOriginX, y - mOriginY, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent me) {
|
||||
final int index = me.getActionIndex();
|
||||
final int id = me.getPointerId(index);
|
||||
if (id == mTrackerId) {
|
||||
final MotionEvent translated = translateMotionEvent(me.getAction(), me.getX(index),
|
||||
me.getY(index), me.getEventTime());
|
||||
super.onTouchEvent(translated);
|
||||
translated.recycle();
|
||||
}
|
||||
return true;
|
||||
me.offsetLocation(-mOriginX, -mOriginY);
|
||||
return super.onTouchEvent(me);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue