Java Code Examples for android.view.accessibility.AccessibilityNodeInfo#ACTION_FOCUS

The following examples show how to use android.view.accessibility.AccessibilityNodeInfo#ACTION_FOCUS . 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: BrowserAccessibilityManager.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @see AccessibilityNodeProvider#performAction(int, int, Bundle)
 */
protected boolean performAction(int virtualViewId, int action, Bundle arguments) {
    if (!mAccessibilityManager.isEnabled() || mNativeObj == 0) {
        return false;
    }

    switch (action) {
        case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS:
            if (mAccessibilityFocusId == virtualViewId) {
                return true;
            }

            mAccessibilityFocusId = virtualViewId;
            sendAccessibilityEvent(mAccessibilityFocusId,
                    AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
            return true;
        case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
            if (mAccessibilityFocusId == virtualViewId) {
                mAccessibilityFocusId = View.NO_ID;
            }
            return true;
        case AccessibilityNodeInfo.ACTION_CLICK:
            nativeClick(mNativeObj, virtualViewId);
            break;
        case AccessibilityNodeInfo.ACTION_FOCUS:
            nativeFocus(mNativeObj, virtualViewId);
            break;
        case AccessibilityNodeInfo.ACTION_CLEAR_FOCUS:
            nativeBlur(mNativeObj);
            break;
        default:
            break;
    }
    return false;
}
 
Example 2
Source File: BrowserAccessibilityManager.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @see AccessibilityNodeProvider#performAction(int, int, Bundle)
 */
protected boolean performAction(int virtualViewId, int action, Bundle arguments) {
    if (!mAccessibilityManager.isEnabled() || mNativeObj == 0) {
        return false;
    }

    switch (action) {
        case AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS:
            if (mAccessibilityFocusId == virtualViewId) {
                return true;
            }

            mAccessibilityFocusId = virtualViewId;
            sendAccessibilityEvent(mAccessibilityFocusId,
                    AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
            return true;
        case AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
            if (mAccessibilityFocusId == virtualViewId) {
                mAccessibilityFocusId = View.NO_ID;
            }
            return true;
        case AccessibilityNodeInfo.ACTION_CLICK:
            nativeClick(mNativeObj, virtualViewId);
            break;
        case AccessibilityNodeInfo.ACTION_FOCUS:
            nativeFocus(mNativeObj, virtualViewId);
            break;
        case AccessibilityNodeInfo.ACTION_CLEAR_FOCUS:
            nativeBlur(mNativeObj);
            break;
        default:
            break;
    }
    return false;
}
 
Example 3
Source File: DefaultNavigationMode.java    From brailleback with Apache License 2.0 4 votes vote down vote up
private boolean activateNode(AccessibilityNodeInfoCompat node,
        int position) {
    if (node == null) {
        return false;
    }
    AccessibilityNodeInfoRef current =
            AccessibilityNodeInfoRef.unOwned(node);
    try {
        do {
            LogUtils.log(this, Log.VERBOSE,
                    "Considering to click: %s",
                    current.get().getInfo());
            int supportedActions = current.get().getActions();
            int action = 0;
            // For edit texts, the click action doesn't currently focus
            // the view, so we special case it here.
            // TODO: Revise when that changes.
            if (AccessibilityNodeInfoUtils.nodeMatchesClassByType(
                    mAccessibilityService, current.get(),
                    EditText.class)) {
                if ((supportedActions & AccessibilityNodeInfo.ACTION_FOCUS)
                        != 0) {
                    action = AccessibilityNodeInfo.ACTION_FOCUS;
                } else {
                    // Put accessibility focus on the field.  If it is
                    // already focused and the IME is selected, that will
                    // activate the editing.
                    action = AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS;
                }
            } else if (position >= 0 && isSelfBrailled(current.get())
                    && (supportedActions
                            & AccessibilityNodeInfo.ACTION_CLICK) != 0) {
                // Generate a fake "action". For instance, a click at
                // position 33 maps to -275000033.
                // TODO: Remove this hack when a better way to pass this
                // information exists.
                int fakeAction = ACTION_BRAILLE_CLICK_MAX - position;
                if (fakeAction < ACTION_BRAILLE_CLICK_MIN) {
                    LogUtils.log(this, Log.WARN,
                        "underflow activating node %s at position %d",
                        current.get(), position);
                    fakeAction = ACTION_BRAILLE_CLICK_MIN;
                } else if (fakeAction > ACTION_BRAILLE_CLICK_MAX) {
                    LogUtils.log(this, Log.WARN,
                        "overflow activating node %s at position %d",
                        current.get(), position);
                    fakeAction = ACTION_BRAILLE_CLICK_MAX;
                }
                if (WebInterfaceUtils.performSpecialAction(current.get(),
                            fakeAction)) {
                    return true;
                }
            } else if ((supportedActions
                            & AccessibilityNodeInfo.ACTION_CLICK) != 0) {
                action = AccessibilityNodeInfo.ACTION_CLICK;
            }
            if (action != 0 && current.get().performAction(action)) {
                return true;
            } else {
                LogUtils.log(this, Log.VERBOSE, "Action %d failed",
                        action);
            }
        } while (current.parent());
    } finally {
        current.recycle();
    }
    LogUtils.log(this, Log.VERBOSE, "Click action failed");
    return false;
}