优化布局分析显示
This commit is contained in:
@@ -61,8 +61,7 @@ class LayoutInspector(private val mContext: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshChildList(root: AccessibilityNodeInfo?) {
|
private fun refreshChildList(root: AccessibilityNodeInfo?) {
|
||||||
if (root == null)
|
if (root == null) return
|
||||||
return
|
|
||||||
root.refresh()
|
root.refresh()
|
||||||
val childCount = root.childCount
|
val childCount = root.childCount
|
||||||
for (i in 0 until childCount) {
|
for (i in 0 until childCount) {
|
||||||
|
|||||||
@@ -1,31 +1,24 @@
|
|||||||
package org.autojs.autojs.core.ui;
|
package org.autojs.autojs.core.ui
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup
|
||||||
|
import org.autojs.autojs.core.ui.inflater.util.Ids
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.autojs.autojs.core.ui.inflater.util.Ids;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/5/14.
|
* Created by Stardust on 2017/5/14.
|
||||||
*/
|
*/
|
||||||
public class JsViewHelper {
|
object JsViewHelper {
|
||||||
|
@JvmStatic
|
||||||
@Nullable
|
fun findViewByStringId(view: View, id: String?): View? {
|
||||||
public static View findViewByStringId(View view, String id) {
|
var result = view.findViewById<View>(Ids.parse(id))
|
||||||
View result = view.findViewById(Ids.parse(id));
|
if (result != null) return result
|
||||||
if (result != null)
|
if (view !is ViewGroup) {
|
||||||
return result;
|
return null
|
||||||
if (!(view instanceof ViewGroup group)) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
for (int i = 0; i < group.getChildCount(); i++) {
|
for (i in 0 until view.childCount) {
|
||||||
result = findViewByStringId(group.getChildAt(i), id);
|
result = findViewByStringId(view.getChildAt(i), id)
|
||||||
if (result != null)
|
if (result != null) return result
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.autojs.autojs.ui.floating.layoutinspector
|
package org.autojs.autojs.ui.floating.layoutinspector
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Canvas
|
import android.graphics.Canvas
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
@@ -97,7 +98,7 @@ open class LayoutBoundsView : View {
|
|||||||
draw(canvas, child)
|
draw(canvas, child)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
override fun onTouchEvent(event: MotionEvent): Boolean {
|
override fun onTouchEvent(event: MotionEvent): Boolean {
|
||||||
if (mRootNode != null) {
|
if (mRootNode != null) {
|
||||||
setSelectedNode(findNodeAt(mRootNode!!, event.rawX.toInt(), event.rawY.toInt()))
|
setSelectedNode(findNodeAt(mRootNode!!, event.rawX.toInt(), event.rawY.toInt()))
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.autojs.autojs.ui.floating.layoutinspector;
|
package org.autojs.autojs.ui.floating.layoutinspector;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@@ -18,12 +19,7 @@ import org.autojs.autojs.ui.widget.LevelBeamView;
|
|||||||
import org.autojs.autojs.util.ViewUtils;
|
import org.autojs.autojs.util.ViewUtils;
|
||||||
import org.autojs.autojs6.R;
|
import org.autojs.autojs6.R;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.Stack;
|
|
||||||
|
|
||||||
import pl.openrnd.multilevellistview.ItemInfo;
|
import pl.openrnd.multilevellistview.ItemInfo;
|
||||||
import pl.openrnd.multilevellistview.MultiLevelListAdapter;
|
import pl.openrnd.multilevellistview.MultiLevelListAdapter;
|
||||||
@@ -186,7 +182,7 @@ public class LayoutHierarchyView extends MultiLevelListView {
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ViewHolder {
|
private static class ViewHolder {
|
||||||
TextView nameView;
|
TextView nameView;
|
||||||
TextView infoView;
|
TextView infoView;
|
||||||
ImageView arrowView;
|
ImageView arrowView;
|
||||||
@@ -220,6 +216,7 @@ public class LayoutHierarchyView extends MultiLevelListView {
|
|||||||
return mInitiallyExpandedNodes.contains((NodeInfo) object);
|
return mInitiallyExpandedNodes.contains((NodeInfo) object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("InflateParams")
|
||||||
@Override
|
@Override
|
||||||
public View getViewForObject(Object object, View convertView, ItemInfo itemInfo) {
|
public View getViewForObject(Object object, View convertView, ItemInfo itemInfo) {
|
||||||
NodeInfo nodeInfo = (NodeInfo) object;
|
NodeInfo nodeInfo = (NodeInfo) object;
|
||||||
@@ -231,8 +228,8 @@ public class LayoutHierarchyView extends MultiLevelListView {
|
|||||||
} else {
|
} else {
|
||||||
viewHolder = (ViewHolder) convertView.getTag();
|
viewHolder = (ViewHolder) convertView.getTag();
|
||||||
}
|
}
|
||||||
|
//对于id,desc,text,clickable,longClickable不为空的显示信息
|
||||||
viewHolder.nameView.setText(simplifyClassName(nodeInfo.getClassName()));
|
viewHolder.nameView.setText(extraInfo(nodeInfo));
|
||||||
viewHolder.nodeInfo = nodeInfo;
|
viewHolder.nodeInfo = nodeInfo;
|
||||||
if (viewHolder.infoView.getVisibility() == VISIBLE)
|
if (viewHolder.infoView.getVisibility() == VISIBLE)
|
||||||
viewHolder.infoView.setText(getItemInfoDsc(itemInfo));
|
viewHolder.infoView.setText(getItemInfoDsc(itemInfo));
|
||||||
@@ -266,6 +263,25 @@ public class LayoutHierarchyView extends MultiLevelListView {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String extraInfo(NodeInfo nodeInfo) {
|
||||||
|
String extra = simplifyClassName(nodeInfo.getClassName());
|
||||||
|
ArrayList<String> info = new ArrayList<>();
|
||||||
|
if (nodeInfo.getSimpleId() != null) {
|
||||||
|
info.add("id=" + nodeInfo.getSimpleId());
|
||||||
|
}
|
||||||
|
if (!nodeInfo.getText().equals("")) {
|
||||||
|
info.add("text=" + nodeInfo.getText());
|
||||||
|
}
|
||||||
|
if (nodeInfo.getDesc() != null) {
|
||||||
|
info.add("desc=" + nodeInfo.getDesc());
|
||||||
|
}
|
||||||
|
//字符串拼接
|
||||||
|
String others = String.join(", ", info);
|
||||||
|
if (!others.isEmpty()) {
|
||||||
|
return extra + " [" + others + "]";
|
||||||
|
}
|
||||||
|
return extra;
|
||||||
|
}
|
||||||
|
|
||||||
private String getItemInfoDsc(ItemInfo itemInfo) {
|
private String getItemInfoDsc(ItemInfo itemInfo) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.autojs.autojs.ui.floating.layoutinspector
|
package org.autojs.autojs.ui.floating.layoutinspector
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@@ -41,6 +42,7 @@ class NodeInfoView : RecyclerView {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
fun setNodeInfo(nodeInfo: NodeInfo) {
|
fun setNodeInfo(nodeInfo: NodeInfo) {
|
||||||
for (i in FIELDS.indices) {
|
for (i in FIELDS.indices) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package org.autojs.autojs.ui.floating.layoutinspector;
|
package org.autojs.autojs.ui.floating.layoutinspector
|
||||||
|
|
||||||
import org.autojs.autojs.core.accessibility.NodeInfo;
|
import org.autojs.autojs.core.accessibility.NodeInfo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Stardust on 2017/3/10.
|
* Created by Stardust on 2017/3/10.
|
||||||
*/
|
*/
|
||||||
public interface OnNodeInfoSelectListener {
|
fun interface OnNodeInfoSelectListener {
|
||||||
|
fun onNodeSelect(info: NodeInfo)
|
||||||
void onNodeSelect(NodeInfo info);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user