Add more feedback parameters to onCardLongPress

onCardLongPress now passes information about the detail
texture being passed, and where the touch happened.

Also fixing a bug that caused long-press to be interpreted
as selection.

Change-Id: I4ee189c7c006abbc6ad71ac60778d1f18e8684a2
diff --git a/carousel/java/com/android/ex/carousel/CarouselRS.java b/carousel/java/com/android/ex/carousel/CarouselRS.java
index 74fcb35..1e9175c 100644
--- a/carousel/java/com/android/ex/carousel/CarouselRS.java
+++ b/carousel/java/com/android/ex/carousel/CarouselRS.java
@@ -18,6 +18,7 @@
 
 import android.content.res.Resources;
 import android.graphics.Bitmap;
+import android.graphics.Rect;
 import android.renderscript.*;
 import android.renderscript.RenderScript.RSMessageHandler;
 import android.util.Log;
@@ -118,8 +119,10 @@
         /**
          * Called when a card is long-pressed
          * @param n the id of the card
+         * @param touchPosition position of where the user pressed, in screen coordinates
+         * @param detailCoordinates position of detail texture, in screen coordinates
          */
-        void onCardLongPress(int n);
+        void onCardLongPress(int n, int touchPosition[], Rect detailCoordinates);
 
         /**
          * Called when texture is needed for card n.  This happens when the given card becomes
@@ -188,7 +191,9 @@
                     break;
 
                 case CMD_CARD_LONGPRESS:
-                    mCallback.onCardLongPress(mData[0]);
+                    int touchPosition[] = { mData[1], mData[2] };
+                    Rect detailCoordinates = new Rect(mData[3], mData[4], mData[5], mData[6]);
+                    mCallback.onCardLongPress(mData[0], touchPosition, detailCoordinates);
                     break;
 
                 case CMD_REQUEST_TEXTURE:
diff --git a/carousel/java/com/android/ex/carousel/CarouselViewHelper.java b/carousel/java/com/android/ex/carousel/CarouselViewHelper.java
index a8a2c82..5fc74ac 100644
--- a/carousel/java/com/android/ex/carousel/CarouselViewHelper.java
+++ b/carousel/java/com/android/ex/carousel/CarouselViewHelper.java
@@ -3,6 +3,7 @@
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.Matrix;
+import android.graphics.Rect;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.Looper;
@@ -256,8 +257,9 @@
         if (DBG) Log.v(TAG, "onDetailSelected(" + n + ", " + x + ", " + y + ")");
     }
 
-    public void onCardLongPress(int n) {
-        if (DBG) Log.v(TAG, "onCardLongPress(" + n + ")");
+    public void onCardLongPress(int n, int touchPosition[], Rect detailCoordinates) {
+        if (DBG) Log.v(TAG, "onCardLongPress(" + n + ", (" + touchPosition + "), (" +
+                detailCoordinates +") )");
     }
 
     public void onAnimationStarted() {
diff --git a/carousel/java/com/android/ex/carousel/carousel.rs b/carousel/java/com/android/ex/carousel/carousel.rs
index 5991644..45dbd21 100644
--- a/carousel/java/com/android/ex/carousel/carousel.rs
+++ b/carousel/java/com/android/ex/carousel/carousel.rs
@@ -1045,12 +1045,18 @@
     int64_t currentTime = rsUptimeMillis();
     updateAllocationVars(cards);
     // Selection happens for most recent position detected in doMotion()
-    int selection = doSelection(lastPosition.x, lastPosition.y);
-    if (selection != -1) {
-        if (debugSelection) rsDebug("doLongPress(), selection = ", selection);
-        int data[1];
-        data[0] = selection;
+    if (enableSelection && animatedSelection != -1) {
+        if (debugSelection) rsDebug("doLongPress(), selection = ", animatedSelection);
+        int data[7];
+        data[0] = animatedSelection;
+        data[1] = lastPosition.x;
+        data[2] = lastPosition.y;
+        data[3] = cards[animatedSelection].detailTexturePosition[0].x;
+        data[4] = cards[animatedSelection].detailTexturePosition[0].y;
+        data[5] = cards[animatedSelection].detailTexturePosition[1].x;
+        data[6] = cards[animatedSelection].detailTexturePosition[1].y;
         rsSendToClientBlocking(CMD_CARD_LONGPRESS, data, sizeof(data));
+        enableSelection = false;
     }
     lastTime = rsUptimeMillis();
 }