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