Move key hysteresis distance parameter to KeyDetector class
Bug: 4768084 Change-Id: Ib8771afd7363a4a5590b2b4a586e3014c026be34main
parent
5f6816fa8b
commit
a19b84dcf6
|
@ -89,9 +89,6 @@
|
||||||
<!-- Size of the text for key press feedback popup, int the proportion of key height -->
|
<!-- Size of the text for key press feedback popup, int the proportion of key height -->
|
||||||
<attr name="keyPreviewTextRatio" format="float" />
|
<attr name="keyPreviewTextRatio" format="float" />
|
||||||
|
|
||||||
<!-- Hysteresis distance for key debouncing -->
|
|
||||||
<attr name="keyHysteresisDistance" format="dimension" />
|
|
||||||
|
|
||||||
<!-- Amount to offset the touch Y coordinate by, for bias correction. -->
|
<!-- Amount to offset the touch Y coordinate by, for bias correction. -->
|
||||||
<attr name="verticalCorrection" format="dimension" />
|
<attr name="verticalCorrection" format="dimension" />
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,6 @@
|
||||||
<item name="keyPreviewHeight">@dimen/key_preview_height</item>
|
<item name="keyPreviewHeight">@dimen/key_preview_height</item>
|
||||||
<item name="keyPreviewTextRatio">@fraction/key_preview_text_ratio</item>
|
<item name="keyPreviewTextRatio">@fraction/key_preview_text_ratio</item>
|
||||||
<item name="popupLayout">@layout/keyboard_popup</item>
|
<item name="popupLayout">@layout/keyboard_popup</item>
|
||||||
<item name="keyHysteresisDistance">@dimen/key_hysteresis_distance</item>
|
|
||||||
<item name="verticalCorrection">@dimen/keyboard_vertical_correction</item>
|
<item name="verticalCorrection">@dimen/keyboard_vertical_correction</item>
|
||||||
<item name="shadowColor">#BB000000</item>
|
<item name="shadowColor">#BB000000</item>
|
||||||
<item name="shadowRadius">2.75</item>
|
<item name="shadowRadius">2.75</item>
|
||||||
|
@ -70,7 +69,6 @@
|
||||||
</style>
|
</style>
|
||||||
<style name="PopupMiniKeyboardView" parent="KeyboardView">
|
<style name="PopupMiniKeyboardView" parent="KeyboardView">
|
||||||
<item name="keyBackground">@drawable/btn_keyboard_key_popup</item>
|
<item name="keyBackground">@drawable/btn_keyboard_key_popup</item>
|
||||||
<item name="keyHysteresisDistance">0dip</item>
|
|
||||||
<item name="verticalCorrection">@dimen/mini_keyboard_vertical_correction</item>
|
<item name="verticalCorrection">@dimen/mini_keyboard_vertical_correction</item>
|
||||||
</style>
|
</style>
|
||||||
<style name="PopupMiniKeyboardPanelStyle">
|
<style name="PopupMiniKeyboardPanelStyle">
|
||||||
|
|
|
@ -28,6 +28,8 @@ public class KeyDetector {
|
||||||
public static final int NOT_A_CODE = -1;
|
public static final int NOT_A_CODE = -1;
|
||||||
public static final int NOT_A_KEY = -1;
|
public static final int NOT_A_KEY = -1;
|
||||||
|
|
||||||
|
private final int mKeyHysteresisDistanceSquared;
|
||||||
|
|
||||||
private Keyboard mKeyboard;
|
private Keyboard mKeyboard;
|
||||||
private int mCorrectionX;
|
private int mCorrectionX;
|
||||||
private int mCorrectionY;
|
private int mCorrectionY;
|
||||||
|
@ -39,12 +41,28 @@ public class KeyDetector {
|
||||||
private final int[] mDistances = new int[MAX_NEARBY_KEYS];
|
private final int[] mDistances = new int[MAX_NEARBY_KEYS];
|
||||||
private final int[] mIndices = new int[MAX_NEARBY_KEYS];
|
private final int[] mIndices = new int[MAX_NEARBY_KEYS];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class handles key detection.
|
||||||
|
*
|
||||||
|
* @param keyHysteresisDistance if the pointer movement distance is smaller than this, the
|
||||||
|
* movement will not been handled as meaningful movement. The unit is pixel.
|
||||||
|
*/
|
||||||
|
public KeyDetector(float keyHysteresisDistance) {
|
||||||
|
mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance);
|
||||||
|
}
|
||||||
|
|
||||||
public void setKeyboard(Keyboard keyboard, float correctionX, float correctionY) {
|
public void setKeyboard(Keyboard keyboard, float correctionX, float correctionY) {
|
||||||
if (keyboard == null)
|
if (keyboard == null)
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
mCorrectionX = (int)correctionX;
|
mCorrectionX = (int)correctionX;
|
||||||
mCorrectionY = (int)correctionY;
|
mCorrectionY = (int)correctionY;
|
||||||
mKeyboard = keyboard;
|
mKeyboard = keyboard;
|
||||||
|
final int threshold = keyboard.getMostCommonKeyWidth();
|
||||||
|
mProximityThresholdSquare = threshold * threshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getKeyHysteresisDistanceSquared() {
|
||||||
|
return mKeyHysteresisDistanceSquared;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getTouchX(int x) {
|
protected int getTouchX(int x) {
|
||||||
|
|
|
@ -59,7 +59,6 @@ public class LatinKeyboardBaseView extends KeyboardView {
|
||||||
private final int mKeyRepeatInterval;
|
private final int mKeyRepeatInterval;
|
||||||
|
|
||||||
// XML attribute
|
// XML attribute
|
||||||
private final float mKeyHysteresisDistance;
|
|
||||||
private final float mVerticalCorrection;
|
private final float mVerticalCorrection;
|
||||||
private final int mPopupLayout;
|
private final int mPopupLayout;
|
||||||
|
|
||||||
|
@ -81,7 +80,7 @@ public class LatinKeyboardBaseView extends KeyboardView {
|
||||||
private int mOldPointerCount = 1;
|
private int mOldPointerCount = 1;
|
||||||
private int mOldKeyIndex;
|
private int mOldKeyIndex;
|
||||||
|
|
||||||
protected KeyDetector mKeyDetector = new KeyDetector();
|
protected KeyDetector mKeyDetector;
|
||||||
|
|
||||||
// Swipe gesture detector
|
// Swipe gesture detector
|
||||||
protected GestureDetector mGestureDetector;
|
protected GestureDetector mGestureDetector;
|
||||||
|
@ -182,8 +181,6 @@ public class LatinKeyboardBaseView extends KeyboardView {
|
||||||
|
|
||||||
final TypedArray a = context.obtainStyledAttributes(
|
final TypedArray a = context.obtainStyledAttributes(
|
||||||
attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
|
attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
|
||||||
mKeyHysteresisDistance = a.getDimensionPixelOffset(
|
|
||||||
R.styleable.KeyboardView_keyHysteresisDistance, 0);
|
|
||||||
mVerticalCorrection = a.getDimensionPixelOffset(
|
mVerticalCorrection = a.getDimensionPixelOffset(
|
||||||
R.styleable.KeyboardView_verticalCorrection, 0);
|
R.styleable.KeyboardView_verticalCorrection, 0);
|
||||||
|
|
||||||
|
@ -193,6 +190,8 @@ public class LatinKeyboardBaseView extends KeyboardView {
|
||||||
|
|
||||||
final Resources res = getResources();
|
final Resources res = getResources();
|
||||||
|
|
||||||
|
final float keyHysteresisDistance = res.getDimension(R.dimen.key_hysteresis_distance);
|
||||||
|
mKeyDetector = new KeyDetector(keyHysteresisDistance);
|
||||||
mSwipeThreshold = (int) (500 * res.getDisplayMetrics().density);
|
mSwipeThreshold = (int) (500 * res.getDisplayMetrics().density);
|
||||||
// TODO: Refer to frameworks/base/core/res/res/values/config.xml
|
// TODO: Refer to frameworks/base/core/res/res/values/config.xml
|
||||||
mDisambiguateSwipe = res.getBoolean(R.bool.config_swipeDisambiguation);
|
mDisambiguateSwipe = res.getBoolean(R.bool.config_swipeDisambiguation);
|
||||||
|
@ -309,7 +308,7 @@ public class LatinKeyboardBaseView extends KeyboardView {
|
||||||
mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(),
|
mKeyDetector.setKeyboard(keyboard, -getPaddingLeft(),
|
||||||
-getPaddingTop() + mVerticalCorrection);
|
-getPaddingTop() + mVerticalCorrection);
|
||||||
for (PointerTracker tracker : mPointerTrackers) {
|
for (PointerTracker tracker : mPointerTrackers) {
|
||||||
tracker.setKeyboard(keyboard, mKeyHysteresisDistance);
|
tracker.setKeyboard(keyboard, mKeyDetector);
|
||||||
}
|
}
|
||||||
mKeyDetector.setProximityThreshold(keyboard.getMostCommonKeyWidth());
|
mKeyDetector.setProximityThreshold(keyboard.getMostCommonKeyWidth());
|
||||||
mPopupPanelCache.clear();
|
mPopupPanelCache.clear();
|
||||||
|
@ -484,7 +483,7 @@ public class LatinKeyboardBaseView extends KeyboardView {
|
||||||
final PointerTracker tracker =
|
final PointerTracker tracker =
|
||||||
new PointerTracker(i, this, mHandler, mKeyDetector, this);
|
new PointerTracker(i, this, mHandler, mKeyDetector, this);
|
||||||
if (keyboard != null)
|
if (keyboard != null)
|
||||||
tracker.setKeyboard(keyboard, mKeyHysteresisDistance);
|
tracker.setKeyboard(keyboard, mKeyDetector);
|
||||||
if (listener != null)
|
if (listener != null)
|
||||||
tracker.setOnKeyboardActionListener(listener);
|
tracker.setOnKeyboardActionListener(listener);
|
||||||
pointers.add(tracker);
|
pointers.add(tracker);
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class MiniKeyboardKeyDetector extends KeyDetector {
|
||||||
private final int mSlideAllowanceSquareTop;
|
private final int mSlideAllowanceSquareTop;
|
||||||
|
|
||||||
public MiniKeyboardKeyDetector(float slideAllowance) {
|
public MiniKeyboardKeyDetector(float slideAllowance) {
|
||||||
super();
|
super(/* keyHysteresisDistance */0);
|
||||||
mSlideAllowanceSquare = (int)(slideAllowance * slideAllowance);
|
mSlideAllowanceSquare = (int)(slideAllowance * slideAllowance);
|
||||||
// Top slide allowance is slightly longer (sqrt(2) times) than other edges.
|
// Top slide allowance is slightly longer (sqrt(2) times) than other edges.
|
||||||
mSlideAllowanceSquareTop = mSlideAllowanceSquare * 2;
|
mSlideAllowanceSquareTop = mSlideAllowanceSquare * 2;
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class PointerTracker {
|
||||||
private final LatinKeyboardBaseView mKeyboardView;
|
private final LatinKeyboardBaseView mKeyboardView;
|
||||||
private final UIProxy mProxy;
|
private final UIProxy mProxy;
|
||||||
private final UIHandler mHandler;
|
private final UIHandler mHandler;
|
||||||
private final KeyDetector mKeyDetector;
|
private KeyDetector mKeyDetector;
|
||||||
private KeyboardActionListener mListener = EMPTY_LISTENER;
|
private KeyboardActionListener mListener = EMPTY_LISTENER;
|
||||||
private final KeyboardSwitcher mKeyboardSwitcher;
|
private final KeyboardSwitcher mKeyboardSwitcher;
|
||||||
private final boolean mHasDistinctMultitouch;
|
private final boolean mHasDistinctMultitouch;
|
||||||
|
@ -67,7 +67,6 @@ public class PointerTracker {
|
||||||
|
|
||||||
private Keyboard mKeyboard;
|
private Keyboard mKeyboard;
|
||||||
private List<Key> mKeys;
|
private List<Key> mKeys;
|
||||||
private int mKeyHysteresisDistanceSquared = -1;
|
|
||||||
private int mKeyQuarterWidthSquared;
|
private int mKeyQuarterWidthSquared;
|
||||||
|
|
||||||
private final PointerTrackerKeyState mKeyState;
|
private final PointerTrackerKeyState mKeyState;
|
||||||
|
@ -198,12 +197,13 @@ public class PointerTracker {
|
||||||
mListener.onCancelInput();
|
mListener.onCancelInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyboard(Keyboard keyboard, float keyHysteresisDistance) {
|
public void setKeyboard(Keyboard keyboard, KeyDetector keyDetector) {
|
||||||
if (keyboard == null || keyHysteresisDistance < 0)
|
if (keyboard == null || keyDetector == null)
|
||||||
throw new IllegalArgumentException();
|
throw new NullPointerException();
|
||||||
mKeyboard = keyboard;
|
mKeyboard = keyboard;
|
||||||
mKeys = keyboard.getKeys();
|
mKeys = keyboard.getKeys();
|
||||||
mKeyHysteresisDistanceSquared = (int)(keyHysteresisDistance * keyHysteresisDistance);
|
mKeyDetector = keyDetector;
|
||||||
|
mKeyState.setKeyDetector(keyDetector);
|
||||||
final int keyQuarterWidth = keyboard.getKeyWidth() / 4;
|
final int keyQuarterWidth = keyboard.getKeyWidth() / 4;
|
||||||
mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth;
|
mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth;
|
||||||
// Mark that keyboard layout has been changed.
|
// Mark that keyboard layout has been changed.
|
||||||
|
@ -602,13 +602,14 @@ public class PointerTracker {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMajorEnoughMoveToBeOnNewKey(int x, int y, int newKey) {
|
private boolean isMajorEnoughMoveToBeOnNewKey(int x, int y, int newKey) {
|
||||||
if (mKeys == null || mKeyHysteresisDistanceSquared < 0)
|
if (mKeys == null || mKeyDetector == null)
|
||||||
throw new IllegalStateException("keyboard and/or hysteresis not set");
|
throw new NullPointerException("keyboard and/or key detector not set");
|
||||||
int curKey = mKeyState.getKeyIndex();
|
int curKey = mKeyState.getKeyIndex();
|
||||||
if (newKey == curKey) {
|
if (newKey == curKey) {
|
||||||
return false;
|
return false;
|
||||||
} else if (isValidKeyIndex(curKey)) {
|
} else if (isValidKeyIndex(curKey)) {
|
||||||
return mKeys.get(curKey).squaredDistanceToEdge(x, y) >= mKeyHysteresisDistanceSquared;
|
return mKeys.get(curKey).squaredDistanceToEdge(x, y)
|
||||||
|
>= mKeyDetector.getKeyHysteresisDistanceSquared();
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import com.android.inputmethod.keyboard.PointerTracker;
|
||||||
* This class keeps track of a key index and a position where {@link PointerTracker} is.
|
* This class keeps track of a key index and a position where {@link PointerTracker} is.
|
||||||
*/
|
*/
|
||||||
public class PointerTrackerKeyState {
|
public class PointerTrackerKeyState {
|
||||||
private final KeyDetector mKeyDetector;
|
private KeyDetector mKeyDetector;
|
||||||
|
|
||||||
// The position and time at which first down event occurred.
|
// The position and time at which first down event occurred.
|
||||||
private long mDownTime;
|
private long mDownTime;
|
||||||
|
@ -43,6 +43,10 @@ public class PointerTrackerKeyState {
|
||||||
mKeyDetector = keyDetecor;
|
mKeyDetector = keyDetecor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setKeyDetector(KeyDetector keyDetector) {
|
||||||
|
mKeyDetector = keyDetector;
|
||||||
|
}
|
||||||
|
|
||||||
public int getKeyIndex() {
|
public int getKeyIndex() {
|
||||||
return mKeyIndex;
|
return mKeyIndex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class SuggestHelper {
|
||||||
// (and not try to find a dictionary provider for a specified locale)
|
// (and not try to find a dictionary provider for a specified locale)
|
||||||
mSuggest = new Suggest(context, dictionaryId, null);
|
mSuggest = new Suggest(context, dictionaryId, null);
|
||||||
mKeyboard = new LatinKeyboard(context, keyboardId, keyboardId.mWidth);
|
mKeyboard = new LatinKeyboard(context, keyboardId, keyboardId.mWidth);
|
||||||
mKeyDetector = new KeyDetector();
|
mKeyDetector = new KeyDetector(0);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class SuggestHelper {
|
||||||
KeyboardId keyboardId) {
|
KeyboardId keyboardId) {
|
||||||
mSuggest = new Suggest(context, dictionaryPath, startOffset, length, null);
|
mSuggest = new Suggest(context, dictionaryPath, startOffset, length, null);
|
||||||
mKeyboard = new LatinKeyboard(context, keyboardId, keyboardId.mWidth);
|
mKeyboard = new LatinKeyboard(context, keyboardId, keyboardId.mWidth);
|
||||||
mKeyDetector = new KeyDetector();
|
mKeyDetector = new KeyDetector(0);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue