am c3b55809: am c7c6203f: Merge "Introduce multiple PointerTracker" into gingerbread
Merge commit 'c3b55809a5e650200a67c8f8164ba48db995c24c' * commit 'c3b55809a5e650200a67c8f8164ba48db995c24c': Introduce multiple PointerTrackermain
commit
35682aff05
|
@ -39,11 +39,11 @@ import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewConfiguration;
|
|
||||||
import android.view.ViewGroup.LayoutParams;
|
import android.view.ViewGroup.LayoutParams;
|
||||||
import android.widget.PopupWindow;
|
import android.widget.PopupWindow;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -199,7 +199,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
/** Listener for {@link OnKeyboardActionListener}. */
|
/** Listener for {@link OnKeyboardActionListener}. */
|
||||||
private OnKeyboardActionListener mKeyboardActionListener;
|
private OnKeyboardActionListener mKeyboardActionListener;
|
||||||
|
|
||||||
private final PointerTracker mPointerTracker;
|
private final ArrayList<PointerTracker> mPointerTrackers = new ArrayList<PointerTracker>();
|
||||||
private final float mDebounceHysteresis;
|
private final float mDebounceHysteresis;
|
||||||
|
|
||||||
private final ProximityKeyDetector mProximityKeyDetector = new ProximityKeyDetector();
|
private final ProximityKeyDetector mProximityKeyDetector = new ProximityKeyDetector();
|
||||||
|
@ -473,13 +473,14 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
final boolean ignoreMultitouch = true;
|
final boolean ignoreMultitouch = true;
|
||||||
mGestureDetector = new GestureDetector(getContext(), listener, null, ignoreMultitouch);
|
mGestureDetector = new GestureDetector(getContext(), listener, null, ignoreMultitouch);
|
||||||
mGestureDetector.setIsLongpressEnabled(false);
|
mGestureDetector.setIsLongpressEnabled(false);
|
||||||
|
|
||||||
mPointerTracker = new PointerTracker(mHandler, mProximityKeyDetector, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnKeyboardActionListener(OnKeyboardActionListener listener) {
|
public void setOnKeyboardActionListener(OnKeyboardActionListener listener) {
|
||||||
mKeyboardActionListener = listener;
|
mKeyboardActionListener = listener;
|
||||||
mPointerTracker.setOnKeyboardActionListener(listener);
|
for (PointerTracker tracker : mPointerTrackers) {
|
||||||
|
if (tracker != null)
|
||||||
|
tracker.setOnKeyboardActionListener(listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -509,7 +510,10 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
List<Key> keys = mKeyboard.getKeys();
|
List<Key> keys = mKeyboard.getKeys();
|
||||||
mKeys = keys.toArray(new Key[keys.size()]);
|
mKeys = keys.toArray(new Key[keys.size()]);
|
||||||
mProximityKeyDetector.setKeyboard(keyboard, mKeys);
|
mProximityKeyDetector.setKeyboard(keyboard, mKeys);
|
||||||
mPointerTracker.setKeyboard(mKeys, mDebounceHysteresis);
|
for (PointerTracker tracker : mPointerTrackers) {
|
||||||
|
if (tracker != null)
|
||||||
|
tracker.setKeyboard(mKeys, mDebounceHysteresis);
|
||||||
|
}
|
||||||
requestLayout();
|
requestLayout();
|
||||||
// Hint to reallocate the buffer if the size changed
|
// Hint to reallocate the buffer if the size changed
|
||||||
mKeyboardChanged = true;
|
mKeyboardChanged = true;
|
||||||
|
@ -779,7 +783,8 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
if (mShowTouchPoints) {
|
if (mShowTouchPoints) {
|
||||||
PointerTracker tracker = mPointerTracker;
|
for (PointerTracker tracker : mPointerTrackers) {
|
||||||
|
if (tracker == null) continue;
|
||||||
int startX = tracker.getStartX();
|
int startX = tracker.getStartX();
|
||||||
int startY = tracker.getStartY();
|
int startY = tracker.getStartY();
|
||||||
int lastX = tracker.getLastX();
|
int lastX = tracker.getLastX();
|
||||||
|
@ -794,6 +799,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
canvas.drawCircle((startX + lastX) / 2, (startY + lastY) / 2, 2, paint);
|
canvas.drawCircle((startX + lastX) / 2, (startY + lastY) / 2, 2, paint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mDrawPending = false;
|
mDrawPending = false;
|
||||||
mDirtyRect.setEmpty();
|
mDirtyRect.setEmpty();
|
||||||
|
@ -801,8 +807,9 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
|
|
||||||
// TODO: clean up this method.
|
// TODO: clean up this method.
|
||||||
private void dismissKeyPreview() {
|
private void dismissKeyPreview() {
|
||||||
mPointerTracker.updateKey(NOT_A_KEY);
|
for (PointerTracker tracker : mPointerTrackers)
|
||||||
showPreview(NOT_A_KEY, mPointerTracker);
|
tracker.updateKey(NOT_A_KEY);
|
||||||
|
showPreview(NOT_A_KEY, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showPreview(int keyIndex, PointerTracker tracker) {
|
public void showPreview(int keyIndex, PointerTracker tracker) {
|
||||||
|
@ -813,7 +820,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
if (keyIndex == NOT_A_KEY) {
|
if (keyIndex == NOT_A_KEY) {
|
||||||
mHandler.cancelPopupPreview();
|
mHandler.cancelPopupPreview();
|
||||||
mHandler.dismissPreview(DELAY_AFTER_PREVIEW);
|
mHandler.dismissPreview(DELAY_AFTER_PREVIEW);
|
||||||
} else {
|
} else if (tracker != null) {
|
||||||
mHandler.popupPreview(DELAY_BEFORE_PREVIEW, keyIndex, tracker);
|
mHandler.popupPreview(DELAY_BEFORE_PREVIEW, keyIndex, tracker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1042,6 +1049,25 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
return (int)y + mVerticalCorrection - getPaddingTop();
|
return (int)y + mVerticalCorrection - getPaddingTop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PointerTracker getPointerTracker(final int id) {
|
||||||
|
final ArrayList<PointerTracker> pointers = mPointerTrackers;
|
||||||
|
final Key[] keys = mKeys;
|
||||||
|
final OnKeyboardActionListener listener = mKeyboardActionListener;
|
||||||
|
|
||||||
|
// Create pointer trackers until we can get 'id+1'-th tracker, if needed.
|
||||||
|
for (int i = pointers.size(); i <= id; i++) {
|
||||||
|
final PointerTracker tracker =
|
||||||
|
new PointerTracker(mHandler, mProximityKeyDetector, this);
|
||||||
|
if (keys != null)
|
||||||
|
tracker.setKeyboard(keys, mDebounceHysteresis);
|
||||||
|
if (listener != null)
|
||||||
|
tracker.setOnKeyboardActionListener(listener);
|
||||||
|
pointers.add(tracker);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pointers.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent me) {
|
public boolean onTouchEvent(MotionEvent me) {
|
||||||
// Convert multi-pointer up/down events to single up/down events to
|
// Convert multi-pointer up/down events to single up/down events to
|
||||||
|
@ -1082,25 +1108,27 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener,
|
||||||
// Up event will pass through.
|
// Up event will pass through.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Should remove this implicit reference to id=0 pointer tracker in the future.
|
||||||
|
PointerTracker tracker = getPointerTracker(0);
|
||||||
int touchX = getTouchX(me.getX());
|
int touchX = getTouchX(me.getX());
|
||||||
int touchY = getTouchY(me.getY());
|
int touchY = getTouchY(me.getY());
|
||||||
if (pointerCount != mOldPointerCount) {
|
if (pointerCount != mOldPointerCount) {
|
||||||
if (pointerCount == 1) {
|
if (pointerCount == 1) {
|
||||||
// Send a down event for the latest pointer
|
// Send a down event for the latest pointer
|
||||||
mPointerTracker.onDownEvent(touchX, touchY, eventTime);
|
tracker.onDownEvent(touchX, touchY, eventTime);
|
||||||
// If it's an up action, then deliver the up as well.
|
// If it's an up action, then deliver the up as well.
|
||||||
if (action == MotionEvent.ACTION_UP) {
|
if (action == MotionEvent.ACTION_UP) {
|
||||||
mPointerTracker.onUpEvent(touchX, touchY, eventTime);
|
tracker.onUpEvent(touchX, touchY, eventTime);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Send an up event for the last pointer
|
// Send an up event for the last pointer
|
||||||
mPointerTracker.onUpEvent(mOldPointerX, mOldPointerY, eventTime);
|
tracker.onUpEvent(mOldPointerX, mOldPointerY, eventTime);
|
||||||
}
|
}
|
||||||
mOldPointerCount = pointerCount;
|
mOldPointerCount = pointerCount;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (pointerCount == 1) {
|
if (pointerCount == 1) {
|
||||||
mPointerTracker.onModifiedTouchEvent(action, touchX, touchY, eventTime);
|
tracker.onModifiedTouchEvent(action, touchX, touchY, eventTime);
|
||||||
mOldPointerX = touchX;
|
mOldPointerX = touchX;
|
||||||
mOldPointerY = touchY;
|
mOldPointerY = touchY;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class PointerTracker {
|
||||||
private final StringBuilder mPreviewLabel = new StringBuilder(1);
|
private final StringBuilder mPreviewLabel = new StringBuilder(1);
|
||||||
|
|
||||||
// pressed key
|
// pressed key
|
||||||
private int mPreviousKey;
|
private int mPreviousKey = NOT_A_KEY;
|
||||||
|
|
||||||
public PointerTracker(UIHandler handler, ProximityKeyDetector keyDetector, UIProxy proxy) {
|
public PointerTracker(UIHandler handler, ProximityKeyDetector keyDetector, UIProxy proxy) {
|
||||||
if (proxy == null || handler == null || keyDetector == null)
|
if (proxy == null || handler == null || keyDetector == null)
|
||||||
|
|
Loading…
Reference in New Issue