Example usage for android.support.v4.view.accessibility AccessibilityNodeInfoCompat getWindowId

List of usage examples for android.support.v4.view.accessibility AccessibilityNodeInfoCompat getWindowId

Introduction

In this page you can find the example usage for android.support.v4.view.accessibility AccessibilityNodeInfoCompat getWindowId.

Prototype

public int getWindowId() 

Source Link

Document

Gets the id of the window from which the info comes from.

Usage

From source file:com.googlecode.eyesfree.utils.TreeDebug.java

/**
 * Gets a description of the properties of a node.
 *//*ww  w. java2s.com*/
public static CharSequence nodeDebugDescription(AccessibilityNodeInfoCompat node) {
    StringBuilder sb = new StringBuilder();
    sb.append(node.getWindowId());

    if (node.getClassName() != null) {
        appendSimpleName(sb, node.getClassName());
    } else {
        sb.append("??");
    }

    if (!node.isVisibleToUser()) {
        sb.append(":invisible");
    }

    if (node.getText() != null) {
        sb.append(":");
        sb.append(node.getText().toString().trim());
    }

    if (node.getContentDescription() != null) {
        sb.append(":");
        sb.append(node.getContentDescription().toString().trim());
    }

    int actions = node.getActions();
    if (actions != 0) {
        sb.append(":");
        if ((actions & AccessibilityNodeInfoCompat.ACTION_FOCUS) != 0) {
            sb.append("F");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("A");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("a");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) != 0) {
            sb.append("-");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) != 0) {
            sb.append("+");
        }
    }

    if (node.isCheckable()) {
        sb.append(":");
        if (node.isChecked()) {
            sb.append("(X)");
        } else {
            sb.append("( )");
        }
    }

    if (node.isFocusable()) {
        sb.append(":focusable");
    }

    if (node.isFocused()) {
        sb.append(":focused");
    }

    if (node.isSelected()) {
        sb.append(":selected");
    }

    if (node.isClickable()) {
        sb.append(":clickable");
    }

    if (node.isLongClickable()) {
        sb.append(":longClickable");
    }

    if (node.isAccessibilityFocused()) {
        sb.append(":accessibilityFocused");
    }

    if (!node.isEnabled()) {
        sb.append(":disabled");
    }

    return sb.toString();
}

From source file:com.android.utils.TreeDebug.java

/**
 * Gets a description of the properties of a node.
 *//*from w w w.j a v  a  2s.co  m*/
private static CharSequence nodeDebugDescription(AccessibilityNodeInfoCompat node) {
    StringBuilder sb = new StringBuilder();
    sb.append(node.getWindowId());

    if (node.getClassName() != null) {
        appendSimpleName(sb, node.getClassName());
    } else {
        sb.append("??");
    }

    if (!node.isVisibleToUser()) {
        sb.append(":invisible");
    }

    Rect rect = new Rect();
    node.getBoundsInScreen(rect);
    sb.append(":");
    sb.append("(").append(rect.left).append(", ").append(rect.top).append(" - ").append(rect.right).append(", ")
            .append(rect.bottom).append(")");

    if (node.getText() != null) {
        sb.append(":");
        sb.append(node.getText().toString().trim());
    }

    if (node.getContentDescription() != null) {
        sb.append(":");
        sb.append(node.getContentDescription().toString().trim());
    }

    int actions = node.getActions();
    if (actions != 0) {
        sb.append(":");
        if ((actions & AccessibilityNodeInfoCompat.ACTION_FOCUS) != 0) {
            sb.append("F");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("A");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("a");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) != 0) {
            sb.append("-");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_CLICK) != 0) {
            sb.append("C");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_LONG_CLICK) != 0) {
            sb.append("L");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) != 0) {
            sb.append("+");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_EXPAND) != 0) {
            sb.append("e");
        }
        if ((actions & AccessibilityNodeInfoCompat.ACTION_COLLAPSE) != 0) {
            sb.append("c");
        }
    }

    if (node.isCheckable()) {
        sb.append(":");
        if (node.isChecked()) {
            sb.append("(X)");
        } else {
            sb.append("( )");
        }
    }

    if (node.isFocusable()) {
        sb.append(":focusable");
    }

    if (node.isFocused()) {
        sb.append(":focused");
    }

    if (node.isSelected()) {
        sb.append(":selected");
    }

    if (node.isClickable()) {
        sb.append(":clickable");
    }

    if (node.isLongClickable()) {
        sb.append(":longClickable");
    }

    if (node.isAccessibilityFocused()) {
        sb.append(":accessibilityFocused");
    }

    if (!node.isEnabled()) {
        sb.append(":disabled");
    }

    if (node.getCollectionInfo() != null) {
        sb.append(":collection");
        sb.append("#R");
        sb.append(node.getCollectionInfo().getRowCount());
        sb.append("C");
        sb.append(node.getCollectionInfo().getColumnCount());
    }

    if (node.getCollectionItemInfo() != null) {
        if (node.getCollectionItemInfo().isHeading()) {
            sb.append(":heading");
        } else {
            sb.append(":item");
        }

        sb.append("#r");
        sb.append(node.getCollectionItemInfo().getRowIndex());
        sb.append("c");
        sb.append(node.getCollectionItemInfo().getColumnIndex());
    }

    return sb.toString();
}

