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

Commit c9986f59 authored by Tony Wickham's avatar Tony Wickham Committed by Android (Google) Code Review
Browse files

Merge "Remove TaskViewDrawable, scale RecentsView instead" into ub-launcher3-qt-dev

parents b05fbb89 1eb65b8a
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS;
import com.android.launcher3.Launcher;
import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.quickstep.util.ClipAnimationHelper;
import com.android.quickstep.util.LayoutUtils;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskView;
@@ -61,8 +62,8 @@ public class BackgroundAppState extends OverviewState {
            return super.getOverviewScaleAndTranslation(launcher);
        }
        TaskView dummyTask = recentsView.getTaskViewAt(recentsView.getCurrentPage());
        return recentsView.getTempClipAnimationHelper()
                .getOverviewFullscreenScaleAndTranslation(dummyTask);
        return recentsView.getTempClipAnimationHelper().updateForFullscreenOverview(dummyTask)
                .getScaleAndTranslation();
    }

    @Override
+3 −2
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@ package com.android.launcher3.uioverrides.touchcontrollers;
import static com.android.launcher3.AbstractFloatingView.TYPE_ACCESSIBLE;
import static com.android.launcher3.Utilities.SINGLE_FRAME_MS;
import static com.android.launcher3.anim.Interpolators.scrollInterpolatorForVelocity;
import static com.android.launcher3.config.FeatureFlags.QUICKSTEP_SPRINGS;
import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE;
import static com.android.launcher3.config.FeatureFlags.QUICKSTEP_SPRINGS;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
@@ -231,7 +231,8 @@ public abstract class TaskViewTouchController<T extends BaseDraggingActivity>
        } else {
            mFlingBlockCheck.onEvent();
        }
        mCurrentAnimation.setPlayFraction(totalDisplacement * mProgressMultiplier);
        mCurrentAnimation.setPlayFraction(Utilities.boundToRange(
                totalDisplacement * mProgressMultiplier, 0, 1));

        if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
            if (mRecentsView.getCurrentPage() != 0 || isGoingUp) {
+8 −26
Original line number Diff line number Diff line
@@ -285,13 +285,20 @@ public class ClipAnimationHelper {
    /**
     * Compute scale and translation y such that the specified task view fills the screen.
     */
    public LauncherState.ScaleAndTranslation getOverviewFullscreenScaleAndTranslation(TaskView v) {
    public ClipAnimationHelper updateForFullscreenOverview(TaskView v) {
        TaskThumbnailView thumbnailView = v.getThumbnail();
        RecentsView recentsView = v.getRecentsView();
        fromTaskThumbnailView(thumbnailView, recentsView);
        Rect taskSize = new Rect();
        recentsView.getTaskSize(taskSize);
        updateTargetRect(taskSize);
        return this;
    }

    /**
     * @return The source rect's scale and translation relative to the target rect.
     */
    public LauncherState.ScaleAndTranslation getScaleAndTranslation() {
        float scale = mSourceRect.width() / mTargetRect.width();
        float translationY = mSourceRect.centerY() - mSourceRect.top - mTargetRect.centerY();
        return new LauncherState.ScaleAndTranslation(scale, 0, translationY);
@@ -332,35 +339,10 @@ public class ClipAnimationHelper {
        mSourceStackBounds.offset(left, insets.top + fullDp.availableHeightPx - taskHeight);
    }

    public void drawForProgress(TaskThumbnailView ttv, Canvas canvas, float progress) {
        RectF currentRect =  mRectFEvaluator.evaluate(progress, mSourceRect, mTargetRect);
        canvas.translate(mSourceStackBounds.left - mHomeStackBounds.left,
                mSourceStackBounds.top - mHomeStackBounds.top);
        mTmpMatrix.setRectToRect(mTargetRect, currentRect, ScaleToFit.FILL);

        canvas.concat(mTmpMatrix);
        canvas.translate(mTargetRect.left, mTargetRect.top);

        float scale = mTargetRect.width() / mSourceRect.width();
        float insetProgress = (1 - progress);
        float windowCornerRadius = mUseRoundedCornersOnWindows
                ? mWindowCornerRadius : 0;
        ttv.drawOnCanvas(canvas,
                -mSourceWindowClipInsets.left * insetProgress,
                -mSourceWindowClipInsets.top * insetProgress,
                ttv.getMeasuredWidth() + mSourceWindowClipInsets.right * insetProgress,
                ttv.getMeasuredHeight() + mSourceWindowClipInsets.bottom * insetProgress,
                Utilities.mapRange(progress, windowCornerRadius * scale, ttv.getCornerRadius()));
    }

    public RectF getTargetRect() {
        return mTargetRect;
    }

    public RectF getSourceRect() {
        return mSourceRect;
    }

    public float getCurrentCornerRadius() {
        return mCurrentCornerRadius;
    }
+0 −151
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.quickstep.util;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.util.FloatProperty;
import android.view.View;

import com.android.launcher3.BaseActivity;
import com.android.launcher3.Utilities;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskThumbnailView;
import com.android.quickstep.views.TaskView;

public class TaskViewDrawable extends Drawable {

    public static final FloatProperty<TaskViewDrawable> PROGRESS =
            new FloatProperty<TaskViewDrawable>("progress") {
                @Override
                public void setValue(TaskViewDrawable taskViewDrawable, float v) {
                    taskViewDrawable.setProgress(v);
                }

                @Override
                public Float get(TaskViewDrawable taskViewDrawable) {
                    return taskViewDrawable.mProgress;
                }
            };

    /**
     * The progress at which we play the atomic icon scale animation.
     */
    private static final float ICON_SCALE_THRESHOLD = 0.95f;

    private final RecentsView mParent;
    private final View mIconView;
    private final float[] mIconPos;
    private final TaskView mTaskView;

    private final TaskThumbnailView mThumbnailView;

    private final ClipAnimationHelper mClipAnimationHelper;

    private float mProgress = 1;
    private boolean mPassedIconScaleThreshold;
    private ValueAnimator mIconScaleAnimator;
    private float mIconScale;

    public TaskViewDrawable(TaskView tv, RecentsView parent) {
        mParent = parent;
        mTaskView = tv;
        mIconView = tv.getIconView();
        mIconPos = new float[2];
        mIconScale = mIconView.getScaleX();
        Utilities.getDescendantCoordRelativeToAncestor(mIconView, parent, mIconPos, true);

        mThumbnailView = tv.getThumbnail();
        mClipAnimationHelper = new ClipAnimationHelper(parent.getContext());
        mClipAnimationHelper.fromTaskThumbnailView(mThumbnailView, parent);
        mClipAnimationHelper.prepareAnimation(
                BaseActivity.fromContext(tv.getContext()).getDeviceProfile(), true /* isOpening */);
    }

    public void setProgress(float progress) {
        mProgress = progress;
        mParent.invalidate();
        boolean passedIconScaleThreshold = progress <= ICON_SCALE_THRESHOLD;
        if (mPassedIconScaleThreshold != passedIconScaleThreshold) {
            mPassedIconScaleThreshold = passedIconScaleThreshold;
            animateIconScale(mPassedIconScaleThreshold ? 0 : 1);
        }
    }

    private void animateIconScale(float toScale) {
        if (mIconScaleAnimator != null) {
            mIconScaleAnimator.cancel();
        }
        mIconScaleAnimator = ValueAnimator.ofFloat(mIconScale, toScale);
        mIconScaleAnimator.addUpdateListener(valueAnimator -> {
            mIconScale = (float) valueAnimator.getAnimatedValue();
            if (mProgress > ICON_SCALE_THRESHOLD) {
                // Speed up the icon scale to ensure it is 1 when progress is 1.
                float iconProgress = (mProgress - ICON_SCALE_THRESHOLD) / (1 - ICON_SCALE_THRESHOLD);
                if (iconProgress > mIconScale) {
                    mIconScale = iconProgress;
                }
            }
            invalidateSelf();
        });
        mIconScaleAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mIconScaleAnimator = null;
            }
        });
        mIconScaleAnimator.setDuration(TaskView.SCALE_ICON_DURATION);
        mIconScaleAnimator.start();
    }

    @Override
    public void draw(Canvas canvas) {
        canvas.save();
        canvas.translate(mParent.getScrollX(), mParent.getScrollY());
        mClipAnimationHelper.drawForProgress(mThumbnailView, canvas, mProgress);
        canvas.restore();

        canvas.save();
        canvas.translate(mIconPos[0], mIconPos[1]);
        canvas.scale(mIconScale, mIconScale, mIconView.getWidth() / 2, mIconView.getHeight() / 2);
        mIconView.draw(canvas);
        canvas.restore();
    }

    public ClipAnimationHelper getClipAnimationHelper() {
        return mClipAnimationHelper;
    }

    @Override
    public void setAlpha(int i) { }

    @Override
    public void setColorFilter(ColorFilter colorFilter) { }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }

    public TaskView getTaskView() {
        return mTaskView;
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
@@ -178,6 +179,21 @@ public class LauncherRecentsView extends RecentsView<Launcher> {
        return anim;
    }

    @Override
    protected void onTaskLaunchAnimationUpdate(float progress, TaskView tv) {
        if (ENABLE_QUICKSTEP_LIVE_TILE.get()) {
            if (mRecentsAnimationWrapper.targetSet != null && tv.isRunningTask()) {
                mTransformParams.setProgress(1 - progress)
                        .setSyncTransactionApplier(mSyncTransactionApplier)
                        .setForLiveTile(true);
                mClipAnimationHelper.applyTransform(mRecentsAnimationWrapper.targetSet,
                        mTransformParams);
            } else {
                redrawLiveTile(true);
            }
        }
    }

    @Override
    public PendingAnimation createTaskDismissAnimation(TaskView taskView, boolean animateTaskView,
            boolean shouldRemoveTask, long duration) {
Loading