Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6672fb4e authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Color extracted gradient on Overview

Picking system wallpaper colors and drawing them
instead of the default black overlay.
Alpha also changed to 80% to match new designs.

Bug: 37013382
Test: visual - background color shouldn't be black
Change-Id: I8d68fa03729f663a701b49ad179b15040fe2b0bd
parent 072661f5
Loading
Loading
Loading
Loading
+32 −11
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.app.ActivityOptions.OnAnimationStartedListener;
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -76,6 +77,9 @@ import com.android.systemui.recents.views.RecentsTransitionHelper.AnimationSpecC
import com.android.systemui.stackdivider.WindowManagerProxy;
import com.android.systemui.statusbar.FlingAnimationUtils;

import com.google.android.colorextraction.ColorExtractor;
import com.google.android.colorextraction.drawable.GradientDrawable;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -85,13 +89,12 @@ import java.util.List;
 * This view is the the top level layout that contains TaskStacks (which are laid out according
 * to their SpaceNode bounds.
 */
public class RecentsView extends FrameLayout {
public class RecentsView extends FrameLayout implements ColorExtractor.OnColorsChangedListener {

    private static final String TAG = "RecentsView";

    private static final int DEFAULT_UPDATE_SCRIM_DURATION = 200;
    private static final float DEFAULT_SCRIM_ALPHA = 0.33f;
    private static final float GRID_LAYOUT_SCRIM_ALPHA = 0.45f;
    private static final float DEFAULT_SCRIM_ALPHA = 0.8f;

    private static final int SHOW_STACK_ACTION_BUTTON_DURATION = 134;
    private static final int HIDE_STACK_ACTION_BUTTON_DURATION = 100;
@@ -108,7 +111,8 @@ public class RecentsView extends FrameLayout {
    private int mDividerSize;

    private final float mScrimAlpha;
    private final Drawable mBackgroundScrim;
    private final GradientDrawable mBackgroundScrim;
    private final ColorExtractor mColorExtractor;
    private Animator mBackgroundScrimAnimator;

    private RecentsTransitionHelper mTransitionHelper;
@@ -137,10 +141,15 @@ public class RecentsView extends FrameLayout {
        mDividerSize = ssp.getDockedDividerSize(context);
        mTouchHandler = new RecentsViewTouchHandler(this);
        mFlingAnimationUtils = new FlingAnimationUtils(context, 0.3f);
        mScrimAlpha = Recents.getConfiguration().isGridEnabled
                ? GRID_LAYOUT_SCRIM_ALPHA : DEFAULT_SCRIM_ALPHA;
        mBackgroundScrim = new ColorDrawable(
                Color.argb((int) (mScrimAlpha * 255), 0, 0, 0)).mutate();
        mScrimAlpha = DEFAULT_SCRIM_ALPHA;
        mBackgroundScrim = new GradientDrawable(context);
        mBackgroundScrim.setCallback(this);
        mBackgroundScrim.setAlpha((int) (mScrimAlpha * 255));
        mColorExtractor = new ColorExtractor(context);
        mColorExtractor.setListener(this);
        // We don't want to interpolate colors because we're defining the initial state.
        // Gradient should be set/ready when you open "Recents".
        mBackgroundScrim.setColors(mColorExtractor.getColors(WallpaperManager.FLAG_SYSTEM), false);

        LayoutInflater inflater = LayoutInflater.from(context);
        if (RecentsDebugFlags.Static.EnableStackActionButton) {
@@ -188,7 +197,7 @@ public class RecentsView extends FrameLayout {
            // the tasks for the home animation.
            if (launchState.launchedViaDockGesture || launchState.launchedFromApp
                    || isTaskStackEmpty) {
                mBackgroundScrim.setAlpha(255);
                mBackgroundScrim.setAlpha((int) (mScrimAlpha * 255));
            } else {
                mBackgroundScrim.setAlpha(0);
            }
@@ -373,6 +382,11 @@ public class RecentsView extends FrameLayout {
            mEmptyView.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
        }

        // Needs to know the screen size since the gradient never scales up or down
        // even when bounds change.
        mBackgroundScrim.setScreenSize(right - left, bottom - top);
        mBackgroundScrim.setBounds(left, top, right, bottom);

        if (RecentsDebugFlags.Static.EnableStackActionButton) {
            // Layout the stack action button such that its drawable is start-aligned with the
            // stack, vertically centered in the available space above the stack
@@ -763,8 +777,8 @@ public class RecentsView extends FrameLayout {
    private void animateBackgroundScrim(float alpha, int duration) {
        Utilities.cancelAnimationWithoutCallbacks(mBackgroundScrimAnimator);
        // Calculate the absolute alpha to animate from
        int fromAlpha = (int) ((mBackgroundScrim.getAlpha() / (mScrimAlpha * 255)) * 255);
        int toAlpha = (int) (alpha * 255);
        int fromAlpha = mBackgroundScrim.getAlpha();
        int toAlpha = (int) (alpha * mScrimAlpha * 255);
        mBackgroundScrimAnimator = ObjectAnimator.ofInt(mBackgroundScrim, Utilities.DRAWABLE_ALPHA,
                fromAlpha, toAlpha);
        mBackgroundScrimAnimator.setDuration(duration);
@@ -807,4 +821,11 @@ public class RecentsView extends FrameLayout {
            mTaskStackView.dump(innerPrefix, writer);
        }
    }

    @Override
    public void onColorsChanged(ColorExtractor.GradientColors colors, int which) {
        if ((which & WallpaperManager.FLAG_SYSTEM) != 0) {
            mBackgroundScrim.setColors(colors);
        }
    }
}