Example usage for android.view.accessibility AccessibilityEvent setSource

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

Introduction

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

Prototype

public void setSource(View source) 

Source Link

Document

Sets the event source.

Usage

From source file:android.support.v7.internal.widget.ActionBarContextView.java

@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    if (Build.VERSION.SDK_INT >= 14) {
        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
            // Action mode started
            event.setSource(this);
            event.setClassName(getClass().getName());
            event.setPackageName(getContext().getPackageName());
            event.setContentDescription(mTitle);
        } else {//  w  w  w.  j a  va2 s . com
            super.onInitializeAccessibilityEvent(event);
        }
    }
}

From source file:com.googlecode.eyesfree.testing.BaseAccessibilityInstrumentationTestCase.java

/**
 * Finds an {@link android.view.accessibility.AccessibilityNodeInfo} by View id in the active window.
 * The search is performed from the root node.
 *
 * @param viewId The id of a View.//from   w  w w. j a v a2  s.  c  o  m
 * @return An {@link android.view.accessibility.AccessibilityNodeInfo} if found, null otherwise.
 */
protected final AccessibilityNodeInfo findAccessibilityNodeInfoByViewIdInActiveWindow(int viewId) {
    startRecordingEvents();

    final View view = getViewForId(viewId);
    assertNotNull("Obtain view from activity", view);

    final AccessibilityEvent event = AccessibilityEvent.obtain();
    event.setEnabled(false);
    event.setEventType(NODE_INFO_EVENT_TYPE);
    event.setParcelableData(SYNC_PARCELABLE);
    event.setSource(view);

    // Sending the event through the manager sets the event time and
    // may clear the source node. Only certain event types can be
    // dispatched (see the framework's AccessibilityManagerService
    // canDispatchAccessibilityEvent() method).
    mManager.sendAccessibilityEvent(event);

    final AccessibilityEvent syncedEvent = stopRecordingEventsAfter(mNodeInfoEventFilter);
    assertNotNull("Synchronized event queue", syncedEvent);

    final AccessibilityNodeInfo sourceNode = syncedEvent.getSource();
    assertNotNull("Obtained source node from event", sourceNode);

    return sourceNode;
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void announceForAccessibilityCompat(final Context context, final View view,
        final CharSequence text, final Class<?> cls) {
    final AccessibilityManager accessibilityManager = (AccessibilityManager) context
            .getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (!accessibilityManager.isEnabled())
        return;//  w ww. ja  va  2s.co m
    // Prior to SDK 16, announcements could only be made through FOCUSED
    // events. Jelly Bean (SDK 16) added support for speaking text verbatim
    // using the ANNOUNCEMENT event type.
    final int eventType;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
    } else {
        eventType = AccessibilityEventCompat.TYPE_ANNOUNCEMENT;
    }

    // Construct an accessibility event with the minimum recommended
    // attributes. An event without a class name or package may be dropped.
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.getText().add(text);
    event.setClassName(cls.getName());
    event.setPackageName(context.getPackageName());
    event.setSource(view);

    // Sends the event directly through the accessibility manager. If your
    // application only targets SDK 14+, you should just call
    // getParent().requestSendAccessibilityEvent(this, event);
    accessibilityManager.sendAccessibilityEvent(event);
}