Merge "Further preventing drags while loading is in progress. (Bug 6276881)" into jb-dev
diff --git a/res/values-ja/strings.xml b/res/values-ja/strings.xml
index 6fa6b28..0fc144d 100644
--- a/res/values-ja/strings.xml
+++ b/res/values-ja/strings.xml
@@ -20,7 +20,7 @@
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <string name="application_name" msgid="8424725141379931883">"ランチャー"</string>
-    <string name="home" msgid="5921706419368316758">"ホーム"</string>
+    <string name="home" msgid="5921706419368316758">"Home"</string>
     <string name="uid_name" msgid="3371120195364560632">"Android Core Apps"</string>
     <string name="folder_name" msgid="8551881338202938211"></string>
     <string name="chooser_wallpaper" msgid="6063168087625352235">"壁紙の選択"</string>
diff --git a/src/com/android/launcher2/ApplicationInfo.java b/src/com/android/launcher2/ApplicationInfo.java
index 1fc1d1f..281d59c 100644
--- a/src/com/android/launcher2/ApplicationInfo.java
+++ b/src/com/android/launcher2/ApplicationInfo.java
@@ -102,6 +102,12 @@
         firstInstallTime = info.firstInstallTime;
     }
 
+    /** Returns the package name that the shortcut's intent will resolve to, or an empty string if
+     *  none exists. */
+    String getPackageName() {
+        return super.getPackageName(intent);
+    }
+
     /**
      * Creates the application intent based on a component name and various launch flags.
      * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}.
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index fe9334b..5bd0ac6 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -524,10 +524,6 @@
                 mPressedIcon.lockDrawableState();
             }
 
-            // NOTE: we need to re-enable the wallpaper visibility if we want correct transitions
-            // between items that are launched from the workspace and all apps.  It will be disabled
-            // correctly the next time the window is visible in AppsCustomizeTabHost.
-            mLauncher.updateWallpaperVisibility(true);
             mLauncher.startActivitySafely(v, appInfo.intent, appInfo);
 
         } else if (v instanceof PagedViewWidget) {
diff --git a/src/com/android/launcher2/DragController.java b/src/com/android/launcher2/DragController.java
index b9d7dd4..b4b20c6 100644
--- a/src/com/android/launcher2/DragController.java
+++ b/src/com/android/launcher2/DragController.java
@@ -381,8 +381,8 @@
                     if (dragInfo != null &&
                         dragInfo.intent != null &&
                         info.intent != null) {
-                        boolean isSamePackage = dragInfo.intent.getPackage().equals(
-                                info.intent.getPackage());
+                        boolean isSamePackage = dragInfo.getPackageName().equals(
+                                info.getPackageName());
                         if (isSamePackage) {
                             cancelDrag();
                             return;
diff --git a/src/com/android/launcher2/ItemInfo.java b/src/com/android/launcher2/ItemInfo.java
index 11a6c0d..d34b87e 100644
--- a/src/com/android/launcher2/ItemInfo.java
+++ b/src/com/android/launcher2/ItemInfo.java
@@ -16,13 +16,14 @@
 
 package com.android.launcher2;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
 import android.content.ContentValues;
+import android.content.Intent;
 import android.graphics.Bitmap;
 import android.util.Log;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
 /**
  * Represents an item in the launcher.
  */
@@ -109,6 +110,21 @@
         container = info.container;
     }
 
