am 294d1c08: am 513f1b04: Merge "Add hack to translate sudden move to up/down events" into honeycomb

* commit '294d1c08f4ee87710237fffc6866a7ab11153aaf':
  Add hack to translate sudden move to up/down events
main
Tadashi G. Takaoka 2011-01-27 23:42:28 -08:00 committed by Android Git Automerger
commit 69a15051a0
3 changed files with 40 additions and 20 deletions

View File

@ -16,6 +16,7 @@
package com.android.inputmethod.keyboard; package com.android.inputmethod.keyboard;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.voice.VoiceIMEConnector; import com.android.inputmethod.voice.VoiceIMEConnector;
@ -23,10 +24,13 @@ import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
// TODO: We should remove this class // TODO: We should remove this class
public class LatinKeyboardView extends KeyboardView { public class LatinKeyboardView extends KeyboardView {
private static final String TAG = LatinKeyboardView.class.getSimpleName();
private static boolean DEBUG_MODE = LatinImeLogger.sDBG;
/** Whether we've started dropping move events because we found a big jump */ /** Whether we've started dropping move events because we found a big jump */
private boolean mDroppingEvents; private boolean mDroppingEvents;
@ -208,7 +212,11 @@ public class LatinKeyboardView extends KeyboardView {
if (keyboard == null) return true; if (keyboard == null) return true;
// If there was a sudden jump, return without processing the actual motion event. // If there was a sudden jump, return without processing the actual motion event.
if (handleSuddenJump(me)) return true; if (handleSuddenJump(me)) {
if (DEBUG_MODE)
Log.w(TAG, "onTouchEvent: ignore sudden jump " + me);
return true;
}
// Reset any bounding box controls in the keyboard // Reset any bounding box controls in the keyboard
if (me.getAction() == MotionEvent.ACTION_DOWN) { if (me.getAction() == MotionEvent.ACTION_DOWN) {

View File

@ -17,6 +17,7 @@
package com.android.inputmethod.keyboard; package com.android.inputmethod.keyboard;
import com.android.inputmethod.keyboard.KeyboardView.UIHandler; import com.android.inputmethod.keyboard.KeyboardView.UIHandler;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.R;
import android.content.res.Resources; import android.content.res.Resources;
@ -31,6 +32,7 @@ public class PointerTracker {
private static final boolean DEBUG_EVENT = false; private static final boolean DEBUG_EVENT = false;
private static final boolean DEBUG_MOVE_EVENT = false; private static final boolean DEBUG_MOVE_EVENT = false;
private static final boolean DEBUG_LISTENER = false; private static final boolean DEBUG_LISTENER = false;
private static boolean DEBUG_MODE = LatinImeLogger.sDBG;
public interface UIProxy { public interface UIProxy {
public void invalidateKey(Key key); public void invalidateKey(Key key);
@ -62,6 +64,7 @@ public class PointerTracker {
private Keyboard mKeyboard; private Keyboard mKeyboard;
private Key[] mKeys; private Key[] mKeys;
private int mKeyHysteresisDistanceSquared = -1; private int mKeyHysteresisDistanceSquared = -1;
private int mKeyQuarterWidthSquared;
private final PointerTrackerKeyState mKeyState; private final PointerTrackerKeyState mKeyState;
@ -166,6 +169,8 @@ public class PointerTracker {
mKeyboard = keyboard; mKeyboard = keyboard;
mKeys = keys; mKeys = keys;
mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance); mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance);
final int keyQuarterWidth = keyboard.getKeyWidth() / 4;
mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth;
// Mark that keyboard layout has been changed. // Mark that keyboard layout has been changed.
mKeyboardLayoutHasBeenChanged = true; mKeyboardLayoutHasBeenChanged = true;
} }
@ -268,10 +273,6 @@ public class PointerTracker {
if (DEBUG_EVENT) if (DEBUG_EVENT)
printTouchEvent("onDownEvent:", x, y, eventTime); printTouchEvent("onDownEvent:", x, y, eventTime);
// TODO: up-to-down filter, if (down-up) is less than threshold, removeMessage(UP, this) in
// Handler, and just ignore this down event.
// TODO: down-to-up filter, just record down time. do not enqueue pointer now.
// Naive up-to-down noise filter. // Naive up-to-down noise filter.
final long deltaT = eventTime - mKeyState.getUpTime(); final long deltaT = eventTime - mKeyState.getUpTime();
if (deltaT < mTouchNoiseThresholdMillis) { if (deltaT < mTouchNoiseThresholdMillis) {
@ -279,8 +280,9 @@ public class PointerTracker {
final int dy = y - mKeyState.getLastY(); final int dy = y - mKeyState.getLastY();
final int distanceSquared = (dx * dx + dy * dy); final int distanceSquared = (dx * dx + dy * dy);
if (distanceSquared < mTouchNoiseThresholdDistanceSquared) { if (distanceSquared < mTouchNoiseThresholdDistanceSquared) {
Log.w(TAG, "onDownEvent: ignore potential noise: time=" + deltaT if (DEBUG_MODE)
+ " distance=" + distanceSquared); Log.w(TAG, "onDownEvent: ignore potential noise: time=" + deltaT
+ " distance=" + distanceSquared);
setAlreadyProcessed(); setAlreadyProcessed();
return; return;
} }
@ -333,9 +335,8 @@ public class PointerTracker {
return; return;
final PointerTrackerKeyState keyState = mKeyState; final PointerTrackerKeyState keyState = mKeyState;
// TODO: down-to-up filter, if (eventTime-downTime) is less than threshold, just ignore final int lastX = keyState.getLastX();
// this move event. Otherwise fire {@link onDownEventInternal} and continue. final int lastY = keyState.getLastY();
int keyIndex = keyState.onMoveKey(x, y); int keyIndex = keyState.onMoveKey(x, y);
final Key oldKey = getKey(keyState.getKeyIndex()); final Key oldKey = getKey(keyState.getKeyIndex());
if (isValidKeyIndex(keyIndex)) { if (isValidKeyIndex(keyIndex)) {
@ -365,8 +366,22 @@ public class PointerTracker {
keyState.onMoveToNewKey(keyIndex, x, y); keyState.onMoveToNewKey(keyIndex, x, y);
startLongPressTimer(keyIndex); startLongPressTimer(keyIndex);
} else { } else {
setAlreadyProcessed(); // HACK: On some devices, quick successive touches may be translated to sudden
showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY); // move by touch panel firmware. This hack detects the case and translates the
// move event to successive up and down events.
final int dx = x - lastX;
final int dy = y - lastY;
final int lastMoveSquared = dx * dx + dy * dy;
if (lastMoveSquared >= mKeyQuarterWidthSquared) {
if (DEBUG_MODE)
Log.w(TAG, String.format("onMoveEvent: sudden move is translated to "
+ "up[%d,%d]/down[%d,%d] events", lastX, lastY, x, y));
onUpEventInternal(lastX, lastY, eventTime);
onDownEventInternal(x, y, eventTime);
} else {
setAlreadyProcessed();
showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY);
}
return; return;
} }
} }
@ -389,17 +404,11 @@ public class PointerTracker {
showKeyPreviewAndUpdateKeyGraphics(mKeyState.getKeyIndex()); showKeyPreviewAndUpdateKeyGraphics(mKeyState.getKeyIndex());
} }
// TODO: up-to-down filter, if delayed UP message is fired, invoke {@link onUpEventInternal}.
public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
if (ENABLE_ASSERTION) checkAssertion(queue); if (ENABLE_ASSERTION) checkAssertion(queue);
if (DEBUG_EVENT) if (DEBUG_EVENT)
printTouchEvent("onUpEvent :", x, y, eventTime); printTouchEvent("onUpEvent :", x, y, eventTime);
// TODO: up-to-down filter, just sendDelayedMessage(UP, this) to Handler.
// TODO: down-to-up filter, if (eventTime-downTime) is less than threshold, just ignore
// this up event. Otherwise fire {@link onDownEventInternal} and {@link onUpEventInternal}.
if (queue != null) { if (queue != null) {
if (isModifier()) { if (isModifier()) {
// Before processing an up event of modifier key, all pointers already being // Before processing an up event of modifier key, all pointers already being

View File

@ -128,8 +128,11 @@ public class Utils {
+ ", " + maxEditDistanceOfNativeDictionary); + ", " + maxEditDistanceOfNativeDictionary);
} }
if (distance > maxEditDistanceOfNativeDictionary) { if (distance > maxEditDistanceOfNativeDictionary) {
Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. " if (DBG) {
+ "Turning off auto-correction."); Log.d(TAG, "Safety net: before = " + typedWord + ", after = " + candidateWord);
Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. "
+ "Turning off auto-correction.");
}
return true; return true;
} else { } else {
return false; return false;