List of usage examples for android.view.accessibility AccessibilityEvent getSource
public AccessibilityNodeInfo getSource()
From source file:com.android.screenspeak.eventprocessor.ProcessorFocusAndSingleTap.java
@Override public void onAccessibilityEvent(AccessibilityEvent event) { if (!mAccessibilityManager.isTouchExplorationEnabled()) { // Don't manage focus when touch exploration is disabled. return;/*w w w. j a v a 2 s .c om*/ } final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event); switch (event.getEventType()) { case AccessibilityEvent.TYPE_VIEW_CLICKED: // Prevent conflicts between lift-to-type and single tap. This // is only necessary when a CLICKED event occurs during a touch // interaction sequence (e.g. before an INTERACTION_END event), // but it isn't harmful to call more often. cancelSingleTap(); break; case AccessibilityEvent.TYPE_VIEW_FOCUSED: case AccessibilityEvent.TYPE_VIEW_SELECTED: if (!mFirstWindowFocusManager.shouldProcessFocusEvent(event)) { return; } boolean isViewFocusedEvent = (AccessibilityEvent.TYPE_VIEW_FOCUSED == event.getEventType()); if (!setFocusOnView(record, isViewFocusedEvent)) { // It is possible that the only speakable child of source node is invisible // at the moment, but could be made visible when view scrolls, or window state // changes. Cache it now. And try to focus on the cached record on: // VIEW_SCROLLED, WINDOW_CONTENT_CHANGED, WINDOW_STATE_CHANGED. // The above 3 are the events that could affect view visibility. if (mCachedPotentiallyFocusableRecordQueue.size() == MAX_CACHED_FOCUSED_RECORD_QUEUE) { mCachedPotentiallyFocusableRecordQueue.remove().first.recycle(); } mCachedPotentiallyFocusableRecordQueue .add(new Pair<>(AccessibilityRecordCompat.obtain(record), event.getEventType())); } else { emptyCachedPotentialFocusQueue(); } break; case AccessibilityEvent.TYPE_VIEW_HOVER_ENTER: final AccessibilityNodeInfoCompat touchedNode = record.getSource(); try { if ((touchedNode != null) && !setFocusFromViewHoverEnter(touchedNode)) { mHandler.sendEmptyTouchAreaFeedbackDelayed(touchedNode); } } finally { AccessibilityNodeInfoUtils.recycleNodes(touchedNode); } break; case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED: mHandler.cancelEmptyTouchAreaFeedback(); AccessibilityNodeInfo source = event.getSource(); if (source != null) { AccessibilityNodeInfoCompat compatSource = new AccessibilityNodeInfoCompat(source); mLastFocusedItem = AccessibilityNodeInfoCompat.obtain(compatSource); } break; case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED: mFirstWindowFocusManager.registerWindowChange(event); handleWindowStateChange(event); break; case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED: handleWindowContentChanged(); break; case AccessibilityEvent.TYPE_VIEW_SCROLLED: handleViewScrolled(event, record); break; case AccessibilityEventCompat.TYPE_TOUCH_INTERACTION_START: // This event type only exists on API 17+ (JB MR1). handleTouchInteractionStart(); break; case AccessibilityEventCompat.TYPE_TOUCH_INTERACTION_END: // This event type only exists on API 17+ (JB MR1). handleTouchInteractionEnd(); break; } }