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" + "});";
}
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);
}
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;
}
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);
}
};
}
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;
}
Aggregations