diff options
| author | Tadashi G. Takaoka <takaoka@google.com> | 2011-08-23 12:08:36 +0900 |
|---|---|---|
| committer | Tadashi G. Takaoka <takaoka@google.com> | 2011-08-23 17:51:57 +0900 |
| commit | 32572948d7e3956efebcbd69d7c7d8403bb659e6 (patch) | |
| tree | 1be05c192a454a4dc5105eecfaa6b8b8688d0588 /java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java | |
| parent | 2d306a225c4a9c0ea7b78a022c9dcc986ddffa46 (diff) | |
Refactor and rename popup mini keyoard related classes
Change-Id: Ia92ec4612090b03829db9a87ce68d701db6e15bc
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java')
| -rw-r--r-- | java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java index fb932e3e8..1230dfb44 100644 --- a/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/PopupMiniKeyboardView.java @@ -28,6 +28,8 @@ import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.latin.R; +import java.util.List; + /** * A view that renders a virtual {@link MiniKeyboard}. It handles rendering of keys and detecting * key presses and touch movements. @@ -43,6 +45,51 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel { private int mOriginX; private int mOriginY; + private static class MiniKeyboardKeyDetector extends KeyDetector { + private final int mSlideAllowanceSquare; + private final int mSlideAllowanceSquareTop; + + public MiniKeyboardKeyDetector(float slideAllowance) { + super(/* keyHysteresisDistance */0); + mSlideAllowanceSquare = (int)(slideAllowance * slideAllowance); + // Top slide allowance is slightly longer (sqrt(2) times) than other edges. + mSlideAllowanceSquareTop = mSlideAllowanceSquare * 2; + } + + @Override + public boolean alwaysAllowsSlidingInput() { + return true; + } + + @Override + protected int getMaxNearbyKeys() { + // No nearby key will be returned. + return 1; + } + + @Override + public int getKeyIndexAndNearbyCodes(int x, int y, final int[] allCodes) { + final List<Key> keys = getKeyboard().mKeys; + final int touchX = getTouchX(x); + final int touchY = getTouchY(y); + + int nearestIndex = NOT_A_KEY; + int nearestDist = (y < 0) ? mSlideAllowanceSquareTop : mSlideAllowanceSquare; + final int keyCount = keys.size(); + for (int index = 0; index < keyCount; index++) { + final int dist = keys.get(index).squaredDistanceToEdge(touchX, touchY); + if (dist < nearestDist) { + nearestIndex = index; + nearestDist = dist; + } + } + + if (allCodes != null && nearestIndex != NOT_A_KEY) + allCodes[0] = keys.get(nearestIndex).mCode; + return nearestIndex; + } + } + private static final TimerProxy EMPTY_TIMER_PROXY = new TimerProxy() { @Override public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker) {} @@ -146,11 +193,6 @@ public class PopupMiniKeyboardView extends KeyboardView implements PopupPanel { } @Override - protected void onSizeChanged(int w, int h, int oldw, int oldh) { - // Do nothing for the mini keyboard. - } - - @Override public void setKeyPreviewPopupEnabled(boolean previewEnabled, int delay) { // Mini keyboard needs no pop-up key preview displayed, so we pass always false with a // delay of 0. The delay does not matter actually since the popup is not shown anyway. |
