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

Commit b2d2442a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Color extracted gradient on Overview"

parents d4610749 6672fb4e
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);
        }
    }
}