Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a9adee6

Browse files
author
Kaushik Iska
committed
fix lint problems
1 parent a29148d commit a9adee6

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

shell/platform/android/io/flutter/embedding/android/MotionEventTracker.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.flutter.embedding.android;
22

3+
import android.util.LongSparseArray;
34
import android.view.MotionEvent;
45
import androidx.annotation.Nullable;
5-
import java.util.HashMap;
6-
import java.util.Map;
6+
import java.util.PriorityQueue;
77
import java.util.concurrent.atomic.AtomicLong;
88

99
/** Tracks the motion events received by the FlutterView. */
@@ -31,7 +31,8 @@ public long getId() {
3131
}
3232
}
3333

34-
private final Map<Long, MotionEvent> eventById;
34+
private final LongSparseArray<MotionEvent> eventById;
35+
private final PriorityQueue<Long> unusedEvents;
3536
private static MotionEventTracker INSTANCE;
3637

3738
public static MotionEventTracker getInstance() {
@@ -42,13 +43,15 @@ public static MotionEventTracker getInstance() {
4243
}
4344

4445
private MotionEventTracker() {
45-
eventById = new HashMap<>();
46+
eventById = new LongSparseArray<>();
47+
unusedEvents = new PriorityQueue<>();
4648
}
4749

4850
/** Tracks the event and returns a unique MotionEventId identifying the event. */
4951
public MotionEventId track(MotionEvent event) {
5052
MotionEventId eventId = MotionEventId.createUnique();
5153
eventById.put(eventId.id, event);
54+
unusedEvents.add(eventId.id);
5255
return eventId;
5356
}
5457

@@ -59,7 +62,18 @@ public MotionEventId track(MotionEvent event) {
5962
*/
6063
@Nullable
6164
public MotionEvent pop(MotionEventId eventId) {
62-
// TODO(kaushikiska) do the actual timestamp based book-keeping.
63-
return eventById.remove(eventId.id);
65+
// remove all the older events.
66+
while (!unusedEvents.isEmpty() && unusedEvents.peek() < eventId.id) {
67+
eventById.remove(unusedEvents.poll());
68+
}
69+
70+
// remove the current event from the heap if it exists.
71+
if (!unusedEvents.isEmpty() && unusedEvents.peek() == eventId.id) {
72+
unusedEvents.poll();
73+
}
74+
75+
MotionEvent event = eventById.get(eventId.id);
76+
eventById.remove(eventId.id);
77+
return event;
6478
}
6579
}

0 commit comments

Comments
 (0)