Example usage for android.view.accessibility AccessibilityEvent TYPE_VIEW_ACCESSIBILITY_FOCUSED

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

Introduction

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

Prototype

int TYPE_VIEW_ACCESSIBILITY_FOCUSED

To view the source code for android.view.accessibility AccessibilityEvent TYPE_VIEW_ACCESSIBILITY_FOCUSED.

Click Source Link

Document

Represents the event of gaining accessibility focus.

Usage

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

public void onAccessibilityEvent(AccessibilityEvent event) {
    if (mTestingListener != null) {
        mTestingListener.onAccessibilityEvent(event);
    }/*w w  w. jav a  2s  .c om*/

    // 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.talkback.eventprocessor.AccessibilityEventProcessorTest.java

@MediumTest
public void testQuickRefocusSameNode_eventDropped() {
    final SeekBar seekBar = (SeekBar) getViewForId(R.id.seek_bar);
    final AccessibilityNodeInfoCompat seekBarNode = getNodeForView(seekBar);

    getService().getCursorController().setCursor(seekBarNode);
    waitForAccessibilityIdleSync();//from  w ww .jav a2s  .c o m

    mMatchEventType = AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED;
    mMatchNode = AccessibilityNodeInfoCompat.obtain(seekBarNode);

    seekBarNode.performAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS);
    seekBarNode.performAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    waitForAccessibilityIdleSync();

    assertFalse(mMatched);
}

From source file:com.android.screenspeak.contextmenu.ListMenuManager.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED && mDeferredAction != null) {
        Handler handler = new Handler();
        handler.post(new Runnable() {
            @Override// w ww.j av  a 2  s .  c  o m
            public void run() {
                if (mDeferredAction != null) {
                    mDeferredAction.run();
                    mDeferredAction = null;
                }
            }
        });
        mService.postRemoveEventListener(this);
    }
}

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

@MediumTest
public void testQuickRefocusSameNode_fromTalkBack_eventNotDropped() {
    final SeekBar seekBar = (SeekBar) getViewForId(R.id.seek_bar);
    final AccessibilityNodeInfoCompat seekBarNode = getNodeForView(seekBar);

    getService().getCursorController().setCursor(seekBarNode);
    waitForAccessibilityIdleSync();//from w w  w.j av  a  2 s .  c  om

    mMatchEventType = AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED;
    mMatchNode = AccessibilityNodeInfoCompat.obtain(seekBarNode);

    getService().getCursorController().refocus();
    waitForAccessibilityIdleSync();

    assertTrue(mMatched);
}

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;/*ww w  .  j av  a2 s  .c  o  m*/
    }

    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;
    }
}

From source file:com.samknows.measurement.activity.SamKnowsAggregateStatViewerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*/*from w w w  .j av  a2  s  .  c  o  m*/
     * device = (DeviceDescription) getIntent().getSerializableExtra(
     * Constants.INTENT_EXTRA_DEVICE); isCurrentDevice =
     * getIntent().getBooleanExtra(
     * Constants.INTENT_EXTRA_IS_CURRENT_DEVICE, false);
     * 
     * List<DeviceDescription> devices = AppSettings.getInstance()
     * .getDevices(); String imei =
     * PhoneIdentityDataCollector.getImei(this); currentDevice = new
     * CurrentDeviceDescription(imei); OtherUtils.removeDeviceForImei(imei,
     * devices);
     */

    this.setTitle(getString(R.string.average_results_title));

    setContentView(R.layout.page_views);

    dbHelper = new DBHelper(SamKnowsAggregateStatViewerActivity.this);
    dbHelperAsync = new DBHelper(SamKnowsAggregateStatViewerActivity.this);
    adapter = new MyPagerAdapter(this);

    viewPager = (ViewPager) findViewById(R.id.viewPager);

    viewPager.setAdapter(adapter);
    // viewPager.setOffscreenPageLimit(3);

    final TextView tvHeader = (TextView) findViewById(R.id.textViewHeader);

    viewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int page) {
            tvHeader.setText(getString(R.string.page) + " " + (page + 1));
            if (page == 0) {
                on_aggregate_page = true;
                boolean db_refresh = false;

                SamKnowsAggregateStatViewerActivity.this.setTitle(getString(R.string.average_results));

                TextView timestamp;
                View v;
                v = viewPager.findViewWithTag(page);

                timestamp = (TextView) v.findViewById(R.id.average_results_title);

                timestamp.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);

                if (setTotalArchiveRecords()) {
                    adapter = new MyPagerAdapter(SamKnowsAggregateStatViewerActivity.this);
                    viewPager = (ViewPager) findViewById(R.id.viewPager);
                    viewPager.setAdapter(adapter);
                }

            } else {
                TextView timestamp;
                View v;
                v = viewPager.findViewWithTag(page);

                timestamp = (TextView) v.findViewById(R.id.timestamp);
                timestamp.setContentDescription(getString(R.string.archive_result) + " " + timestamp.getText());
                timestamp.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
                on_aggregate_page = false;
                SamKnowsAggregateStatViewerActivity.this.setTitle(getString(R.string.archive_result));
            }
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageScrollStateChanged(int state) {
            if (state == ViewPager.SCROLL_STATE_SETTLING) {

            }

        }
    });

    Util.initializeFonts(this);
    Util.overrideFonts(this, findViewById(android.R.id.content));

}

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/*ww w.jav a2 s .co 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.googlecode.eyesfree.brailleback.DefaultNavigationMode.java

@Override
public boolean onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
        brailleNodeFromEvent(event);//  w w  w  .  j  ava 2s  .  c  o  m
        break;
    case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
        brailleFocusedNode();
        break;
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        if (!brailleFocusedNode()) {
            // Since focus is typically not set in a newly opened
            // window, so braille the window as-if the first focusable
            // node had focus.  We don't update the focus because that
            // will make other services (e.g. talkback) reflect this
            // change, which is not desired.
            brailleFirstFocusableNode();
        }
        break;
    }
    return true;
}

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

public boolean isFromRefocusAction(AccessibilityEvent event) {
    long eventTime = event.getEventTime();
    int eventType = event.getEventType();
    if (eventType != AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED
            && eventType != AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED) {
        return false;
    }//from  w w w  .j  a  v a2  s  .c  o m
    AccessibilityNodeInfo source = event.getSource();
    try {
        return mLastRefocusStartTime < eventTime
                && (mLastRefocusEndTime > eventTime || mLastRefocusEndTime < mLastRefocusStartTime)
                && mLastRefocusedNode != null && mLastRefocusedNode.getInfo().equals(source);
    } finally {
        if (source != null) {
            source.recycle();
        }
    }
}