Search in sources :

Example 1 with UiObject

use of com.stardust.automator.UiObject in project Auto.js by hyb1996.

the class CodeGenerator method generateCodeForCollectionChild.

private String generateCodeForCollectionChild(UiObject collection, UiObject target) {
    UiObject parent = target.parent();
    if (parent == null)
        return null;
    UiObject collectionItem = null;
    for (int i = 0; i < collection.childCount(); i++) {
        if (inherits(collection.child(i), target)) {
            collectionItem = collection.child(i);
            break;
        }
    }
    if (collectionItem == null)
        return null;
    String collectionCode = generateCode(mRoot, collection, 2, 0);
    if (collectionCode == null)
        return null;
    String itemCode = generateCode(collectionItem, target, 1, 2, false);
    if (itemCode == null)
        return null;
    return collectionCode + ".children().forEach(child => {\n" + "var target = child.findOne(" + itemCode + ");\n" + "target." + getAction() + ";\n" + "});";
}
Also used : UiObject(com.stardust.automator.UiObject)

Example 2 with UiObject

use of com.stardust.automator.UiObject in project Auto.js by hyb1996.

the class CodeGenerator method generateCode.

public String generateCode() {
    UiObject collection = getCollectionParent(mTarget);
    if (collection != null) {
        return generateCodeForCollectionChild(collection, mTarget);
    }
    UiSelectorGenerator generator = new UiSelectorGenerator(mRoot, mTarget);
    generator.setSearchMode(mSearchMode);
    generator.setUsingDesc(mUsingDesc);
    generator.setUsingId(mUsingId);
    generator.setUsingText(mUsingText);
    String selector = generateCode(generator, mRoot, mTarget, 2, 2);
    if (selector == null)
        return null;
    return generateAction(selector);
}
Also used : UiObject(com.stardust.automator.UiObject)

Example 3 with UiObject

use of com.stardust.automator.UiObject in project Auto.js by hyb1996.

the class CodeGenerator method generateCode.

protected String generateCode(UiSelectorGenerator generator, UiObject root, UiObject target, int maxParentLevel, int maxChildrenLevel, boolean withFind) {
    String selector;
    if (withFind) {
        selector = generator.generateSelectorCode();
    } else {
        UiGlobalSelector s = generator.generateSelector();
        selector = s == null ? null : s.toString();
    }
    if (selector != null) {
        return selector;
    }
    if (maxChildrenLevel > 0) {
        for (int i = 0; i < target.childCount(); i++) {
            UiObject child = target.child(i);
            if (child == null)
                continue;
            String childCode = generateCode(root, child, 0, maxChildrenLevel - 1);
            if (childCode != null) {
                return childCode + ".parent()";
            }
        }
    }
    if (maxParentLevel > 0 && target.parent() != null) {
        int index = target.indexInParent();
        if (index > 0) {
            String parentCode = generateCode(root, target.parent(), maxParentLevel - 1, 0);
            if (parentCode != null) {
                return parentCode + "child(" + index + ")";
            }
        }
    }
    return null;
}
Also used : UiObject(com.stardust.automator.UiObject) UiGlobalSelector(com.stardust.automator.UiGlobalSelector)

Example 4 with UiObject

use of com.stardust.automator.UiObject in project Auto.js by hyb1996.

the class ActionFactory method createActionWithEditableFilter.

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static SimpleAction createActionWithEditableFilter(final int action, int index, final String text) {
    return new SearchTargetAction(action, new FilterAction.EditableFilter(index)) {

        @Override
        protected void performAction(UiObject node) {
            Bundle args = new Bundle();
            if (action == AccessibilityNodeInfo.ACTION_SET_TEXT) {
                args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text);
            } else {
                args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, node.text() + text);
            }
            node.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, args);
        }
    };
}
Also used : UiObject(com.stardust.automator.UiObject) Bundle(android.os.Bundle) RequiresApi(android.support.annotation.RequiresApi)

Example 5 with UiObject

use of com.stardust.automator.UiObject in project Auto.js by hyb1996.

the class DepthFirstSearchTargetAction method searchTarget.

@Override
public UiObject searchTarget(UiObject n) {
    if (n == null)
        return null;
    if (mAble.isAble(n))
        return n;
    for (int i = 0; i < n.getChildCount(); i++) {
        UiObject child = n.child(i);
        if (child == null)
            continue;
        UiObject node = searchTarget(child);
        if (node != null)
            return node;
    }
    return null;
}
Also used : UiObject(com.stardust.automator.UiObject)

Aggregations

UiObject (com.stardust.automator.UiObject)14 TestUiObject (com.stardust.automator.test.TestUiObject)4 Test (org.junit.Test)4 Bundle (android.os.Bundle)1 RequiresApi (android.support.annotation.RequiresApi)1 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)1 UiGlobalSelector (com.stardust.automator.UiGlobalSelector)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1