Java Code Examples for android.view.accessibility.AccessibilityNodeInfo#isFocused()

The following examples show how to use android.view.accessibility.AccessibilityNodeInfo#isFocused() . 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: Tree.java    From oversec with GNU General Public License v3.0 6 votes vote down vote up
public void refresh(AccessibilityNodeInfo node) {
    if (sealed) {
        throw new IllegalArgumentException("sealed! " + super.toString());
    }

    mFocused = node.isFocused();
    node.getBoundsInScreen(mBoundsInScreen);
    node.getBoundsInParent(mBoundsInParent);

    mBoundsInScreen.offset(0, -OverlayDecryptView.SCREEN_OFFSET_Y);


    mText = AccessibilityNodeInfoUtils.getNodeText(node);
    mTextString = mText == null ? null : mText.toString();

    mIsEncoded = mText == null ? false : CryptoHandlerFacade.Companion.isEncoded(mCtx, mTextString);
    if (mIsEncoded) {
        mIsTextView = true;
    }
    mIsEditableTextNode = (node.isEditable()
            && node.isEnabled()
            && mIsEditText
            && !node.isPassword());
}
 
Example 2
Source File: UiObject.java    From za-Farmer with MIT License 5 votes vote down vote up
/**
 * Check if the UI element's <code>focused</code> property is currently true
 *
 * @return true if it is else false
 * @throws UiObjectNotFoundException
 * @since API Level 16
 */
public boolean isFocused() throws UiObjectNotFoundException {
    Tracer.trace();
    AccessibilityNodeInfo node = findAccessibilityNodeInfo(mConfig.getWaitForSelectorTimeout());
    if(node == null) {
        throw new UiObjectNotFoundException(mUiSelector.toString());
    }
    return node.isFocused();
}
 
Example 3
Source File: OversecAccessibilityService.java    From oversec with GNU General Public License v3.0 5 votes vote down vote up
private void checkFocusedNode_PreLollipop(AccessibilityNodeInfo node) {
    //if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) return;
    //need to keep that anyway if we want to find focus in WebViews
    synchronized (mSEMAPHORE_FocusedNode_PreLollipop) {

        if (node.isFocused()) {
            mFocusedNode_PreLollipop_INTRANSACTION = AccessibilityNodeInfo.obtain(node);
        }
    }
}
 
Example 4
Source File: UiObject.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Check if the UI element's <code>focused</code> property is currently true
 *
 * @return true if it is else false
 * @throws UiObjectNotFoundException
 * @since API Level 16
 */
public boolean isFocused() throws UiObjectNotFoundException {
    Tracer.trace();
    AccessibilityNodeInfo node = findAccessibilityNodeInfo(mConfig.getWaitForSelectorTimeout());
    if(node == null) {
        throw new UiObjectNotFoundException(mUiSelector.toString());
    }
    return node.isFocused();
}
 
Example 5
Source File: AccessibilityNodeInfoDumper.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
public static void dumpNode(AccessibilityNodeInfo info, Node root,
		int index, int width, int height) {
	root.sourceId = info.getSourceNodeId();
	root.index = index;
	root.text = safeCharSeqToString(info.getText());
	root.res = safeCharSeqToString(info.getViewIdResourceName());
	root.clazz = safeCharSeqToString(info.getClassName());
	root.pkg = safeCharSeqToString(info.getPackageName());
	root.desc = safeCharSeqToString(info.getContentDescription());
	root.checkable = info.isCheckable();
	root.checked = info.isChecked();
	root.clickable = info.isClickable();
	root.enabled = info.isEnabled();
	root.focusable = info.isFocusable();
	root.focused = info.isFocused();
	root.scrollable = info.isScrollable();
	root.longClickable = info.isLongClickable();
	root.password = info.isPassword();
	root.selected = info.isSelected();
	android.graphics.Rect r = AccessibilityNodeInfoHelper
			.getVisibleBoundsInScreen(info, width, height);
	root.rect = new Rect(r.left, r.top, r.right, r.bottom);
	root.children = new ArrayList<Node>();
	int count = info.getChildCount();
	for (int i = 0; i < count; i++) {
		AccessibilityNodeInfo child = info.getChild(i);
		if (child != null) {
			if (child.isVisibleToUser()) {
				Node childNode = new Node();
				dumpNode(child, childNode, i, width, height);
				root.children.add(childNode);
				child.recycle();
			}
		}
	}
}
 
