Skip to content

Commit c1bee68

Browse files
committed
add function to show all widgets for active window
1 parent 0189b34 commit c1bee68

File tree

2 files changed

+58
-13
lines changed

2 files changed

+58
-13
lines changed

app/src/main/java/com/zfdang/touchhelper/TouchHelperServiceImpl.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import android.accessibilityservice.AccessibilityService;
44
import android.accessibilityservice.GestureDescription;
55
import android.annotation.SuppressLint;
6+
import android.content.ClipData;
7+
import android.content.ClipboardManager;
68
import android.content.Context;
79
import android.content.Intent;
810
import android.content.IntentFilter;
@@ -546,6 +548,24 @@ private void findAllNode(List<AccessibilityNodeInfo> roots, List<AccessibilityNo
546548
}
547549
}
548550

551+
private String dumpRootNode(AccessibilityNodeInfo root) {
552+
ArrayList<AccessibilityNodeInfo> nodeList = new ArrayList<>();
553+
StringBuilder dumpString = new StringBuilder();
554+
dumpChildNodes(root, nodeList, dumpString, "");
555+
return dumpString.toString();
556+
}
557+
558+
private void dumpChildNodes(AccessibilityNodeInfo root, List<AccessibilityNodeInfo> list, StringBuilder dumpString, String indent) {
559+
if(root == null) return;
560+
list.add(root);
561+
dumpString.append(indent + Utilities.describeAccessibilityNode(root) + "\n");
562+
563+
for (int n = 0; n < root.getChildCount(); n++) {
564+
AccessibilityNodeInfo child = root.getChild(n);
565+
dumpChildNodes(child, list, dumpString,indent + " ");
566+
}
567+
}
568+
549569
/**
550570
* 模拟点击
551571
*/
@@ -673,6 +693,7 @@ private void showActivityCustomizationDialog() {
673693
final Button btAddWidget = viewCustomization.findViewById(R.id.button_add_widget);
674694
Button btShowTarget = viewCustomization.findViewById(R.id.button_show_target);
675695
final Button btAddPosition = viewCustomization.findViewById(R.id.button_add_position);
696+
Button btDumpScreen = viewCustomization.findViewById(R.id.button_dump_screen);
676697
Button btQuit = viewCustomization.findViewById(R.id.button_quit);
677698

678699
final View viewTarget = inflater.inflate(R.layout.layout_accessibility_node_desc, null);
@@ -900,6 +921,20 @@ public void onClick(View v) {
900921
Settings.getInstance().setPackagePositions(mapPackagePositions);
901922
}
902923
});
924+
btDumpScreen.setOnClickListener(new View.OnClickListener() {
925+
@Override
926+
public void onClick(View v) {
927+
AccessibilityNodeInfo root = service.getRootInActiveWindow();
928+
if (root == null) return;
929+
String result = dumpRootNode(root);
930+
931+
ClipboardManager clipboard = (ClipboardManager) service.getSystemService(Context.CLIPBOARD_SERVICE);
932+
ClipData clip = ClipData.newPlainText("ACTIVITY", result);
933+
clipboard.setPrimaryClip(clip);
934+
935+
ShowToastInIntentService("窗口控件已复制到剪贴板!");
936+
}
937+
});
903938
btQuit.setOnClickListener(new View.OnClickListener() {
904939
@Override
905940
public void onClick(View v) {

app/src/main/res/layout/layout_activity_customization.xml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
android:background="#FFFFC107"
66
android:gravity="center"
77
android:orientation="vertical"
8-
android:paddingStart="10dp"
8+
android:paddingStart="6dp"
99
android:paddingTop="2dp"
10-
android:paddingEnd="10dp"
10+
android:paddingEnd="6dp"
1111
android:paddingBottom="2dp">
1212

1313
<TableLayout
@@ -97,59 +97,69 @@
9797
android:id="@+id/button_show_outline"
9898
android:layout_width="wrap_content"
9999
android:layout_height="wrap_content"
100-
android:layout_margin="2dp"
100+
android:layout_margin="1dp"
101101
android:layout_weight="1"
102102
android:padding="0dp"
103103
android:text="显示布局"
104104
android:textColor="@color/textColor"
105-
android:textSize="12sp" />
105+
android:textSize="10sp" />
106106

107107
<Button
108108
android:id="@+id/button_add_widget"
109109
android:layout_width="wrap_content"
110110
android:layout_height="wrap_content"
111-
android:layout_margin="2dp"
111+
android:layout_margin="1dp"
112112
android:layout_weight="1"
113113
android:enabled="false"
114114
android:padding="0dp"
115115
android:text="添加控件"
116116
android:textColor="@color/textColor"
117-
android:textSize="12sp" />
117+
android:textSize="10sp" />
118118

119119
<Button
120120
android:id="@+id/button_show_target"
121121
android:layout_width="wrap_content"
122122
android:layout_height="wrap_content"
123-
android:layout_margin="2dp"
123+
android:layout_margin="1dp"
124124
android:layout_weight="1"
125125
android:padding="0dp"
126126
android:text="显示准心"
127127
android:textColor="@color/textColor"
128-
android:textSize="12sp" />
128+
android:textSize="10sp" />
129129

130130
<Button
131131
android:id="@+id/button_add_position"
132132
android:layout_width="wrap_content"
133133
android:layout_height="wrap_content"
134-
android:layout_margin="2dp"
134+
android:layout_margin="1dp"
135135
android:layout_weight="1"
136136
android:enabled="false"
137137
android:padding="0dp"
138138
android:text="添加坐标"
139139
android:textColor="@color/textColor"
140-
android:textSize="12sp" />
140+
android:textSize="10sp" />
141+
142+
<Button
143+
android:id="@+id/button_dump_screen"
144+
android:layout_width="wrap_content"
145+
android:layout_height="wrap_content"
146+
android:layout_margin="1dp"
147+
android:layout_weight="1"
148+
android:padding="0dp"
149+
android:text="检查窗口"
150+
android:textColor="@color/textColor"
151+
android:textSize="10sp" />
141152

142153
<Button
143154
android:id="@+id/button_quit"
144155
android:layout_width="wrap_content"
145156
android:layout_height="wrap_content"
146-
android:layout_margin="2dp"
157+
android:layout_margin="1dp"
147158
android:layout_weight="1"
148159
android:padding="0dp"
149160
android:text="退出"
150161
android:textColor="@color/textColor"
151-
android:textSize="12sp" />
152-
162+
android:textSize="10sp" />
153163

154164
</LinearLayout>
155165
</LinearLayout>

0 commit comments

Comments
 (0)