Example usage for android.view.accessibility AccessibilityEvent obtain

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

Introduction

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

Prototype

public static AccessibilityEvent obtain(AccessibilityEvent event) 

Source Link

Document

Returns a cached instance if such is available or a new one is created.

Usage

From source file:com.googlecode.eyesfree.utils.ExploreByTouchHelper.java

private AccessibilityEvent getEventForRoot(int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    mHost.onInitializeAccessibilityEvent(event);

    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    record.setSource(mHost, ROOT_ID);//from  w w  w. j av  a  2s .com

    return event;
}

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

/**
 * Constructs and returns an {@link AccessibilityEvent} populated with
 * information about the specified item.
 *
 * @param virtualViewId The virtual view id for the item for which to
 *            construct an event.// ww w  . ja va  2 s.c  o m
 * @param eventType The type of event to construct.
 * @return An {@link AccessibilityEvent} populated with information about
 *         the specified item.
 */
private AccessibilityEvent getEventForVirtualViewId(int virtualViewId, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);

    // Ensure the client has good defaults.
    event.setEnabled(true);
    event.setClassName(mHost.getClass().getName() + DEFAULT_CLASS_NAME);

    // Allow the client to populate the event.
    populateEventForVirtualViewId(virtualViewId, event);

    if (event.getText().isEmpty() && TextUtils.isEmpty(event.getContentDescription())) {
        throw new RuntimeException("You must add text or a content description in populateEventForItem()");
    }

    // Don't allow the client to override these properties.
    event.setPackageName(mHost.getContext().getPackageName());

    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    record.setSource(mHost, virtualViewId);

    return event;
}

From source file:com.googlecode.eyesfree.utils.ExploreByTouchHelper.java

/**
 * Constructs and returns an {@link AccessibilityEvent} populated with
 * information about the specified item.
 *
 * @param virtualViewId The virtual view id for the item for which to
 *            construct an event./* ww  w. j a  v  a2  s  . c o m*/
 * @param eventType The type of event to construct.
 * @return An {@link AccessibilityEvent} populated with information about
 *         the specified item.
 */
private AccessibilityEvent getEventForVirtualViewId(int virtualViewId, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);

    // Ensure the client has good defaults.
    event.setEnabled(true);
    event.setClassName(mHost.getClass().getName() + DEFAULT_CLASS_NAME);

    // Allow the client to populate the event.
    populateEventForVirtualViewId(virtualViewId, event);

    if (event.getText().isEmpty() && TextUtils.isEmpty(event.getContentDescription())) {
        throw new RuntimeException("You must add text or a content description in populateEventForItem()");
    }

    // Don't allow the client to override these properties.
    event.setPackageName(mHost.getContext().getPackageName());

    // Virtual view hierarchies are only supported in API 16+.
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    record.setSource(mHost, virtualViewId);

    return event;
}

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

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

    if ((mDumpEventMask & event.getEventType()) != 0) {
        Log.v(DUMP_EVNET_LOG_TAG, event.toString());
    }

    if (shouldDropRefocusEvent(event)) {
        return;
    }

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

    // We need to save the last focused event so that we can filter out related selected events.
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
        if (mLastFocusedEvent != null) {
            mLastFocusedEvent.recycle();
        }

        mLastFocusedEvent = AccessibilityEvent.obtain(event);
    }

    if (AccessibilityEventUtils.eventMatchesAnyType(event, MASK_DELAYED_EVENT_TYPES)) {
        mHandler.postProcessEvent(event);
    } else {
        processEvent(event);
    }

    if (mTestingListener != null) {
        mTestingListener.afterAccessibilityEvent(event);
    }
}

From source file:com.aboveware.common.crouton.Manager.java

/**
 * Generates and dispatches an SDK-specific spoken announcement.
 * <p>// w  w  w.j  a v a 2  s  .c  om
 * For backwards compatibility, we're constructing an event from scratch
 * using the appropriate event type. If your application only targets SDK
 * 16+, you can just call View.announceForAccessibility(CharSequence).
 * </p>
 *
 * note: AccessibilityManager is only available from API lvl 4.
 *
 * Adapted from https://http://eyes-free.googlecode.com/files/accessibility_codelab_demos_v2_src.zip
 * via https://github.com/coreform/android-formidable-validation
 *
 * @param context Used to get {@link AccessibilityManager}
 * @param text The text to announce.
 */
