Example usage for android.view.accessibility AccessibilityWindowInfo isActive

List of usage examples for android.view.accessibility AccessibilityWindowInfo isActive

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityWindowInfo isActive.

Prototype

public boolean isActive() 

Source Link

Document

Gets if this window is active.

Usage

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

private void updateScreenState(AccessibilityEvent event) {
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        // Do nothing if split screen mode is available since it can be covered by
        // TYPE_WINDOWS_CHANGED events.
        if (mIsSplitScreenModeAvailable) {
            return;
        }//from   w ww  .  ja va2  s  . c  o m

        mWindowIdA = getWindowId(event);
        break;
    case AccessibilityEvent.TYPE_WINDOWS_CHANGED:
        // Do nothing if split screen mode is NOT available since it can be covered by
        // TYPE_WINDOW_STATE_CHANGED events.
        if (!mIsSplitScreenModeAvailable) {
            return;
        }

        ArrayList<AccessibilityWindowInfo> applicationWindows = new ArrayList<>();
        ArrayList<AccessibilityWindowInfo> systemWindows = new ArrayList<>();
        ArrayList<AccessibilityWindowInfo> accessibilityOverlayWindows = new ArrayList<>();
        List<AccessibilityWindowInfo> windows = mService.getWindows();

        // If there are no windows available, clear the cached IDs.
        if (windows.isEmpty()) {
            mAccessibilityOverlayWindowId = WINDOW_ID_NONE;
            mWindowIdA = WINDOW_ID_NONE;
            mWindowIdB = WINDOW_ID_NONE;
            return;
        }

        for (int i = 0; i < windows.size(); i++) {
            AccessibilityWindowInfo window = windows.get(i);
            switch (window.getType()) {
            case AccessibilityWindowInfo.TYPE_APPLICATION:
                if (window.getParent() == null) {
                    applicationWindows.add(window);
                }
                break;
            case AccessibilityWindowInfo.TYPE_SYSTEM:
                systemWindows.add(window);
                break;
            case AccessibilityWindowInfo.TYPE_ACCESSIBILITY_OVERLAY:
                accessibilityOverlayWindows.add(window);
                break;
            }
        }

        if (accessibilityOverlayWindows.size() == windows.size()) {
            // TODO: investigate whether there is a case where we have more than one
            // accessibility overlay, and add a logic for it if there is.
            mAccessibilityOverlayWindowId = accessibilityOverlayWindows.get(0).getId();
            return;
        }

        mAccessibilityOverlayWindowId = WINDOW_ID_NONE;

        if (applicationWindows.size() == 0) {
            mWindowIdA = WINDOW_ID_NONE;
            mWindowIdB = WINDOW_ID_NONE;

            // If there is no application window but a system window, consider it as a
            // current window. This logic handles notification shade and lock screen.
            if (systemWindows.size() > 0) {
                Collections.sort(systemWindows,
                        new WindowManager.WindowPositionComparator(mService.isScreenLayoutRTL()));

                mWindowIdA = systemWindows.get(0).getId();
            }
        } else if (applicationWindows.size() == 1) {
            mWindowIdA = applicationWindows.get(0).getId();
            mWindowIdB = WINDOW_ID_NONE;
        } else if (applicationWindows.size() == 2) {
            Collections.sort(applicationWindows,
                    new WindowManager.WindowPositionComparator(mService.isScreenLayoutRTL()));

            mWindowIdA = applicationWindows.get(0).getId();
            mWindowIdB = applicationWindows.get(1).getId();
        } else {
            // If there are more than 2 windows, report the active window as the current
            // window.
            for (AccessibilityWindowInfo applicationWindow : applicationWindows) {
                if (applicationWindow.isActive()) {
                    mWindowIdA = applicationWindow.getId();
                    mWindowIdB = WINDOW_ID_NONE;
                    return;
                }
            }
        }
        break;
    }
}