aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2014-04-24 01:08:28 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-04-24 01:08:28 +0000
commit2a0e7c6fc91e6146ee99e3a63f22a3d6c84cca4a (patch)
tree86007f44e52769866e6c0a00803609394f53f71c /java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
parent5ce053b8067e3c18bf6075bd24884084194baefa (diff)
parentf7edc6582ace41aa36dd7cb0f802097a8f3ae9b5 (diff)
downloadlatinime-2a0e7c6fc91e6146ee99e3a63f22a3d6c84cca4a.tar.gz
latinime-2a0e7c6fc91e6146ee99e3a63f22a3d6c84cca4a.tar.xz
latinime-2a0e7c6fc91e6146ee99e3a63f22a3d6c84cca4a.zip
am f7edc658: Move simulateKeyPress method to AccessibleKeyboardViewProxy
* commit 'f7edc6582ace41aa36dd7cb0f802097a8f3ae9b5': Move simulateKeyPress method to AccessibleKeyboardViewProxy
Diffstat (limited to 'java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java')
-rw-r--r--java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java36
1 files changed, 35 insertions, 1 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
index c8fbb3d5a..e3455c1a1 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.accessibility;
import android.content.Context;
import android.inputmethodservice.InputMethodService;
+import android.os.SystemClock;
import android.support.v4.view.AccessibilityDelegateCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.accessibility.AccessibilityEventCompat;
@@ -241,7 +242,8 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
// Make sure we're not getting an EXIT event because the user slid
// off the keyboard area, then force a key press.
if (key != null) {
- getAccessibilityNodeProvider().simulateKeyPress(key);
+ final long downTime = simulateKeyPress(key);
+ simulateKeyRelease(key, downTime);
}
//$FALL-THROUGH$
case MotionEvent.ACTION_HOVER_ENTER:
@@ -282,6 +284,38 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
}
/**
+ * Simulates a key press by injecting touch event into the keyboard view.
+ * This avoids the complexity of trackers and listeners within the keyboard.
+ *
+ * @param key The key to press.
+ */
+ private long simulateKeyPress(final Key key) {
+ final int x = key.getHitBox().centerX();
+ final int y = key.getHitBox().centerY();
+ final long downTime = SystemClock.uptimeMillis();
+ final MotionEvent downEvent = MotionEvent.obtain(
+ downTime, downTime, MotionEvent.ACTION_DOWN, x, y, 0);
+ mView.onTouchEvent(downEvent);
+ downEvent.recycle();
+ return downTime;
+ }
+
+ /**
+ * Simulates a key release by injecting touch event into the keyboard view.
+ * This avoids the complexity of trackers and listeners within the keyboard.
+ *
+ * @param key The key to release.
+ */
+ private void simulateKeyRelease(final Key key, final long downTime) {
+ final int x = key.getHitBox().centerX();
+ final int y = key.getHitBox().centerY();
+ final MotionEvent upEvent = MotionEvent.obtain(
+ downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, x, y, 0);
+ mView.onTouchEvent(upEvent);
+ upEvent.recycle();
+ }
+
+ /**
* Simulates a transition between two {@link Key}s by sending a HOVER_EXIT on the previous key,
* a HOVER_ENTER on the current key, and a HOVER_MOVE on the current key.
*