aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java
diff options
context:
space:
mode:
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 160e554ae..d2031d155 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;
@@ -261,7 +262,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:
@@ -302,6 +304,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.
*