Locking pressed state for AllApps icons.

- Setting workaround for transition state bug until b/5897600 is fixed.

Change-Id: Icb29a4cd7bfaf527a9db5b853e7fb24c63b58b30
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 691228d..eac3c47 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -166,7 +166,8 @@
  * The Apps/Customize page that displays all the applications, widgets, and shortcuts.
  */
 public class AppsCustomizePagedView extends PagedViewWithDraggableItems implements
-        AllAppsView, View.OnClickListener, View.OnKeyListener, DragSource {
+        AllAppsView, View.OnClickListener, View.OnKeyListener, DragSource,
+        PagedViewIcon.PressedCallback {
     static final String LOG_TAG = "AppsCustomizePagedView";
 
     /**
@@ -185,6 +186,7 @@
 
     // Save and Restore
     private int mSaveInstanceStateItemIndex = -1;
+    private PagedViewIcon mPressedIcon;
 
     // Content
     private ArrayList<ApplicationInfo> mApps;
@@ -593,6 +595,9 @@
 
         if (!super.beginDragging(v)) return false;
 
+        // Reset the alpha on the dragged icon before we drag
+        resetDrawableState();
+
         // Go into spring loaded mode (must happen before we startDrag())
         mLauncher.enterSpringLoadedDragMode();
 
@@ -751,7 +756,7 @@
             ApplicationInfo info = mApps.get(i);
             PagedViewIcon icon = (PagedViewIcon) mLayoutInflater.inflate(
                     R.layout.apps_customize_application, layout, false);
-            icon.applyFromApplicationInfo(info, true);
+            icon.applyFromApplicationInfo(info, true, this);
             icon.setOnClickListener(this);
             icon.setOnLongClickListener(this);
             icon.setOnTouchListener(this);
@@ -1427,6 +1432,22 @@
         cancelAllTasks();
     }
 
+    @Override
+    public void iconPressed(PagedViewIcon icon) {
+        // Reset the previously pressed icon and store a reference to the pressed icon so that
+        // we can reset it on return to Launcher (in Launcher.onResume())
+        if (mPressedIcon != null) {
+            mPressedIcon.resetDrawableState();
+        }
+        mPressedIcon = icon;
+    }
+
+    public void resetDrawableState() {
+        if (mPressedIcon != null) {
+            mPressedIcon.resetDrawableState();
+            mPressedIcon = null;
+        }
+    }
 
     /*
      * We load an extra page on each side to prevent flashes from scrolling and loading of the
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 2b91302..6ac9fe2 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -561,9 +561,17 @@
             mRestoring = false;
             mOnResumeNeedsLoad = false;
         }
+
+        // Reset the pressed state of icons that were locked in the press state while activities
+        // were launching
         if (mWaitingForResume != null) {
+            // Resets the previous workspace icon press state
             mWaitingForResume.setStayPressed(false);
         }
+        if (mAppsCustomizeContent != null) {
+            // Resets the previous all apps icon press state
+            mAppsCustomizeContent.resetDrawableState();
+        }
         // When we resume Launcher, a different Activity might be responsible for the app
         // market intent, so refresh the icon
         updateAppMarketIcon();
diff --git a/src/com/android/launcher2/PagedViewIcon.java b/src/com/android/launcher2/PagedViewIcon.java
index 548b394..00f9321 100644
--- a/src/com/android/launcher2/PagedViewIcon.java
+++ b/src/com/android/launcher2/PagedViewIcon.java
@@ -26,7 +26,16 @@
  * drawables on the top).
  */
 public class PagedViewIcon extends TextView {
+    /** A simple callback interface to allow a PagedViewIcon to notify when it has been pressed */
+    public static interface PressedCallback {
+        void iconPressed(PagedViewIcon icon);
+    }
+
     private static final String TAG = "PagedViewIcon";
+    private static final float PRESS_ALPHA = 0.4f;
+
+    private PagedViewIcon.PressedCallback mPressedCallback;
+    private boolean mResetDrawableState = false;
 
     private Bitmap mIcon;
 
@@ -42,15 +51,38 @@
         super(context, attrs, defStyle);
     }
 
-    public void applyFromApplicationInfo(ApplicationInfo info, boolean scaleUp) {
+    public void applyFromApplicationInfo(ApplicationInfo info, boolean scaleUp,
+            PagedViewIcon.PressedCallback cb) {
         mIcon = info.iconBitmap;
+        mPressedCallback = cb;
         setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(mIcon), null, null);
         setText(info.title);
         setTag(info);
     }
 
+    public void resetDrawableState() {
+        mResetDrawableState = true;
+        post(new Runnable() {
+            @Override
+            public void run() {
+                refreshDrawableState();
+            }
+        });
+    }
+
     protected void drawableStateChanged() {
-        setAlpha(isPressed() ? 0.5f : 1f);
         super.drawableStateChanged();
+
+        // We keep in the pressed state until resetDrawableState() is called to reset the press
+        // feedback
+        if (isPressed()) {
+            setAlpha(PRESS_ALPHA);
+            if (mPressedCallback != null) {
+                mPressedCallback.iconPressed(this);
+            }
+        } else if (mResetDrawableState) {
+            setAlpha(1f);
+            mResetDrawableState = false;
+        }
     }
 }
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 4ecc1a5..ab78a8c 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -231,7 +231,7 @@
     private float[] mNewBackgroundAlphaMultipliers;
     private float[] mNewAlphas;
     private float[] mNewRotationYs;
-    private float mTransitionProgress;
+    private float mTransitionProgress = 1f;
 
     /**
      * Used to inflate the Workspace from XML.