From source file:com.google.android.marvin.mytalkback.CursorGranularityManager.java

/**
 * Processes TYPE_VIEW_ACCESSIBILITY_FOCUSED events by clearing the
 * currently locked node and associated state variables if the provided node
 * is different from the locked node and from the same window.
 *
 * @param node The node to compare against the locked node.
 *///from  w w w. java 2  s  .  co  m
public void onNodeFocused(AccessibilityNodeInfoCompat node) {
    if ((mLockedNode == null) || (node == null)) {
        return;
    }

    if (!mLockedNode.equals(node) && (mLockedNode.getWindowId() == node.getWindowId())) {
        clear();
    }
}

From source file:com.android.screenspeak.CursorGranularityManager.java

/**
 * Processes TYPE_VIEW_ACCESSIBILITY_FOCUSED events by clearing the
 * currently locked node and associated state variables if the provided node
 * is different from the locked node and from the same window.
 *
 * @param node The node to compare against the locked node.
 *///from w ww  .j  a va  2s .  c  om
public void onNodeFocused(AccessibilityNodeInfoCompat node) {
    if ((mLockedNode == null) || (node == null)) {
        return;
    }

    if (!mLockedNode.equals(node) && (mLockedNode.getWindowId() == node.getWindowId())) {
        clearAndRetainGranularity(node);
    }
}

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

private void addEarconWhenAccessibilityFocusMovesToTheDivider(Utterance utterance,
        AccessibilityNodeInfoCompat announcedNode) {
    if (!BuildCompat.isAtLeastN() || mLastFocusedWindowId == announcedNode.getWindowId()) {
        return;//from  w  ww.  j av  a  2s .c o m
    }

    // TODO: Use AccessibilityWindowInfoCompat.TYPE_SPLIT_SCREEN_DIVIDER once it's
    // added.
    if (getWindowType(announcedNode) != AccessibilityWindowInfo.TYPE_SPLIT_SCREEN_DIVIDER) {
        return;
    }

    utterance.addAuditory(R.raw.complete);
}

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 w w .j  ava2s. co  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.screenspeak.eventprocessor.ProcessorVolumeStream.java

private boolean attemptNavigation(int button) {
    AccessibilityNodeInfoCompat node = mCursorController.getCursor();

    // Clear focus if it is on an IME
    if (node != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            for (AccessibilityWindowInfo awi : mService.getWindows()) {
                if (awi.getId() == node.getWindowId()) {
                    if (awi.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD) {
                        node.recycle();/*from  www  .  j a v  a  2 s . c om*/
                        node = null;
                    }
                    break;
                }
            }
        }
    }

    if (node == null) {
        node = findInputFocus();
    }

    if (node == null)
        return false;
    try {
        if (AccessibilityNodeInfoUtils.nodeMatchesClassByType(node, SeekBar.class)) {
            navigateSlider(button);
            return true;
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            if (((AccessibilityNodeInfo) node.getInfo()).isEditable()) {
                navigateEditText(button, node);
                return true;
            }
        } else {
            if (AccessibilityNodeInfoUtils.nodeMatchesClassByType(node, EditText.class)
                    || AccessibilityNodeInfoUtils.nodeMatchesClassByName(node,
                            "com.google.android.search.searchplate.SimpleSearchText")) {
                navigateEditText(button, node);
                return true;
            }
        }

        return false;
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(node);
    }
}

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

