optimize: code generation
This commit is contained in:
@@ -178,6 +178,11 @@ public class UiGlobalSelector {
|
||||
protected boolean isIncluded(UiObject nodeInfo) {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && nodeInfo.getDrawingOrder() == order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "drawingOrder(" + order + ")";
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
@@ -430,5 +435,13 @@ public class UiGlobalSelector {
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (ListFilter filter : mFilters) {
|
||||
str.append(filter.toString()).append(".");
|
||||
}
|
||||
str.deleteCharAt(str.length() - 1);
|
||||
return str.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,37 +37,39 @@ public class UiObject extends AccessibilityNodeInfoCompat {
|
||||
|
||||
|
||||
public static UiObject createRoot(AccessibilityNodeInfo root) {
|
||||
return new UiObject(root, null, 0);
|
||||
return new UiObject(root, null, 0, -1);
|
||||
}
|
||||
|
||||
public static UiObject createRoot(AccessibilityNodeInfo root, AccessibilityNodeInfoAllocator allocator) {
|
||||
return new UiObject(root, allocator, 0);
|
||||
return new UiObject(root, allocator, 0, -1);
|
||||
}
|
||||
|
||||
|
||||
private AccessibilityNodeInfoAllocator mAllocator = null;
|
||||
private String mStackTrace = "";
|
||||
private int mDepth = 0;
|
||||
private final int mIndexInParent;
|
||||
|
||||
public UiObject(Object info) {
|
||||
this(info, 0);
|
||||
this(info, 0, -1);
|
||||
}
|
||||
|
||||
public UiObject(Object info, AccessibilityNodeInfoAllocator allocator, int depth) {
|
||||
public UiObject(Object info, AccessibilityNodeInfoAllocator allocator, int depth, int indexInParent) {
|
||||
super(info);
|
||||
mDepth = depth;
|
||||
mAllocator = allocator;
|
||||
mIndexInParent = indexInParent;
|
||||
if (DEBUG)
|
||||
mStackTrace = Arrays.toString(Thread.currentThread().getStackTrace());
|
||||
}
|
||||
|
||||
|
||||
public UiObject(Object info, AccessibilityNodeInfoAllocator allocator) {
|
||||
this(info, allocator, 0);
|
||||
public UiObject(Object info, AccessibilityNodeInfoAllocator allocator, int indexInParent) {
|
||||
this(info, allocator, 0, indexInParent);
|
||||
}
|
||||
|
||||
public UiObject(Object info, int depth) {
|
||||
this(info, null, depth);
|
||||
public UiObject(Object info, int depth, int indexInParent) {
|
||||
this(info, null, depth, indexInParent);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -76,7 +78,7 @@ public class UiObject extends AccessibilityNodeInfoCompat {
|
||||
AccessibilityNodeInfoCompat parent = super.getParent();
|
||||
if (parent == null)
|
||||
return null;
|
||||
return new UiObject(parent.getInfo(), mDepth - 1);
|
||||
return new UiObject(parent.getInfo(), mDepth - 1, -1);
|
||||
} catch (IllegalStateException e) {
|
||||
// FIXME: 2017/5/5
|
||||
return null;
|
||||
@@ -89,13 +91,17 @@ public class UiObject extends AccessibilityNodeInfoCompat {
|
||||
AccessibilityNodeInfoCompat child = super.getChild(i);
|
||||
if (child == null)
|
||||
return null;
|
||||
return new UiObject(child.getInfo(), mDepth + 1);
|
||||
return new UiObject(child.getInfo(), mDepth + 1, i);
|
||||
} catch (IllegalStateException e) {
|
||||
// FIXME: 2017/5/5
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int indexInParent() {
|
||||
return mIndexInParent;
|
||||
}
|
||||
|
||||
public UiObjectCollection find(UiGlobalSelector selector) {
|
||||
return selector.findOf(this);
|
||||
}
|
||||
@@ -105,11 +111,11 @@ public class UiObject extends AccessibilityNodeInfoCompat {
|
||||
}
|
||||
|
||||
public UiObjectCollection children() {
|
||||
ArrayList<AccessibilityNodeInfoCompat> list = new ArrayList<>(getChildCount());
|
||||
ArrayList<UiObject> list = new ArrayList<>(getChildCount());
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
list.add(getChild(i));
|
||||
list.add(child(i));
|
||||
}
|
||||
return UiObjectCollection.ofCompat(list);
|
||||
return UiObjectCollection.of(list);
|
||||
}
|
||||
|
||||
public int childCount() {
|
||||
@@ -428,20 +434,6 @@ public class UiObject extends AccessibilityNodeInfoCompat {
|
||||
return new UiGlobalSelector().id(viewId).findAndReturnList(this);
|
||||
}
|
||||
|
||||
public static List<UiObject> compatListToUiObjectList(List<AccessibilityNodeInfoCompat> compats, AccessibilityNodeInfoAllocator allocator) {
|
||||
// FIXME: 2017/11/5 lost depth info
|
||||
List<UiObject> uiObjects = new ArrayList<>(compats.size());
|
||||
for (AccessibilityNodeInfoCompat compat : compats) {
|
||||
if (compat != null)
|
||||
uiObjects.add(new UiObject(compat.getInfo(), allocator));
|
||||
}
|
||||
return uiObjects;
|
||||
}
|
||||
|
||||
public static List<UiObject> compatListToUiObjectList(List<AccessibilityNodeInfoCompat> compats) {
|
||||
return compatListToUiObjectList(compats, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recycle() {
|
||||
try {
|
||||
@@ -451,4 +443,5 @@ public class UiObject extends AccessibilityNodeInfoCompat {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -31,10 +31,6 @@ public class UiObjectCollection {
|
||||
|
||||
public static final UiObjectCollection EMPTY = UiObjectCollection.of(Collections.<UiObject>emptyList());
|
||||
|
||||
public static UiObjectCollection ofCompat(List<AccessibilityNodeInfoCompat> list) {
|
||||
return new UiObjectCollection(UiObject.compatListToUiObjectList(list));
|
||||
}
|
||||
|
||||
public static UiObjectCollection of(List<UiObject> list) {
|
||||
return new UiObjectCollection(list);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isCheckable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "checkable";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier CHECKED = new BooleanSupplier() {
|
||||
@@ -50,6 +55,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isChecked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "checked";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier FOCUSABLE = new BooleanSupplier() {
|
||||
@@ -58,6 +68,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isFocusable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "focusable";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier FOCUSED = new BooleanSupplier() {
|
||||
@@ -66,6 +81,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isFocused();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "focused";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier VISIBLE_TO_USER = new BooleanSupplier() {
|
||||
@@ -74,6 +94,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isVisibleToUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "visibleToUser";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier ACCESSIBILITY_FOCUSED = new BooleanSupplier() {
|
||||
@@ -82,6 +107,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isAccessibilityFocused();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "accessibilityFocused";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier SELECTED = new BooleanSupplier() {
|
||||
@@ -90,6 +120,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isSelected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "selected";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier CLICKABLE = new BooleanSupplier() {
|
||||
@@ -98,6 +133,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isClickable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "clickable";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier LONG_CLICKABLE = new BooleanSupplier() {
|
||||
@@ -106,6 +146,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isLongClickable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "longClickable";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier ENABLED = new BooleanSupplier() {
|
||||
@@ -114,6 +159,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "enabled";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -123,6 +173,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isPassword();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "password";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier SCROLLABLE = new BooleanSupplier() {
|
||||
@@ -131,6 +186,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isScrollable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "scrollable";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier EDITABLE = new BooleanSupplier() {
|
||||
@@ -139,6 +199,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isEditable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "editable";
|
||||
}
|
||||
};
|
||||
public static final BooleanSupplier CONTENT_INVALID = new BooleanSupplier() {
|
||||
|
||||
@@ -146,6 +211,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isContentInvalid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "contentInvalid";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier CONTEXT_CLICKABLE = new BooleanSupplier() {
|
||||
@@ -155,6 +225,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isContextClickable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "checkable";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier MULTI_LINE = new BooleanSupplier() {
|
||||
@@ -163,6 +238,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isMultiLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "multiLine";
|
||||
}
|
||||
};
|
||||
|
||||
public static final BooleanSupplier DISMISSABLE = new BooleanSupplier() {
|
||||
@@ -171,6 +251,11 @@ public class BooleanFilter extends DfsFilter {
|
||||
public boolean get(UiObject node) {
|
||||
return node.isDismissable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "dismissable";
|
||||
}
|
||||
};
|
||||
|
||||
private BooleanSupplier mBooleanSupplier;
|
||||
@@ -186,4 +271,8 @@ public class BooleanFilter extends DfsFilter {
|
||||
return nodeInfo != null && mBooleanSupplier.get(nodeInfo) == mExceptedValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mBooleanSupplier.toString() + "(" + mExceptedValue + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import android.graphics.Rect;
|
||||
import com.stardust.automator.UiObject;
|
||||
import com.stardust.view.accessibility.AccessibilityNodeInfoHelper;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/9.
|
||||
*/
|
||||
@@ -33,4 +35,11 @@ public class BoundsFilter extends DfsFilter {
|
||||
return boundsInScreen.equals(mBounds);
|
||||
return mBounds.contains(boundsInScreen);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(Locale.getDefault(), "bounds%s(%d, %d, %d, %d)", mType == TYPE_EQUALS ? "" :
|
||||
mType == TYPE_INSIDE ? "Inside" : "Contains",
|
||||
mBounds.left, mBounds.top, mBounds.right, mBounds.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,11 @@ public class ClassNameFilter {
|
||||
CharSequence charSequence = nodeInfo.getClassName();
|
||||
return charSequence == null ? null : charSequence.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "className";
|
||||
}
|
||||
};
|
||||
|
||||
public static ListFilter equals(String text) {
|
||||
|
||||
@@ -14,6 +14,11 @@ public class DescFilter {
|
||||
CharSequence charSequence = nodeInfo.getContentDescription();
|
||||
return charSequence == null ? null : charSequence.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "desc";
|
||||
}
|
||||
};
|
||||
|
||||
public static ListFilter equals(String text) {
|
||||
|
||||
@@ -16,6 +16,11 @@ public class IdFilter extends ListFilter.Default {
|
||||
public String getKey(UiObject nodeInfo) {
|
||||
return nodeInfo.getViewIdResourceName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "id";
|
||||
}
|
||||
};
|
||||
|
||||
public static StringEqualsFilter equals(String id) {
|
||||
|
||||
@@ -17,6 +17,11 @@ public class IntFilter extends DfsFilter {
|
||||
public int get(UiObject object) {
|
||||
return object.depth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "depth";
|
||||
}
|
||||
};
|
||||
|
||||
public static final IntProperty ROW = new IntProperty() {
|
||||
@@ -24,6 +29,11 @@ public class IntFilter extends DfsFilter {
|
||||
public int get(UiObject object) {
|
||||
return object.row();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "row";
|
||||
}
|
||||
};
|
||||
|
||||
public static final IntProperty ROW_COUNT = new IntProperty() {
|
||||
@@ -31,6 +41,11 @@ public class IntFilter extends DfsFilter {
|
||||
public int get(UiObject object) {
|
||||
return object.rowCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "rowCount";
|
||||
}
|
||||
};
|
||||
|
||||
public static final IntProperty ROW_SPAN = new IntProperty() {
|
||||
@@ -38,6 +53,11 @@ public class IntFilter extends DfsFilter {
|
||||
public int get(UiObject object) {
|
||||
return object.rowSpan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "rowSpan";
|
||||
}
|
||||
};
|
||||
|
||||
public static final IntProperty COLUMN = new IntProperty() {
|
||||
@@ -45,6 +65,11 @@ public class IntFilter extends DfsFilter {
|
||||
public int get(UiObject object) {
|
||||
return object.column();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "column";
|
||||
}
|
||||
};
|
||||
|
||||
public static final IntProperty COLUMN_COUNT = new IntProperty() {
|
||||
@@ -52,6 +77,11 @@ public class IntFilter extends DfsFilter {
|
||||
public int get(UiObject object) {
|
||||
return object.columnCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "columnCount";
|
||||
}
|
||||
};
|
||||
|
||||
public static final IntProperty COLUMN_SPAN = new IntProperty() {
|
||||
@@ -59,6 +89,11 @@ public class IntFilter extends DfsFilter {
|
||||
public int get(UiObject object) {
|
||||
return object.columnSpan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "columnSpan";
|
||||
}
|
||||
};
|
||||
|
||||
private IntProperty mIntProperty;
|
||||
@@ -73,4 +108,9 @@ public class IntFilter extends DfsFilter {
|
||||
protected boolean isIncluded(UiObject nodeInfo) {
|
||||
return mIntProperty.get(nodeInfo) == mValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mIntProperty.toString() + "(" + mValue + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,11 @@ public class PackageNameFilter {
|
||||
CharSequence charSequence = nodeInfo.getPackageName();
|
||||
return charSequence == null ? null : charSequence.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "packageName";
|
||||
}
|
||||
};
|
||||
|
||||
public static ListFilter equals(String text) {
|
||||
|
||||
@@ -21,4 +21,8 @@ public class StringContainsFilter extends DfsFilter {
|
||||
return key != null && key.contains(mContains);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mKeyGetter.toString() + "Contains(\"" + mContains + "\")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,8 @@ public class StringEndsWithFilter extends DfsFilter {
|
||||
return key != null && key.endsWith(mSuffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mKeyGetter.toString() + "EndsWith(\"" + mSuffix + "\")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,14 @@ public class StringEqualsFilter extends DfsFilter {
|
||||
@Override
|
||||
protected boolean isIncluded(UiObject nodeInfo) {
|
||||
String key = mKeyGetter.getKey(nodeInfo);
|
||||
if(key != null){
|
||||
if (key != null) {
|
||||
return key.equals(mText);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mKeyGetter.toString() + "(\"" + mText + "\")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,8 @@ public class StringMatchesFilter extends DfsFilter {
|
||||
return key != null && key.matches(mRegex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mKeyGetter.toString() + "Matches(\"" + mRegex + "\")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,4 +22,8 @@ public class StringStartsWithFilter extends DfsFilter {
|
||||
return key != null && key.startsWith(mPrefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return mKeyGetter.toString() + "StartsWith(\"" + mPrefix + "\")";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,11 @@ public class TextFilter extends ListFilter.Default {
|
||||
CharSequence charSequence = nodeInfo.getText();
|
||||
return charSequence == null ? null : charSequence.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "text";
|
||||
}
|
||||
};
|
||||
|
||||
public static ListFilter equals(String text) {
|
||||
|
||||
@@ -61,10 +61,10 @@ public class AccessibilityService extends android.accessibilityservice.Accessibi
|
||||
Log.v(TAG, "onAccessibilityEvent: " + event);
|
||||
if (!containsAllEventTypes && !eventTypes.contains(event.getEventType()))
|
||||
return;
|
||||
int type = event.getEventType();
|
||||
if (type == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED || type == AccessibilityEvent.TYPE_VIEW_HOVER_ENTER
|
||||
|| type == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) {
|
||||
mFastRootInActiveWindow = super.getRootInActiveWindow();
|
||||
AccessibilityNodeInfo root = super.getRootInActiveWindow();
|
||||
if (root != null) {
|
||||
mFastRootInActiveWindow = root;
|
||||
Log.v(TAG, "root not null: " + event);
|
||||
}
|
||||
for (Map.Entry<Integer, AccessibilityDelegate> entry : mDelegates.entrySet()) {
|
||||
AccessibilityDelegate delegate = entry.getValue();
|
||||
@@ -164,4 +164,5 @@ public class AccessibilityService extends android.accessibilityservice.Accessibi
|
||||
return stickOnKeyObserver;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -28,23 +28,28 @@ public class LayoutInspector {
|
||||
Log.d(LOG_TAG, "captureCurrentWindow: service = null");
|
||||
mCapture = null;
|
||||
} else {
|
||||
final AccessibilityNodeInfo root = service.getRootInActiveWindow();
|
||||
final AccessibilityNodeInfo root = getRootInActiveWindow(service);
|
||||
if (root == null) {
|
||||
Log.d(LOG_TAG, "captureCurrentWindow: root = null");
|
||||
mCapture = null;
|
||||
} else {
|
||||
mExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mDumping = true;
|
||||
mCapture = NodeInfo.capture(root);
|
||||
mDumping = false;
|
||||
}
|
||||
mExecutor.execute(() -> {
|
||||
mDumping = true;
|
||||
mCapture = NodeInfo.capture(root);
|
||||
mDumping = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private AccessibilityNodeInfo getRootInActiveWindow(AccessibilityService service) {
|
||||
AccessibilityNodeInfo root = service.getRootInActiveWindow();
|
||||
if (root == null)
|
||||
return service.fastRootInActiveWindow();
|
||||
return root;
|
||||
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
|
||||
private void refreshChildList(AccessibilityNodeInfo root) {
|
||||
if (root == null)
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.stardust.view.accessibility;
|
||||
import android.graphics.Rect;
|
||||
import android.support.annotation.Keep;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
|
||||
@@ -49,9 +50,10 @@ public class NodeInfo {
|
||||
public boolean checkable;
|
||||
public boolean focused;
|
||||
public boolean visibleToUser;
|
||||
public NodeInfo parent;
|
||||
|
||||
|
||||
public NodeInfo(UiObject node) {
|
||||
public NodeInfo(UiObject node, NodeInfo parent) {
|
||||
id = simplifyId(node.getViewIdResourceName());
|
||||
desc = node.desc();
|
||||
className = node.className();
|
||||
@@ -86,6 +88,8 @@ public class NodeInfo {
|
||||
node.getBoundsInParent(mBoundsInParent);
|
||||
bounds = boundsToString(mBoundsInScreen);
|
||||
|
||||
this.parent = parent;
|
||||
|
||||
}
|
||||
|
||||
private String simplifyId(String idResourceName) {
|
||||
@@ -109,13 +113,13 @@ public class NodeInfo {
|
||||
}
|
||||
|
||||
|
||||
public static NodeInfo capture(@NonNull UiObject parent) {
|
||||
NodeInfo nodeInfo = new NodeInfo(parent);
|
||||
int childCount = parent.getChildCount();
|
||||
public static NodeInfo capture(@NonNull UiObject uiObject, @Nullable NodeInfo parent) {
|
||||
NodeInfo nodeInfo = new NodeInfo(uiObject, parent);
|
||||
int childCount = uiObject.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
UiObject child = parent.child(i);
|
||||
UiObject child = uiObject.child(i);
|
||||
if (child != null) {
|
||||
nodeInfo.children.add(capture(child));
|
||||
nodeInfo.children.add(capture(child, nodeInfo));
|
||||
}
|
||||
}
|
||||
return nodeInfo;
|
||||
@@ -123,11 +127,48 @@ public class NodeInfo {
|
||||
|
||||
public static NodeInfo capture(@NonNull AccessibilityNodeInfo root) {
|
||||
UiObject r = UiObject.createRoot(root);
|
||||
return capture(r);
|
||||
return capture(r, null);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<NodeInfo> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return className + "{" +
|
||||
"childCount=" + children.size() +
|
||||
", mBoundsInScreen=" + mBoundsInScreen +
|
||||
", mBoundsInParent=" + mBoundsInParent +
|
||||
", id='" + id + '\'' +
|
||||
", desc='" + desc + '\'' +
|
||||
", packageName='" + packageName + '\'' +
|
||||
", text='" + text + '\'' +
|
||||
", depth=" + depth +
|
||||
", drawingOrder=" + drawingOrder +
|
||||
", accessibilityFocused=" + accessibilityFocused +
|
||||
", checked=" + checked +
|
||||
", clickable=" + clickable +
|
||||
", contextClickable=" + contextClickable +
|
||||
", dismissable=" + dismissable +
|
||||
", editable=" + editable +
|
||||
", enabled=" + enabled +
|
||||
", focusable=" + focusable +
|
||||
", longClickable=" + longClickable +
|
||||
", row=" + row +
|
||||
", column=" + column +
|
||||
", rowCount=" + rowCount +
|
||||
", columnCount=" + columnCount +
|
||||
", rowSpan=" + rowSpan +
|
||||
", columnSpan=" + columnSpan +
|
||||
", selected=" + selected +
|
||||
", scrollable=" + scrollable +
|
||||
", bounds='" + bounds + '\'' +
|
||||
", checkable=" + checkable +
|
||||
", focused=" + focused +
|
||||
", visibleToUser=" + visibleToUser +
|
||||
", parent=" + parent.className +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user