|
43 | 43 | import com.yhao.floatwindow.MoveType;
|
44 | 44 |
|
45 | 45 | import java.util.Calendar;
|
| 46 | +import java.util.LinkedList; |
| 47 | +import java.util.List; |
46 | 48 |
|
47 | 49 | import apijson.demo.R;
|
48 | 50 | import apijson.demo.application.DemoApplication;
|
@@ -85,13 +87,29 @@ public void handleMessage(Message msg) {
|
85 | 87 | super.handleMessage(msg);
|
86 | 88 |
|
87 | 89 | if (isRecovering) {
|
88 |
| - if (lastCurTime >= System.currentTimeMillis()) { |
| 90 | + //通过遍历数组来实现 |
| 91 | +// if (lastCurTime >= System.currentTimeMillis()) { |
| 92 | +// isRecovering = false; |
| 93 | +// pbUIAutoDivider.setVisibility(View.GONE); |
| 94 | +// } |
| 95 | +// |
| 96 | +// MotionEvent event = (MotionEvent) msg.obj; |
| 97 | +// dispatchEventToCurrentActivity(event); |
| 98 | + |
| 99 | + |
| 100 | + //根据递归链表来实现,能精准地实现两个事件之间的间隔,不受处理时间不一致,甚至卡顿等影响。还能及时终止 |
| 101 | + Node<MotionEvent> eventNode = ( Node<MotionEvent>) msg.obj; |
| 102 | + dispatchEventToCurrentActivity(eventNode.item); |
| 103 | + |
| 104 | + if (eventNode.next == null) { |
89 | 105 | isRecovering = false;
|
90 | 106 | pbUIAutoDivider.setVisibility(View.GONE);
|
| 107 | + return; |
91 | 108 | }
|
92 | 109 |
|
93 |
| - MotionEvent event = (MotionEvent) msg.obj; |
94 |
| - dispatchEventToCurrentActivity(event); |
| 110 | + msg = Message.obtain(); |
| 111 | + msg.obj = eventNode.next; |
| 112 | + sendMessageDelayed(msg, eventNode.next.item.getEventTime() - eventNode.item.getEventTime()); |
95 | 113 | }
|
96 | 114 | }
|
97 | 115 | };
|
@@ -581,13 +599,18 @@ protected void onDestroy() {
|
581 | 599 | // }
|
582 | 600 |
|
583 | 601 |
|
| 602 | + private Node<MotionEvent> firstEventNode; |
| 603 | + private Node<MotionEvent> eventNode; |
| 604 | + |
584 | 605 | private long firstTime = 0;
|
585 | 606 | private long lastTime = 0;
|
586 | 607 | private long firstCurTime = 0;
|
587 | 608 | private long lastCurTime = 0;
|
588 | 609 | public void recover(JSONArray touchList) {
|
589 | 610 | isRecovering = true;
|
590 | 611 |
|
| 612 | + List<MotionEvent> list = new LinkedList<>(); |
| 613 | + |
591 | 614 | showCover(true, DemoApplication.getInstance().getCurrentActivity());
|
592 | 615 |
|
593 | 616 | JSONObject first = touchList == null || touchList.isEmpty() ? null : touchList.getJSONObject(0);
|
@@ -619,16 +642,32 @@ public void recover(JSONArray touchList) {
|
619 | 642 | event.setSource(obj.getIntValue("source"));
|
620 | 643 | // event.setEdgeFlags(obj.getIntValue("edgeFlags"));
|
621 | 644 |
|
| 645 | + list.add(event); |
| 646 | + |
622 | 647 | long time = obj.getIntValue("time");
|
623 |
| - if (i >= touchList.size() - 1) { |
| 648 | + if (i <= 0) { |
| 649 | + firstEventNode = new Node<>(null, event, null); |
| 650 | + eventNode = firstEventNode; |
| 651 | + } |
| 652 | + else if (i >= touchList.size() - 1) { |
624 | 653 | lastTime = time;
|
625 | 654 | lastCurTime = firstCurTime + lastTime - firstTime;
|
626 | 655 | }
|
627 | 656 |
|
628 |
| - Message msg = handler.obtainMessage(); |
629 |
| - msg.obj = event; |
630 |
| - handler.sendMessageDelayed(msg, i <= 0 ? 0 : time - firstTime); |
| 657 | + eventNode.next = new Node<>(eventNode, event, null); |
| 658 | + eventNode = eventNode.next; |
| 659 | + |
| 660 | + //通过遍历数组来实现 |
| 661 | +// Message msg = handler.obtainMessage(); |
| 662 | +// msg.obj = event; |
| 663 | +// handler.sendMessageDelayed(msg, i <= 0 ? 0 : time - firstTime); |
631 | 664 | }
|
| 665 | + |
| 666 | + //通过递归链表来实现 |
| 667 | + Message msg = handler.obtainMessage(); |
| 668 | + msg.obj = firstEventNode; |
| 669 | + handler.sendMessage(msg); |
| 670 | + |
632 | 671 | }
|
633 | 672 | }
|
634 | 673 |
|
@@ -656,5 +695,20 @@ public void run() {
|
656 | 695 | }
|
657 | 696 |
|
658 | 697 | }
|
| 698 | + |
| 699 | + |
| 700 | + |
| 701 | + private static class Node<E> { |
| 702 | + E item; |
| 703 | + Node<E> next; |
| 704 | + Node<E> prev; |
| 705 | + |
| 706 | + Node(Node<E> prev, E element, Node<E> next) { |
| 707 | + this.item = element; |
| 708 | + this.next = next; |
| 709 | + this.prev = prev; |
| 710 | + } |
| 711 | + } |
| 712 | + |
659 | 713 | }
|
660 | 714 |
|
0 commit comments