Java Code Examples for android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#findFocus()

The following examples show how to use android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#findFocus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IMENavigationMode.java    From brailleback with Apache License 2.0 6 votes vote down vote up
/** Returns true if a field suitable for modal editing is focused. */
private boolean isModalFieldFocused() {
    // Only instances of EditText with both input and accessibility focus
    // should be edited modally.
    AccessibilityNodeInfoCompat root = null;
    AccessibilityNodeInfoCompat accessibilityFocused = null;
    try {
        root = AccessibilityServiceCompatUtils.getRootInActiveWindow(
                mAccessibilityService);
        if (root == null) {
            return false;
        }
        accessibilityFocused = root.findFocus(
            AccessibilityNodeInfoCompat.FOCUS_ACCESSIBILITY);
        return (accessibilityFocused != null &&
                accessibilityFocused.isFocused() &&
                AccessibilityNodeInfoUtils.nodeMatchesClassByType(
                        mAccessibilityService, accessibilityFocused,
                        EditText.class));
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(
            root, accessibilityFocused);
    }
}
 
Example 2
Source File: IMENavigationMode.java    From brailleback with Apache License 2.0 6 votes vote down vote up
/** Returns true if a self-brailled node is focused. */
private boolean isSelfBrailledFieldFocused() {
    AccessibilityNodeInfoCompat root = null;
    AccessibilityNodeInfoCompat inputFocused = null;
    AccessibilityNodeInfoCompat accessibilityFocused = null;
    try {
        root = AccessibilityServiceCompatUtils.getRootInActiveWindow(
                mAccessibilityService);
        if (root == null) {
            return false;
        }
        inputFocused = root.findFocus(
            AccessibilityNodeInfoCompat.FOCUS_INPUT);
        if (!mSelfBrailleManager.hasContentForNode(inputFocused)) {
            return false;
        }
        accessibilityFocused = root.findFocus(
            AccessibilityNodeInfoCompat.FOCUS_ACCESSIBILITY);
        return inputFocused.equals(accessibilityFocused);
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(
            root, inputFocused, accessibilityFocused);
    }
}
 
Example 3
Source File: IMENavigationMode.java    From brailleback with Apache License 2.0 6 votes vote down vote up
/** Returns the node with both accessibility and input focus, if any. */
private AccessibilityNodeInfoCompat getFocusedNode() {
    AccessibilityNodeInfoCompat root = null;
    AccessibilityNodeInfoCompat inputFocused = null;
    AccessibilityNodeInfoCompat accessibilityFocused = null;
    try {
        root = AccessibilityServiceCompatUtils.getRootInActiveWindow(
                mAccessibilityService);
        if (root == null) {
            return null;
        }
        inputFocused = root.findFocus(
            AccessibilityNodeInfoCompat.FOCUS_INPUT);
        if (inputFocused == null) {
            return null;
        }
        accessibilityFocused = root.findFocus(
            AccessibilityNodeInfoCompat.FOCUS_ACCESSIBILITY);
        return inputFocused.equals(accessibilityFocused)
            ? inputFocused : null;
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(
            root, accessibilityFocused);
    }
}
 
Example 4
Source File: FocusTracker.java    From brailleback with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the accessibility focus to the node that currently has
 * input focus, if accessibility focus is not already set
 * in the currently focused window.
 */
private void setFocusFromInput() {
    AccessibilityNodeInfoCompat root =
            AccessibilityServiceCompatUtils.getRootInActiveWindow(
                    mAccessibilityService);
    if (root == null) {
        return;
    }
    AccessibilityNodeInfoCompat accessibilityFocused = null;
    AccessibilityNodeInfoCompat inputFocused = null;
    try {
        accessibilityFocused = root.findFocus(
                AccessibilityNodeInfoCompat.FOCUS_ACCESSIBILITY);
        if (accessibilityFocused != null) {
            return;
        }
        inputFocused = root.findFocus(
                AccessibilityNodeInfoCompat.FOCUS_INPUT);
        if (inputFocused == null
                || !AccessibilityNodeInfoUtils.shouldFocusNode(
                        mAccessibilityService, inputFocused)) {
            return;
        }
        inputFocused.performAction(
                AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS);
    } finally {
        AccessibilityNodeInfoUtils.recycleNodes(root, inputFocused,
                accessibilityFocused);
    }
}