Search in sources :

Example 66 with AccessibilityEvent

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

the class ExploreByTouchHelper method createEventForHost.

/**
     * Constructs and returns an {@link AccessibilityEvent} for the host node.
     *
     * @param eventType The type of event to construct.
     * @return An {@link AccessibilityEvent} populated with information about
     *         the specified item.
     */
private AccessibilityEvent createEventForHost(int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    mView.onInitializeAccessibilityEvent(event);
    // Allow the client to populate the event.
    onPopulateEventForHost(event);
    return event;
}
Also used : AccessibilityEvent(android.view.accessibility.AccessibilityEvent)

Example 67 with AccessibilityEvent

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

the class View method announceForAccessibility.

/**
     * Convenience method for sending a {@link AccessibilityEvent#TYPE_ANNOUNCEMENT}
     * {@link AccessibilityEvent} to make an announcement which is related to some
     * sort of a context change for which none of the events representing UI transitions
     * is a good fit. For example, announcing a new page in a book. If accessibility
     * is not enabled this method does nothing.
     *
     * @param text The announcement text.
     */
public void announceForAccessibility(CharSequence text) {
    if (AccessibilityManager.getInstance(mContext).isEnabled() && mParent != null) {
        AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        onInitializeAccessibilityEvent(event);
        event.getText().add(text);
        event.setContentDescription(null);
        mParent.requestSendAccessibilityEvent(this, event);
    }
}
Also used : AccessibilityEvent(android.view.accessibility.AccessibilityEvent)

Example 68 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project android_frameworks_base by crdroidandroid.

the class AdapterView method onRequestSendAccessibilityEventInternal.

/** @hide */
@Override
public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) {
    if (super.onRequestSendAccessibilityEventInternal(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 69 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project android_frameworks_base by crdroidandroid.

the class UiDevice method waitForWindowUpdate.

/**
     * Waits for a window content update event to occur.
     *
     * If a package name for the window is specified, but the current window
     * does not have the same package name, the function returns immediately.
     *
     * @param packageName the specified window package name (can be <code>null</code>).
     *        If <code>null</code>, a window update from any front-end window will end the wait
     * @param timeout the timeout for the wait
     *
     * @return true if a window update occurred, false if timeout has elapsed or if the current
     *         window does not have the specified package name
     * @since API Level 16
     */
public boolean waitForWindowUpdate(final String packageName, long timeout) {
    Tracer.trace(packageName, timeout);
    if (packageName != null) {
        if (!packageName.equals(getCurrentPackageName())) {
            return false;
        }
    }
    Runnable emptyRunnable = new Runnable() {

        @Override
        public void run() {
        }
    };
    AccessibilityEventFilter checkWindowUpdate = new AccessibilityEventFilter() {

        @Override
        public boolean accept(AccessibilityEvent t) {
            if (t.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
                return packageName == null || packageName.equals(t.getPackageName());
            }
            return false;
        }
    };
    try {
        getAutomatorBridge().executeCommandAndWaitForAccessibilityEvent(emptyRunnable, checkWindowUpdate, timeout);
    } catch (TimeoutException e) {
        return false;
    } catch (Exception e) {
        Log.e(LOG_TAG, "waitForWindowUpdate: general exception from bridge", e);
        return false;
    }
    return true;
}
Also used : AccessibilityEventFilter(android.app.UiAutomation.AccessibilityEventFilter) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) TimeoutException(java.util.concurrent.TimeoutException) RemoteException(android.os.RemoteException) TimeoutException(java.util.concurrent.TimeoutException)

Example 70 with AccessibilityEvent

use of android.view.accessibility.AccessibilityEvent in project android_frameworks_base by crdroidandroid.

the class PasswordTextView method sendAccessibilityEventTypeViewTextChanged.

void sendAccessibilityEventTypeViewTextChanged(String beforeText, int fromIndex, int removedCount, int addedCount) {
    if (AccessibilityManager.getInstance(mContext).isEnabled() && (isFocused() || isSelected() && isShown())) {
        if (!shouldSpeakPasswordsForAccessibility()) {
            beforeText = null;
        }
        AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED);
        event.setFromIndex(fromIndex);
        event.setRemovedCount(removedCount);
        event.setAddedCount(addedCount);
        event.setBeforeText(beforeText);
        event.setPassword(true);
        sendAccessibilityEventUnchecked(event);
    }
}
Also used : AccessibilityEvent(android.view.accessibility.AccessibilityEvent)

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