1package io.flutter.embedding.android;
3import android.util.LongSparseArray;
5import androidx.annotation.NonNull;
6import androidx.annotation.Nullable;
7import java.util.PriorityQueue;
8import java.util.concurrent.atomic.AtomicLong;
12 private static final String TAG =
"MotionEventTracker";
15 private static final AtomicLong ID_COUNTER =
new AtomicLong(0);
16 private final long id;
37 private final LongSparseArray<MotionEvent> eventById;
38 private final PriorityQueue<Long> unusedEvents;
43 if (INSTANCE ==
null) {
50 eventById =
new LongSparseArray<>();
51 unusedEvents =
new PriorityQueue<>();
64 MotionEvent eventCopy = MotionEvent.obtain(
event);
65 eventById.put(eventId.id, eventCopy);
66 unusedEvents.add(eventId.id);
78 while (!unusedEvents.isEmpty() && unusedEvents.peek() < eventId.id) {
79 eventById.remove(unusedEvents.poll());
83 if (!unusedEvents.isEmpty() && unusedEvents.peek() == eventId.id) {
87 MotionEvent
event = eventById.get(eventId.id);
88 eventById.remove(eventId.id);
static MotionEventId from(long id)
static MotionEventId createUnique()
MotionEventId track(@NonNull MotionEvent event)
static MotionEventTracker getInstance()
MotionEvent pop(@NonNull MotionEventId eventId)