Search in sources :

Example 91 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project SunDay by iQuick.

the class Manager method announceForAccessibilityCompat.

/**
 * Generates and dispatches an SDK-specific spoken announcement.
 * <p>
 * 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 android.view.accessibility.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);
    }
}
Also used : AccessibilityManager(android.view.accessibility.AccessibilityManager) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) AccessibilityManager(android.view.accessibility.AccessibilityManager)

Example 92 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project ActionBarSherlock by JakeWharton.

the class IcsAdapterView method onRequestSendAccessibilityEvent.

@Override
public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
    if (super.onRequestSendAccessibilityEvent(child, event)) {
        // Add a record for ourselves as well.
        AccessibilityEvent record = AccessibilityEvent.obtain();
        onInitializeAccessibilityEvent(record);
        // Populate with the text of the requesting child.
        child.dispatchPopulateAccessibilityEvent(record);
        event.appendRecord(record);
        return true;
    }
    return false;
}
Also used : AccessibilityEvent(android.view.accessibility.AccessibilityEvent)

Example 93 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project HoloEverywhere by Prototik.

the class TouchExplorationHelper method getEventForItem.

private AccessibilityEvent getEventForItem(T item, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    final int virtualDescendantId = getIdForItem(item);
    // Ensure the client has good defaults.
    event.setEnabled(true);
    // Allow the client to populate the event.
    populateEventForItem(item, 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.setClassName(item.getClass().getName());
    event.setPackageName(mParentView.getContext().getPackageName());
    record.setSource(mParentView, virtualDescendantId);
    return event;
}
Also used : AccessibilityRecordCompat(android.support.v4.view.accessibility.AccessibilityRecordCompat) AccessibilityEvent(android.view.accessibility.AccessibilityEvent)

Example 94 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project robolectric by robolectric.

the class ShadowAccessibilityEventTest method shouldRecordParcelables.

@Test
public void shouldRecordParcelables() {
    final Notification notification = new Notification();
    event.setParcelableData(notification);
    AccessibilityEvent anotherEvent = AccessibilityEvent.obtain(event);
    assertThat(anotherEvent.getParcelableData()).isInstanceOf(Notification.class);
    assertThat(anotherEvent.getParcelableData()).isEqualTo(notification);
    anotherEvent.recycle();
}
Also used : AccessibilityEvent(android.view.accessibility.AccessibilityEvent) Notification(android.app.Notification) Test(org.junit.Test)

Example 95 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project robolectric by robolectric.

the class ShadowAccessibilityRecordTest method init_shouldCopyBothRealAndShadowFields.

@Test
public void init_shouldCopyBothRealAndShadowFields() {
    AccessibilityNodeInfo source = AccessibilityNodeInfo.obtain();
    source.setClassName("fakeClassName");
    AccessibilityEvent event = AccessibilityEvent.obtain(TYPE_WINDOW_CONTENT_CHANGED);
    shadowOf(event).setSourceNode(source);
    final int fromIndex = 5;
    event.setFromIndex(fromIndex);
    AccessibilityEvent eventCopy = AccessibilityEvent.obtain(event);
    assertThat(eventCopy.getSource()).isEqualTo(source);
    assertThat(eventCopy.getFromIndex()).isEqualTo(fromIndex);
}
Also used : AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) Test(org.junit.Test)

Aggregations

AccessibilityEvent (android.view.accessibility.AccessibilityEvent)241 AccessibilityManager (android.view.accessibility.AccessibilityManager)49 LargeTest (android.test.suitebuilder.annotation.LargeTest)40 AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)20 ViewParent (android.view.ViewParent)13 TimeoutException (java.util.concurrent.TimeoutException)11 MediumTest (android.test.suitebuilder.annotation.MediumTest)10 IAccessibilityManager (android.view.accessibility.IAccessibilityManager)10 Notification (android.app.Notification)7 ITransientNotification (android.app.ITransientNotification)6 Context (android.content.Context)6 RemoteException (android.os.RemoteException)6 StatusBarNotification (android.service.notification.StatusBarNotification)6 AccessibilityRecordCompat (android.support.v4.view.accessibility.AccessibilityRecordCompat)6 ViewGroup (android.view.ViewGroup)6 Test (org.junit.Test)6 SuppressLint (android.annotation.SuppressLint)5 AccessibilityEventFilter (android.app.UiAutomation.AccessibilityEventFilter)5 OnAccessibilityEventListener (android.app.UiAutomation.OnAccessibilityEventListener)5 UiAutomationShellWrapper (com.android.uiautomator.core.UiAutomationShellWrapper)5