Search in sources :

Example 81 with AccessibilityEvent

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

the class VolumeDialog method dismissH.

protected void dismissH(int reason) {
    if (mMotion.isAnimating()) {
        return;
    }
    mHandler.removeMessages(H.DISMISS);
    mHandler.removeMessages(H.SHOW);
    if (!mShowing)
        return;
    mShowing = false;
    mMotion.startDismiss(new Runnable() {

        @Override
        public void run() {
            updateExpandedH(false, /* expanding */
            true);
        }
    });
    if (mAccessibilityMgr.isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
        event.setPackageName(mContext.getPackageName());
        event.setClassName(CustomDialog.class.getSuperclass().getName());
        event.getText().add(mContext.getString(R.string.volume_dialog_accessibility_dismissed_message));
        mAccessibilityMgr.sendAccessibilityEvent(event);
    }
    Events.writeEvent(mContext, Events.EVENT_DISMISS_DIALOG, reason);
    mController.notifyVisible(false);
    synchronized (mSafetyWarningLock) {
        if (mSafetyWarning != null) {
            if (D.BUG)
                Log.d(TAG, "SafetyWarning dismissed");
            mSafetyWarning.dismiss();
        }
    }
}
Also used : AccessibilityEvent(android.view.accessibility.AccessibilityEvent)

Example 82 with AccessibilityEvent

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

the class UiAutomation method executeAndWaitForEvent.

/**
     * Executes a command and waits for a specific accessibility event up to a
     * given wait timeout. To detect a sequence of events one can implement a
     * filter that keeps track of seen events of the expected sequence and
     * returns true after the last event of that sequence is received.
     * <p>
     * <strong>Note:</strong> It is caller's responsibility to recycle the returned event.
     * </p>
     * @param command The command to execute.
     * @param filter Filter that recognizes the expected event.
     * @param timeoutMillis The wait timeout in milliseconds.
     *
     * @throws TimeoutException If the expected event is not received within the timeout.
     */
public AccessibilityEvent executeAndWaitForEvent(Runnable command, AccessibilityEventFilter filter, long timeoutMillis) throws TimeoutException {
    // Acquire the lock and prepare for receiving events.
    synchronized (mLock) {
        throwIfNotConnectedLocked();
        mEventQueue.clear();
        // Prepare to wait for an event.
        mWaitingForEventDelivery = true;
    }
    // Note: We have to release the lock since calling out with this lock held
    // can bite. We will correctly filter out events from other interactions,
    // so starting to collect events before running the action is just fine.
    // We will ignore events from previous interactions.
    final long executionStartTimeMillis = SystemClock.uptimeMillis();
    // Execute the command *without* the lock being held.
    command.run();
    // Acquire the lock and wait for the event.
    synchronized (mLock) {
        try {
            // Wait for the event.
            final long startTimeMillis = SystemClock.uptimeMillis();
            while (true) {
                // Drain the event queue
                while (!mEventQueue.isEmpty()) {
                    AccessibilityEvent event = mEventQueue.remove(0);
                    // Ignore events from previous interactions.
                    if (event.getEventTime() < executionStartTimeMillis) {
                        continue;
                    }
                    if (filter.accept(event)) {
                        return event;
                    }
                    event.recycle();
                }
                // Check if timed out and if not wait.
                final long elapsedTimeMillis = SystemClock.uptimeMillis() - startTimeMillis;
                final long remainingTimeMillis = timeoutMillis - elapsedTimeMillis;
                if (remainingTimeMillis <= 0) {
                    throw new TimeoutException("Expected event not received within: " + timeoutMillis + " ms.");
                }
                try {
                    mLock.wait(remainingTimeMillis);
                } catch (InterruptedException ie) {
                /* ignore */
                }
            }
        } finally {
            mWaitingForEventDelivery = false;
            mEventQueue.clear();
            mLock.notifyAll();
        }
    }
}
Also used : AccessibilityEvent(android.view.accessibility.AccessibilityEvent) TimeoutException(java.util.concurrent.TimeoutException)

Example 83 with AccessibilityEvent

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

the class View method clearAccessibilityFocusNoCallbacks.

/**
     * Clears accessibility focus without calling any callback methods
     * normally invoked in {@link #clearAccessibilityFocus()}. This method
     * is used separately from that one for clearing accessibility focus when
     * giving this focus to another view.
     *
     * @param action The action, if any, that led to focus being cleared. Set to
     * AccessibilityNodeInfo#ACTION_ACCESSIBILITY_FOCUS to specify that focus is moving within
     * the window.
     */
void clearAccessibilityFocusNoCallbacks(int action) {
    if ((mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0) {
        mPrivateFlags2 &= ~PFLAG2_ACCESSIBILITY_FOCUSED;
        invalidate();
        if (AccessibilityManager.getInstance(mContext).isEnabled()) {
            AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
            event.setAction(action);
            if (mAccessibilityDelegate != null) {
                mAccessibilityDelegate.sendAccessibilityEventUnchecked(this, event);
            } else {
                sendAccessibilityEventUnchecked(event);
            }
        }
    }
}
Also used : AccessibilityEvent(android.view.accessibility.AccessibilityEvent)

Example 84 with AccessibilityEvent

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

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 85 with AccessibilityEvent

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

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)

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