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

Commit dedbc8ac authored by Alex Chau's avatar Alex Chau
Browse files

Remove grid scaling in Overveiw

- Grid scaling has problem that scales task icon and menu, which makes it hard to control icon size and text size in the manula
- Replaced the whole concept with dedicated Task size calculation in grid layout
- Support different icon size in TaskView in grid and removed task_thumbnail_top_margin
- Removed grid progress in TaskViewSimulator as well
- Refactored how ClearAllButton scroll and translations are calcualted to align clear all properly in grid
- Make page center calculation aware of PagedView pivot and scaling

Bug: 174464863
Test: Manual on two screens
Change-Id: I47b13ef6e55c6e16c52ea04225f5bde02ed82fc2
parent 21aa7042
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

<resources>
    <dimen name="task_thumbnail_icon_size">48dp</dimen>
    <dimen name="task_thumbnail_icon_size_grid">32dp</dimen>
    <!-- For screens without rounded corners -->
    <dimen name="task_corner_radius_small">2dp</dimen>

+5 −6
Original line number Diff line number Diff line
@@ -923,6 +923,9 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
        float currentShift = mCurrentShift.value;
        final GestureEndTarget endTarget = calculateEndTarget(velocity, endVelocity,
                isFling, isCancel);
        // Set the state, but don't notify until the animation completes
        mGestureState.setEndTarget(endTarget, false /* isAtomic */);

        float endShift = endTarget.isLauncher ? 1 : 0;
        final float startShift;
        if (!isFling) {
@@ -945,7 +948,7 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
        }
        Interpolator interpolator;
        S state = mActivityInterface.stateFromGestureEndTarget(endTarget);
        if (state.displayOverviewTasksAsGrid(mActivity.getDeviceProfile())) {
        if (state.displayOverviewTasksAsGrid(mDp)) {
            interpolator = ACCEL_DEACCEL;
        } else if (endTarget == RECENTS) {
            interpolator = OVERSHOOT_1_2;
@@ -1055,8 +1058,6 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
    @UiThread
    private void animateToProgressInternal(float start, float end, long duration,
            Interpolator interpolator, GestureEndTarget target, PointF velocityPxPerMs) {
        // Set the state, but don't notify until the animation completes
        mGestureState.setEndTarget(target, false /* isAtomic */);
        maybeUpdateRecentsAttachedState();

        // If we are transitioning to launcher, then listen for the activity to be restarted while
@@ -1147,10 +1148,8 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
            });
            animatorSet.play(windowAnim);
            S state = mActivityInterface.stateFromGestureEndTarget(mGestureState.getEndTarget());
            if (mRecentsView != null && state.displayOverviewTasksAsGrid(
                    mActivity.getDeviceProfile())) {
            if (mRecentsView != null && state.displayOverviewTasksAsGrid(mDp)) {
                animatorSet.play(ObjectAnimator.ofFloat(mRecentsView, RECENTS_GRID_PROGRESS, 1));
                animatorSet.play(mTaskViewSimulator.gridProgress.animateToValue(0, 1));
            }
            animatorSet.setDuration(duration).setInterpolator(interpolator);
            animatorSet.start();
+57 −31
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.animation.Animator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Build;
import android.view.Gravity;
@@ -43,6 +44,7 @@ import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.statehandlers.DepthController;
import com.android.launcher3.statemanager.BaseState;
import com.android.launcher3.statemanager.StatefulActivity;
@@ -195,12 +197,29 @@ public abstract class BaseActivityInterface<STATE_TYPE extends BaseState<STATE_T
    }

    /**
     * Calculates the taskView size for the provided device configuration
     * Calculates the taskView size for the provided device configuration.
     */
    public final void calculateTaskSize(Context context, DeviceProfile dp, Rect outRect,
            PagedOrientationHandler orientedState) {
        Resources res = context.getResources();

        if (dp.isTablet && FeatureFlags.ENABLE_OVERVIEW_GRID.get()) {
            Rect gridRect = new Rect();
            calculateGridSize(context, dp, gridRect);

            int rowSpacing = res.getDimensionPixelSize(R.dimen.overview_grid_row_spacing);
            float rowHeight = (gridRect.height() - rowSpacing) / 2f;

            PointF taskDimension = getTaskDimension(context, dp);
            float scale = (rowHeight - dp.overviewTaskThumbnailTopMarginPx) / Math.max(
                    taskDimension.x, taskDimension.y);
            int outWidth = Math.round(scale * taskDimension.x);
            int outHeight = Math.round(scale * taskDimension.y);

            int gravity = Gravity.TOP;
            gravity |= orientedState.getRecentsRtlSetting(res) ? Gravity.RIGHT : Gravity.LEFT;
            gridRect.inset(0, dp.overviewTaskThumbnailTopMarginPx, 0, 0);
            Gravity.apply(gravity, outWidth, outHeight, gridRect, outRect);
        } else {
            int taskMargin = dp.overviewTaskMarginPx;
            int proactiveRowAndMargin;
            if (dp.isVerticalBarLayout()) {
@@ -208,7 +227,8 @@ public abstract class BaseActivityInterface<STATE_TYPE extends BaseState<STATE_T
                // the actions row.
                proactiveRowAndMargin = 0;
            } else {
            proactiveRowAndMargin = res.getDimensionPixelSize(R.dimen.overview_proactive_row_height)
                proactiveRowAndMargin = res.getDimensionPixelSize(
                        R.dimen.overview_proactive_row_height)
                        + res.getDimensionPixelSize(R.dimen.overview_proactive_row_bottom_margin);
            }
            calculateTaskSizeInternal(context, dp,
@@ -217,23 +237,13 @@ public abstract class BaseActivityInterface<STATE_TYPE extends BaseState<STATE_T
                    res.getDimensionPixelSize(R.dimen.overview_minimum_next_prev_size) + taskMargin,
                    outRect);
        }
    }

    private void calculateTaskSizeInternal(Context context, DeviceProfile dp,
            int claimedSpaceAbove, int claimedSpaceBelow, int minimumHorizontalPadding,
            Rect outRect) {
        float taskWidth, taskHeight;
        PointF taskDimension = getTaskDimension(context, dp);
        Rect insets = dp.getInsets();
        if (dp.isMultiWindowMode) {
            WindowBounds bounds = SplitScreenBounds.INSTANCE.getSecondaryWindowBounds(context);
            taskWidth = bounds.availableSize.x;
            taskHeight = bounds.availableSize.y;
        } else if (TaskView.CLIP_STATUS_AND_NAV_BARS) {
            taskWidth = dp.availableWidthPx;
            taskHeight = dp.availableHeightPx;
        } else {
            taskWidth = dp.widthPx;
            taskHeight = dp.heightPx;
        }

        Rect potentialTaskRect = new Rect(0, 0, dp.widthPx, dp.heightPx);
        potentialTaskRect.inset(insets.left, insets.top, insets.right, insets.bottom);
@@ -244,14 +254,30 @@ public abstract class BaseActivityInterface<STATE_TYPE extends BaseState<STATE_T
                claimedSpaceBelow);

        float scale = Math.min(
                potentialTaskRect.width() / taskWidth,
                potentialTaskRect.height() / taskHeight);
        int outWidth = Math.round(scale * taskWidth);
        int outHeight = Math.round(scale * taskHeight);
                potentialTaskRect.width() / taskDimension.x,
                potentialTaskRect.height() / taskDimension.y);
        int outWidth = Math.round(scale * taskDimension.x);
        int outHeight = Math.round(scale * taskDimension.y);

        Gravity.apply(Gravity.CENTER, outWidth, outHeight, potentialTaskRect, outRect);
    }

    private PointF getTaskDimension(Context context, DeviceProfile dp) {
        PointF dimension = new PointF();
        if (dp.isMultiWindowMode) {
            WindowBounds bounds = SplitScreenBounds.INSTANCE.getSecondaryWindowBounds(context);
            dimension.x = bounds.availableSize.x;
            dimension.y = bounds.availableSize.y;
        } else if (TaskView.CLIP_STATUS_AND_NAV_BARS) {
            dimension.x = dp.availableWidthPx;
            dimension.y = dp.availableHeightPx;
        } else {
            dimension.x = dp.widthPx;
            dimension.y = dp.heightPx;
        }
        return dimension;
    }

    /**
     * Calculates the overview grid size for the provided device configuration.
     */
