forked from snailuncle/autojsDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path显示指定控件信息2.js
336 lines (273 loc) · 9.21 KB
/
显示指定控件信息2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/**
*作者QQ: 1811588980
*完成时间: 2019年6月15日 下午9:30:33
*测试机型: vivo PD1813D
*Android版本: 8.1.0
*屏幕: 1080*2280
*API: 27
*备注: 在屏幕上显示悬浮窗中心十字所指示位置上最小的控件信息。
*长按中心十字关闭。
**/
auto();
//要显示的空间数据。
var show_ary = ["bounds","className", "clickable", "id", "desc", "scrollable", "text"];
var rainbowColor = [-65536, -23296, -256, -16711936, -16744449, -16776961, -7667457];
let 当前方向 = context.getResources().getConfiguration().orientation
let 当前数组 = new Array;
let 当前坐标 = {
x: 0,
y: 0
};
var win = floaty.rawWindow(
<frame >
<ImageView id="canvas" w="*"h="*"/>
</frame>
);
var ASK=new 绘布(win.canvas);
win.setTouchable(false);
win.setSize(-1, -1);
var win_ = floaty.rawWindow(
<frame w="{{Math.floor(device.width/2)}}px"h="{{Math.floor(device.width/2)}}px">
<button id="but" w="*" h="*" bg="#40400000" text="+" textColor="#ff0000"textSize="30" layout_gravity="center"gravity="center"/>
<button id="but_g" w="{{Math.floor(device.width/8)}}px"h="{{Math.floor(device.width/8)}}px" bg="#00000000" layout_gravity="center"gravity="center"/>
</frame>
);
win_.setPosition(device.width / 4, device.width / 4);
setInterval(() => {
ASK.isOK();
方向 = context.getResources().getConfiguration().orientation
//log(方向)
if (方向 == 1 && 方向 != 当前方向) {
当前方向 = 方向
win_.setPosition(device.width / 4, device.width / 4);
//sleep(1000)
} else if (方向 == 2 && 方向 != 当前方向) {
当前方向 = 方向
toastLog("横屏")
win_.setPosition(device.width / 4, device.width / 4);
}
}, 500);
//setTimeout(()=>{exit();},5000);
var paint1 = new Paint;
//paint1.setTextAlign(Paint.Align.CENTER);
paint1.setStrokeWidth(8);
//paint1.setStyle(Paint.Style.STROKE);
//paint1.setStyle(Paint.Style.FILL);
//paint1.setARGB(255, 0, 255, 0);
paint1.setTextSize(40);
var kg = false;
var isbig=true;
//win.canvas.setMaxFps(60);
ASK.setDraw(function(canvas) {
try {
//canvas.drawColor(android.graphics.Color.TRANSPARENT, android.graphics.PorterDuff.Mode.CLEAR);
var w = canvas.getWidth();
var h = canvas.getHeight();
//canvas.drawRoundRect(4, 4, w - 4, h - 4, 100, 100, paint1);
if (kg) {
canvas.drawARGB(127,0,0,0);
paint1.setStyle(Paint.Style.STROKE);
if(false){
for (let i = 0; i < 当前数组.length; i++) {
paint1.setColor(rainbowColor[i % rainbowColor.length]);
let uiObj = 当前数组[i];
if (uiObj) {
let rect = uiObj.bounds();
canvas.drawRect(rect, paint1);
if (i == 当前数组.length - 1) {
paint1.setStyle(Paint.Style.FILL);
paint1.setColor(反色(paint1.getColor()));
for (let i = 0; i < show_ary.length; i++) {
canvas.drawText(show_ary[i] + ": " + uiObj[show_ary[i]](), w / 10, h / 5 + paint1.getTextSize() * i, paint1);
};
};
};
};
}else{
paint1.setColor(rainbowColor[(当前数组.length-1) % rainbowColor.length]);
let uiObj = 当前数组[当前数组.length-1];
if (uiObj) {
let rect = uiObj.bounds();
canvas.drawRect(rect, paint1);
paint1.setStyle(Paint.Style.FILL);
paint1.setColor(colors.WHITE);
for (let i = 0; i < show_ary.length; i++) {
canvas.drawText(show_ary[i] + ": " + uiObj[show_ary[i]](), w / 10, h / 5 + paint1.getTextSize() * i, paint1);
};
};
};
};
} catch (e) {
toastLog(e);
};
});
win_.but_g.longClick(function(){
toastLog("已关闭");
exit();
});
var thread;
var isMove=false;
win_.but.setOnTouchListener(function(view, event) {
switch (event.getAction()) {
case event.ACTION_DOWN:
x = event.getRawX();
y = event.getRawY();
windowX = win_.getX();
windowY = win_.getY();
downTime = new Date().getTime();
kg=false;
isMove=false;
return true;
case event.ACTION_MOVE:
isMove=true;
//移动手指时调整悬浮窗位置
fcx = windowX + (event.getRawX() - x)
fcy = windowY + (event.getRawY() - y)
win_.setPosition(fcx, fcy);
if (isbig&&(!thread || !thread.isAlive())) {
thread = threads.start(function() {
当前数组 = getUiObj(fcx + win_.getWidth() / 2, fcy + win_.getWidth() / 2);
kg = true;
ASK.Refresh();
});
};
return true;
case event.ACTION_UP:
ASK.Refresh();
return true;
if(!isMove){
if(isbig){
win_.setSize(Math.floor(device.width/8),Math.floor(device.width/8));
isbig=false;
}else{
win_.setSize(Math.floor(device.width/2),Math.floor(device.width/2));
isbig=true;
};
};
return true;
}
return true;
})
function 反色(color) {
return (-1 - colors.argb(0, colors.red(color), colors.green(color), colors.blue(color)));
};
function RToxy(R) {
var x = Math.cos(R);
var y = Math.sin(R);
return [x, y];
};
function weiyi(ary) {
var sum = 0;
for (var i = 0; i < ary.length; i++) {
sum += Math.pow(ary[i], 2);
};
return Math.sqrt(sum);
};
function getsd(s, ary) {
var sum = weiyi(ary);
var S = s / sum;
for (var i = 0; i < ary.length; i++) {
ary[i] = ary[i] * S;
};
return ary;
};
function 窗口移动(x, y) {
//w.setPosition()
x1 = Math.floor(x + device.width / 4);
y1 = Math.floor(y + device.width / 4);
//var img = captureScreen();
if ((当前方向 == 1 && device.width > x1 && x1 > 0 && device.height > y1 && y1 > 0) || (当前方向 == 2 && device.width > y1 && y1 > 0 && device.height > x1 && x1 > 0)) {
if (kg) {
当前颜色 = images.pixel(当前截图, x1, y1);
当前反颜色 = 反色(当前颜色);
当前坐标.x = x1;
当前坐标.y = y1;
};
//显示该颜色值
};
};
function RgbToHsl(r, g, b) {
r /= 255, g /= 255, b /= 255;
var max = Math.max(r, g, b),
min = Math.min(r, g, b);
var h, s, l = (max + min) / 2;
if (max == min) {
h = s = 0;
} else {
var d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch (max) {
case r:
h = (g - b) / d + (g < b ? 6 : 0);
break;
case g:
h = (b - r) / d + 2;
break;
case b:
h = (r - g) / d + 4;
break;
}
h /= 6;
}
return [Math.floor(h * 100), Math.round(s * 100) + "%", Math.round(l * 100) + "%"];
}
function getUiObj(x, y) {
//let x=500,y=500;
let uiObj_ary = filter(function(uiObj) {
let rect = uiObj.bounds();
return rect.contains(x, y);
}).find().sort(function(A,B){
AR=A.bounds();
BR=B.bounds();
return BR.width()*BR.height()-AR.width()*AR.height();
});
/*
uiObj_ary.forEach(function(uiObj){
log(uiObj.bounds());
});
*/
return uiObj_ary;
};
function 绘布(view) {
if (view.accessibilityClassName != "android.widget.ImageView") {
//throw "我报错";
};
this.width = view.getWidth();
this.height = view.getHeight();
this.bitmap = android.graphics.Bitmap.createBitmap(this.width || 1000, this.height || 1000, android.graphics.Bitmap.Config.ARGB_8888);
this.canvas = new Canvas(this.bitmap);
this.matrix = new android.graphics.Matrix();
//threads.start(new java.lang.Runnable(() => {}));
this.isOK = () => {
this.width = view.getWidth();
this.height = view.getHeight();
this.bitmap = android.graphics.Bitmap.createBitmap(this.width || 1000, this.height || 1000, android.graphics.Bitmap.Config.ARGB_8888);
this.canvas = new Canvas(this.bitmap);
if (this.width <= 0 || this.height <= 0) {
return false;
};
return true;
};
this.Draw = function() {};
this.setDraw = function(fun) {
if (typeof fun == "function") {
this.Draw = fun;
};
};
this.Refresh = (fun) => {
try {
this.bitmap.eraseColor(0);
this.canvas.setMatrix(this.matrix);
if (typeof fun == "function") {
fun(this.canvas);
} else {
this.Draw(this.canvas);
};
ui.run(() => {
view.setImageBitmap(this.bitmap);
});
} catch (e) {
toastLog(e);
};
};
};