Example usage for android.view.accessibility AccessibilityWindowInfo getId

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

Introduction

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

Prototype

public int getId() 

Source Link

Document

Gets the unique window id.

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.
 */// ww  w. java 2s  .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.controller.CursorControllerApp.java

private boolean navigateToNextOrPreviousWindow(@TraversalStrategy.SearchDirection int direction,
        int windowTypeFilter, int focusStrategy, boolean useInputFocusAsPivot, int inputMode) {
    if (!mIsWindowNavigationAvailable) {
        return false;
    }//from w ww. j a va2 s. co  m

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

    AccessibilityWindowInfo pivotWindow = windowManager.getCurrentWindow(useInputFocusAsPivot);
    if (pivotWindow == null || !matchWindowType(pivotWindow, windowTypeFilter)) {
        return false;
    }

    AccessibilityWindowInfo targetWindow = pivotWindow;
    while (true) {
        @TraversalStrategy.SearchDirection
        int logicalDirection = TraversalStrategyUtils.getLogicalDirection(direction,
                mService.isScreenLayoutRTL());
        if (logicalDirection == TraversalStrategy.SEARCH_FOCUS_FORWARD) {
            targetWindow = windowManager.getNextWindow(targetWindow);
        } else if (logicalDirection == TraversalStrategy.SEARCH_FOCUS_BACKWARD) {
            targetWindow = windowManager.getPreviousWindow(targetWindow);
        } else {
            throw new IllegalStateException("Unknown logical direction");
        }

        if (targetWindow == null || pivotWindow.equals(targetWindow)) {
            return false;
        }

        if (!matchWindowType(targetWindow, windowTypeFilter)) {
            continue;
        }

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

        AccessibilityNodeInfoCompat compatRoot = new AccessibilityNodeInfoCompat(windowRoot);

        if (focusStrategy == FOCUS_STRATEGY_RESUME_FOCUS) {
            if (resumeLastFocus(targetWindow.getId(), inputMode)) {
                return true;
            }

            // If it cannot resume last focus, try to focus the first focusable element.
            TraversalStrategy traversalStrategy = TraversalStrategyUtils.getTraversalStrategy(compatRoot,
                    TraversalStrategy.SEARCH_FOCUS_FORWARD);
            if (navigateWrapAround(compatRoot, TraversalStrategy.SEARCH_FOCUS_FORWARD, traversalStrategy,
                    inputMode)) {
                return true;
            }
        } else {
            TraversalStrategy traversalStrategy = TraversalStrategyUtils.getTraversalStrategy(compatRoot,
                    direction);
            if (navigateWrapAround(compatRoot, direction, traversalStrategy, inputMode)) {
                return true;
            }
        }
    }
}