From 78ac86ff9ddfa354567c3146c67c914fc354d3a0 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 1 Dec 2011 17:50:37 +0900 Subject: [PATCH] Use Iterator in PointerTrackerQueue Change-Id: Ia5ad7d4511b2f2db056f2acf7cc0e002001e2123 --- .../internal/PointerTrackerQueue.java | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java index 08e7a7a4e..d9181f786 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java +++ b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java @@ -18,6 +18,7 @@ package com.android.inputmethod.keyboard.internal; import com.android.inputmethod.keyboard.PointerTracker; +import java.util.Iterator; import java.util.LinkedList; public class PointerTrackerQueue { @@ -27,18 +28,23 @@ public class PointerTrackerQueue { mQueue.add(tracker); } + public synchronized void remove(PointerTracker tracker) { + mQueue.remove(tracker); + } + public synchronized void releaseAllPointersOlderThan(PointerTracker tracker, long eventTime) { - if (mQueue.lastIndexOf(tracker) < 0) { + if (!mQueue.contains(tracker)) { return; } - final LinkedList queue = mQueue; - int oldestPos = 0; - for (PointerTracker t = queue.get(oldestPos); t != tracker; t = queue.get(oldestPos)) { - if (t.isModifier()) { - oldestPos++; - } else { + final Iterator it = mQueue.iterator(); + while (it.hasNext()) { + final PointerTracker t = it.next(); + if (t == tracker) { + break; + } + if (!t.isModifier()) { 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) { - for (PointerTracker t : mQueue) { - if (t == tracker) { - continue; + final Iterator it = mQueue.iterator(); + while (it.hasNext()) { + 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() { @@ -75,13 +75,12 @@ public class PointerTrackerQueue { @Override public String toString() { - StringBuilder sb = new StringBuilder("["); - for (PointerTracker tracker : mQueue) { - if (sb.length() > 1) + final StringBuilder sb = new StringBuilder(); + for (final PointerTracker tracker : mQueue) { + if (sb.length() > 0) sb.append(" "); - sb.append(String.format("%d", tracker.mPointerId)); + sb.append(tracker.mPointerId); } - sb.append("]"); - return sb.toString(); + return "[" + sb + "]"; } }