+4 −3
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static com.android.launcher3.QuickstepTransitionManager.RECENTS_LAUNCH_DU
import static com.android.launcher3.Utilities.getDescendantCoordRelativeToAncestor;
import static com.android.launcher3.anim.Interpolators.LINEAR;
import static com.android.launcher3.anim.Interpolators.TOUCH_RESPONSE_INTERPOLATOR;
import static com.android.launcher3.anim.Interpolators.TOUCH_RESPONSE_INTERPOLATOR_ACCEL_DEACCEL;
import static com.android.launcher3.anim.Interpolators.clampToProgress;
import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE;
import static com.android.launcher3.statehandlers.DepthController.DEPTH;
@@ -200,8 +201,7 @@ public final class TaskViewUtils {
            tsv.setPreview(targets.apps[targets.apps.length - 1]);
            tsv.fullScreenProgress.value = 0;
            tsv.recentsViewScale.value = 1;
            tsv.gridProgress.value = gridProgress;
            tsv.gridTranslationSecondary.value = gridTranslationSecondary;
            tsv.taskSecondaryTranslation.value = gridTranslationSecondary;
            tsv.setScroll(startScroll);

            // Fade in the task during the initial 20% of the animation
@@ -214,7 +214,8 @@ public final class TaskViewUtils {
                    AnimatedFloat.VALUE, 1, TOUCH_RESPONSE_INTERPOLATOR);
            out.setFloat(tsv.recentsViewScale,
                    AnimatedFloat.VALUE, tsv.getFullScreenScale(), TOUCH_RESPONSE_INTERPOLATOR);
            out.setFloat(tsv.gridProgress, AnimatedFloat.VALUE, 0, TOUCH_RESPONSE_INTERPOLATOR);
            out.setFloat(tsv.taskSecondaryTranslation, AnimatedFloat.VALUE, 0,
                    TOUCH_RESPONSE_INTERPOLATOR_ACCEL_DEACCEL);
            out.setInt(tsv, TaskViewSimulator.SCROLL, 0, TOUCH_RESPONSE_INTERPOLATOR);

            TaskViewSimulator finalTsv = tsv;
+0 −36
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
 */
package com.android.quickstep.util;

import static com.android.launcher3.anim.Interpolators.ACCEL_DEACCEL;
import static com.android.launcher3.states.RotationHelper.deltaRotation;
import static com.android.launcher3.touch.PagedOrientationHandler.MATRIX_POST_TRANSLATE;
import static com.android.quickstep.util.NavigationModeFeatureFlag.LIVE_TILE;
@@ -36,7 +35,6 @@ import android.util.IntProperty;
import androidx.annotation.NonNull;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.touch.PagedOrientationHandler;
@@ -79,7 +77,6 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
    private final boolean mIsRecentsRtl;

    private final Rect mTaskRect = new Rect();
    private final Rect mGridRect = new Rect();
    private boolean mDrawsBelowRecents;
    private final PointF mPivot = new PointF();
    private DeviceProfile mDp;
@@ -98,21 +95,18 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
    private final FullscreenDrawParams mCurrentFullscreenParams;
    public final AnimatedFloat taskPrimaryTranslation = new AnimatedFloat();
    public final AnimatedFloat taskSecondaryTranslation = new AnimatedFloat();
    public final AnimatedFloat gridTranslationSecondary = new AnimatedFloat();

    // RecentsView properties
    public final AnimatedFloat recentsViewScale = new AnimatedFloat();
    public final AnimatedFloat fullScreenProgress = new AnimatedFloat();
    public final AnimatedFloat recentsViewSecondaryTranslation = new AnimatedFloat();
    public final AnimatedFloat recentsViewPrimaryTranslation = new AnimatedFloat();
    public final AnimatedFloat gridProgress = new AnimatedFloat();
    private final ScrollState mScrollState = new ScrollState();

    // Cached calculations
    private boolean mLayoutValid = false;
    private boolean mScrollValid = false;
    private int mOrientationStateId;
    private final int mRowSpacing;

    public TaskViewSimulator(Context context, BaseActivityInterface sizeStrategy) {
        mContext = context;
@@ -124,7 +118,6 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
        mOrientationStateId = mOrientationState.getStateId();
        Resources resources = context.getResources();
        mIsRecentsRtl = mOrientationState.getOrientationHandler().getRecentsRtlSetting(resources);
        mRowSpacing = (int) resources.getDimension(R.dimen.overview_grid_row_spacing);
    }

    /**
@@ -266,7 +259,6 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
            mOrientationStateId = mOrientationState.getStateId();

            getFullScreenScale();
            mSizeStrategy.calculateGridSize(mContext, mDp, mGridRect);
            mThumbnailData.rotation = mOrientationState.getDisplayRotation();

            // mIsRecentsRtl is the inverse of TaskView RTL.
@@ -307,34 +299,6 @@ public class TaskViewSimulator implements TransformParams.BuilderProxy {
        mMatrix.postTranslate(insets.left, insets.top);
        mMatrix.postScale(scale, scale);

        // Apply TaskView matrix: gridProgress related properties
        float interpolatedGridProgress = ACCEL_DEACCEL.getInterpolation(gridProgress.value);
        final int boxLength = (int) Math.max(taskWidth, taskHeight);
        float availableHeight = mGridRect.height();
        float rowHeight = (availableHeight - mRowSpacing) / 2;
        float gridScale = rowHeight / (boxLength + mDp.overviewTaskThumbnailTopMarginPx);
        scale = Utilities.mapRange(interpolatedGridProgress, 1f, gridScale);
        mMatrix.postScale(scale, scale, mIsRecentsRtl ? 0 : taskWidth, 0);
        mOrientationState.getOrientationHandler().setSecondary(mMatrix, MATRIX_POST_TRANSLATE,
                Utilities.mapRange(interpolatedGridProgress, 0, gridTranslationSecondary.value));

        // Apply TaskView matrix: task rect and grid rect difference
        float scaledWidth = taskWidth * gridScale;
        float taskGridHorizontalDiff;
        if (mIsRecentsRtl) {
            float taskRight = mTaskRect.left + scaledWidth;
            taskGridHorizontalDiff = mGridRect.right - taskRight;
        } else {
            float taskLeft = mTaskRect.right - scaledWidth;
            taskGridHorizontalDiff = mGridRect.left - taskLeft;
        }
        float taskGridVerticalDiff =
                mGridRect.top + mDp.overviewTaskThumbnailTopMarginPx * gridScale - mTaskRect.top;
        mOrientationState.getOrientationHandler().set(mMatrix, MATRIX_POST_TRANSLATE,
                Utilities.mapRange(interpolatedGridProgress, 0, taskGridHorizontalDiff));
        mOrientationState.getOrientationHandler().setSecondary(mMatrix, MATRIX_POST_TRANSLATE,
                Utilities.mapRange(interpolatedGridProgress, 0, taskGridVerticalDiff));

        // Apply TaskView matrix: translate, scroll
        mMatrix.postTranslate(mTaskRect.left, mTaskRect.top);
        mOrientationState.getOrientationHandler().set(mMatrix, MATRIX_POST_TRANSLATE,
Loading