+    /** Returns the package name that the intent will resolve to, or an empty string if
+     *  none exists. */
+    static String getPackageName(Intent intent) {
+        if (intent != null) {
+            String packageName = intent.getPackage();
+            if (packageName == null) {
+                packageName = intent.getComponent().getPackageName();
+            }
+            if (packageName != null) {
+                return packageName;
+            }
+        }
+        return "";
+    }
+
     /**
      * Write the fields of this item to the DB
      * 
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 623313d..d0f4b86 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -671,6 +671,11 @@
 
     @Override
     protected void onPause() {
+        // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled
+        // to be consistent.  So re-enable the flag here, and we will re-disable it as necessary
+        // when Launcher resumes and we are still in AllApps.
+        updateWallpaperVisibility(true);
+
         super.onPause();
         mPaused = true;
         mDragController.cancelDrag();
@@ -2832,7 +2837,9 @@
             if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
             searchButton.setVisibility(View.GONE);
             voiceButton.setVisibility(View.GONE);
-            voiceButtonProxy.setVisibility(View.GONE);
+            if (voiceButtonProxy != null) {
+                voiceButtonProxy.setVisibility(View.GONE);
+            }
             return false;
         }
     }
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
index ba5370d..7e4901e 100644
--- a/src/com/android/launcher2/LauncherModel.java
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -1702,7 +1702,7 @@
         for (ItemInfo i : sWorkspaceItems) {
             if (i instanceof ShortcutInfo) {
                 ShortcutInfo info = (ShortcutInfo) i;
-                if (info.intent.getComponent().getPackageName().equals(packageName)) {
+                if (packageName.equals(info.getPackageName())) {
                     infos.add(info);
                 }
             }
diff --git a/src/com/android/launcher2/PagedView.java b/src/com/android/launcher2/PagedView.java
index adfe0de..b850ce2 100644
--- a/src/com/android/launcher2/PagedView.java
+++ b/src/com/android/launcher2/PagedView.java
@@ -627,7 +627,9 @@
         if (isScrollingIndicatorEnabled()) {
             updateScrollingIndicator();
         }
-        if (mFadeInAdjacentScreens) {
+        boolean isInOverscroll = mOverScrollX < 0 || mOverScrollX > mMaxScrollX;
+
+        if (mFadeInAdjacentScreens && !isInOverscroll) {
             for (int i = 0; i < getChildCount(); i++) {
                 View child = getChildAt(i);
                 if (child != null) {
diff --git a/src/com/android/launcher2/ShortcutInfo.java b/src/com/android/launcher2/ShortcutInfo.java
index 76892db..533059f 100644
--- a/src/com/android/launcher2/ShortcutInfo.java
+++ b/src/com/android/launcher2/ShortcutInfo.java
@@ -98,6 +98,12 @@
         return mIcon;
     }
 
+    /** Returns the package name that the shortcut's intent will resolve to, or an empty string if
+     *  none exists. */
+    String getPackageName() {
+        return super.getPackageName(intent);
+    }
+
     public void updateIcon(IconCache iconCache) {
         mIcon = iconCache.getIcon(intent);
         usingFallbackIcon = iconCache.isDefaultIcon(mIcon);
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 456224f..5e45c99 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -182,6 +182,7 @@
     private float mOverscrollFade = 0;
     private boolean mOverscrollTransformsSet;
     public static final int DRAG_BITMAP_PADDING = 2;
+    private boolean mWorkspaceFadeInAdjacentScreens;
 
     // Camera and Matrix used to determine the final position of a neighboring CellLayout
     private final Matrix mMatrix = new Matrix();
@@ -247,7 +248,6 @@
     private float[] mOldScaleXs;
     private float[] mOldScaleYs;
     private float[] mOldBackgroundAlphas;
-    private float[] mOldBackgroundAlphaMultipliers;
     private float[] mOldAlphas;
     private float[] mOldRotationYs;
     private float[] mNewTranslationXs;
@@ -255,7 +255,6 @@
     private float[] mNewScaleXs;
     private float[] mNewScaleYs;
     private float[] mNewBackgroundAlphas;
-    private float[] mNewBackgroundAlphaMultipliers;
     private float[] mNewAlphas;
     private float[] mNewRotationYs;
     private float mTransitionProgress;
@@ -286,7 +285,8 @@
         setDataIsReady();
 
         final Resources res = getResources();
-        mFadeInAdjacentScreens = res.getBoolean(R.bool.config_workspaceFadeAdjacentScreens);
+        mWorkspaceFadeInAdjacentScreens = res.getBoolean(R.bool.config_workspaceFadeAdjacentScreens);
+        mFadeInAdjacentScreens = false;
         mWallpaperManager = WallpaperManager.getInstance(context);
 
         int cellCountX = DEFAULT_CELL_COUNT_X;
@@ -721,7 +721,7 @@
 
         // If we are not fading in adjacent screens, we still need to restore the alpha in case the
         // user scrolls while we are transitioning (should not affect dispatchDraw optimizations)
-        if (!mFadeInAdjacentScreens) {
+        if (!mWorkspaceFadeInAdjacentScreens) {
             for (int i = 0; i < getChildCount(); ++i) {
                 ((CellLayout) getPageAt(i)).setShortcutAndWidgetAlpha(1f);
             }
@@ -1192,55 +1192,26 @@
         return Math.min(r / threshold, 1.0f);
     }
 
-    private void screenScrolledLargeUI(int screenCenter) {
-        if (isSwitchingState()) return;
-        boolean isInOverscroll = false;
-        for (int i = 0; i < getChildCount(); i++) {
-            CellLayout cl = (CellLayout) getChildAt(i);
-            if (cl != null) {
-                float scrollProgress = getScrollProgress(screenCenter, cl, i);
-                float rotation = WORKSPACE_ROTATION * scrollProgress;
-                float translationX = getOffsetXForRotation(rotation, cl.getWidth(), cl.getHeight());
+    @Override
+    protected void screenScrolled(int screenCenter) {
+        super.screenScrolled(screenCenter);
 
-                // If the current page (i) is being over scrolled, we use a different
-                // set of rules for setting the background alpha multiplier.
-                if (!isSmall()) {
-                    if ((mOverScrollX < 0 && i == 0) || (mOverScrollX > mMaxScrollX &&
-                            i == getChildCount() -1)) {
-                        isInOverscroll = true;
-                        rotation *= -1;
-                        cl.setBackgroundAlphaMultiplier(
-                                overScrollBackgroundAlphaInterpolator(Math.abs(scrollProgress)));
-                        mOverScrollPageIndex = i;
-                        cl.setOverScrollAmount(Math.abs(scrollProgress), i == 0);
-                        if (!mOverscrollTransformsSet) {
-                            mOverscrollTransformsSet = true;
-                            cl.setPivotX(cl.getMeasuredWidth() * (i == 0 ? 0.75f : 0.25f));
-                            cl.setPivotY(cl.getMeasuredHeight() * 0.5f);
-                            cl.setOverscrollTransformsDirty(true);
-                        }
-                    } else if (mOverScrollPageIndex != i) {
-                        cl.setBackgroundAlphaMultiplier(
-                                backgroundAlphaInterpolator(Math.abs(scrollProgress)));
-                    }
-                }
-                cl.setTranslationX(translationX);
-                cl.setRotationY(rotation);
-                if (mFadeInAdjacentScreens && !isSmall()) {
+        boolean isInOverscroll = mOverScrollX < 0 || mOverScrollX > mMaxScrollX;
+        if (mWorkspaceFadeInAdjacentScreens &&
+                mState == State.NORMAL &&
+                !mIsSwitchingState &&
+                !isInOverscroll) {
+            for (int i = 0; i < getChildCount(); i++) {
+                CellLayout child = (CellLayout) getChildAt(i);
+                if (child != null) {
+                    float scrollProgress = getScrollProgress(screenCenter, child, i);
                     float alpha = 1 - Math.abs(scrollProgress);
-                    cl.setShortcutAndWidgetAlpha(alpha);
+                    child.getShortcutsAndWidgets().setAlpha(alpha);
                 }
             }
+            invalidate();
         }
-        if (mOverscrollTransformsSet && !isInOverscroll) {
-            mOverscrollTransformsSet = false;
-            ((CellLayout) getChildAt(0)).resetOverscrollTransforms();
-            ((CellLayout) getChildAt(getChildCount() - 1)).resetOverscrollTransforms();
-        }
-        invalidate();
-    }
 
-    private void screenScrolledStandardUI(int screenCenter) {
         if (mOverScrollX < 0 || mOverScrollX > mMaxScrollX) {
             int index = mOverScrollX < 0 ? 0 : getChildCount() - 1;
             CellLayout cl = (CellLayout) getChildAt(index);
@@ -1269,24 +1240,8 @@
     }
 
     @Override
-    protected void screenScrolled(int screenCenter) {
-        if (LauncherApplication.isScreenLarge()) {
-            // We don't call super.screenScrolled() here because we handle the adjacent pages alpha
-            // ourselves (for efficiency), and there are no scrolling indicators to update.
-            screenScrolledLargeUI(screenCenter);
-        } else {
-            super.screenScrolled(screenCenter);
-            screenScrolledStandardUI(screenCenter);
-        }
-    }
-
-    @Override
     protected void overScroll(float amount) {
-        if (LauncherApplication.isScreenLarge()) {
-            dampedOverScroll(amount);
-        } else {
-            acceleratedOverScroll(amount);
-        }
+        acceleratedOverScroll(amount);
     }
 
     protected void onAttachedToWindow() {
@@ -1519,7 +1474,6 @@
         mOldScaleXs = new float[childCount];
         mOldScaleYs = new float[childCount];
         mOldBackgroundAlphas = new float[childCount];
-        mOldBackgroundAlphaMultipliers = new float[childCount];
         mOldAlphas = new float[childCount];
         mOldRotationYs = new float[childCount];
         mNewTranslationXs = new float[childCount];
@@ -1527,7 +1481,6 @@
         mNewScaleXs = new float[childCount];
         mNewScaleYs = new float[childCount];
         mNewBackgroundAlphas = new float[childCount];
-        mNewBackgroundAlphaMultipliers = new float[childCount];
         mNewAlphas = new float[childCount];
         mNewRotationYs = new float[childCount];
     }
@@ -1582,11 +1535,10 @@
                 getResources().getInteger(R.integer.config_appsCustomizeWorkspaceShrinkTime);
         for (int i = 0; i < getChildCount(); i++) {
             final CellLayout cl = (CellLayout) getChildAt(i);
-            float rotation = 0f;
-            float initialAlpha = cl.getAlpha();
-            float finalAlphaMultiplierValue = 1f;
-            float finalAlpha = (!mFadeInAdjacentScreens || stateIsSpringLoaded ||
+            float finalAlpha = (!mWorkspaceFadeInAdjacentScreens || stateIsSpringLoaded ||
                     (i == mCurrentPage)) ? 1f : 0f;
+            float currentAlpha = cl.getShortcutsAndWidgets().getAlpha();
+            float initialAlpha = currentAlpha;
 
             // Determine the pages alpha during the state transition
             if ((oldStateIsSmall && stateIsNormal) ||
@@ -1596,29 +1548,12 @@
                 //                     or, if we're in spring-loaded mode
                 if (i == mCurrentPage || !animated || oldStateIsSpringLoaded) {
                     finalAlpha = 1f;
-                    finalAlphaMultiplierValue = 0f;
                 } else {
                     initialAlpha = 0f;
                     finalAlpha = 0f;
                 }
             }
 
-            // Update the rotation of the screen (don't apply rotation on Phone UI)
-            if (LauncherApplication.isScreenLarge()) {
-                if (i < mCurrentPage) {
-                    rotation = WORKSPACE_ROTATION;
-                } else if (i > mCurrentPage) {
-                    rotation = -WORKSPACE_ROTATION;
-                }
-            }
-
-            // If the screen is not xlarge, then don't rotate the CellLayouts
-            // NOTE: If we don't update the side pages alpha, then we should not hide the side
-            //       pages. see unshrink().
-            if (LauncherApplication.isScreenLarge()) {
-                translationX = getOffsetXForRotation(rotation, cl.getWidth(), cl.getHeight());
-            }
-
             mOldAlphas[i] = initialAlpha;
             mNewAlphas[i] = finalAlpha;
             if (animated) {
@@ -1627,25 +1562,19 @@
                 mOldScaleXs[i] = cl.getScaleX();
                 mOldScaleYs[i] = cl.getScaleY();
                 mOldBackgroundAlphas[i] = cl.getBackgroundAlpha();
-                mOldBackgroundAlphaMultipliers[i] = cl.getBackgroundAlphaMultiplier();
-                mOldRotationYs[i] = cl.getRotationY();
 
                 mNewTranslationXs[i] = translationX;
                 mNewTranslationYs[i] = translationY;
                 mNewScaleXs[i] = finalScaleFactor;
                 mNewScaleYs[i] = finalScaleFactor;
                 mNewBackgroundAlphas[i] = finalBackgroundAlpha;
-                mNewBackgroundAlphaMultipliers[i] = finalAlphaMultiplierValue;
-                mNewRotationYs[i] = rotation;
             } else {
                 cl.setTranslationX(translationX);
                 cl.setTranslationY(translationY);
                 cl.setScaleX(finalScaleFactor);
                 cl.setScaleY(finalScaleFactor);
                 cl.setBackgroundAlpha(finalBackgroundAlpha);
-                cl.setBackgroundAlphaMultiplier(finalAlphaMultiplierValue);
                 cl.setShortcutAndWidgetAlpha(finalAlpha);
-                cl.setRotationY(rotation);
             }
         }
 
@@ -1653,13 +1582,13 @@
             for (int index = 0; index < getChildCount(); index++) {
                 final int i = index;
                 final CellLayout cl = (CellLayout) getChildAt(i);
+                float currentAlpha = cl.getShortcutsAndWidgets().getAlpha();
                 if (mOldAlphas[i] == 0 && mNewAlphas[i] == 0) {
                     cl.setTranslationX(mNewTranslationXs[i]);
                     cl.setTranslationY(mNewTranslationYs[i]);
                     cl.setScaleX(mNewScaleXs[i]);
                     cl.setScaleY(mNewScaleYs[i]);
                     cl.setBackgroundAlpha(mNewBackgroundAlphas[i]);
-                    cl.setBackgroundAlphaMultiplier(mNewBackgroundAlphaMultipliers[i]);
                     cl.setShortcutAndWidgetAlpha(mNewAlphas[i]);
                     cl.setRotationY(mNewRotationYs[i]);
                 } else {
@@ -1672,7 +1601,7 @@
                         .setInterpolator(mZoomInInterpolator);
                     anim.play(a);
 
-                    if (mOldAlphas[i] != mNewAlphas[i]) {
+                    if (mOldAlphas[i] != mNewAlphas[i] || currentAlpha != mNewAlphas[i]) {
                         LauncherViewPropertyAnimator alphaAnim =
                             new LauncherViewPropertyAnimator(cl.getShortcutsAndWidgets());
                         alphaAnim.alpha(mNewAlphas[i])
@@ -1680,20 +1609,8 @@
                             .setInterpolator(mZoomInInterpolator);
                         anim.play(alphaAnim);
                     }
-                    if (mOldRotationYs[i] != 0 || mNewRotationYs[i] != 0) {
-                        ValueAnimator rotate = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
-                        rotate.setInterpolator(new DecelerateInterpolator(2.0f));
-                        rotate.addUpdateListener(new LauncherAnimatorUpdateListener() {
-                                public void onAnimationUpdate(float a, float b) {
-                                    cl.setRotationY(a * mOldRotationYs[i] + b * mNewRotationYs[i]);
-                                }
-                            });
-                        anim.play(rotate);
-                    }
                     if (mOldBackgroundAlphas[i] != 0 ||
-                        mNewBackgroundAlphas[i] != 0 ||
-                        mOldBackgroundAlphaMultipliers[i] != 0 ||
-                        mNewBackgroundAlphaMultipliers[i] != 0) {
+                        mNewBackgroundAlphas[i] != 0) {
                         ValueAnimator bgAnim = ValueAnimator.ofFloat(0f, 1f).setDuration(duration);
                         bgAnim.setInterpolator(mZoomInInterpolator);
                         bgAnim.addUpdateListener(new LauncherAnimatorUpdateListener() {
@@ -1701,9 +1618,6 @@
                                     cl.setBackgroundAlpha(
                                             a * mOldBackgroundAlphas[i] +
                                             b * mNewBackgroundAlphas[i]);
-                                    cl.setBackgroundAlphaMultiplier(
-                                            a * mOldBackgroundAlphaMultipliers[i] +
-                                            b * mNewBackgroundAlphaMultipliers[i]);
                                 }
                             });
                         anim.play(bgAnim);
@@ -1751,7 +1665,7 @@
         // ensure that only the current page is visible during (and subsequently, after) the
         // transition animation.  If fade adjacent pages is disabled, then re-enable the page
         // visibility after the transition animation.
-        if (!mFadeInAdjacentScreens) {
+        if (!mWorkspaceFadeInAdjacentScreens) {
             for (int i = 0; i < getChildCount(); i++) {
                 final CellLayout cl = (CellLayout) getChildAt(i);
                 cl.setShortcutAndWidgetAlpha(1f);
@@ -3708,7 +3622,8 @@
                         for (String intentStr : newApps) {
                             try {
                                 Intent intent = Intent.parseUri(intentStr, 0);
-                                if (packageNames.contains(intent.getComponent().getPackageName())) {
+                                String pn = ItemInfo.getPackageName(intent);
+                                if (packageNames.contains(pn)) {
                                     newApps.remove(intentStr);
                                 }
                             } catch (URISyntaxException e) {}