am 5c269d1e: Merge "Use Iterator in PointerTrackerQueue"

* commit '5c269d1e0d31987d86ff9401044289e51c029fb4':
  Use Iterator in PointerTrackerQueue
main
Tadashi G. Takaoka 2011-12-01 01:37:46 -08:00 committed by Android Git Automerger
commit 84ba9230de
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); t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime);
} it.remove();
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();
} }
} }