am 308ceb89: am 694ccb5b: Cosmetic change to PointerTracker

* commit '308ceb89c76728890a34327181dc856d027906cc':
  Cosmetic change to PointerTracker
main
Tadashi G. Takaoka 2012-08-22 23:30:08 -07:00 committed by Android Git Automerger
commit d9768e006e
1 changed files with 68 additions and 54 deletions

View File

@ -196,7 +196,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
setParameters(MainKeyboardView.PointerTrackerParams.DEFAULT); setParameters(MainKeyboardView.PointerTrackerParams.DEFAULT);
} }
public static void setParameters(MainKeyboardView.PointerTrackerParams params) { public static void setParameters(final MainKeyboardView.PointerTrackerParams params) {
sParams = params; sParams = params;
sTouchNoiseThresholdDistanceSquared = (int)( sTouchNoiseThresholdDistanceSquared = (int)(
params.mTouchNoiseThresholdDistance * params.mTouchNoiseThresholdDistance); params.mTouchNoiseThresholdDistance * params.mTouchNoiseThresholdDistance);
@ -210,17 +210,17 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
// Note that this method is called from a non-UI thread. // Note that this method is called from a non-UI thread.
public static void setMainDictionaryAvailability(boolean mainDictionaryAvailable) { public static void setMainDictionaryAvailability(final boolean mainDictionaryAvailable) {
sMainDictionaryAvailable = mainDictionaryAvailable; sMainDictionaryAvailable = mainDictionaryAvailable;
updateGestureHandlingMode(); updateGestureHandlingMode();
} }
public static void setGestureHandlingEnabledByUser(boolean gestureHandlingEnabledByUser) { public static void setGestureHandlingEnabledByUser(final boolean gestureHandlingEnabledByUser) {
sGestureHandlingEnabledByUser = gestureHandlingEnabledByUser; sGestureHandlingEnabledByUser = gestureHandlingEnabledByUser;
updateGestureHandlingMode(); updateGestureHandlingMode();
} }
public static PointerTracker getPointerTracker(final int id, KeyEventHandler handler) { public static PointerTracker getPointerTracker(final int id, final KeyEventHandler handler) {
final ArrayList<PointerTracker> trackers = sTrackers; final ArrayList<PointerTracker> trackers = sTrackers;
// Create pointer trackers until we can get 'id+1'-th tracker, if needed. // Create pointer trackers until we can get 'id+1'-th tracker, if needed.
@ -236,7 +236,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
return sPointerTrackerQueue != null ? sPointerTrackerQueue.isAnyInSlidingKeyInput() : false; return sPointerTrackerQueue != null ? sPointerTrackerQueue.isAnyInSlidingKeyInput() : false;
} }
public static void setKeyboardActionListener(KeyboardActionListener listener) { public static void setKeyboardActionListener(final KeyboardActionListener listener) {
final int trackersSize = sTrackers.size(); final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) { for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i); final PointerTracker tracker = sTrackers.get(i);
@ -244,7 +244,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
public static void setKeyDetector(KeyDetector keyDetector) { public static void setKeyDetector(final KeyDetector keyDetector) {
final int trackersSize = sTrackers.size(); final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) { for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i); final PointerTracker tracker = sTrackers.get(i);
@ -298,9 +298,10 @@ public class PointerTracker implements PointerTrackerQueue.Element {
sAggregratedPointers.reset(); sAggregratedPointers.reset();
} }
private PointerTracker(int id, KeyEventHandler handler) { private PointerTracker(final int id, final KeyEventHandler handler) {
if (handler == null) if (handler == null) {
throw new NullPointerException(); throw new NullPointerException();
}
mPointerId = id; mPointerId = id;
mGestureStroke = new GestureStroke(id); mGestureStroke = new GestureStroke(id);
setKeyDetectorInner(handler.getKeyDetector()); setKeyDetectorInner(handler.getKeyDetector());
@ -310,7 +311,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
// Returns true if keyboard has been changed by this callback. // Returns true if keyboard has been changed by this callback.
private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key) { private boolean callListenerOnPressAndCheckKeyboardLayoutChange(final Key key) {
if (mInGesture) { if (mInGesture) {
return false; return false;
} }
@ -335,7 +336,8 @@ public class PointerTracker implements PointerTrackerQueue.Element {
// Note that we need primaryCode argument because the keyboard may in shifted state and the // Note that we need primaryCode argument because the keyboard may in shifted state and the
// primaryCode is different from {@link Key#mCode}. // primaryCode is different from {@link Key#mCode}.
private void callListenerOnCodeInput(Key key, int primaryCode, int x, int y) { private void callListenerOnCodeInput(final Key key, final int primaryCode, final int x,
final int y) {
final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier(); final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier();
final boolean altersCode = key.altCodeWhileTyping() && mTimerProxy.isTypingState(); final boolean altersCode = key.altCodeWhileTyping() && mTimerProxy.isTypingState();
final int code = altersCode ? key.mAltCode : primaryCode; final int code = altersCode ? key.mAltCode : primaryCode;
@ -364,7 +366,8 @@ public class PointerTracker implements PointerTrackerQueue.Element {
// Note that we need primaryCode argument because the keyboard may in shifted state and the // Note that we need primaryCode argument because the keyboard may in shifted state and the
// primaryCode is different from {@link Key#mCode}. // primaryCode is different from {@link Key#mCode}.
private void callListenerOnRelease(Key key, int primaryCode, boolean withSliding) { private void callListenerOnRelease(final Key key, final int primaryCode,
final boolean withSliding) {
if (mInGesture) { if (mInGesture) {
return; return;
} }
@ -387,15 +390,16 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
private void callListenerOnCancelInput() { private void callListenerOnCancelInput() {
if (DEBUG_LISTENER) if (DEBUG_LISTENER) {
Log.d(TAG, "onCancelInput"); Log.d(TAG, "onCancelInput");
}
if (ProductionFlag.IS_EXPERIMENTAL) { if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.pointerTracker_callListenerOnCancelInput(); ResearchLogger.pointerTracker_callListenerOnCancelInput();
} }
mListener.onCancelInput(); mListener.onCancelInput();
} }
private void setKeyDetectorInner(KeyDetector keyDetector) { private void setKeyDetectorInner(final KeyDetector keyDetector) {
mKeyDetector = keyDetector; mKeyDetector = keyDetector;
mKeyboard = keyDetector.getKeyboard(); mKeyboard = keyDetector.getKeyboard();
mIsAlphabetKeyboard = mKeyboard.mId.isAlphabetKeyboard(); mIsAlphabetKeyboard = mKeyboard.mId.isAlphabetKeyboard();
@ -425,11 +429,11 @@ public class PointerTracker implements PointerTrackerQueue.Element {
return mCurrentKey != null && mCurrentKey.isModifier(); return mCurrentKey != null && mCurrentKey.isModifier();
} }
public Key getKeyOn(int x, int y) { public Key getKeyOn(final int x, final int y) {
return mKeyDetector.detectHitKey(x, y); return mKeyDetector.detectHitKey(x, y);
} }
private void setReleasedKeyGraphics(Key key) { private void setReleasedKeyGraphics(final Key key) {
mDrawingProxy.dismissKeyPreview(this); mDrawingProxy.dismissKeyPreview(this);
if (key == null) { if (key == null) {
return; return;
@ -460,7 +464,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
private void setPressedKeyGraphics(Key key) { private void setPressedKeyGraphics(final Key key) {
if (key == null) { if (key == null) {
return; return;
} }
@ -499,17 +503,17 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
private void updateReleaseKeyGraphics(Key key) { private void updateReleaseKeyGraphics(final Key key) {
key.onReleased(); key.onReleased();
mDrawingProxy.invalidateKey(key); mDrawingProxy.invalidateKey(key);
} }
private void updatePressKeyGraphics(Key key) { private void updatePressKeyGraphics(final Key key) {
key.onPressed(); key.onPressed();
mDrawingProxy.invalidateKey(key); mDrawingProxy.invalidateKey(key);
} }
public void drawGestureTrail(Canvas canvas, Paint paint) { public void drawGestureTrail(final Canvas canvas, final Paint paint) {
if (mInGesture) { if (mInGesture) {
mGestureStroke.drawGestureTrail(canvas, paint); mGestureStroke.drawGestureTrail(canvas, paint);
} }
@ -527,22 +531,22 @@ public class PointerTracker implements PointerTrackerQueue.Element {
return mDownTime; return mDownTime;
} }
private Key onDownKey(int x, int y, long eventTime) { private Key onDownKey(final int x, final int y, final long eventTime) {
mDownTime = eventTime; mDownTime = eventTime;
return onMoveToNewKey(onMoveKeyInternal(x, y), x, y); return onMoveToNewKey(onMoveKeyInternal(x, y), x, y);
} }
private Key onMoveKeyInternal(int x, int y) { private Key onMoveKeyInternal(final int x, final int y) {
mLastX = x; mLastX = x;
mLastY = y; mLastY = y;
return mKeyDetector.detectHitKey(x, y); return mKeyDetector.detectHitKey(x, y);
} }
private Key onMoveKey(int x, int y) { private Key onMoveKey(final int x, final int y) {
return onMoveKeyInternal(x, y); return onMoveKeyInternal(x, y);
} }
private Key onMoveToNewKey(Key newKey, int x, int y) { private Key onMoveToNewKey(final Key newKey, final int x, final int y) {
mCurrentKey = newKey; mCurrentKey = newKey;
mKeyX = x; mKeyX = x;
mKeyY = y; mKeyY = y;
@ -557,14 +561,14 @@ public class PointerTracker implements PointerTrackerQueue.Element {
mListener.onStartBatchInput(); mListener.onStartBatchInput();
} }
private void updateBatchInput(InputPointers batchPoints) { private void updateBatchInput(final InputPointers batchPoints) {
if (DEBUG_LISTENER) { if (DEBUG_LISTENER) {
Log.d(TAG, "onUpdateBatchInput: batchPoints=" + batchPoints.getPointerSize()); Log.d(TAG, "onUpdateBatchInput: batchPoints=" + batchPoints.getPointerSize());
} }
mListener.onUpdateBatchInput(batchPoints); mListener.onUpdateBatchInput(batchPoints);
} }
private void endBatchInput(InputPointers batchPoints) { private void endBatchInput(final InputPointers batchPoints) {
if (DEBUG_LISTENER) { if (DEBUG_LISTENER) {
Log.d(TAG, "onEndBatchInput: batchPoints=" + batchPoints.getPointerSize()); Log.d(TAG, "onEndBatchInput: batchPoints=" + batchPoints.getPointerSize());
} }
@ -585,7 +589,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
mLastRecognitionTime = 0; mLastRecognitionTime = 0;
} }
private boolean updateBatchInputRecognitionState(long eventTime, int size) { private boolean updateBatchInputRecognitionState(final long eventTime, final int size) {
if (size > mLastRecognitionPointSize if (size > mLastRecognitionPointSize
&& eventTime > mLastRecognitionTime + MIN_GESTURE_RECOGNITION_TIME) { && eventTime > mLastRecognitionTime + MIN_GESTURE_RECOGNITION_TIME) {
mLastRecognitionPointSize = size; mLastRecognitionPointSize = size;
@ -595,8 +599,8 @@ public class PointerTracker implements PointerTrackerQueue.Element {
return false; return false;
} }
public void processMotionEvent(int action, int x, int y, long eventTime, public void processMotionEvent(final int action, final int x, final int y, final long eventTime,
KeyEventHandler handler) { final KeyEventHandler handler) {
switch (action) { switch (action) {
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_POINTER_DOWN:
@ -615,9 +619,11 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
public void onDownEvent(int x, int y, long eventTime, KeyEventHandler handler) { public void onDownEvent(final int x, final int y, final long eventTime,
if (DEBUG_EVENT) final KeyEventHandler handler) {
if (DEBUG_EVENT) {
printTouchEvent("onDownEvent:", x, y, eventTime); printTouchEvent("onDownEvent:", x, y, eventTime);
}
mDrawingProxy = handler.getDrawingProxy(); mDrawingProxy = handler.getDrawingProxy();
mTimerProxy = handler.getTimerProxy(); mTimerProxy = handler.getTimerProxy();
@ -665,7 +671,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
private void onDownEventInternal(int x, int y, long eventTime) { private void onDownEventInternal(final int x, final int y, final long eventTime) {
Key key = onDownKey(x, y, eventTime); Key key = onDownKey(x, y, eventTime);
// Sliding key is allowed when 1) enabled by configuration, 2) this pointer starts sliding // Sliding key is allowed when 1) enabled by configuration, 2) this pointer starts sliding
// from modifier key, or 3) this pointer's KeyDetector always allows sliding input. // from modifier key, or 3) this pointer's KeyDetector always allows sliding input.
@ -690,15 +696,15 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
private void startSlidingKeyInput(Key key) { private void startSlidingKeyInput(final Key key) {
if (!mIsInSlidingKeyInput) { if (!mIsInSlidingKeyInput) {
mIgnoreModifierKey = key.isModifier(); mIgnoreModifierKey = key.isModifier();
} }
mIsInSlidingKeyInput = true; mIsInSlidingKeyInput = true;
} }
private void onGestureMoveEvent(PointerTracker tracker, int x, int y, long eventTime, private void onGestureMoveEvent(final PointerTracker tracker, final int x, final int y,
boolean isHistorical, Key key) { final long eventTime, final boolean isHistorical, final Key key) {
final int gestureTime = (int)(eventTime - tracker.getDownTime()); final int gestureTime = (int)(eventTime - tracker.getDownTime());
if (sShouldHandleGesture && mIsPossibleGesture) { if (sShouldHandleGesture && mIsPossibleGesture) {
final GestureStroke stroke = mGestureStroke; final GestureStroke stroke = mGestureStroke;
@ -717,11 +723,13 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
public void onMoveEvent(int x, int y, long eventTime, MotionEvent me) { public void onMoveEvent(final int x, final int y, final long eventTime, final MotionEvent me) {
if (DEBUG_MOVE_EVENT) if (DEBUG_MOVE_EVENT) {
printTouchEvent("onMoveEvent:", x, y, eventTime); printTouchEvent("onMoveEvent:", x, y, eventTime);
if (mKeyAlreadyProcessed) }
if (mKeyAlreadyProcessed) {
return; return;
}
if (me != null) { if (me != null) {
// Add historical points to gesture path. // Add historical points to gesture path.
@ -841,9 +849,10 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
public void onUpEvent(int x, int y, long eventTime) { public void onUpEvent(final int x, final int y, final long eventTime) {
if (DEBUG_EVENT) if (DEBUG_EVENT) {
printTouchEvent("onUpEvent :", x, y, eventTime); printTouchEvent("onUpEvent :", x, y, eventTime);
}
final PointerTrackerQueue queue = sPointerTrackerQueue; final PointerTrackerQueue queue = sPointerTrackerQueue;
if (queue != null) { if (queue != null) {
@ -865,9 +874,10 @@ public class PointerTracker implements PointerTrackerQueue.Element {
// This pointer tracker needs to keep the key top graphics "pressed", but needs to get a // This pointer tracker needs to keep the key top graphics "pressed", but needs to get a
// "virtual" up event. // "virtual" up event.
@Override @Override
public void onPhantomUpEvent(long eventTime) { public void onPhantomUpEvent(final long eventTime) {
if (DEBUG_EVENT) if (DEBUG_EVENT) {
printTouchEvent("onPhntEvent:", getLastX(), getLastY(), eventTime); printTouchEvent("onPhntEvent:", getLastX(), getLastY(), eventTime);
}
onUpEventInternal(); onUpEventInternal();
mKeyAlreadyProcessed = true; mKeyAlreadyProcessed = true;
} }
@ -898,14 +908,15 @@ public class PointerTracker implements PointerTrackerQueue.Element {
// This event will be recognized as a regular code input. Clear unused batch points so they // This event will be recognized as a regular code input. Clear unused batch points so they
// are not mistakenly included in the next batch event. // are not mistakenly included in the next batch event.
clearBatchInputPointsOfAllPointerTrackers(); clearBatchInputPointsOfAllPointerTrackers();
if (mKeyAlreadyProcessed) if (mKeyAlreadyProcessed) {
return; return;
}
if (mCurrentKey != null && !mCurrentKey.isRepeatable()) { if (mCurrentKey != null && !mCurrentKey.isRepeatable()) {
detectAndSendKey(mCurrentKey, mKeyX, mKeyY); detectAndSendKey(mCurrentKey, mKeyX, mKeyY);
} }
} }
public void onShowMoreKeysPanel(int x, int y, KeyEventHandler handler) { public void onShowMoreKeysPanel(final int x, final int y, final KeyEventHandler handler) {
abortBatchInput(); abortBatchInput();
onLongPressed(); onLongPressed();
mIsShowingMoreKeysPanel = true; mIsShowingMoreKeysPanel = true;
@ -921,9 +932,10 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
public void onCancelEvent(int x, int y, long eventTime) { public void onCancelEvent(final int x, final int y, final long eventTime) {
if (DEBUG_EVENT) if (DEBUG_EVENT) {
printTouchEvent("onCancelEvt:", x, y, eventTime); printTouchEvent("onCancelEvt:", x, y, eventTime);
}
final PointerTrackerQueue queue = sPointerTrackerQueue; final PointerTrackerQueue queue = sPointerTrackerQueue;
if (queue != null) { if (queue != null) {
@ -943,24 +955,25 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
private void startRepeatKey(Key key) { private void startRepeatKey(final Key key) {
if (key != null && key.isRepeatable() && !mInGesture) { if (key != null && key.isRepeatable() && !mInGesture) {
onRegisterKey(key); onRegisterKey(key);
mTimerProxy.startKeyRepeatTimer(this); mTimerProxy.startKeyRepeatTimer(this);
} }
} }
public void onRegisterKey(Key key) { public void onRegisterKey(final Key key) {
if (key != null) { if (key != null) {
detectAndSendKey(key, key.mX, key.mY); detectAndSendKey(key, key.mX, key.mY);
mTimerProxy.startTypingStateTimer(key); mTimerProxy.startTypingStateTimer(key);
} }
} }
private boolean isMajorEnoughMoveToBeOnNewKey(int x, int y, Key newKey) { private boolean isMajorEnoughMoveToBeOnNewKey(final int x, final int y, final Key newKey) {
if (mKeyDetector == null) if (mKeyDetector == null) {
throw new NullPointerException("keyboard and/or key detector not set"); throw new NullPointerException("keyboard and/or key detector not set");
Key curKey = mCurrentKey; }
final Key curKey = mCurrentKey;
if (newKey == curKey) { if (newKey == curKey) {
return false; return false;
} else if (curKey != null) { } else if (curKey != null) {
@ -971,24 +984,25 @@ public class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
private void startLongPressTimer(Key key) { private void startLongPressTimer(final Key key) {
if (key != null && key.isLongPressEnabled() && !mInGesture) { if (key != null && key.isLongPressEnabled() && !mInGesture) {
mTimerProxy.startLongPressTimer(this); mTimerProxy.startLongPressTimer(this);
} }
} }
private void detectAndSendKey(Key key, int x, int y) { private void detectAndSendKey(final Key key, final int x, final int y) {
if (key == null) { if (key == null) {
callListenerOnCancelInput(); callListenerOnCancelInput();
return; return;
} }
int code = key.mCode; final int code = key.mCode;
callListenerOnCodeInput(key, code, x, y); callListenerOnCodeInput(key, code, x, y);
callListenerOnRelease(key, code, false); callListenerOnRelease(key, code, false);
} }
private void printTouchEvent(String title, int x, int y, long eventTime) { private void printTouchEvent(final String title, final int x, final int y,
final long eventTime) {
final Key key = mKeyDetector.detectHitKey(x, y); final Key key = mKeyDetector.detectHitKey(x, y);
final String code = KeyDetector.printableCode(key); final String code = KeyDetector.printableCode(key);
Log.d(TAG, String.format("%s%s[%d] %4d %4d %5d %s", title, Log.d(TAG, String.format("%s%s[%d] %4d %4d %5d %s", title,