Merge "Don't hide text in pre-drag when opening popup above icon" into ub-launcher3-dorval-polish
diff --git a/res/layout/gradient_scrim.xml b/res/layout/gradient_scrim.xml
index c40c5fc..15516b0 100644
--- a/res/layout/gradient_scrim.xml
+++ b/res/layout/gradient_scrim.xml
@@ -26,6 +26,5 @@
         android:id="@+id/scrim_bg"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:visibility="gone"
-        app:layout_ignoreInsets="true"/>
+        android:visibility="gone"/>
 </merge>
\ No newline at end of file
diff --git a/src/com/android/launcher3/anim/SpringAnimationHandler.java b/src/com/android/launcher3/anim/SpringAnimationHandler.java
index 5792127..488657c 100644
--- a/src/com/android/launcher3/anim/SpringAnimationHandler.java
+++ b/src/com/android/launcher3/anim/SpringAnimationHandler.java
@@ -164,7 +164,7 @@
     }
 
     private void computeVelocity() {
-        getVelocityTracker().computeCurrentVelocity(300);
+        getVelocityTracker().computeCurrentVelocity(175);
 
         mCurrentVelocity = isVerticalDirection()
                 ? getVelocityTracker().getYVelocity()
diff --git a/src/com/android/launcher3/compat/WallpaperManagerCompatVL.java b/src/com/android/launcher3/compat/WallpaperManagerCompatVL.java
index b175f21..3431664 100644
--- a/src/com/android/launcher3/compat/WallpaperManagerCompatVL.java
+++ b/src/com/android/launcher3/compat/WallpaperManagerCompatVL.java
@@ -132,14 +132,15 @@
         String[] parts = value.split(",");
         Integer wallpaperId = Integer.parseInt(parts[1]);
         if (parts.length == 2) {
+            // There is no wallpaper color info present, eg when live wallpaper has no preview.
             return Pair.create(wallpaperId, null);
         }
 
-        SparseIntArray colors = new SparseIntArray((parts.length - 2) / 2);
+        SparseIntArray colorsToOccurrences = new SparseIntArray((parts.length - 2) / 2);
         for (int i = 2; i < parts.length; i += 2) {
-            colors.put(Integer.parseInt(parts[i]), Integer.parseInt(parts[i + 1]));
+            colorsToOccurrences.put(Integer.parseInt(parts[i]), Integer.parseInt(parts[i + 1]));
         }
-        return Pair.create(wallpaperId, new WallpaperColorsCompat(colors, false));
+        return Pair.create(wallpaperId, new WallpaperColorsCompat(colorsToOccurrences, false));
     }
 
     /**
@@ -178,7 +179,7 @@
 
                         if (requestedArea > MAX_WALLPAPER_EXTRACTION_AREA) {
                             double areaRatio =
-                                    MAX_WALLPAPER_EXTRACTION_AREA / (double) requestedArea;
+                                    (double) requestedArea / MAX_WALLPAPER_EXTRACTION_AREA;
                             double nearestPowOf2 =
                                     Math.floor(Math.log(areaRatio) / (2 * Math.log(2)));
                             options.inSampleSize = (int) Math.pow(2, nearestPowOf2);
diff --git a/src/com/android/launcher3/graphics/ScrimView.java b/src/com/android/launcher3/graphics/ScrimView.java
index feb3f03..c102cab 100644
--- a/src/com/android/launcher3/graphics/ScrimView.java
+++ b/src/com/android/launcher3/graphics/ScrimView.java
@@ -29,10 +29,12 @@
 import android.view.animation.AccelerateInterpolator;
 import android.view.animation.Interpolator;
 
+import com.android.launcher3.DeviceProfile;
+import com.android.launcher3.Launcher;
 import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
 
-public class ScrimView extends View {
+public class ScrimView extends View implements DeviceProfile.LauncherLayoutChangeListener {
 
     private static final boolean DEBUG = false;
 
@@ -57,6 +59,10 @@
     private final Interpolator mAccelerator = new AccelerateInterpolator();
     private final Paint mDebugPaint = DEBUG ? new Paint() : null;
 
+    private int mPaddingLeft;
+    private int mPaddingRight;
+    private int mAlphaStart;
+
     public ScrimView(Context context, AttributeSet attrs) {
         super(context, attrs);
         mMaskHeight = Utilities.pxFromDp(MASK_HEIGHT_DP, getResources().getDisplayMetrics());
@@ -75,6 +81,21 @@
     }
 
     @Override
+    protected void onAttachedToWindow() {
+        super.onAttachedToWindow();
+        updatePaddingAndAlphaStart();
+        Launcher.getLauncher(getContext()).getDeviceProfile()
+                .addLauncherLayoutChangedListener(this);
+    }
+
+    @Override
+    protected void onDetachedFromWindow() {
+        super.onDetachedFromWindow();
+        Launcher.getLauncher(getContext()).getDeviceProfile()
+                .removeLauncherLayoutChangedListener(this);
+    }
+
+    @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
         int width = MeasureSpec.getSize(widthMeasureSpec);
@@ -91,7 +112,8 @@
         setTranslationY(linTranslationY);
 
         if (APPLY_ALPHA) {
-            int alpha = 55 + (int) (200f * mAccelerator.getInterpolation(progress));
+            int alpha = mAlphaStart + (int) ((255f - mAlphaStart)
+                    * mAccelerator.getInterpolation(progress));
             mPaint.setAlpha(alpha);
             invalidate();
         }
@@ -99,8 +121,8 @@
 
     @Override
     protected void onDraw(Canvas canvas) {
-        mAlphaMaskRect.set(0, 0, getWidth(), mMaskHeight);
-        mFinalMaskRect.set(0, mMaskHeight, getWidth(), getHeight());
+        mAlphaMaskRect.set(mPaddingLeft, 0, getWidth() - mPaddingRight, mMaskHeight);
+        mFinalMaskRect.set(mPaddingLeft, mMaskHeight, getWidth() - mPaddingRight, getHeight());
         canvas.drawBitmap(sAlphaScrimMask, null, mAlphaMaskRect, mPaint);
         canvas.drawBitmap(sFinalScrimMask, null, mFinalMaskRect, mPaint);
 
@@ -111,4 +133,23 @@
         }
     }
 
+    @Override
+    public void onLauncherLayoutChanged() {
+        updatePaddingAndAlphaStart();
+        invalidate();
+    }
+
+    private void updatePaddingAndAlphaStart() {
+        DeviceProfile grid = Launcher.getLauncher(getContext()).getDeviceProfile();
+        if (grid.isVerticalBarLayout()) {
+            int[] padding = grid.getContainerPadding();
+            mPaddingLeft = padding[0] + grid.edgeMarginPx;
+            mPaddingRight = padding[1] + grid.edgeMarginPx;
+            mAlphaStart = 0;
+        } else {
+            mPaddingLeft = 0;
+            mPaddingRight = 0;
+            mAlphaStart = 55;
+        }
+    }
 }