From 389e849a421b6045dcbbc30ad1303f9fa800c214 Mon Sep 17 00:00:00 2001 From: ryanlwlin Date: Tue, 17 Sep 2019 20:42:45 +0800 Subject: [PATCH] Implement text entry key API for accessibility services in AOSP Keyboard From Android Q, Talkback supports lift-to-type feature if the node claims it is a text entry key via setTextEntryKey(). We implement this API to show how this API is applied. This CL uses AccessibilityNodeInfoCompat instead of AccessibilityNodeInfo so that the same functionality can be used even on pre-Q devices when the AccessibilityService supports it. With that, this CL removes the legacy code of lift-to-type feature, which was implemented in the AOSP Keyboard side. Bug: 131644969 Test: manual - enable Talkback suporting lift-to-type,check Talback perform click action when finger is lifted. Change-Id: I1ec2928f5a9ba0bde999b09d4c0b9c922f179a2a --- .../accessibility/KeyboardAccessibilityDelegate.java | 1 - .../KeyboardAccessibilityNodeProvider.java | 11 ++++------- .../MainKeyboardAccessibilityDelegate.java | 8 -------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java b/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java index f7a11639d..5c03d26a9 100644 --- a/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java +++ b/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityDelegate.java @@ -243,7 +243,6 @@ public class KeyboardAccessibilityDelegate // 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) { - performClickOn(key); onHoverExitFrom(key); } setLastHoverKey(null); diff --git a/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityNodeProvider.java b/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityNodeProvider.java index a3511c63f..7266aa88a 100644 --- a/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityNodeProvider.java +++ b/java/src/com/android/inputmethod/accessibility/KeyboardAccessibilityNodeProvider.java @@ -236,6 +236,7 @@ final class KeyboardAccessibilityNodeProvider // Obtain and initialize an AccessibilityNodeInfo with information about the virtual view. final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); info.setPackageName(mKeyboardView.getContext().getPackageName()); + info.setTextEntryKey(true); info.setClassName(key.getClass().getName()); info.setContentDescription(keyDescription); info.setBoundsInParent(boundsInParent); @@ -244,13 +245,9 @@ final class KeyboardAccessibilityNodeProvider info.setSource(mKeyboardView, virtualViewId); info.setEnabled(key.isEnabled()); info.setVisibleToUser(true); - // Don't add ACTION_CLICK and ACTION_LONG_CLOCK actions while hovering on the key. - // See {@link #onHoverEnterTo(Key)} and {@link #onHoverExitFrom(Key)}. - if (virtualViewId != mHoveringNodeId) { - info.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK); - if (key.isLongPressEnabled()) { - info.addAction(AccessibilityNodeInfoCompat.ACTION_LONG_CLICK); - } + info.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK); + if (key.isLongPressEnabled()) { + info.addAction(AccessibilityNodeInfoCompat.ACTION_LONG_CLICK); } if (mAccessibilityFocusedView == virtualViewId) { diff --git a/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java b/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java index edda32d52..3234993cf 100644 --- a/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java +++ b/java/src/com/android/inputmethod/accessibility/MainKeyboardAccessibilityDelegate.java @@ -62,13 +62,10 @@ public final class MainKeyboardAccessibilityDelegate // The rectangle region to ignore hover events. private final Rect mBoundsToIgnoreHoverEvent = new Rect(); - private final AccessibilityLongPressTimer mAccessibilityLongPressTimer; public MainKeyboardAccessibilityDelegate(final MainKeyboardView mainKeyboardView, final KeyDetector keyDetector) { super(mainKeyboardView, keyDetector); - mAccessibilityLongPressTimer = new AccessibilityLongPressTimer( - this /* callback */, mainKeyboardView.getContext()); } /** @@ -233,7 +230,6 @@ public final class MainKeyboardAccessibilityDelegate Log.d(TAG, "onHoverEnterTo: key=" + key + " inIgnoreBounds=" + mBoundsToIgnoreHoverEvent.contains(x, y)); } - mAccessibilityLongPressTimer.cancelLongPress(); if (mBoundsToIgnoreHoverEvent.contains(x, y)) { return; } @@ -241,9 +237,6 @@ public final class MainKeyboardAccessibilityDelegate // Further hover events should be handled. mBoundsToIgnoreHoverEvent.setEmpty(); super.onHoverEnterTo(key); - if (key.isLongPressEnabled()) { - mAccessibilityLongPressTimer.startLongPress(key); - } } @Override @@ -254,7 +247,6 @@ public final class MainKeyboardAccessibilityDelegate Log.d(TAG, "onHoverExitFrom: key=" + key + " inIgnoreBounds=" + mBoundsToIgnoreHoverEvent.contains(x, y)); } - mAccessibilityLongPressTimer.cancelLongPress(); super.onHoverExitFrom(key); }