Example usage for android.view.accessibility AccessibilityNodeInfo ACTION_FOCUS

List of usage examples for android.view.accessibility AccessibilityNodeInfo ACTION_FOCUS

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityNodeInfo ACTION_FOCUS.

Prototype

int ACTION_FOCUS

To view the source code for android.view.accessibility AccessibilityNodeInfo ACTION_FOCUS.

Click Source Link

Document

Action that gives input focus to the node.

Usage

From source file:com.googlecode.eyesfree.brailleback.TreeDebugNavigationMode.java

private CharSequence formatNode(AccessibilityNodeInfo node) {
    StringBuilder sb = new StringBuilder();
    sb.append(node.getWindowId());/*from w  ww.j a v a2s  .  c  om*/
    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());
    }
    if (node.getContentDescription() != null) {
        sb.append(":");
        sb.append(node.getContentDescription());
    }
    int actions = node.getActions();
    if (actions != 0) {
        sb.append(":");
        if ((actions & AccessibilityNodeInfo.ACTION_FOCUS) != 0) {
            sb.append("F");
        }
        if ((actions & AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("A");
        }
        if ((actions & AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS) != 0) {
            sb.append("a");
        }
        if ((actions & AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) != 0) {
            sb.append("-");
        }
        if ((actions & AccessibilityNodeInfo.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.googlecode.eyesfree.brailleback.TreeDebugNavigationMode.java

private boolean activateCurrent() {
    if (mCurrentNode == null) {
        return false;
    }/*from   ww w  .  j a  va  2s  . c om*/
    boolean ret = mCurrentNode.performAction(AccessibilityNodeInfo.ACTION_FOCUS);
    return ret;
}

From source file:com.googlecode.eyesfree.brailleback.DefaultNavigationMode.java

private boolean activateNode(AccessibilityNodeInfoCompat node, int position) {
    if (node == null) {
        return false;
    }/*from w ww.j  a  v a 2s  . c o m*/
    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;
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

private void toSignIn() {
    AccessibilityNodeInfo mAccessibilityNodeInfo = this.getRootInActiveWindow();
    if (mAccessibilityNodeInfo == null)
        return;//from   www .j  a  v a2 s. co  m
    List<AccessibilityNodeInfo> mEdPhoneNodes = mAccessibilityNodeInfo
            .findAccessibilityNodeInfosByViewId(PHONE_ID);
    if (mEdPhoneNodes == null || mEdPhoneNodes.isEmpty())
        return;
    isChecking = true;
    AccessibilityNodeInfo mEdPhoneNode = mEdPhoneNodes.get(0);
    CharSequence mCharSequence = mEdPhoneNode.getText();

    if (mCharSequence != null && !mCharSequence.toString().equals(targetCheckInAcount.getAccount())) {
        mEdPhoneNode.performAction(AccessibilityNodeInfo.ACTION_FOCUS);//?
        Rect mRect = new Rect();
        mEdPhoneNode.getBoundsInScreen(mRect);
        doShellCmdInputTap(mRect.right - 10, mRect.centerY());
        setTextToView(mEdPhoneNode, "");
        setTextToView(mEdPhoneNode, targetCheckInAcount.getAccount());
    }

    List<AccessibilityNodeInfo> mEdPasswordNodes = mAccessibilityNodeInfo
            .findAccessibilityNodeInfosByViewId(PASSWORD_ID);
    if (mEdPasswordNodes == null)
        return;
    AccessibilityNodeInfo mEdPasswordNode = mEdPasswordNodes.get(0);
    CharSequence mCharSequencePassword = mEdPasswordNode.getText();
    setTextToView(mEdPasswordNode, "");
    setTextToView(mEdPasswordNode, targetCheckInAcount.getPassword());

    /*?*/
    inputClick(BUTTON_ID);
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

/**
 * //from  ww  w  .j  av  a2 s .  c om
 */
private void setTextToView(AccessibilityNodeInfo node, String text) {
    Bundle arguments = new Bundle();
    arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT,
            AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD);
    arguments.putBoolean(AccessibilityNodeInfo.ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN, true);
    node.performAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY, arguments);
    /*?*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Bundle args = new Bundle();
        args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text);
        node.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, args);
    } else {
        ClipData data = ClipData.newPlainText("reply", text);
        ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        clipboardManager.setPrimaryClip(data);
        node.performAction(AccessibilityNodeInfo.ACTION_FOCUS); // ?
        node.performAction(AccessibilityNodeInfo.ACTION_PASTE); // 
    }

}