Use Iterator in PointerTrackerQueue

Change-Id: Ia5ad7d4511b2f2db056f2acf7cc0e002001e2123
main
Tadashi G. Takaoka 2011-12-01 17:50:37 +09:00
parent 33f595c33b
commit 78ac86ff9d
1 changed files with 25 additions and 26 deletions

View File

@ -18,6 +18,7 @@ package com.android.inputmethod.keyboard.internal;
import com.android.inputmethod.keyboard.PointerTracker; import com.android.inputmethod.keyboard.PointerTracker;
import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
public class PointerTrackerQueue { public class PointerTrackerQueue {
@ -27,18 +28,23 @@ public class PointerTrackerQueue {
mQueue.add(tracker); mQueue.add(tracker);
} }
public synchronized void remove(PointerTracker tracker) {
mQueue.remove(tracker);
}
public synchronized void releaseAllPointersOlderThan(PointerTracker tracker, long eventTime) { public synchronized void releaseAllPointersOlderThan(PointerTracker tracker, long eventTime) {
if (mQueue.lastIndexOf(tracker) < 0) { if (!mQueue.contains(tracker)) {
return; return;
} }
final LinkedList<PointerTracker> queue = mQueue; final Iterator<PointerTracker> it = mQueue.iterator();
int oldestPos = 0; while (it.hasNext()) {
for (PointerTracker t = queue.get(oldestPos); t != tracker; t = queue.get(oldestPos)) { final PointerTracker t = it.next();
if (t.isModifier()) { if (t == tracker) {
oldestPos++; break;
} else { }
if (!t.isModifier()) {
t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime); t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime);
queue.remove(oldestPos); it.remove();
} }
} }
} }
@ -48,20 +54,14 @@ public class PointerTrackerQueue {
} }
public synchronized void releaseAllPointersExcept(PointerTracker tracker, long eventTime) { public synchronized void releaseAllPointersExcept(PointerTracker tracker, long eventTime) {
for (PointerTracker t : mQueue) { final Iterator<PointerTracker> it = mQueue.iterator();
if (t == tracker) { while (it.hasNext()) {
continue; final PointerTracker t = it.next();
if (t != tracker) {
t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime);
it.remove();
} }
t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime);
} }
mQueue.clear();
if (tracker != null) {
mQueue.add(tracker);
}
}
public synchronized void remove(PointerTracker tracker) {
mQueue.remove(tracker);
} }
public synchronized boolean isAnyInSlidingKeyInput() { public synchronized boolean isAnyInSlidingKeyInput() {
@ -75,13 +75,12 @@ public class PointerTrackerQueue {
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder("["); final StringBuilder sb = new StringBuilder();
for (PointerTracker tracker : mQueue) { for (final PointerTracker tracker : mQueue) {
if (sb.length() > 1) if (sb.length() > 0)
sb.append(" "); sb.append(" ");
sb.append(String.format("%d", tracker.mPointerId)); sb.append(tracker.mPointerId);
} }
sb.append("]"); return "[" + sb + "]";
return sb.toString();
} }
} }