Example usage for android.view.accessibility AccessibilityEvent TYPE_WINDOW_STATE_CHANGED

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

Introduction

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

Prototype

int TYPE_WINDOW_STATE_CHANGED

To view the source code for android.view.accessibility AccessibilityEvent TYPE_WINDOW_STATE_CHANGED.

Click Source Link

Document

Represents the event of a change to a visually distinct section of the user interface.

Usage

From source file:com.actionbarsherlock.internal.view.StandaloneActionMode.java

@Override
public void finish() {
    if (mFinished) {
        return;/*from  ww  w .j ava2  s  .co m*/
    }
    mFinished = true;

    mContextView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
    mCallback.onDestroyActionMode(this);
}

From source file:com.android.talkbacktests.MainActivity.java

@Override
public void onTitleChanged(CharSequence title, int color) {
    super.onTitleChanged(title, color);
    // Fire a TYPE_WINDOW_STATE_CHANGED event so that the accessibility service will be notified
    // of window title change.
    getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
}

From source file:com.android.inputmethod.accessibility.KeyboardAccessibilityDelegate.java

/**
 * Sends a window state change event with the specified text.
 *
 * @param text The text to send with the event.
 *//* w  w  w  .  j a  v  a  2s.c o m*/
protected void sendWindowStateChanged(final String text) {
    final AccessibilityEvent stateChange = AccessibilityEvent
            .obtain(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
    mKeyboardView.onInitializeAccessibilityEvent(stateChange);
    stateChange.getText().add(text);
    stateChange.setContentDescription(null);

    final ViewParent parent = mKeyboardView.getParent();
    if (parent != null) {
        parent.requestSendAccessibilityEvent(mKeyboardView, stateChange);
    }
}

From source file:com.android.talkback.formatter.TouchExplorationFormatter.java

/**
 * Resets cached scrollable state when touch exploration after window state
 * changes.//from  w  w  w. j a v a  2  s.  co m
 */
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        // Reset cached scrollable state.
        mLastNodeWasScrollable = false;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // Store window title in the map.
            List<CharSequence> titles = event.getText();
            if (titles.size() > 0) {
                AccessibilityNodeInfo node = event.getSource();
                if (node != null) {
                    int windowType = getWindowType(node);
                    if (windowType == AccessibilityWindowInfo.TYPE_APPLICATION
                            || windowType == AccessibilityWindowInfo.TYPE_SYSTEM) {
                        mWindowTitlesMap.put(node.getWindowId(), titles.get(0));
                    }
                    node.recycle();
                }
            }
        }
        break;
    case AccessibilityEvent.TYPE_WINDOWS_CHANGED:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // Copy key set not to modify original map.
            HashSet<Integer> windowIdsToBeRemoved = new HashSet<Integer>();
            windowIdsToBeRemoved.addAll(mWindowTitlesMap.keySet());

            // Enumerate window ids to be removed.
            List<AccessibilityWindowInfo> windows = mService.getWindows();
            for (AccessibilityWindowInfo window : windows) {
                windowIdsToBeRemoved.remove(window.getId());
            }

            // Delete titles of non-existing window ids.
            for (Integer windowId : windowIdsToBeRemoved) {
                mWindowTitlesMap.remove(windowId);
            }
        }
        break;
    }
}

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

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    int eventType = event.getEventType();
    if (eventType != AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
            && eventType != AccessibilityEvent.TYPE_WINDOWS_CHANGED) {
        return;//from w  w  w .  ja v  a 2s .c o  m
    }

    int windowIdABefore = mWindowIdA;
    CharSequence windowTitleABefore = getWindowTitle(mWindowIdA);
    int windowIdBBefore = mWindowIdB;
    CharSequence windowTitleBBefore = getWindowTitle(mWindowIdB);
    int accessibilityOverlayWindowIdBefore = mAccessibilityOverlayWindowId;
    CharSequence accessibilityOverlayWindowTitleBefore = getWindowTitle(mAccessibilityOverlayWindowId);

    updateWindowTitlesMap(event);
    updateScreenState(event);

    // If there is no screen update, do not provide spoken feedback.
    if (windowIdABefore == mWindowIdA && TextUtils.equals(windowTitleABefore, getWindowTitle(mWindowIdA))
            && windowIdBBefore == mWindowIdB && TextUtils.equals(windowTitleBBefore, getWindowTitle(mWindowIdB))
            && accessibilityOverlayWindowIdBefore == mAccessibilityOverlayWindowId && TextUtils.equals(
                    accessibilityOverlayWindowTitleBefore, getWindowTitle(mAccessibilityOverlayWindowId))) {
        return;
    }

    // If the user performs a cursor control(copy, paste, start selection mode, etc) in the
    // local context menu and lands back to the edit text, a TYPE_WINDOWS_CHANGED and a
    // TYPE_WINDOW_STATE_CHANGED events will be fired. We should skip these two events to
    // avoid announcing the window title.
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOWS_CHANGED && EventState.getInstance()
            .checkAndClearRecentEvent(EventState.EVENT_SKIP_WINDOWS_CHANGED_PROCESSING_AFTER_CURSOR_CONTROL)) {
        return;
    }
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
            && EventState.getInstance().checkAndClearRecentEvent(
                    EventState.EVENT_SKIP_WINDOW_STATE_CHANGED_PROCESSING_AFTER_CURSOR_CONTROL)) {
        return;
    }

    // Generate spoken feedback.
    CharSequence utterance;
    boolean isUiStabilized;
    if (mAccessibilityOverlayWindowId != WINDOW_ID_NONE) {
        // Case where accessibility overlay is shown. Use separated logic for accessibility
        // overlay not to say out of split screen mode, e.g. accessibility overlay is shown when
        // user is in split screen mode.
        utterance = getWindowTitleForFeedback(mAccessibilityOverlayWindowId);
        isUiStabilized = true;
    } else if (mWindowIdB == WINDOW_ID_NONE) {
        // Single window mode.
        CharSequence windowTitleA = getWindowTitle(mWindowIdA);
        if (windowTitleA == null) {
            // In single window mode, do not provide feedback if window title is not set.
            return;
        }

        utterance = getWindowTitleForFeedback(mWindowIdA);

        if (IS_IN_ARC) {
            // If windowIdABefore was WINDOW_ID_NONE, we consider it as the focus comes into Arc
            // window.
            utterance = formatAnnouncementForArc(utterance,
                    windowIdABefore == WINDOW_ID_NONE /* focusIntoArc */);
        }

        // Consider UI is stabilized if it's alert dialog to provide faster feedback.
        isUiStabilized = !mIsSplitScreenModeAvailable || isAlertDialog(mWindowIdA);
    } else {
        // Split screen mode.
        int feedbackTemplate;
        if (mService.isScreenOrientationLandscape()) {
            if (mService.isScreenLayoutRTL()) {
                feedbackTemplate = R.string.template_split_screen_mode_landscape_rtl;
            } else {
                feedbackTemplate = R.string.template_split_screen_mode_landscape_ltr;
            }
        } else {
            feedbackTemplate = R.string.template_split_screen_mode_portrait;
        }

        utterance = mService.getString(feedbackTemplate, getWindowTitleForFeedback(mWindowIdA),
                getWindowTitleForFeedback(mWindowIdB));
        isUiStabilized = !mIsSplitScreenModeAvailable || isAlertDialog(mWindowIdA) || isAlertDialog(mWindowIdB);
    }

    // Speak.
    if (!isUiStabilized) {
        // If UI is not stabilized, wait SCREEN_FEEDBACK_DELAY for next accessibility event.
        speakLater(utterance, SCREEN_FEEDBACK_DELAY);
    } else {
        speak(utterance);
    }
}

