Fix gesture floating preview on up event

This is a follow up of Iddb26ba1.

Bug: 7119032
Change-Id: Ibbc94a1a4880ca31bd8aeece89893691b14acc4d
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index e762b23..2417d6e 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -545,12 +545,15 @@
     }
 
     private void startBatchInput() {
-        if (DEBUG_LISTENER) {
-            Log.d(TAG, "onStartBatchInput");
+        if (!sInGesture && mGestureStrokeWithPreviewTrail.isStartOfAGesture()) {
+            if (DEBUG_LISTENER) {
+                Log.d(TAG, "onStartBatchInput");
+            }
+            sInGesture = true;
+            mListener.onStartBatchInput();
         }
-        sInGesture = true;
-        mListener.onStartBatchInput();
-        mDrawingProxy.showGesturePreviewTrail(this, true /* isOldestTracker */);
+        final boolean isOldestTracker = sPointerTrackerQueue.getOldestElement() == this;
+        mDrawingProxy.showGesturePreviewTrail(this, isOldestTracker);
     }
 
     private void updateBatchInput(final long eventTime) {
@@ -585,7 +588,8 @@
                 clearBatchInputPointsOfAllPointerTrackers();
             }
         }
-        mDrawingProxy.showGesturePreviewTrail(this,  true /* isOldestTracker */);
+        final boolean isOldestTracker = sPointerTrackerQueue.getOldestElement() == this;
+        mDrawingProxy.showGesturePreviewTrail(this, isOldestTracker);
     }
 
     private static void abortBatchInput() {
@@ -721,12 +725,8 @@
             final boolean isHistorical, final Key key) {
         final int gestureTime = (int)(eventTime - sGestureFirstDownTime);
         if (mIsDetectingGesture) {
-            final GestureStroke stroke = mGestureStrokeWithPreviewTrail;
-            stroke.addPoint(x, y, gestureTime, isHistorical);
-            if (!sInGesture && stroke.isStartOfAGesture()) {
-                startBatchInput();
-            }
-
+            mGestureStrokeWithPreviewTrail.addPoint(x, y, gestureTime, isHistorical);
+            startBatchInput();
             if (sInGesture && key != null) {
                 updateBatchInput(eventTime);
             }