Example usage for android.view.accessibility AccessibilityEvent TYPE_VIEW_SELECTED

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

Introduction

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

Prototype

int TYPE_VIEW_SELECTED

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

Click Source Link

Document

Represents the event of selecting an item usually in the context of an android.widget.AdapterView .

Usage

From source file:com.android.talkback.formatter.FallbackFormatter.java

@Override
public boolean format(AccessibilityEvent event, TalkBackService context, Utterance utterance) {
    final AccessibilityNodeInfo source = event.getSource();

    // Drop events that have source nodes.
    if (source != null) {
        source.recycle();// w w w  . j av  a  2  s  . c om
        return false;
    }

    boolean hasEarcons = true;

    // Add earcons and patterns since the event doesn't have a source node
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_VIEW_FOCUSED:
        utterance.addHaptic(R.array.view_focused_or_selected_pattern);
        utterance.addAuditory(R.raw.focus_actionable);
        break;
    case AccessibilityEvent.TYPE_VIEW_SELECTED:
        utterance.addHaptic(R.array.view_focused_or_selected_pattern);
        utterance.addAuditory(R.raw.focus_actionable);
        break;
    case AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER:
        utterance.addHaptic(R.array.view_hovered_pattern);
        utterance.addAuditory(R.raw.focus);
        break;
    default:
        hasEarcons = false;
        break;
    }

    final CharSequence text = AccessibilityEventUtils.getEventTextOrDescription(event);
    if (!TextUtils.isEmpty(text)) {
        utterance.addSpoken(text);
    }

    return hasEarcons || !utterance.getSpoken().isEmpty();
}

From source file:com.android.screenspeak.formatter.FallbackFormatter.java

@Override
public boolean format(AccessibilityEvent event, ScreenSpeakService context, Utterance utterance) {
    final AccessibilityNodeInfo source = event.getSource();

    // Drop events that have source nodes.
    if (source != null) {
        source.recycle();//from w  w w. ja va  2s . c  o  m
        return false;
    }

    // Add earcons and patterns since the event doesn't have a source node
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_VIEW_FOCUSED:
        utterance.addHaptic(R.array.view_focused_or_selected_pattern);
        utterance.addAuditory(R.raw.focus_actionable);
        break;
    case AccessibilityEvent.TYPE_VIEW_SELECTED:
        utterance.addHaptic(R.array.view_focused_or_selected_pattern);
        utterance.addAuditory(R.raw.focus_actionable);
        break;
    case AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER:
        utterance.addHaptic(R.array.view_hovered_pattern);
        utterance.addAuditory(R.raw.focus);
        break;
    }

    final CharSequence text = AccessibilityEventUtils.getEventTextOrDescription(event);
    if (!TextUtils.isEmpty(text)) {
        utterance.addSpoken(text);
    }

    return true;
}

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

@MediumTest
public void testViewFocused_overridesViewSelected() {
    final View outerView = getViewForId(R.id.outer_view);
    final View middleView = getViewForId(R.id.middle_view);
    final View innerView = getViewForId(R.id.inner_view);

    mMatchEventType = AccessibilityEvent.TYPE_VIEW_SELECTED;

    getInstrumentation().runOnMainSync(new Runnable() {
        @Override//from   w  w w. j a  v  a 2  s  .  c  om
        public void run() {
            middleView.requestFocus();
            outerView.setSelected(true);
            innerView.setSelected(true);
        }
    });
    getInstrumentation().waitForIdleSync();
    waitForAccessibilityIdleSync();

    assertFalse(mMatched);
}

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

@MediumTest
public void testViewFocused_doesntOverrideUnrelatedViewSelected() {
    final View outerView = getViewForId(R.id.outer_view);
    final View middleView = getViewForId(R.id.middle_view);
    final View seekBar = getViewForId(R.id.seek_bar);

    mMatchEventType = AccessibilityEvent.TYPE_VIEW_SELECTED;
    mMatchNode = AccessibilityNodeInfoCompat.obtain(seekBar);

    getInstrumentation().runOnMainSync(new Runnable() {
        @Override/*from   w w w  .  j  av a2 s.co m*/
        public void run() {
            middleView.requestFocus();
            outerView.setSelected(true);
            seekBar.setSelected(true);
        }
    });
    getInstrumentation().waitForIdleSync();
    waitForAccessibilityIdleSync();

    assertTrue(mMatched);
}

From source file:com.android.utils.AccessibilityEventUtils.java