Example 6
Source File: AccessibilityInteractionController.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void enforceNodeTreeConsistent(List<AccessibilityNodeInfo> nodes) {
    LongSparseArray<AccessibilityNodeInfo> nodeMap =
            new LongSparseArray<AccessibilityNodeInfo>();
    final int nodeCount = nodes.size();
    for (int i = 0; i < nodeCount; i++) {
        AccessibilityNodeInfo node = nodes.get(i);
        nodeMap.put(node.getSourceNodeId(), node);
    }

    // If the nodes are a tree it does not matter from
    // which node we start to search for the root.
    AccessibilityNodeInfo root = nodeMap.valueAt(0);
    AccessibilityNodeInfo parent = root;
    while (parent != null) {
        root = parent;
        parent = nodeMap.get(parent.getParentNodeId());
    }

    // Traverse the tree and do some checks.
    AccessibilityNodeInfo accessFocus = null;
    AccessibilityNodeInfo inputFocus = null;
    HashSet<AccessibilityNodeInfo> seen = new HashSet<AccessibilityNodeInfo>();
    Queue<AccessibilityNodeInfo> fringe = new LinkedList<AccessibilityNodeInfo>();
    fringe.add(root);

    while (!fringe.isEmpty()) {
        AccessibilityNodeInfo current = fringe.poll();

        // Check for duplicates
        if (!seen.add(current)) {
            throw new IllegalStateException("Duplicate node: "
                    + current + " in window:"
                    + mViewRootImpl.mAttachInfo.mAccessibilityWindowId);
        }

        // Check for one accessibility focus.
        if (current.isAccessibilityFocused()) {
            if (accessFocus != null) {
                throw new IllegalStateException("Duplicate accessibility focus:"
                        + current
                        + " in window:" + mViewRootImpl.mAttachInfo.mAccessibilityWindowId);
            } else {
                accessFocus = current;
            }
        }

        // Check for one input focus.
        if (current.isFocused()) {
            if (inputFocus != null) {
                throw new IllegalStateException("Duplicate input focus: "
                    + current + " in window:"
                    + mViewRootImpl.mAttachInfo.mAccessibilityWindowId);
            } else {
                inputFocus = current;
            }
        }

        final int childCount = current.getChildCount();
        for (int j = 0; j < childCount; j++) {
            final long childId = current.getChildId(j);
            final AccessibilityNodeInfo child = nodeMap.get(childId);
            if (child != null) {
                fringe.add(child);
            }
        }
    }

    // Check for disconnected nodes.
    for (int j = nodeMap.size() - 1; j >= 0; j--) {
        AccessibilityNodeInfo info = nodeMap.valueAt(j);
        if (!seen.contains(info)) {
            throw new IllegalStateException("Disconnected node: " + info);
        }
    }
}
 
Example 7
Source File: OversecAccessibilityService.java    From oversec with GNU General Public License v3.0 3 votes vote down vote up
private void refreshNode_MAIN(AccessibilityNodeInfo node) {
    checkHandlerThread();
    if (LoggingConfig.INSTANCE.getLOG()) {
        Ln.d("SKRAPE: refreshNode node= %s", node.hashCode());
    }

    long t1 = System.currentTimeMillis();

    //no need to explicitly refresh, the ACS event shouldhave passed us the latest version already!
    //node.refresh();
    if (node.isFocused()) {
        checkFocusedNode_PreLollipop(node);
    }


    Tree.TreeNode treeNode = mTree.get(node);


    if (treeNode == null) {
        mTree.put(node);
    } else {
        treeNode.refresh(node);
    }


    long t2 = System.currentTimeMillis();
    Ln.d("SKRAPE refreshNode took %s", (t2 - t1));


}