From source file:com.googlecode.eyesfree.brailleback.BrailleMenuNavigationMode.java

@Override
public boolean onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        closeMenu();//ww w.  j  av a 2 s.c o m
        return true;
    }
    // Don't let fall through.
    return true;
}

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

/**
 * This is a special case: the screen is off and telephony reports that the phone isn't
 * ringing. However, telephony might be a split-second too late; the dialer might appear and
 * send the accessibility event BEFORE telephony switches to ringing state. In this case,
 * we should still process the event!/*from  w  w  w .j  a v  a2 s .  com*/
 */
@MediumTest
public void testWindowStateChanged_fromDialer_screenOff_notRinging() {
    mMatchEventType = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
    mMatchNode = null;

    if (!simulateTelephonyState(TelephonyManager.EXTRA_STATE_IDLE)) {
        return;
    }
    simulateScreenState(false);
    sendEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, getDialerClassName());

    assertTrue(mMatched);
}

From source file:com.googlecode.eyesfree.brailleback.SearchNavigationMode.java

@Override
public boolean onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
        DisplayManager.Content content = formatEventToBraille(event);
        if (content != null) {
            mDisplayManager.setContent(content);
        }//from   w  ww. ja  v a  2s  . c om
        return true;
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        finishSearch();
        // Let it fall through so other navigation mode can
        // receive the window_state_changed event.
        return false;
    case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
        // This will re-evaluate the search and refocus if necessary.
        mMatchedNode.reset(AccessibilityNodeInfoUtils.refreshNode(mMatchedNode.get()));
        evaluateSearch();
        return true;
    }
    // Don't let fall through.
    return true;
}

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

@MediumTest
public void testWindowStateChanged_fromDialer_screenOn_notRinging() {
    mMatchEventType = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
    mMatchNode = null;// w  w w  . j  a v a2 s . c  o m

    if (!simulateTelephonyState(TelephonyManager.EXTRA_STATE_IDLE)) {
        return;
    }
    simulateScreenState(true);
    sendEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, getDialerClassName());

    assertTrue(mMatched);
}

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

@MediumTest
public void testWindowStateChanged_fromDialer_screenOff_ringing() {
    mMatchEventType = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
    mMatchNode = null;/* w ww. ja  va2  s. c o  m*/

    if (!simulateTelephonyState(TelephonyManager.EXTRA_STATE_RINGING)) {
        return;
    }
    simulateScreenState(false);
    sendEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED, getDialerClassName());

    assertTrue(mMatched);
}