public static int[] getAllEventTypes() {
    return new int[] { AccessibilityEvent.TYPE_ANNOUNCEMENT, AccessibilityEvent.TYPE_ASSIST_READING_CONTEXT,
            AccessibilityEvent.TYPE_GESTURE_DETECTION_END, AccessibilityEvent.TYPE_GESTURE_DETECTION_START,
            AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED,
            AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END,
            AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START,
            AccessibilityEvent.TYPE_TOUCH_INTERACTION_END, AccessibilityEvent.TYPE_TOUCH_INTERACTION_START,
            AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED,
            AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED, AccessibilityEvent.TYPE_VIEW_CLICKED,
            AccessibilityEvent.TYPE_VIEW_CONTEXT_CLICKED, AccessibilityEvent.TYPE_VIEW_FOCUSED,
            AccessibilityEvent.TYPE_VIEW_HOVER_ENTER, AccessibilityEvent.TYPE_VIEW_HOVER_EXIT,
            AccessibilityEvent.TYPE_VIEW_LONG_CLICKED, AccessibilityEvent.TYPE_VIEW_SCROLLED,
            AccessibilityEvent.TYPE_VIEW_SELECTED, AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED,
            AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED,
            AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY,
            AccessibilityEvent.TYPE_WINDOWS_CHANGED, AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED,
            AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED };
}

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

/**
 * Make sure that selection-event elimination does not get rid of progress bar VIEW_SELECTED
 * events./*  ww  w .  j a v  a  2s.  co  m*/
 */
@MediumTest
public void testProgressBarSelectedEvents() {
    final ProgressBar progressBar = (ProgressBar) getViewForId(R.id.progress_bar);
    final AccessibilityNodeInfoCompat progressBarNode = getNodeForView(progressBar);

    mMatchEventType = AccessibilityEvent.TYPE_VIEW_SELECTED;
    mMatchNode = AccessibilityNodeInfoCompat.obtain(progressBarNode);

    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            progressBar.requestFocus();
            progressBar.setProgress(25);
        }
    });
    getInstrumentation().waitForIdleSync();
    waitForAccessibilityIdleSync();

    assertTrue(mMatched);
}

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

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    updateRecentlyExplored(event);// ww  w.  j  av  a2s  . co m

    if (shouldIgnoreEvent(event)) {
        return;
    }

    mHandler.cancelSeekFeedback();
    mHandler.cancelScrollFeedback();

    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        // Window state changes clear the cache.
        mCachedFromValues.clear();
        break;
    case AccessibilityEvent.TYPE_VIEW_SCROLLED:
        mHandler.postScrollFeedback(event);
        break;
    case AccessibilityEvent.TYPE_VIEW_SELECTED:
        // SeekBars incorrectly send TYPE_VIEW_SELECTED events (verified
        // up to 4.1.2).
        if (AccessibilityEventUtils.eventMatchesClass(mContext, event,
                android.widget.SeekBar.class.getName())) {
            mHandler.postSeekFeedback(event);
        }
        break;
    }
}

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

/**
 * Make sure that selection-event elimination does not get rid of selection bar VIEW_SELECTED
 * events./* w ww  . ja  va 2s. com*/
 */
@MediumTest
public void testSeekBarSelectedEvents() {
    final SeekBar seekBar = (SeekBar) getViewForId(R.id.seek_bar);
    final AccessibilityNodeInfoCompat seekBarNode = getNodeForView(seekBar);

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

    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            seekBar.requestFocus();
            seekBar.setProgress(25);
        }
    });
    getInstrumentation().waitForIdleSync();
    waitForAccessibilityIdleSync();

    assertTrue(mMatched);
}

From source file:com.googlecode.eyesfree.brailleback.TreeDebugNavigationMode.java

@Override
public void onObserveAccessibilityEvent(AccessibilityEvent event) {
    AccessibilityNodeInfo source = event.getSource();
    if (source == null) {
        return;// w  w  w .  j a  v a  2 s. co m
    }
    boolean isNewWindow = false;
    if (mCurrentNode == null || mCurrentNode.getWindowId() != source.getWindowId()) {
        isNewWindow = true;
    }
    int t = event.getEventType();
    boolean isInterestingEventType = false;
    if (t == AccessibilityEvent.TYPE_VIEW_SELECTED || t == AccessibilityEvent.TYPE_VIEW_FOCUSED
            || t == AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED
            || t != AccessibilityEvent.TYPE_VIEW_HOVER_ENTER) {
        isInterestingEventType = true;
    }
    if (isNewWindow || isInterestingEventType) {
        setPendingNode(source);
    }
}

From source file:at.linuxtage.companion.widgets.SlidingTabLayout.java

static void setSelectedCompat(View view, boolean selected) {
    final boolean becomeSelected = selected && !view.isSelected();
    view.setSelected(selected);/*from ww w .j  a  v  a  2s.  c  o m*/
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN && becomeSelected) {
        // Pre-JB we need to manually send the TYPE_VIEW_SELECTED event
        view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
    }
}