private boolean attemptNavigation(int button) {
    AccessibilityNodeInfoCompat node = mCursorController.getCursorOrInputCursor();

    // Clear focus if it is on an IME
    if (node != null) {
        if (API_LEVEL_SUPPORTS_WINDOW_NAVIGATION) {
            for (AccessibilityWindowInfo awi : mService.getWindows()) {
                if (awi.getId() == node.getWindowId()) {
                    if (awi.getType() == AccessibilityWindowInfo.TYPE_INPUT_METHOD) {
                        node.recycle();/* w ww. j  a  v  a  2s. co m*/
                        node = null;
                    }
                    break;
                }
            }
        }
    }

    // If we cleared the focus before it is on an IME, try to get the current node again.
    if (node == null) {
        node = mCursorController.getCursorOrInputCursor();
    }

    if (node == null)
        return false;
    try {
        if (Role.getRole(node) == Role.ROLE_SEEK_CONTROL) {
            navigateSlider(button, node);
            return true;
        }

        // In general, do not allow volume key navigation when the a11y focus is placed but
        // it is not on the edit field that the keyboard is currently editing.
        //
        // Example 1:
        // EditText1 has input focus and EditText2 has accessibility focus.
        // getCursorOrInputCursor() will return EditText2 based on its priority order.
        // EditText2.isFocused() = false, so we should not allow volume keys to control text.
        //
        // Example 2:
        // EditText1 in Window1 has input focus. EditText2 in Window2 has input focus as well.
        // If Window1 is input-focused but Window2 has the accessibility focus, don't allow
        // the volume keys to control the text.
        boolean nodeWindowFocused;
        if (API_LEVEL_SUPPORTS_WINDOW_NAVIGATION) {
            nodeWindowFocused = node.getWindow() != null && node.getWindow().isFocused();
        } else {
            nodeWindowFocused = true;
        }

        if (node.isFocused() && nodeWindowFocused && AccessibilityNodeInfoUtils.isEditable(node)) {
            navigateEditText(button, node);
            return true;
        }

        return false;
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(node);
    }
}

From source file:com.google.android.marvin.mytalkback.ProcessorFocusAndSingleTap.java

private void handleWindowStateChange(AccessibilityEvent event) {
    mLastWindowStateChangedEvent = event.getEventTime();

    // Invalidate scrolling information.
    if (mLastScrollSource != null) {
        mLastScrollSource.recycle();/*from  w  ww  .ja  v  a 2  s  .c o m*/
        mLastScrollSource = null;
    }
    mLastScrollAction = 0;
    mLastScrollFromIndex = -1;
    mLastScrollToIndex = -1;

    // Since we may get WINDOW_STATE_CHANGE events from the keyboard even
    // though the active window is still another app, only clear focus if
    // the event's window ID matches the cursor's window ID.
    final AccessibilityNodeInfoCompat cursor = mCursorController.getCursor();
    if ((cursor != null) && (cursor.getWindowId() == event.getWindowId())) {
        mCursorController.clearCursor();
    }

    AccessibilityNodeInfoUtils.recycleNodes(cursor);
}

From source file:com.android.screenspeak.eventprocessor.ProcessorFocusAndSingleTap.java

private void handleWindowStateChange(AccessibilityEvent event) {
    if (mLastFocusedItem != null) {
        mLastFocusedItem.recycle();/*from   ww w  .j  a  va2s  . c o  m*/
        mLastFocusedItem = null;
    }

    clearScrollAction();
    mLastScrollFromIndex = -1;
    mLastScrollToIndex = -1;

    // Since we may get WINDOW_STATE_CHANGE events from the keyboard even
    // though the active window is still another app, only clear focus if
    // the event's window ID matches the cursor's window ID.
    final AccessibilityNodeInfoCompat cursor = mCursorController.getCursor();
    if ((cursor != null) && (cursor.getWindowId() == event.getWindowId())) {
        ensureFocusConsistency();
    }
    if (cursor != null) {
        cursor.recycle();
    }
    tryFocusCachedRecord();
}