Allapps motion changes for landscape
Bug: 38230696 Change-Id: I82e36c240c934ff6b86b55e0a0f07391fd11ec82
This commit is contained in:
parent
66714d3cb7
commit
d15dccf10e
|
@ -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>
|
|
@ -29,10 +29,12 @@ import android.view.View;
|
|||
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 @@ public class ScrimView extends View {
|
|||
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());
|
||||
|
@ -74,6 +80,21 @@ public class ScrimView extends View {
|
|||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
|
@ -91,7 +112,8 @@ public class ScrimView extends View {
|
|||
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 @@ public class ScrimView extends View {
|
|||
|
||||
@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 @@ public class ScrimView extends View {
|
|||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue