forked from APIJSON/APIJSON-Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIAutoActivity.java
More file actions
819 lines (768 loc) · 33.6 KB
/
UIAutoActivity.java
File metadata and controls
819 lines (768 loc) · 33.6 KB
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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/
package apijson.demo.ui;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import com.alibaba.fastjson.JSONArray;
import apijson.demo.R;
import apijson.demo.application.DemoApplication;
/**自动 UI 测试,需要用 UIAuto 发请求到这个设备
* https://github.com/TommyLemon/UIAuto
* @author Lemon
*/
public class UIAutoActivity extends Activity {
private static final String TAG = "UIAutoActivity";
private static final String SPLIT_Y = "SPLIT_Y";
private static final String SPLIT_HEIGHT = "SPLIT_HEIGHT";
private static final String SPLIT_COLOR = "SPLIT_COLOR";
private static final String INTENT_FLOW_ID = "INTENT_FLOW_ID";
private static final String INTENT_TOUCH_LIST = "INTENT_TOUCH_LIST";
/**
* @param context
* @return
*/
public static Intent createIntent(Context context) {
return new Intent(context, UIAutoActivity.class); //.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
/**
* @param context
* @return
*/
public static Intent createIntent(Context context, String list) {
return new Intent(context, UIAutoActivity.class).putExtra(INTENT_TOUCH_LIST, list);
}
// private boolean isRecovering = false;
// private Handler handler = new Handler() {
// @Override
// public void handleMessage(Message msg) {
// super.handleMessage(msg);
//
// if (isRecovering) {
// //通过遍历数组来实现
//// if (lastCurTime >= System.currentTimeMillis()) {
//// isRecovering = false;
//// pbUIAutoSplit.setVisibility(View.GONE);
//// }
////
//// MotionEvent event = (MotionEvent) msg.obj;
//// dispatchEventToCurrentActivity(event);
//
//
// //根据递归链表来实现,能精准地实现两个事件之间的间隔,不受处理时间不一致,甚至卡顿等影响。还能及时终止
// Node<InputEvent> eventNode = ( Node<InputEvent>) msg.obj;
// dispatchEventToCurrentActivity(eventNode.item);
//
// if (eventNode.next == null) {
// isRecovering = false;
// pbUIAutoSplit.setVisibility(View.GONE);
// return;
// }
//
// msg = Message.obtain();
// msg.obj = eventNode.next;
// sendMessageDelayed(msg, eventNode.next.item.getEventTime() - eventNode.item.getEventTime());
// }
// }
// };
private Activity context;
// int screenWidth;
// int screenHeight;
//
// int windowWidth;
// int windowHeight;
// int windowY;
//
// ViewGroup cover;
// ViewGroup split;
// View rlUIAutoSplitY;
// View vUIAutoSplit;
// View ivUIAutoSplit;
// View pbUIAutoSplit;
//
// private float splitY;
// private float splitHeight;
// private boolean moved = false;
private JSONArray touchList;
private long flowId = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//反而让 cover 与底部差一个导航栏高度 requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.ui_auto_activity);
Window window = getWindow();
//反而让 cover 与底部差一个导航栏高度 window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
context = this;
flowId = getIntent().getLongExtra(INTENT_FLOW_ID, flowId);
//太卡 touchList = JSON.parseArray(getIntent().getStringExtra(INTENT_TOUCH_LIST));
//
// DisplayMetrics outMetrics = new DisplayMetrics();
// Display display = getWindowManager().getDefaultDisplay();
//
// windowWidth = display.getWidth();
// windowHeight = display.getHeight();
// windowY = getWindowY(this);
//
// display.getRealMetrics(outMetrics);
// screenWidth = outMetrics.widthPixels;
// screenHeight = outMetrics.heightPixels;
//
// cache = getSharedPreferences(TAG, Context.MODE_PRIVATE);
//
// splitY = cache.getFloat(SPLIT_Y, 0);
// splitHeight = cache.getFloat(SPLIT_HEIGHT, dip2px(24));
//
// if (splitY <= splitHeight || splitY >= windowHeight - splitHeight) {
// splitY = windowHeight - splitHeight - dip2px(30);
// }
if (touchList != null && touchList.isEmpty() == false) { //TODO 回放操作
// recover(touchList);
startActivity(UIAutoListActivity.createIntent(DemoApplication.getInstance(), touchList == null ? null : touchList.toJSONString()));
// return;
}
// ViewGroup root = (ViewGroup) getWindow().getDecorView();
// cover = (ViewGroup) getLayoutInflater().inflate(R.layout.ui_auto_cover_layout, null);
// split = (ViewGroup) getLayoutInflater().inflate(R.layout.ui_auto_split_y_layout, null);
//
// rlUIAutoSplitY = split.findViewById(R.id.rlUIAutoSplitY);
// vUIAutoSplit = split.findViewById(R.id.vUIAutoSplit);
// ivUIAutoSplit = split.findViewById(R.id.ivUIAutoSplit);
// pbUIAutoSplit = split.findViewById(R.id.pbUIAutoSplit);
// pbUIAutoSplit.setVisibility(View.GONE);
//
// ViewGroup.LayoutParams splitLp = rlUIAutoSplitY.getLayoutParams();
// if (splitLp == null) {
// splitLp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) splitHeight);
// } else {
// splitLp.height = (int) splitHeight;
// }
// rlUIAutoSplitY.setLayoutParams(splitLp);
//
//// cover.addView(split);
//
//// rlUIAutoSplitY.post(new Runnable() {
//// @Override
//// public void run() {
//// rlUIAutoSplitY.setY(splitY - rlUIAutoSplitY.getHeight()/2);
//// cover.setVisibility(View.GONE);
//// }
//// });
//
// vUIAutoSplit.setBackgroundColor(Color.parseColor(cache.getString(SPLIT_COLOR, "#10000000")));
//
// ViewGroup.LayoutParams lineLp = ivUIAutoSplit.getLayoutParams();
// if (lineLp == null) {
// lineLp = new RelativeLayout.LayoutParams((int) splitHeight, (int) splitHeight);
// } else {
// lineLp.width = lineLp.height = (int) splitHeight;
// }
// ivUIAutoSplit.setLayoutParams(lineLp);
//
// ivUIAutoSplit.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// isRecovering = false;
//// ((ViewGroup) v.getParent()).removeView(v);
//
// String cacheKey = UIAutoListActivity.CACHE_TOUCH;
// SharedPreferences cache = getSharedPreferences(UIAutoActivity.TAG, Context.MODE_PRIVATE);
// JSONArray allList = JSON.parseArray(cache.getString(cacheKey, null));
//
// if (allList == null || allList.isEmpty()) {
// allList = touchList;
// }
// else {
// allList.addAll(touchList);
// }
// cache.edit().remove(cacheKey).putString(cacheKey, JSON.toJSONString(allList)).commit();
//
//// startActivity(UIAutoListActivity.createIntent(DemoApplication.getInstance(), flowId)); // touchList == null ? null : touchList.toJSONString()));
//// startActivityForResult(UIAutoListActivity.createIntent(DemoApplication.getInstance(), touchList == null ? null : touchList.toJSONString()), REQUEST_UI_AUTO_LIST);
// startActivity(UIAutoActivity.createIntent(DemoApplication.getInstance(), touchList == null ? null : touchList.toJSONString()));
//
// floatCover = null;
// floatSplitY = null;
// FloatWindow.destroy("v");
// FloatWindow.destroy("v_ball");
// }
// });
// rlUIAutoSplitY.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View v, MotionEvent event) {
//// 都不动了 if (event.getY() - event.getRawY() >= 10) {
// if (event.getAction() == MotionEvent.ACTION_MOVE || event.getAction() == MotionEvent.ACTION_HOVER_MOVE) {
// moved = true;
// split.setY(event.getY());
//// split.invalidate();
// } else {
// if (event.getAction() == MotionEvent.ACTION_DOWN) {
// moved = false;
// }
// else if (event.getAction() == MotionEvent.ACTION_UP) {
// if (! moved) {
// ivUIAutoSplit.performClick();
// }
// }
// }
//// }
// return true;
// }
// });
// ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
// root.addView(cover, lp);
final ScrollView svTouch = findViewById(R.id.svTouch);
final TextView tvTouch = findViewById(R.id.tvTouch);
final View tvButton = findViewById(R.id.tvButton);
final View btnButton = findViewById(R.id.btnButton);
final View vTouch = findViewById(R.id.vTouch);
final View llTouch = findViewById(R.id.llTouch);
final View rlRoot = findViewById(R.id.rlRoot);
final View vDispatchTouch = findViewById(R.id.vDispatchTouch);
// View.OnTouchListener listener = new View.OnTouchListener() {
// @RequiresApi(api = 29)
// @Override
// public boolean onTouch(View v, MotionEvent event) {
// Log.d(TAG, "onTouchEvent " + Calendar.getInstance().getTime().toLocaleString() + " action:" + (event.getAction()) + "; x:" + event.getX() + "; y:" + event.getY());
//
// dispatchEventToCurrentActivity(event);
//
// if (isFinishing() || isDestroyed()) {
//// ActivityManager activityManager=(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
//// Activity runningActivity = activityManager.getRunningTasks(1).get(0);
//// getWindow().getDecorView().dispatchTouchEvent(event);
//
// return true;
// }
//
// vDispatchTouch.dispatchTouchEvent(event);
//
//// vTouch.setOnTouchListener(new View.OnTouchListener() {
//// @Override
//// public boolean onTouch(View v, MotionEvent event) {
//// return false;
//// }
//// });
////
// CharSequence s = tvTouch.getText();
// if (s == null) {
// s = "";
// }
//
// float splitY = floatSplitY.getY() + rlUIAutoSplitY.getHeight()/2;
// float relativeY = event.getY() <= splitY ? event.getY() : (event.getY() - screenHeight);
//
// tvTouch.setText(Calendar.getInstance().getTime().toLocaleString() + " " + InputUtil.getActionName(event.getAction()) + "\nx:" + event.getX() + "; y:" + event.getY() + "; relativeY: " + relativeY + "; pointerCount: " + event.getPointerCount() + "\n" + s);
//// Toast.makeText(context, "vTouch.action:" + (event.getAction()) + "; x:" + event.getX() + "; y:" + event.getY(), Toast.LENGTH_SHORT).show();
//
////死循环 llTouch.dispatchTouchEvent(event);
//// vDispatchTouch.dispatchTouchEvent(event);
//// vDispatchTouch.dispatchTouchEvent(event);
// //onTouchEvent 不能处理事件 vDispatchTouch.onTouchEvent(event);
//// vTouch.setOnTouchListener(this);
// return true; //连续记录只能 return true
// }
// };
// vTouch.setOnTouchListener(listener);
tvButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "tvButton.onClick", Toast.LENGTH_SHORT).show();
}
});
tvButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(context, "tvButton.action:" + (event.getAction()) + "; x:" + event.getX() + "; y:" + event.getY(), Toast.LENGTH_SHORT).show();
return false; //连续记录只能 return true
}
});
btnButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Toast.makeText(context, "btnMain.onLongClick", Toast.LENGTH_SHORT).show();
return true;
}
});
// new Handler().postDelayed(new Runnable() {
// @Override
// public void run() {
//
// MotionEvent e = MotionEvent.obtain(1000, 1000,
// MotionEvent.ACTION_DOWN, screenWidth/2, screenHeight/2, 0);
//
// //TODO onTouchEvent ?
// vTouch.dispatchTouchEvent(e);
// e.setAction(MotionEvent.ACTION_UP);
// vTouch.dispatchTouchEvent(e);
//
// }
// }, 1000);
// cover.setOnTouchListener(listener);
}
public void onClick(View v) {
Toast.makeText(context, "onClick BUTTON", Toast.LENGTH_SHORT).show();
record(v);
// finish();
}
public void toRemote(View v) {
startActivity(UIAutoListActivity.createIntent(context, false));
}
public void toLocal(View v) {
startActivity(UIAutoListActivity.createIntent(context, true));
}
public void record(View v) {
flowId = - System.currentTimeMillis();
// cover.setVisibility(View.VISIBLE);
// showCover(true, context);
// finish();
DemoApplication.getInstance().onUIAutoActivityCreate(this);
DemoApplication.getInstance().prepareRecord(this);
finish();
}
// private IFloatWindow floatCover;
// private IFloatWindow floatSplitY;
//
// private void showCover(boolean show, Activity activity) {
// //TODO 为纵屏、横屏分别加两套,判断屏幕方向来显示对应的一套
//// rlUIAutoSplitY.setVisibility(show ? View.VISIBLE : View.GONE);
//// rlUIAutoSplitY.setY(splitY + splitHeight/2);
//
// floatCover = FloatWindow.get("v");
// if (floatCover == null) {
// FloatWindow
// .with(getApplicationContext())
// .setTag("v")
// .setView(cover)
// .setWidth(windowWidth) //设置控件宽高
// .setHeight(windowHeight)
// .setX(0) //设置控件初始位置
// .setY(windowY)
// .setMoveType(MoveType.inactive)
// .setDesktopShow(true) //必须为 true,否则切换 Activity 就会自动隐藏 //桌面显示
//// .setViewStateListener(mViewStateListener) //监听悬浮控件状态改变
//// .setPermissionListener(mPermissionListener) //监听权限申请结果
// .build();
//
// floatCover = FloatWindow.get("v");
// }
// floatCover.show();
//
//
// floatSplitY = FloatWindow.get("v_ball");
// if (floatSplitY == null) {
// FloatWindow
// .with(getApplicationContext())
// .setTag("v_ball")
// .setView(split)
// .setWidth(windowWidth) //设置控件宽高
// .setHeight((int) splitHeight)
// .setX(0) //设置控件初始位置
// .setY((int) (windowY + splitY - splitHeight/2))
//// .setY(screenHeight/2)
// .setMoveType(MoveType.slide)
// .setDesktopShow(true) //必须为 true,否则切换 Activity 就会自动隐藏 //桌面显示
//// .setViewStateListener(mViewStateListener) //监听悬浮控件状态改变
//// .setPermissionListener(mPermissionListener) //监听权限申请结果
// .build();
//
// floatSplitY = FloatWindow.get("v_ball");
// }
// floatSplitY.show();
//
// //TODO 新建一个 have already added to window manager
//
//// if (FloatWindow.get("h")== null) {
//// FloatWindow
//// .with(getApplicationContext())
//// .setTag("h")
//// .setView(cover)
//// .setWidth(screenWidth) //设置控件宽高
//// .setHeight(screenHeight)
//// .setX(0) //设置控件初始位置
//// .setY(0)
//// .setMoveType(MoveType.inactive)
//// .setDesktopShow(true) //桌面显示
////// .setViewStateListener(mViewStateListener) //监听悬浮控件状态改变
////// .setPermissionListener(mPermissionListener) //监听权限申请结果
//// .build();
//// }
////
//// if (FloatWindow.get("h_ball") == null) {
//// FloatWindow
//// .with(getApplicationContext())
//// .setTag("h_ball")
//// .setView(split)
//// .setWidth(screenWidth) //设置控件宽高
//// .setHeight((int) splitHeight)
//// .setX(0) //设置控件初始位置
//// .setY((int) (splitY + splitHeight/2))
////// .setY(screenHeight/2)
//// .setMoveType(MoveType.slide)
//// .setDesktopShow(true) //桌面显示
////// .setViewStateListener(mViewStateListener) //监听悬浮控件状态改变
////// .setPermissionListener(mPermissionListener) //监听权限申请结果
//// .build();
//// }
//
//// FloatWindow.get("v").hide();
////// FloatWindow.get("v_ball").hide();
////// FloatWindow.get("h").hide();
////// FloatWindow.get("h_ball").hide();
//// if (show) {
//// if (activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
//// FloatWindow.get("v").show();
//// FloatWindow.get("v_ball").show();
//// } else {
////// FloatWindow.get("h").show();
////// FloatWindow.get("h_ball").show();
//// }
//// }
// }
//
//
// public int getWindowY(Activity a) {
// View decorView = a.getWindow().getDecorView();
//
// Rect rectangle= new Rect();
// decorView.getWindowVisibleDisplayFrame(rectangle);
// return rectangle.top;
// }
//
// public boolean dispatchEventToCurrentActivity(InputEvent ie) {
// Activity activity = DemoApplication.getInstance().getCurrentActivity();
// if (activity != null) {
//// event.offsetLocation(0, a.getWindow().getDecorView().findViewById(android.R.id.content).getTop());
////
//// float y = decorView.getY();
//// float top = decorView.getTop();
//// event.offsetLocation(0, decorView.getTop());
//// View content = decorView.findViewById(android.R.id.content);
//// float cy = content.getY();
//// float ctop = content.getTop();
//
// if (ie instanceof MotionEvent) {
// MotionEvent event = (MotionEvent) ie;
// int windowY = getWindowY(activity);
//
// if (windowY > 0) {
// event = MotionEvent.obtain(event);
// event.offsetLocation(0, windowY);
// }
// activity.dispatchTouchEvent(event);
// }
// else if (ie instanceof KeyEvent) {
// KeyEvent event = (KeyEvent) ie;
// activity.dispatchKeyEvent(event);
// }
//
// }
//
//
//// float splitY = rlUIAutoSplitY.getY() + rlUIAutoSplitY.getHeight()/2;
//// float splitY = floatSplitY.getY() + rlUIAutoSplitY.getHeight()/2;
//// float relativeY = event.getY() <= splitY ? event.getY() : (event.getY() - screenHeight);
////
//// JSONObject obj = new JSONObject(true);
//// obj.put("id", - System.currentTimeMillis());
//// obj.put("flowId", flowId);
//// obj.put("action", event.getAction());
//// obj.put("x", (int) event.getX());
//// obj.put("y", (int) relativeY);
//// obj.put("splitY", (int) splitY);
//// obj.put("rawX", (int) event.getRawX());
//// obj.put("rawY", (int) event.getRawY());
//// obj.put("time", System.currentTimeMillis());
//// obj.put("downTime", event.getDownTime());
//// obj.put("eventTime", event.getEventTime());
//// obj.put("metaState", event.getMetaState());
//// obj.put("size", event.getSize());
//// obj.put("source", event.getSource());
//// obj.put("pressure", event.getPressure());
//// obj.put("deviceId", event.getDeviceId());
//// obj.put("xPrecision", event.getXPrecision());
//// obj.put("yPrecision", event.getYPrecision());
//// obj.put("pointerCount", event.getPointerCount());
//// obj.put("edgeFlags", event.getEdgeFlags());
//
// addInputEvent(ie, activity);
//
// return activity != null;
// }
//
//
//
// /**
// * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
// */
// public int dip2px(float dpValue) {
// final float scale = getResources().getDisplayMetrics().density;
// return (int) (dpValue * scale + 0.5f);
// }
//
// /**
// * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
// */
// public int px2dip(float pxValue) {
// final float scale = getResources().getDisplayMetrics().density;
// return (int) (pxValue / scale + 0.5f);
// }
//
// @Override
// protected void onDestroy() {
// cache.edit().remove(SPLIT_Y).putFloat(SPLIT_Y, rlUIAutoSplitY.getY() + rlUIAutoSplitY.getHeight()/2).apply();
// super.onDestroy();
// }
//
//// @Override
//// public boolean dispatchTouchEvent(MotionEvent ev) {
//// super.dispatchTouchEvent(ev);
//// return false;
//// }
////
//// @Override
//// public boolean onTouchEvent(MotionEvent event) {
//// super.onTouchEvent(event);
//// return false;
//// }
//
//
// private Node<InputEvent> firstEventNode;
// private Node<InputEvent> eventNode;
//
// private long firstTime = 0;
// private long lastTime = 0;
// private long firstCurTime = 0;
// private long lastCurTime = 0;
// public void recover(JSONArray touchList) {
// isRecovering = true;
//
//// List<InputEvent> list = new LinkedList<>();
//
// showCover(true, DemoApplication.getInstance().getCurrentActivity());
//
// JSONObject first = touchList == null || touchList.isEmpty() ? null : touchList.getJSONObject(0);
// firstTime = first == null ? 0 : first.getLongValue("time");
//
// firstCurTime = 0;
// if (firstTime > 0) {
// firstCurTime = System.currentTimeMillis();
// pbUIAutoSplit.setVisibility(View.VISIBLE);
//
// for (int i = 0; i < touchList.size(); i++) {
// JSONObject obj = touchList.getJSONObject(i);
//
// InputEvent event;
// if (obj.getIntValue("type") == 1) {
// /**
// public KeyEvent(long downTime, long eventTime, int action,
// int code, int repeat, int metaState,
// int deviceId, int scancode, int flags, int source) {
// mDownTime = downTime;
// mEventTime = eventTime;
// mAction = action;
// mKeyCode = code;
// mRepeatCount = repeat;
// mMetaState = metaState;
// mDeviceId = deviceId;
// mScanCode = scancode;
// mFlags = flags;
// mSource = source;
// mDisplayId = INVALID_DISPLAY;
// }
// */
// event = new KeyEvent(
// obj.getLongValue("downTime"),
// obj.getLongValue("eventTime"),
// obj.getIntValue("action"),
// obj.getIntValue("keyCode"),
// obj.getIntValue("repeatCount"),
// obj.getIntValue("metaState"),
// obj.getIntValue("deviceId"),
// obj.getIntValue("scanCode"),
// obj.getIntValue("flags"),
// obj.getIntValue("source")
// );
// }
// else {
// /**
// public static MotionEvent obtain(long downTime, long eventTime, int action,
// float x, float y, float pressure, float size, int metaState,
// float xPrecision, float yPrecision, int deviceId, int edgeFlags, int source,
// int displayId)
// */
//
// //居然编译报错,和
// // static public MotionEvent obtain(long downTime, long eventTime,
// // int action, int pointerCount, PointerProperties[] pointerProperties,
// // PointerCoords[] pointerCoords, int metaState, int buttonState,
// // float xPrecision, float yPrecision, int deviceId,
// // int edgeFlags, int source, int displayId, int flags)
// //冲突,实际上类型没传错
//
// // event = MotionEvent.obtain(obj.getLongValue("downTime"), obj.getLongValue("eventTime"), obj.getIntValue("action"),
// // obj.getFloatValue("x"), obj.getFloatValue("y"), obj.getFloatValue("pressure"), obj.getFloatValue("size"), obj.getIntValue("metaState"),
// // obj.getFloatValue("xPrecision"), obj.getFloatValue("yPrecision"), obj.getIntValue("deviceId"), obj.getIntValue("edgeFlags"), obj.getIntValue("source"),
// // obj.getIntValue("displayId"));
//
// event = MotionEvent.obtain(
// obj.getLongValue("downTime"),
// obj.getLongValue("eventTime"),
// obj.getIntValue("action"),
//// obj.getIntValue("pointerCount"),
// obj.getFloatValue("x"),
// obj.getFloatValue("y"),
// obj.getFloatValue("pressure"),
// obj.getFloatValue("size"),
// obj.getIntValue("metaState"),
// obj.getFloatValue("xPrecision"),
// obj.getFloatValue("yPrecision"),
// obj.getIntValue("deviceId"),
// obj.getIntValue("edgeFlags")
//// obj.getIntValue("source"),
//// obj.getIntValue("displayId")
// );
// ((MotionEvent) event).setSource(obj.getIntValue("source"));
//// ((MotionEvent) event).setEdgeFlags(obj.getIntValue("edgeFlags"));
//
// }
//
//
//// list.add(event);
//
// long time = obj.getIntValue("time");
// if (i <= 0) {
// firstEventNode = new Node<>(null, event, null);
// eventNode = firstEventNode;
// }
// else if (i >= touchList.size() - 1) {
// lastTime = time;
// lastCurTime = firstCurTime + lastTime - firstTime;
// }
//
// eventNode.next = new Node<>(eventNode, event, null);
// eventNode = eventNode.next;
//
// //通过遍历数组来实现
//// Message msg = handler.obtainMessage();
//// msg.obj = event;
//// handler.sendMessageDelayed(msg, i <= 0 ? 0 : time - firstTime);
// }
//
// //通过递归链表来实现
// Message msg = handler.obtainMessage();
// msg.obj = firstEventNode;
// handler.sendMessage(msg);
//
// }
// }
//
//
//
// @Override
// public boolean onKeyDown(int keyCode, KeyEvent event) {
// addInputEvent(event, this);
// return super.onKeyDown(keyCode, event);
// }
//
//
// @Override
// public boolean onKeyUp(int keyCode, KeyEvent event) {
// addInputEvent(event, this);
// return super.onKeyUp(keyCode, event);
// }
//
// private JSONArray addInputEvent(InputEvent ie, Activity activity) {
// int splitY = floatSplitY.getY() + rlUIAutoSplitY.getHeight()/2;
// int orientation = activity == null ? Configuration.ORIENTATION_PORTRAIT : activity.getResources().getConfiguration().orientation;
//
// JSONObject obj = new JSONObject(true);
// obj.put("id", - System.currentTimeMillis());
// obj.put("flowId", flowId);
// obj.put("time", System.currentTimeMillis());
// obj.put("orientation", orientation);
// obj.put("splitY", splitY);
//
// if (ie instanceof KeyEvent) {
// KeyEvent event = (KeyEvent) ie;
// obj.put("type", 1);
//
// //虽然 KeyEvent 和 MotionEvent 都有,但都不在父类 InputEvent 中 <<<<<<<<<<<<<<<<<<
// obj.put("action", event.getAction());
// obj.put("downTime", event.getDownTime());
// obj.put("eventTime", event.getEventTime());
// obj.put("metaState", event.getMetaState());
// obj.put("source", event.getSource());
// obj.put("deviceId", event.getDeviceId());
// //虽然 KeyEvent 和 MotionEvent 都有,但都不在父类 InputEvent 中 >>>>>>>>>>>>>>>>>>
//
// obj.put("keyCode", event.getKeyCode());
// obj.put("scanCode", event.getScanCode());
// obj.put("repeatCount", event.getRepeatCount());
// //通过 keyCode 获取的 obj.put("number", event.getNumber());
// obj.put("flags", event.getFlags());
// //通过 mMetaState 获取的 obj.put("modifiers", event.getModifiers());
// //通过 mKeyCode 获取的 obj.put("displayLabel", event.getDisplayLabel());
// //通过 mMetaState 获取的 obj.put("unicodeChar", event.getUnicodeChar());
// }
// else if (ie instanceof MotionEvent) {
// MotionEvent event = (MotionEvent) ie;
// obj.put("type", 0);
//
// //虽然 KeyEvent 和 MotionEvent 都有,但都不在父类 InputEvent 中 <<<<<<<<<<<<<<<<<<
// obj.put("action", event.getAction());
// obj.put("downTime", event.getDownTime());
// obj.put("eventTime", event.getEventTime());
// obj.put("metaState", event.getMetaState());
// obj.put("source", event.getSource());
// obj.put("deviceId", event.getDeviceId());
// //虽然 KeyEvent 和 MotionEvent 都有,但都不在父类 InputEvent 中 >>>>>>>>>>>>>>>>>>
//
// float relativeY = event.getY() <= splitY ? event.getY() : (event.getY() - screenHeight);
//
// obj.put("x", (int) event.getX());
// obj.put("y", (int) relativeY);
// obj.put("rawX", (int) event.getRawX());
// obj.put("rawY", (int) event.getRawY());
// obj.put("size", event.getSize());
// obj.put("pressure", event.getPressure());
// obj.put("xPrecision", event.getXPrecision());
// obj.put("yPrecision", event.getYPrecision());
// obj.put("pointerCount", event.getPointerCount());
// obj.put("edgeFlags", event.getEdgeFlags());
// }
//
// if (touchList == null) {
// touchList = new JSONArray();
// }
// touchList.add(obj);
//
// return touchList;
// }
//
// private static class Node<E> {
// E item;
// Node<E> next;
// Node<E> prev;
//
// Node(Node<E> prev, E element, Node<E> next) {
// this.item = element;
// this.next = next;
// this.prev = prev;
// }
// }
}