Merge "Add click and long click actions to key node info"
This commit is contained in:
commit
593fe9b0cf
2 changed files with 41 additions and 3 deletions
|
@ -305,7 +305,7 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
|
||||||
key.onPressed();
|
key.onPressed();
|
||||||
mKeyboardView.invalidateKey(key);
|
mKeyboardView.invalidateKey(key);
|
||||||
final KeyboardAccessibilityNodeProvider provider = getAccessibilityNodeProvider();
|
final KeyboardAccessibilityNodeProvider provider = getAccessibilityNodeProvider();
|
||||||
provider.sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER);
|
provider.onHoverEnterTo(key);
|
||||||
provider.performActionForKey(key, AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
|
provider.performActionForKey(key, AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,6 +328,6 @@ public class KeyboardAccessibilityDelegate<KV extends KeyboardView>
|
||||||
key.onReleased();
|
key.onReleased();
|
||||||
mKeyboardView.invalidateKey(key);
|
mKeyboardView.invalidateKey(key);
|
||||||
final KeyboardAccessibilityNodeProvider provider = getAccessibilityNodeProvider();
|
final KeyboardAccessibilityNodeProvider provider = getAccessibilityNodeProvider();
|
||||||
provider.sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_EXIT);
|
provider.onHoverExitFrom(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,9 @@ final class KeyboardAccessibilityNodeProvider extends AccessibilityNodeProviderC
|
||||||
/** The virtual view identifier for the focused node. */
|
/** The virtual view identifier for the focused node. */
|
||||||
private int mAccessibilityFocusedView = UNDEFINED;
|
private int mAccessibilityFocusedView = UNDEFINED;
|
||||||
|
|
||||||
|
/** The virtual view identifier for the hovering node. */
|
||||||
|
private int mHoveringNodeId = UNDEFINED;
|
||||||
|
|
||||||
/** The current keyboard view. */
|
/** The current keyboard view. */
|
||||||
private final KeyboardView mKeyboardView;
|
private final KeyboardView mKeyboardView;
|
||||||
|
|
||||||
|
@ -140,6 +143,28 @@ final class KeyboardAccessibilityNodeProvider extends AccessibilityNodeProviderC
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onHoverEnterTo(final Key key) {
|
||||||
|
final int id = getVirtualViewIdOf(key);
|
||||||
|
if (id == View.NO_ID) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Start hovering on the key. Because our accessibility model is lift-to-type, we should
|
||||||
|
// report the node info without click and long click actions to avoid unnecessary
|
||||||
|
// announcements.
|
||||||
|
mHoveringNodeId = id;
|
||||||
|
// Invalidate the node info of the key.
|
||||||
|
sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_WINDOW_CONTENT_CHANGED);
|
||||||
|
sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onHoverExitFrom(final Key key) {
|
||||||
|
mHoveringNodeId = UNDEFINED;
|
||||||
|
// Invalidate the node info of the key to be able to revert the change we have done
|
||||||
|
// in {@link #onHoverEnterTo(Key)}.
|
||||||
|
sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_WINDOW_CONTENT_CHANGED);
|
||||||
|
sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_EXIT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an {@link AccessibilityNodeInfoCompat} representing a virtual
|
* Returns an {@link AccessibilityNodeInfoCompat} representing a virtual
|
||||||
* view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or
|
* view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or
|
||||||
|
@ -214,7 +239,14 @@ final class KeyboardAccessibilityNodeProvider extends AccessibilityNodeProviderC
|
||||||
info.setSource(mKeyboardView, virtualViewId);
|
info.setSource(mKeyboardView, virtualViewId);
|
||||||
info.setEnabled(key.isEnabled());
|
info.setEnabled(key.isEnabled());
|
||||||
info.setVisibleToUser(true);
|
info.setVisibleToUser(true);
|
||||||
// TODO: Add ACTION_CLICK and ACTION_LONG_CLICK.
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mAccessibilityFocusedView == virtualViewId) {
|
if (mAccessibilityFocusedView == virtualViewId) {
|
||||||
info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
|
info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
|
||||||
|
@ -253,6 +285,12 @@ final class KeyboardAccessibilityNodeProvider extends AccessibilityNodeProviderC
|
||||||
sendAccessibilityEventForKey(
|
sendAccessibilityEventForKey(
|
||||||
key, AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
|
key, AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
|
||||||
return true;
|
return true;
|
||||||
|
case AccessibilityNodeInfoCompat.ACTION_CLICK:
|
||||||
|
sendAccessibilityEventForKey(key, AccessibilityEvent.TYPE_VIEW_CLICKED);
|
||||||
|
return true;
|
||||||
|
case AccessibilityNodeInfoCompat.ACTION_LONG_CLICK:
|
||||||
|
sendAccessibilityEventForKey(key, AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
|
||||||
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue