Example usage for android.view.accessibility AccessibilityEvent getWindowId

List of usage examples for android.view.accessibility AccessibilityEvent getWindowId

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityEvent getWindowId.

Prototype

public int getWindowId() 

Source Link

Document

Gets the id of the window from which the event comes from.

Usage

From source file:com.android.talkback.eventprocessor.AccessibilityEventProcessor.java

/**
 * Returns whether the device should drop this event due to refocus issue.
 * Sometimes TalkBack will receive four consecutive events from one single node:.
 * 1. Accessibility_Focus_Cleared// w ww  .  j  ava  2  s  .c o m
 * 2. Accessibility_Focused
 * 3. Accessibility_Focus_Cleared
 * 4. Accessibility_Focused
 * <p/>
 * The cause of this issue could be:
 * i. Chrome clears and set a11y focus for each scroll event.
 * If it is an action to navigate to previous/next element and causes view scrolling. The
 * first two events are caused by navigation, and the last two events are caused by chrome
 * refocus issue. The last two events are not intended to be spoken.
 * If it is a scroll action. It might cause a lot of a11y_focus_cleared and a11y_focused
 * events. In this case all the events are not intended to be spoken.
 * <p/>
 * ii. User taps on screen to refocus on the a11y focused node. In this case event 2 and 4
 * should be spoken to the user.
 *
 * @param event The current event.
 * @return {@code true} if the event should be dropped.
 */
private boolean shouldDropRefocusEvent(AccessibilityEvent event) {
    int eventType = event.getEventType();
    if (eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED) {
        if (sGetSourceNodeIdMethod != null) {
            try {
                mLastClearedSourceId = (long) sGetSourceNodeIdMethod.invoke(event);
                mLastClearedWindowId = event.getWindowId();
                mLastClearA11yFocus = System.currentTimeMillis();
                if (mLastClearedSourceId != mLastPronouncedSourceId
                        || mLastClearedWindowId != mLastPronouncedWindowId
                        || mProcessorFocusAndSingleTap.isFromRefocusAction(event)) {
                    // something strange. not accessibility focused node sends clear focus event
                    // BUG
                    mLastClearedSourceId = -1;
                    mLastClearedWindowId = -1;
                    mLastClearA11yFocus = 0;
                }
            } catch (Exception e) {
                Log.d(LOGTAG, "Exception accessing field: " + e.toString());
            }
        }
        return true;
    }

    if (eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
        if (sGetSourceNodeIdMethod != null
                && !EventState.getInstance().checkAndClearRecentEvent(EventState.EVENT_NODE_REFOCUSED)) {
            try {
                long sourceId = (long) sGetSourceNodeIdMethod.invoke(event);
                int windowId = event.getWindowId();
                // If this event is fired by the "clear and set a11y focus" issue of Chrome,
                // ignore and don't speak to the user, otherwise update the node and window IDs
                // and then process the event.
                if (System.currentTimeMillis() - mLastClearA11yFocus < CLEAR_SET_A11Y_FOCUS_WINDOW
                        && sourceId == mLastClearedSourceId && windowId == mLastClearedWindowId) {
                    return true;
                } else {
                    mLastPronouncedSourceId = sourceId;
                    mLastPronouncedWindowId = windowId;
                }
            } catch (Exception e) {
                Log.d(LOGTAG, "Exception accessing field: " + e.toString());
            }
        }
    }
    return false;
}

From source file:com.android.screenspeak.eventprocessor.AccessibilityEventProcessor.java

public void onAccessibilityEvent(AccessibilityEvent event) {
    if (mTestingListener != null) {
        mTestingListener.onAccessibilityEvent(event);
    }/*from   ww  w  . j  av a 2  s.  c  o m*/

    // Chrome clears and set a11y focus for each scroll event, it is not intended to be spoken
    // to the user. Remove this when chromium is fixed.
    int eventType = event.getEventType();
    if (eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED) {
        if (sGetSourceNodeIdMethod != null) {
            try {
                mLastClearedSourceId = (long) sGetSourceNodeIdMethod.invoke(event);
                mLastClearedWindowId = event.getWindowId();
                mLastClearA11yFocus = System.currentTimeMillis();
                if (mLastClearedSourceId != mLastPronouncedSourceId
                        || mLastClearedWindowId != mLastPronouncedWindowId) {
                    // something strange. not accessibility focused node sends clear focus event
                    // b/22108305
                    mLastClearedSourceId = -1;
                    mLastClearedWindowId = -1;
                    mLastClearA11yFocus = 0;
                }
            } catch (Exception e) {
                Log.d(LOGTAG, "Exception accessing field: " + e.toString());
            }
        }

        return;
    }

    if (eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
        if (System.currentTimeMillis() - mLastClearA11yFocus < CLEAR_SET_A11Y_FOCUS_WINDOW) {
            if (sGetSourceNodeIdMethod != null) {
                try {
                    long sourceId = (long) sGetSourceNodeIdMethod.invoke(event);
                    int windowId = event.getWindowId();
                    if (sourceId == mLastClearedSourceId && windowId == mLastClearedWindowId) {
                        return;
                    }
                    mLastPronouncedSourceId = sourceId;
                    mLastPronouncedWindowId = windowId;
                } catch (Exception e) {
                    Log.d(LOGTAG, "Exception accessing field: " + e.toString());
                }
            }
        }
    }

    if (shouldDropEvent(event)) {
        return;
    }

    maintainExplorationState(event);

    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED
            || event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
            || event.getEventType() == AccessibilityEvent.TYPE_WINDOWS_CHANGED) {
        mService.setRootDirty(true);
    }

    processEvent(event);
}

From source file:com.android.screenspeak.eventprocessor.ProcessorFocusAndSingleTap.java

private void handleWindowStateChange(AccessibilityEvent event) {
    if (mLastFocusedItem != null) {
        mLastFocusedItem.recycle();//from   w w w  . j a  v  a 2 s.c om
        mLastFocusedItem = null;
    }

    clearScrollAction();
    mLastScrollFromIndex = -1;
    mLastScrollToIndex = -1;

    // Since we may get WINDOW_STATE_CHANGE events from the keyboard even
    // though the active window is still another app, only clear focus if
    // the event's window ID matches the cursor's window ID.
    final AccessibilityNodeInfoCompat cursor = mCursorController.getCursor();
    if ((cursor != null) && (cursor.getWindowId() == event.getWindowId())) {
        ensureFocusConsistency();
    }
    if (cursor != null) {
        cursor.recycle();
    }
    tryFocusCachedRecord();
}

From source file:com.google.android.marvin.mytalkback.ProcessorFocusAndSingleTap.java

private void handleWindowStateChange(AccessibilityEvent event) {
    mLastWindowStateChangedEvent = event.getEventTime();

    // Invalidate scrolling information.
    if (mLastScrollSource != null) {
        mLastScrollSource.recycle();//w  ww .j a  v a  2 s  .c  o  m
        mLastScrollSource = null;
    }
    mLastScrollAction = 0;
    mLastScrollFromIndex = -1;
    mLastScrollToIndex = -1;

    // Since we may get WINDOW_STATE_CHANGE events from the keyboard even
    // though the active window is still another app, only clear focus if
    // the event's window ID matches the cursor's window ID.
    final AccessibilityNodeInfoCompat cursor = mCursorController.getCursor();
    if ((cursor != null) && (cursor.getWindowId() == event.getWindowId())) {
        mCursorController.clearCursor();
    }

    AccessibilityNodeInfoUtils.recycleNodes(cursor);
}