public static void announceForAccessibilityCompat(Context context, CharSequence text) {
    if (Build.VERSION.SDK_INT >= 4) {
        AccessibilityManager accessibilityManager = (AccessibilityManager) context
                .getSystemService(Context.ACCESSIBILITY_SERVICE);
        if (!accessibilityManager.isEnabled()) {
            return;
        }

        // 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 < 16) {
            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(Manager.class.getName());
        event.setPackageName(context.getPackageName());

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

From source file:com.prashant.custom.widget.crouton.Manager.java

/**
 * Generates and dispatches an SDK-specific spoken announcement.
 * <p>//from w  ww . j a v  a2  s.c  om
 * For backwards compatibility, we're constructing an event from scratch
 * using the appropriate event type. If your application only targets SDK
 * 16+, you can just call View.announceForAccessibility(CharSequence).
 * </p>
 * <p/>
 * note: AccessibilityManager is only available from API lvl 4.
 * <p/>
 * Adapted from https://http://eyes-free.googlecode.com/files/accessibility_codelab_demos_v2_src.zip
 * via https://github.com/coreform/android-formidable-validation
 *
 * @param context
 *   Used to get {@link AccessibilityManager}
 * @param text
 *   The text to announce.
 */
public static void announceForAccessibilityCompat(Context context, CharSequence text) {
    if (Build.VERSION.SDK_INT >= 4) {
        AccessibilityManager accessibilityManager = (AccessibilityManager) context
                .getSystemService(Context.ACCESSIBILITY_SERVICE);
        if (!accessibilityManager.isEnabled()) {
            return;
        }

        final int eventType;
        eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;

        // 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(Manager.class.getName());
        event.setPackageName(context.getPackageName());

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

From source file:com.partynetwork.iparty.app.widget.crouton.Manager.java

/**
 * Generates and dispatches an SDK-specific spoken announcement.
 * <p>/*from w w  w . j  a va2s  .  c  o  m*/
 * For backwards compatibility, we're constructing an event from scratch
 * using the appropriate event type. If your application only targets SDK
 * 16+, you can just call View.announceForAccessibility(CharSequence).
 * </p>
 * <p/>
 * note: AccessibilityManager is only available from API lvl 4.
 * <p/>
 * Adapted from https://http://eyes-free.googlecode.com/files/
 * accessibility_codelab_demos_v2_src.zip via
 * https://github.com/coreform/android-formidable-validation
 * 
 * @param context
 *            Used to get {@link AccessibilityManager}
 * @param text
 *            The text to announce.
 */
public static void announceForAccessibilityCompat(Context context, CharSequence text) {
    if (Build.VERSION.SDK_INT >= 4) {
        AccessibilityManager accessibilityManager = null;
        if (null != context) {
            accessibilityManager = (AccessibilityManager) context
                    .getSystemService(Context.ACCESSIBILITY_SERVICE);
        }
        if (null == accessibilityManager || !accessibilityManager.isEnabled()) {
            return;
        }

        // 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 < 16) {
            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(Manager.class.getName());
        event.setPackageName(context.getPackageName());

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

From source file:com.elephant.widget.crouton.Manager.java

/**
 * Generates and dispatches an SDK-specific spoken announcement.
 * <p>/*  w ww.ja va2  s .co  m*/
 * For backwards compatibility, we're constructing an event from scratch
 * using the appropriate event type. If your application only targets SDK
 * 16+, you can just call View.announceForAccessibility(CharSequence).
 * </p>
 * <p/>
 * note: AccessibilityManager is only available from API lvl 4.
 * <p/>
 * Adapted from https://http://eyes-free.googlecode.com/files/
 * accessibility_codelab_demos_v2_src.zip via
 * https://github.com/coreform/android-formidable-validation
 * 
 * @param context
 *            Used to get {@link AccessibilityManager}
 * @param text
 *            The text to announce.
 */
public static void announceForAccessibilityCompat(Context context, CharSequence text) {
    if (Build.VERSION.SDK_INT >= 4) {
        AccessibilityManager accessibilityManager = (AccessibilityManager) context
                .getSystemService(Context.ACCESSIBILITY_SERVICE);
        if (!accessibilityManager.isEnabled()) {
            return;
        }

        // 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 < 16) {
            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(Manager.class.getName());
        event.setPackageName(context.getPackageName());

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

From source file:com.arta.lib.widget.crouton.Manager.java

/**
 * Generates and dispatches an SDK-specific spoken announcement.
 * <p>/*w  w  w . jav  a 2s .  c om*/
 * For backwards compatibility, we're constructing an event from scratch
 * using the appropriate event type. If your application only targets SDK
 * 16+, you can just call View.announceForAccessibility(CharSequence).
 * </p>
 * <p/>
 * note: AccessibilityManager is only available from API lvl 4.
 * <p/>
 * Adapted from https://http://eyes-free.googlecode.com/files/accessibility_codelab_demos_v2_src.zip
 * via https://github.com/coreform/android-formidable-validation
 *
 * @param context
 *     Used to get {@link AccessibilityManager}
 * @param text
 *     The text to announce.
 */
public static void announceForAccessibilityCompat(Context context, CharSequence text) {
    if (Build.VERSION.SDK_INT >= 4) {
        AccessibilityManager accessibilityManager = null;
        if (null != context) {
            accessibilityManager = (AccessibilityManager) context
                    .getSystemService(Context.ACCESSIBILITY_SERVICE);
        }
        if (null == accessibilityManager || !accessibilityManager.isEnabled()) {
            return;
        }

        // 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 < 16) {
            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(Manager.class.getName());
        event.setPackageName(context.getPackageName());

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

From source file:cc.flydev.launcher.Folder.java

private void sendCustomAccessibilityEvent(int type, String text) {
    AccessibilityManager accessibilityManager = (AccessibilityManager) getContext()
            .getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (accessibilityManager.isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(type);
        onInitializeAccessibilityEvent(event);
        event.getText().add(text);//from  w  w  w. j ava 2s .c  o  m
        accessibilityManager.sendAccessibilityEvent(event);
    }
}