Example usage for android.view.accessibility AccessibilityWindowInfo getType

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

Introduction

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

Prototype

public int getType() 

Source Link

Document

Gets the type of the window.

Usage

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

/**
 * Populates utterance about window transition. We populate this feedback only when user is in
 * split screen mode to avoid verbosity of feedback.
 *//*from ww w.  ja v  a2s.  c  om*/
private void addWindowTransition(Utterance utterance, AccessibilityNodeInfoCompat announcedNode) {
    int windowId = announcedNode.getWindowId();
    if (windowId == mLastFocusedWindowId) {
        return;
    }

    int windowType = getWindowType(announcedNode);
    if (windowType != AccessibilityWindowInfoCompat.TYPE_APPLICATION
            && windowType != AccessibilityWindowInfoCompat.TYPE_SYSTEM) {
        return;
    }

    List<AccessibilityWindowInfo> windows = mService.getWindows();
    List<AccessibilityWindowInfo> applicationWindows = new ArrayList<>();
    for (AccessibilityWindowInfo window : windows) {
        if (window.getType() == AccessibilityWindowInfo.TYPE_APPLICATION) {
            if (window.getParent() == null) {
                applicationWindows.add(window);
            }
        }
    }

    // Provide window transition feedback only when user is in split screen mode or navigating
    // with keyboard. We consider user is in split screen mode if there are two none-parented
    // application windows.
    if (applicationWindows.size() != 2
            && mService.getInputModeManager().getInputMode() != InputModeManager.INPUT_MODE_KEYBOARD) {
        return;
    }

    WindowManager windowManager = new WindowManager(mService.isScreenLayoutRTL());
    windowManager.setWindows(windows);

    CharSequence title = null;
    if (!applicationWindows.isEmpty() && windowManager.isStatusBar(windowId)) {
        title = mService.getString(R.string.status_bar);
    } else if (!applicationWindows.isEmpty() && windowManager.isNavigationBar(windowId)) {
        title = mService.getString(R.string.navigation_bar);
    } else {
        title = mWindowTitlesMap.get(windowId);

        if (title == null && BuildCompat.isAtLeastN()) {
            for (AccessibilityWindowInfo window : windows) {
                if (window.getId() == windowId) {
                    title = window.getTitle();
                    break;
                }
            }
        }

        if (title == null) {
            title = mService.getApplicationLabel(announcedNode.getPackageName());
        }
    }

    int templateId = windowType == AccessibilityWindowInfo.TYPE_APPLICATION
            ? R.string.template_window_switch_application
            : R.string.template_window_switch_system;
    utterance.addSpoken(
            mService.getString(templateId, WindowManager.formatWindowTitleForFeedback(title, mService)));
}

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;
        }// ww w .  jav  a  2s .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;
    }
}

From source file:com.android.talkback.controller.CursorControllerApp.java

private boolean matchWindowType(AccessibilityWindowInfo window, int windowTypeFilter) {
    int windowType = window.getType();
    if ((windowTypeFilter & WINDOW_TYPE_SYSTEM) != 0 && windowType == AccessibilityWindowInfo.TYPE_SYSTEM) {
        return true;
    } else if ((windowTypeFilter & WINDOW_TYPE_APPLICATION) != 0
            && windowType == AccessibilityWindowInfo.TYPE_APPLICATION) {
        return true;
    } else if ((windowTypeFilter & WINDOW_TYPE_SPLIT_SCREEN_DIVIDER) != 0
            && windowType == AccessibilityWindowInfo.TYPE_SPLIT_SCREEN_DIVIDER) {
        return true;
    } else {//from  ww w  .j  av a 2 s. c  o  m
        return false;
    }
}

From source file:com.android.screenspeak.controller.CursorControllerApp.java

private boolean navigateToNextApplicationWindow(int direction) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        WindowManager windowsManager = new WindowManager();
        windowsManager.setWindows(mService.getWindows());
        if (!windowsManager.isApplicationWindowFocused()) {
            return false;
        }//from ww w .j a  va 2 s .  com

        AccessibilityWindowInfo currentWindow = windowsManager.getCurrentWindow();
        if (currentWindow == null) {
            return false;
        }

        AccessibilityWindowInfo targetWindow = null;
        AccessibilityWindowInfo pivotWindow = currentWindow;
        while (!currentWindow.equals(targetWindow)) {
            switch (direction) {
            case NodeFocusFinder.SEARCH_FORWARD:
                targetWindow = windowsManager.getNextWindow(pivotWindow);
                break;
            case NodeFocusFinder.SEARCH_BACKWARD:
                targetWindow = windowsManager.getPreviousWindow(pivotWindow);
                break;
            }

            pivotWindow = targetWindow;

            if (targetWindow == null) {
                return false;
            }

            if (targetWindow.getType() != AccessibilityWindowInfo.TYPE_APPLICATION) {
                continue;
            }

            AccessibilityNodeInfo windowRoot = targetWindow.getRoot();
            if (windowRoot == null) {
                continue;
            }

            AccessibilityNodeInfoCompat compatRoot = new AccessibilityNodeInfoCompat(windowRoot);
            TraversalStrategy traversalStrategy = new OrderedTraversalStrategy(compatRoot);
            if (navigateWrapAround(compatRoot, direction, traversalStrategy)) {
                return true;
            }
        }
    }

    return false;
}