aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2014-06-02 11:38:39 +0900
committerTadashi G. Takaoka <takaoka@google.com>2014-06-02 12:41:50 +0900
commitfa9b9578d44748de512c947651010e703c663936 (patch)
tree2b1a4130a8596cc817adb40afb2286259ffd0ccb /java/src
parent509d07c76446bc7d6db3067897834629ade92855 (diff)
downloadlatinime-fa9b9578d44748de512c947651010e703c663936.tar.gz
latinime-fa9b9578d44748de512c947651010e703c663936.tar.xz
latinime-fa9b9578d44748de512c947651010e703c663936.zip
Refactor MoreKeysKeyboardView a bit
Bug: 12491371 Change-Id: I3ce1e6557e41a94146b882751f75ae4b5f6bc73d
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java43
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java8
2 files changed, 26 insertions, 25 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
index 4a2b37e4c..50c82e5f7 100644
--- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
@@ -110,25 +110,31 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
@Override
public void onDownEvent(final int x, final int y, final int pointerId, final long eventTime) {
mActivePointerId = pointerId;
- onMoveKeyInternal(x, y, pointerId);
+ mCurrentKey = detectKey(x, y, pointerId);
}
@Override
- public void onMoveEvent(int x, int y, final int pointerId, long eventTime) {
+ public void onMoveEvent(final int x, final int y, final int pointerId, final long eventTime) {
if (mActivePointerId != pointerId) {
return;
}
final boolean hasOldKey = (mCurrentKey != null);
- onMoveKeyInternal(x, y, pointerId);
+ mCurrentKey = detectKey(x, y, pointerId);
if (hasOldKey && mCurrentKey == null) {
- // If the pointer has moved too far away from any target then cancel the panel.
+ // A more keys keyboard is canceled when detecting no key.
mController.onCancelMoreKeysPanel();
}
}
@Override
public void onUpEvent(final int x, final int y, final int pointerId, final long eventTime) {
- if (mCurrentKey != null && mActivePointerId == pointerId) {
+ if (mActivePointerId != pointerId) {
+ return;
+ }
+ // Calling {@link #detectKey(int,int,int)} here is harmless because the last move event and
+ // the following up event share the same coordinates.
+ mCurrentKey = detectKey(x, y, pointerId);
+ if (mCurrentKey != null) {
updateReleaseKeyGraphics(mCurrentKey);
onKeyInput(mCurrentKey, x, y);
mCurrentKey = null;
@@ -152,23 +158,22 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
}
}
- private void onMoveKeyInternal(int x, int y, int pointerId) {
- if (mActivePointerId != pointerId) {
- // Ignore old pointers when newer pointer is active.
- return;
- }
+ private Key detectKey(int x, int y, int pointerId) {
final Key oldKey = mCurrentKey;
final Key newKey = mKeyDetector.detectHitKey(x, y);
- if (newKey != oldKey) {
- mCurrentKey = newKey;
- invalidateKey(mCurrentKey);
- if (oldKey != null) {
- updateReleaseKeyGraphics(oldKey);
- }
- if (newKey != null) {
- updatePressKeyGraphics(newKey);
- }
+ if (newKey == oldKey) {
+ return newKey;
+ }
+ // A new key is detected.
+ if (oldKey != null) {
+ updateReleaseKeyGraphics(oldKey);
+ invalidateKey(oldKey);
+ }
+ if (newKey != null) {
+ updatePressKeyGraphics(newKey);
+ invalidateKey(newKey);
}
+ return newKey;
}
private void updateReleaseKeyGraphics(final Key key) {
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index f80761132..7bf2f6c5c 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -1033,8 +1033,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
final int translatedY = mMoreKeysPanel.translateY(y);
mMoreKeysPanel.onUpEvent(translatedX, translatedY, mPointerId, eventTime);
}
- mMoreKeysPanel.dismissMoreKeysPanel();
- mMoreKeysPanel = null;
+ dismissMoreKeysPanel();
return;
}
@@ -1101,10 +1100,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
sTimerProxy.cancelKeyTimersOf(this);
setReleasedKeyGraphics(mCurrentKey);
resetKeySelectionByDraggingFinger();
- if (isShowingMoreKeysPanel()) {
- mMoreKeysPanel.dismissMoreKeysPanel();
- mMoreKeysPanel = null;
- }
+ dismissMoreKeysPanel();
}
private boolean isMajorEnoughMoveToBeOnNewKey(final int x, final int y, final long eventTime,