Example usage for android.view.accessibility AccessibilityWindowInfo getParent

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

Introduction

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

Prototype

public AccessibilityWindowInfo getParent() 

Source Link

Document

Gets the parent 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 w  ww . j  a  v  a  2  s  . c o  m
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 . j av  a2s. 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;
    }
}