From d43e7c2fd40ed58edafa874bfae732a2edbca823 Mon Sep 17 00:00:00 2001 From: Tracy Zhou Date: Tue, 16 Oct 2018 14:49:55 -0700 Subject: [PATCH] Support Live Tile in Quickstep (Pt1) - Z ordering - Place Launcher above app surface. - Use LauncherLayoutListener to clear the area where the current task is in order to punch a hole and reveal the app view underneath Bug: 111697218 Test: Manual test Change-Id: I4d4e0f1113a8e60566257c030ae9b591789eb3b3 --- .../launcher3/uioverrides/AllAppsState.java | 3 +- .../launcher3/uioverrides/OverviewState.java | 3 +- .../quickstep/ActivityControlHelper.java | 6 +++ .../WindowTransformSwipeHandler.java | 7 +++- .../quickstep/util/ClipAnimationHelper.java | 29 ++++++++------ .../views/LauncherLayoutListener.java | 38 +++++++++++++++---- .../launcher3/AbstractFloatingView.java | 11 ++++++ 7 files changed, 75 insertions(+), 22 deletions(-) diff --git a/quickstep/src/com/android/launcher3/uioverrides/AllAppsState.java b/quickstep/src/com/android/launcher3/uioverrides/AllAppsState.java index 1eaa8bc92c..1906286030 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/AllAppsState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/AllAppsState.java @@ -15,6 +15,7 @@ */ package com.android.launcher3.uioverrides; +import static com.android.launcher3.AbstractFloatingView.TYPE_QUICKSTEP_PREVIEW; import static com.android.launcher3.LauncherAnimUtils.ALL_APPS_TRANSITION_MS; import static com.android.launcher3.anim.Interpolators.DEACCEL_2; @@ -44,7 +45,7 @@ public class AllAppsState extends LauncherState { @Override public void onStateEnabled(Launcher launcher) { - AbstractFloatingView.closeAllOpenViews(launcher); + AbstractFloatingView.closeAllOpenViewsExcept(launcher, TYPE_QUICKSTEP_PREVIEW); dispatchWindowStateChanged(launcher); } diff --git a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java index 0d77bca58b..8f1d46c8d5 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/OverviewState.java @@ -15,6 +15,7 @@ */ package com.android.launcher3.uioverrides; +import static com.android.launcher3.AbstractFloatingView.TYPE_QUICKSTEP_PREVIEW; import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS; import static com.android.launcher3.anim.Interpolators.DEACCEL_2; import static com.android.launcher3.states.RotationHelper.REQUEST_ROTATE; @@ -74,7 +75,7 @@ public class OverviewState extends LauncherState { public void onStateEnabled(Launcher launcher) { RecentsView rv = launcher.getOverviewPanel(); rv.setOverviewStateEnabled(true); - AbstractFloatingView.closeAllOpenViews(launcher); + AbstractFloatingView.closeAllOpenViewsExcept(launcher, TYPE_QUICKSTEP_PREVIEW); } @Override diff --git a/quickstep/src/com/android/quickstep/ActivityControlHelper.java b/quickstep/src/com/android/quickstep/ActivityControlHelper.java index 2331a4e302..c809e28320 100644 --- a/quickstep/src/com/android/quickstep/ActivityControlHelper.java +++ b/quickstep/src/com/android/quickstep/ActivityControlHelper.java @@ -40,6 +40,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.graphics.Rect; +import android.graphics.RectF; import android.os.Build; import android.os.Handler; import android.os.Looper; @@ -537,6 +538,9 @@ public interface ActivityControlHelper { @Override public void finish() { } + + @Override + public void update(boolean shouldFinish, boolean isLongSwipe, RectF currentRect) { } }; } @@ -613,6 +617,8 @@ public interface ActivityControlHelper { void setHandler(WindowTransformSwipeHandler handler); void finish(); + + void update(boolean shouldFinish, boolean isLongSwipe, RectF currentRect); } interface ActivityInitListener { diff --git a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java index 6908b89783..9ea88842d7 100644 --- a/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java +++ b/quickstep/src/com/android/quickstep/WindowTransformSwipeHandler.java @@ -597,6 +597,11 @@ public class WindowTransformSwipeHandler { } private void updateFinalShiftUi() { + if (mRecentsAnimationWrapper.getController() != null && mLayoutListener != null) { + mLayoutListener.update(mCurrentShift.value > 1, mUiLongSwipeMode, + mClipAnimationHelper.getCurrentRectWithInsets()); + } + final boolean passed = mCurrentShift.value >= MIN_PROGRESS_FOR_OVERVIEW; if (passed != mPassedOverviewThreshold) { mPassedOverviewThreshold = passed; @@ -874,7 +879,6 @@ public class WindowTransformSwipeHandler { mLayoutListener.finish(); mActivityControlHelper.getAlphaProperty(mActivity).setValue(1); - mRecentsView.setRunningTaskHidden(false); mRecentsView.setRunningTaskIconScaledDown(false); mQuickScrubController.cancelActiveQuickscrub(); } @@ -895,6 +899,7 @@ public class WindowTransformSwipeHandler { if (mWasLauncherAlreadyVisible && mLauncherTransitionController != null) { mLauncherTransitionController.setPlayFraction(1); } + mRecentsView.setRunningTaskHidden(false); } private void switchToScreenshot() { diff --git a/quickstep/src/com/android/quickstep/util/ClipAnimationHelper.java b/quickstep/src/com/android/quickstep/util/ClipAnimationHelper.java index 8c84f29b7d..57a0e8f8f7 100644 --- a/quickstep/src/com/android/quickstep/util/ClipAnimationHelper.java +++ b/quickstep/src/com/android/quickstep/util/ClipAnimationHelper.java @@ -77,10 +77,11 @@ public class ClipAnimationHelper { public final Rect mHomeStackBounds = new Rect(); // The clip rect in source app window coordinates - private final Rect mClipRect = new Rect(); + private final RectF mClipRectF = new RectF(); private final RectFEvaluator mRectFEvaluator = new RectFEvaluator(); private final Matrix mTmpMatrix = new Matrix(); private final RectF mTmpRectF = new RectF(); + private final RectF mCurrentRectWithInsets = new RectF(); private float mTargetScale = 1f; private float mOffsetScale = 1f; @@ -153,12 +154,12 @@ public class ClipAnimationHelper { mTargetOffset.y * offsetYProgress); } - mClipRect.left = (int) (mSourceWindowClipInsets.left * progress); - mClipRect.top = (int) (mSourceWindowClipInsets.top * progress); - mClipRect.right = (int) - (mSourceStackBounds.width() - (mSourceWindowClipInsets.right * progress)); - mClipRect.bottom = (int) - (mSourceStackBounds.height() - (mSourceWindowClipInsets.bottom * progress)); + mClipRectF.left = mSourceWindowClipInsets.left * progress; + mClipRectF.top = mSourceWindowClipInsets.top * progress; + mClipRectF.right = + mSourceStackBounds.width() - (mSourceWindowClipInsets.right * progress); + mClipRectF.bottom = + mSourceStackBounds.height() - (mSourceWindowClipInsets.bottom * progress); SurfaceParams[] params = new SurfaceParams[targetSet.unfilteredApps.length]; for (int i = 0; i < targetSet.unfilteredApps.length; i++) { @@ -166,11 +167,12 @@ public class ClipAnimationHelper { mTmpMatrix.setTranslate(app.position.x, app.position.y); Rect crop = app.sourceContainerBounds; float alpha = 1f; + int layer; if (app.mode == targetSet.targetMode) { if (app.activityType != RemoteAnimationTargetCompat.ACTIVITY_TYPE_HOME) { mTmpMatrix.setRectToRect(mSourceRect, currentRect, ScaleToFit.FILL); mTmpMatrix.postTranslate(app.position.x, app.position.y); - crop = mClipRect; + mClipRectF.roundOut(crop); } if (app.isNotInRecents @@ -179,17 +181,22 @@ public class ClipAnimationHelper { } alpha = mTaskAlphaCallback.apply(app, alpha); + layer = RemoteAnimationProvider.getLayer(app, mBoostModeTargetLayers); } else { crop = null; + layer = Integer.MAX_VALUE; } - - params[i] = new SurfaceParams(app.leash, alpha, mTmpMatrix, crop, - RemoteAnimationProvider.getLayer(app, mBoostModeTargetLayers)); + params[i] = new SurfaceParams(app.leash, alpha, mTmpMatrix, crop, layer); } applyParams(syncTransactionApplier, params); return currentRect; } + public RectF getCurrentRectWithInsets() { + mTmpMatrix.mapRect(mCurrentRectWithInsets, mClipRectF); + return mCurrentRectWithInsets; + } + private void applyParams(@Nullable SyncRtSurfaceTransactionApplier syncTransactionApplier, SurfaceParams[] params) { if (syncTransactionApplier != null) { diff --git a/quickstep/src/com/android/quickstep/views/LauncherLayoutListener.java b/quickstep/src/com/android/quickstep/views/LauncherLayoutListener.java index 61740d729b..c12a579686 100644 --- a/quickstep/src/com/android/quickstep/views/LauncherLayoutListener.java +++ b/quickstep/src/com/android/quickstep/views/LauncherLayoutListener.java @@ -15,11 +15,17 @@ */ package com.android.quickstep.views; -import static com.android.launcher3.states.RotationHelper.REQUEST_LOCK; +import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static com.android.launcher3.states.RotationHelper.REQUEST_NONE; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; import android.graphics.Rect; +import android.graphics.RectF; import android.view.MotionEvent; +import android.widget.FrameLayout; import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.Insettable; @@ -34,12 +40,28 @@ public class LauncherLayoutListener extends AbstractFloatingView implements Insettable, LayoutListener { private final Launcher mLauncher; + private final Paint mPaint = new Paint(); private WindowTransformSwipeHandler mHandler; + private RectF mCurrentRect; public LauncherLayoutListener(Launcher launcher) { super(launcher, null); mLauncher = launcher; - setVisibility(INVISIBLE); + mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); + setLayoutParams(new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); + } + + @Override + public void update(boolean shouldFinish, boolean isLongSwipe, RectF currentRect) { + if (shouldFinish) { + finish(); + return; + } + + mCurrentRect = currentRect; + + setWillNotDraw(mCurrentRect == null || isLongSwipe); + invalidate(); } @Override @@ -80,11 +102,6 @@ public class LauncherLayoutListener extends AbstractFloatingView } } - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - setMeasuredDimension(1, 1); - } - @Override public void logActionCommand(int command) { // We should probably log the weather @@ -97,8 +114,13 @@ public class LauncherLayoutListener extends AbstractFloatingView @Override public void finish() { - setHandler(null); close(false); + setHandler(null); mLauncher.getRotationHelper().setStateHandlerRequest(REQUEST_NONE); } + + @Override + protected void onDraw(Canvas canvas) { + canvas.drawRect(mCurrentRect, mPaint); + } } diff --git a/src/com/android/launcher3/AbstractFloatingView.java b/src/com/android/launcher3/AbstractFloatingView.java index 45751328a8..7cab18d8d3 100644 --- a/src/com/android/launcher3/AbstractFloatingView.java +++ b/src/com/android/launcher3/AbstractFloatingView.java @@ -219,6 +219,17 @@ public abstract class AbstractFloatingView extends LinearLayout implements Touch closeAllOpenViews(activity, true); } + public static void closeAllOpenViewsExcept(ActivityContext activity, boolean animate, + @FloatingViewType int type) { + closeOpenViews(activity, animate, TYPE_ALL & ~type); + activity.finishAutoCancelActionMode(); + } + + public static void closeAllOpenViewsExcept(ActivityContext activity, + @FloatingViewType int type) { + closeAllOpenViewsExcept(activity, true, type); + } + public static AbstractFloatingView getTopOpenView(ActivityContext activity) { return getTopOpenViewWithType(activity, TYPE_ALL); }