Allapps motion changes for landscape

Bug: 38230696
Change-Id: I82e36c240c934ff6b86b55e0a0f07391fd11ec82
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/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;
+        }
+    }
 }