am f7edc658: Move simulateKeyPress method to AccessibleKeyboardViewProxy
* commit 'f7edc6582ace41aa36dd7cb0f802097a8f3ae9b5': Move simulateKeyPress method to AccessibleKeyboardViewProxymain
commit
2a0e7c6fc9
|
@ -19,14 +19,12 @@ package com.android.inputmethod.accessibility;
|
|||
import android.graphics.Rect;
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.view.accessibility.AccessibilityEventCompat;
|
||||
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
|
||||
import android.support.v4.view.accessibility.AccessibilityNodeProviderCompat;
|
||||
import android.support.v4.view.accessibility.AccessibilityRecordCompat;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
|
@ -236,27 +234,6 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider
|
|||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulates a key press by injecting touch events into the keyboard view.
|
||||
* This avoids the complexity of trackers and listeners within the keyboard.
|
||||
*
|
||||
* @param key The key to press.
|
||||
*/
|
||||
void 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);
|
||||
final MotionEvent upEvent = MotionEvent.obtain(
|
||||
downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, x, y, 0);
|
||||
|
||||
mKeyboardView.onTouchEvent(downEvent);
|
||||
mKeyboardView.onTouchEvent(upEvent);
|
||||
downEvent.recycle();
|
||||
upEvent.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performAction(final int virtualViewId, final int action,
|
||||
final Bundle arguments) {
|
||||
|
|
|
@ -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:
|
||||
|
@ -281,6 +283,38 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
|
|||
&& (localY < (mView.getHeight() - mEdgeSlop));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
|
Loading…
Reference in New Issue