新增 布局界面分析显示十六进制id
This commit is contained in:
@@ -12,6 +12,7 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.autojs.autojs.R;
|
import org.autojs.autojs.R;
|
||||||
|
|
||||||
import com.stardust.view.accessibility.NodeInfo;
|
import com.stardust.view.accessibility.NodeInfo;
|
||||||
import com.stardust.util.ClipboardUtil;
|
import com.stardust.util.ClipboardUtil;
|
||||||
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
|
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
|
||||||
@@ -32,6 +33,7 @@ public class NodeInfoView extends RecyclerView {
|
|||||||
|
|
||||||
private static final String[] FIELD_NAMES = {
|
private static final String[] FIELD_NAMES = {
|
||||||
"id",
|
"id",
|
||||||
|
"idHex",
|
||||||
"bounds",
|
"bounds",
|
||||||
"depth",
|
"depth",
|
||||||
"desc",
|
"desc",
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public abstract class AutoJs {
|
|||||||
private final AccessibilityActionRecorder mAccessibilityActionRecorder = new AccessibilityActionRecorder();
|
private final AccessibilityActionRecorder mAccessibilityActionRecorder = new AccessibilityActionRecorder();
|
||||||
private final AccessibilityNotificationObserver mNotificationObserver;
|
private final AccessibilityNotificationObserver mNotificationObserver;
|
||||||
private ScriptEngineManager mScriptEngineManager;
|
private ScriptEngineManager mScriptEngineManager;
|
||||||
private final LayoutInspector mLayoutInspector = new LayoutInspector();
|
private final LayoutInspector mLayoutInspector;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final Application mApplication;
|
private final Application mApplication;
|
||||||
private final UiHandler mUiHandler;
|
private final UiHandler mUiHandler;
|
||||||
@@ -66,6 +66,7 @@ public abstract class AutoJs {
|
|||||||
protected AutoJs(final Application application) {
|
protected AutoJs(final Application application) {
|
||||||
mContext = application.getApplicationContext();
|
mContext = application.getApplicationContext();
|
||||||
mApplication = application;
|
mApplication = application;
|
||||||
|
mLayoutInspector = new LayoutInspector(mContext);
|
||||||
mUiHandler = new UiHandler(mContext);
|
mUiHandler = new UiHandler(mContext);
|
||||||
mAppUtils = createAppUtils(mContext);
|
mAppUtils = createAppUtils(mContext);
|
||||||
mGlobalConsole = createGlobalConsole();
|
mGlobalConsole = createGlobalConsole();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.stardust.view.accessibility;
|
package com.stardust.view.accessibility;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.annotation.RequiresApi;
|
import android.support.annotation.RequiresApi;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -24,6 +25,11 @@ public class LayoutInspector {
|
|||||||
private volatile boolean mDumping = false;
|
private volatile boolean mDumping = false;
|
||||||
private Executor mExecutor = Executors.newSingleThreadExecutor();
|
private Executor mExecutor = Executors.newSingleThreadExecutor();
|
||||||
private CopyOnWriteArrayList<CaptureAvailableListener> mCaptureAvailableListeners = new CopyOnWriteArrayList<>();
|
private CopyOnWriteArrayList<CaptureAvailableListener> mCaptureAvailableListeners = new CopyOnWriteArrayList<>();
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
|
public LayoutInspector(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean captureCurrentWindow() {
|
public boolean captureCurrentWindow() {
|
||||||
AccessibilityService service = AccessibilityService.getInstance();
|
AccessibilityService service = AccessibilityService.getInstance();
|
||||||
@@ -40,7 +46,7 @@ public class LayoutInspector {
|
|||||||
}
|
}
|
||||||
mExecutor.execute(() -> {
|
mExecutor.execute(() -> {
|
||||||
mDumping = true;
|
mDumping = true;
|
||||||
mCapture = NodeInfo.capture(root);
|
mCapture = NodeInfo.capture(mContext, root);
|
||||||
mDumping = false;
|
mDumping = false;
|
||||||
for (CaptureAvailableListener l : mCaptureAvailableListeners) {
|
for (CaptureAvailableListener l : mCaptureAvailableListeners) {
|
||||||
l.onCaptureAvailable(mCapture);
|
l.onCaptureAvailable(mCapture);
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package com.stardust.view.accessibility;
|
package com.stardust.view.accessibility;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.support.annotation.Keep;
|
import android.support.annotation.Keep;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
@@ -10,6 +13,7 @@ import android.view.accessibility.AccessibilityNodeInfo;
|
|||||||
import com.stardust.automator.UiObject;
|
import com.stardust.automator.UiObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,6 +27,7 @@ public class NodeInfo {
|
|||||||
private Rect mBoundsInParent = new Rect();
|
private Rect mBoundsInParent = new Rect();
|
||||||
|
|
||||||
public String id;
|
public String id;
|
||||||
|
public String idHex;
|
||||||
public String desc;
|
public String desc;
|
||||||
public String className;
|
public String className;
|
||||||
public String packageName;
|
public String packageName;
|
||||||
@@ -54,8 +59,7 @@ public class NodeInfo {
|
|||||||
public NodeInfo parent;
|
public NodeInfo parent;
|
||||||
|
|
||||||
|
|
||||||
|
public NodeInfo(Resources resources, UiObject node, NodeInfo parent) {
|
||||||
public NodeInfo(UiObject node, NodeInfo parent) {
|
|
||||||
id = simplifyId(node.getViewIdResourceName());
|
id = simplifyId(node.getViewIdResourceName());
|
||||||
desc = node.desc();
|
desc = node.desc();
|
||||||
className = node.className();
|
className = node.className();
|
||||||
@@ -92,7 +96,9 @@ public class NodeInfo {
|
|||||||
indexInParent = node.indexInParent();
|
indexInParent = node.indexInParent();
|
||||||
|
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
if (resources != null && packageName != null && id != null) {
|
||||||
|
idHex = "0x" + Integer.toHexString(resources.getIdentifier(node.getViewIdResourceName(), null, null));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String simplifyId(String idResourceName) {
|
private String simplifyId(String idResourceName) {
|
||||||
@@ -116,21 +122,35 @@ public class NodeInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static NodeInfo capture(@NonNull UiObject uiObject, @Nullable NodeInfo parent) {
|
static NodeInfo capture(HashMap<String, Resources> resourcesCache, Context context, @NonNull UiObject uiObject, @Nullable NodeInfo parent) {
|
||||||
NodeInfo nodeInfo = new NodeInfo(uiObject, parent);
|
String pkg = uiObject.packageName();
|
||||||
|
Resources resources = null;
|
||||||
|
if (pkg != null) {
|
||||||
|
resources = resourcesCache.get(pkg);
|
||||||
|
if (resources == null) {
|
||||||
|
try {
|
||||||
|
resources = context.getPackageManager().getResourcesForApplication(pkg);
|
||||||
|
resourcesCache.put(pkg, resources);
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NodeInfo nodeInfo = new NodeInfo(resources, uiObject, parent);
|
||||||
int childCount = uiObject.getChildCount();
|
int childCount = uiObject.getChildCount();
|
||||||
for (int i = 0; i < childCount; i++) {
|
for (int i = 0; i < childCount; i++) {
|
||||||
UiObject child = uiObject.child(i);
|
UiObject child = uiObject.child(i);
|
||||||
if (child != null) {
|
if (child != null) {
|
||||||
nodeInfo.children.add(capture(child, nodeInfo));
|
nodeInfo.children.add(capture(resourcesCache, context, child, nodeInfo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nodeInfo;
|
return nodeInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NodeInfo capture(@NonNull AccessibilityNodeInfo root) {
|
public static NodeInfo capture(Context context, @NonNull AccessibilityNodeInfo root) {
|
||||||
UiObject r = UiObject.createRoot(root);
|
UiObject r = UiObject.createRoot(root);
|
||||||
return capture(r, null);
|
HashMap<String, Resources> resourcesCache = new HashMap<>();
|
||||||
|
return capture(resourcesCache, context, r, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.stardust.auojs.inrt.Pref;
|
|||||||
import com.stardust.auojs.inrt.R;
|
import com.stardust.auojs.inrt.R;
|
||||||
import com.stardust.auojs.inrt.SettingsActivity;
|
import com.stardust.auojs.inrt.SettingsActivity;
|
||||||
import com.stardust.autojs.runtime.ScriptRuntime;
|
import com.stardust.autojs.runtime.ScriptRuntime;
|
||||||
|
import com.stardust.autojs.runtime.api.AppUtils;
|
||||||
import com.stardust.autojs.runtime.exception.ScriptException;
|
import com.stardust.autojs.runtime.exception.ScriptException;
|
||||||
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
|
||||||
import com.stardust.view.accessibility.AccessibilityService;
|
import com.stardust.view.accessibility.AccessibilityService;
|
||||||
@@ -37,6 +38,11 @@ public class AutoJs extends com.stardust.autojs.AutoJs {
|
|||||||
getScriptEngineService().registerGlobalScriptExecutionListener(new ScriptExecutionGlobalListener());
|
getScriptEngineService().registerGlobalScriptExecutionListener(new ScriptExecutionGlobalListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AppUtils createAppUtils(Context context) {
|
||||||
|
return new AppUtils(context, context.getPackageName() + ".fileprovider");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ensureAccessibilityServiceEnabled() {
|
public void ensureAccessibilityServiceEnabled() {
|
||||||
|
|||||||
Reference in New Issue
Block a user