From ec4407b4ef47f397bec8bad9d2aec4078893d520 Mon Sep 17 00:00:00 2001 From: Zak Cohen Date: Thu, 1 Apr 2021 10:49:12 -0700 Subject: [PATCH] Overview - add the ability to color scrim task views. Bug: 184202238 Test: local build and flash Change-Id: If700cb6dffc3966fe860c40d98d40a5899c236e4 --- .../views/DigitalWellBeingToast.java | 15 ++++ .../com/android/quickstep/views/IconView.java | 14 ++++ .../android/quickstep/views/RecentsView.java | 10 +++ .../android/quickstep/views/TaskMenuView.java | 9 +-- .../quickstep/views/TaskThumbnailView.java | 68 +++++-------------- .../com/android/quickstep/views/TaskView.java | 48 +++++++++++-- src/com/android/launcher3/Utilities.java | 20 ++++++ 7 files changed, 123 insertions(+), 61 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java b/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java index 25ae055f71..deb674c4a0 100644 --- a/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java +++ b/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.java @@ -30,6 +30,7 @@ import android.content.Intent; import android.content.pm.LauncherApps; import android.content.pm.LauncherApps.AppUsageLimit; import android.graphics.Outline; +import android.graphics.Paint; import android.icu.text.MeasureFormat; import android.icu.text.MeasureFormat.FormatWidth; import android.icu.util.Measure; @@ -48,6 +49,7 @@ import androidx.annotation.StringRes; import com.android.launcher3.BaseActivity; import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.R; +import com.android.launcher3.Utilities; import com.android.systemui.shared.recents.model.Task; import java.time.Duration; @@ -297,4 +299,17 @@ public final class DigitalWellBeingToast { mBanner.setAlpha(alpha); } } + + void setBannerColorTint(int color, float amount) { + if (mBanner == null) { + return; + } + if (mBannerAlpha == 0 || amount == 0) { + mBanner.setLayerType(View.LAYER_TYPE_NONE, null); + } + Paint layerPaint = new Paint(); + layerPaint.setColorFilter(Utilities.makeColorTintingColorFilter(color, amount)); + mBanner.setLayerType(View.LAYER_TYPE_HARDWARE, layerPaint); + mBanner.setLayerPaint(layerPaint); + } } diff --git a/quickstep/src/com/android/quickstep/views/IconView.java b/quickstep/src/com/android/quickstep/views/IconView.java index ed642df7b4..5b0ade0d17 100644 --- a/quickstep/src/com/android/quickstep/views/IconView.java +++ b/quickstep/src/com/android/quickstep/views/IconView.java @@ -21,6 +21,8 @@ import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.View; +import com.android.launcher3.Utilities; + /** * A view which draws a drawable stretched to fit its size. Unlike ImageView, it avoids relayout * when the drawable changes. @@ -102,4 +104,16 @@ public class IconView extends View { setVisibility(INVISIBLE); } } + + /** + * Set the tint color of the icon, useful for scrimming or dimming. + * + * @param color to blend in. + * @param amount [0,1] 0 no tint, 1 full tint + */ + public void setIconColorTint(int color, float amount) { + if (mDrawable != null) { + mDrawable.setColorFilter(Utilities.makeColorTintingColorFilter(color, amount)); + } + } } diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index bf237fd141..5ea3dea89b 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -3223,6 +3223,16 @@ public abstract class RecentsView extends PagedView return mSizeStrategy; } + /** + * Set all the task views to color tint scrim mode, dimming or tinting them all. Allows the + * tasks to be dimmed while other elements in the recents view are left alone. + */ + public void showForegroundScrim(boolean show) { + for (int i = 0; i < getTaskViewCount(); i++) { + getTaskViewAt(i).showColorTint(show); + } + } + private boolean showAsGrid() { return mOverviewGridEnabled || (mCurrentGestureEndTarget != null && mSizeStrategy.stateFromGestureEndTarget( diff --git a/quickstep/src/com/android/quickstep/views/TaskMenuView.java b/quickstep/src/com/android/quickstep/views/TaskMenuView.java index a46daf38fd..0b84bc92a1 100644 --- a/quickstep/src/com/android/quickstep/views/TaskMenuView.java +++ b/quickstep/src/com/android/quickstep/views/TaskMenuView.java @@ -249,9 +249,11 @@ public class TaskMenuView extends AbstractFloatingView { final Animator revealAnimator = createOpenCloseOutlineProvider() .createRevealAnimator(this, closing); revealAnimator.setInterpolator(Interpolators.DEACCEL); - mOpenCloseAnimator.play(revealAnimator); - mOpenCloseAnimator.play(ObjectAnimator.ofFloat(mTaskView.getThumbnail(), DIM_ALPHA, - closing ? 0 : TaskView.MAX_PAGE_SCRIM_ALPHA)); + mOpenCloseAnimator.playTogether(revealAnimator, + ObjectAnimator.ofFloat( + mTaskView.getThumbnail(), DIM_ALPHA, + closing ? 0 : TaskView.MAX_PAGE_SCRIM_ALPHA), + ObjectAnimator.ofFloat(this, ALPHA, closing ? 0 : 1)); mOpenCloseAnimator.addListener(new AnimationSuccessListener() { @Override public void onAnimationStart(Animator animation) { @@ -265,7 +267,6 @@ public class TaskMenuView extends AbstractFloatingView { } } }); - mOpenCloseAnimator.play(ObjectAnimator.ofFloat(this, ALPHA, closing ? 0 : 1)); mOpenCloseAnimator.setDuration(closing ? REVEAL_CLOSE_DURATION: REVEAL_OPEN_DURATION); mOpenCloseAnimator.start(); } diff --git a/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java b/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java index af62582418..685f725707 100644 --- a/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java +++ b/quickstep/src/com/android/quickstep/views/TaskThumbnailView.java @@ -28,8 +28,6 @@ import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; -import android.graphics.ColorMatrix; -import android.graphics.ColorMatrixColorFilter; import android.graphics.Insets; import android.graphics.Matrix; import android.graphics.Paint; @@ -46,10 +44,10 @@ import android.view.Surface; import android.view.View; import androidx.annotation.RequiresApi; +import androidx.core.graphics.ColorUtils; import com.android.launcher3.BaseActivity; import com.android.launcher3.DeviceProfile; -import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper; @@ -67,10 +65,6 @@ import com.android.systemui.shared.recents.model.ThumbnailData; * A task in the Recents view. */ public class TaskThumbnailView extends View implements PluginListener { - - private static final ColorMatrix COLOR_MATRIX = new ColorMatrix(); - private static final ColorMatrix SATURATION_COLOR_MATRIX = new ColorMatrix(); - private static final MainThreadInitializedObject TEMP_PARAMS = new MainThreadInitializedObject<>(FullscreenDrawParams::new); @@ -89,11 +83,11 @@ public class TaskThumbnailView extends View implements PluginListener - * If dimAlpha is 0, no dimming is applied; if dimAlpha is 1, the thumbnail will be black. + * If dimAlpha is 0, no dimming is applied; if dimAlpha is 1, the thumbnail will be the + * extracted background color. + * */ public void setDimAlpha(float dimAlpha) { mDimAlpha = dimAlpha; @@ -359,15 +350,15 @@ public class TaskThumbnailView extends View implements PluginListener COLOR_TINT = + new FloatProperty("colorTint") { + @Override + public void setValue(TaskView taskView, float v) { + taskView.setColorTint(v); + } + + @Override + public Float get(TaskView taskView) { + return taskView.getColorTint(); + } + }; + private final OnAttachStateChangeListener mTaskMenuStateListener = new OnAttachStateChangeListener() { @Override @@ -314,6 +325,11 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { private final float[] mIconCenterCoords = new float[2]; private final float[] mChipCenterCoords = new float[2]; + // Colored tint for the task view and all its supplementary views (like the task icon and well + // being banner. + private final int mTintingColor; + private float mTintAmount; + private boolean mIsClickableAsLiveTile = true; public TaskView(Context context) { @@ -375,6 +391,8 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { mOutlineProvider = new TaskOutlineProvider(getContext(), mCurrentFullscreenParams, mActivity.getDeviceProfile().overviewTaskThumbnailTopMarginPx); setOutlineProvider(mOutlineProvider); + + mTintingColor = Themes.getColorBackgroundFloating(context); } /** @@ -722,7 +740,6 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { progress = 1 - progress; } mFocusTransitionProgress = progress; - mSnapshotView.setDimAlphaMultipler(0); float iconScalePercentage = (float) SCALE_ICON_DURATION / DIM_ANIM_DURATION; float lowerClamp = invert ? 1f - iconScalePercentage : 0; float upperClamp = invert ? 1 : iconScalePercentage; @@ -781,6 +798,7 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { setTranslationZ(0); setAlpha(mStableAlpha); setIconScaleAndDim(1); + setColorTint(0); } public void setStableAlpha(float parentAlpha) { @@ -1302,6 +1320,26 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { rv.initiateSplitSelect(this, splitPositionOption); } + private void setColorTint(float amount) { + mSnapshotView.setDimAlpha(amount); + mIconView.setIconColorTint(mTintingColor, amount); + mDigitalWellBeingToast.setBannerColorTint(mTintingColor, amount); + } + + private float getColorTint() { + return mTintAmount; + } + + /** + * Show the task view with a color tint (animates value). + */ + public void showColorTint(boolean enable) { + ObjectAnimator tintAnimator = ObjectAnimator.ofFloat( + this, COLOR_TINT, enable ? MAX_PAGE_SCRIM_ALPHA : 0); + tintAnimator.setAutoCancel(true); + tintAnimator.start(); + } + /** * We update and subsequently draw these in {@link #setFullscreenProgress(float)}. */ diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 8825710401..1776777934 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -37,6 +37,8 @@ import android.content.res.Resources; import android.database.ContentObserver; import android.graphics.Bitmap; import android.graphics.Color; +import android.graphics.ColorFilter; +import android.graphics.LightingColorFilter; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Point; @@ -64,6 +66,7 @@ import android.view.View; import android.view.ViewConfiguration; import android.view.animation.Interpolator; +import androidx.core.graphics.ColorUtils; import androidx.core.os.BuildCompat; import com.android.launcher3.dragndrop.FolderAdaptiveIcon; @@ -732,6 +735,23 @@ public final class Utilities { } } + /** + * Make a color filter that blends a color into the destination based on a scalable amout. + * + * @param color to blend in. + * @param tintAmount [0-1] 0 no tinting, 1 full color. + * @return ColorFilter for tinting, or {@code null} if no filter is needed. + */ + public static ColorFilter makeColorTintingColorFilter(int color, float tintAmount) { + if (tintAmount == 0f) { + return null; + } + return new LightingColorFilter( + // This isn't blending in white, its making a multiplication mask for the base color + ColorUtils.blendARGB(Color.WHITE, 0, tintAmount), + ColorUtils.blendARGB(0, color, tintAmount)); + } + private static class FixedSizeEmptyDrawable extends ColorDrawable { private final int mSize;