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

Commit 5cd8ab93 authored by Tony's avatar Tony
Browse files

Cleanup code relating to recents carousel

We can delete a lot of code now  that recents isn't curved and
workspace doesn't offset.

Bug: 70179222
Change-Id: I01f7e3c313cdc370a8db5251a5d9fb406c1eb76c
parent 59a38e67
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -33,9 +33,6 @@
    <dimen name="quickstep_fling_threshold_velocity">500dp</dimen>
    <dimen name="quickstep_fling_min_velocity">250dp</dimen>

    <!-- TODO: can remove -->
    <dimen name="workspace_overview_offset_x">0dp</dimen>

    <!-- Launcher app transition -->
    <dimen name="content_trans_y">25dp</dimen>
    <dimen name="workspace_trans_y">80dp</dimen>
+4 −23
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.view.View;

import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.R;
import com.android.launcher3.Workspace;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.quickstep.RecentsView;
@@ -48,18 +47,13 @@ public class OverviewState extends LauncherState {
    @Override
    public float[] getWorkspaceScaleAndTranslation(Launcher launcher) {
        Rect pageRect = new Rect();
        RecentsView.getScaledDownPageRect(launcher.getDeviceProfile(), launcher, pageRect);
        RecentsView rv = launcher.getOverviewPanel();
        RecentsView.getPageRect(launcher.getDeviceProfile(), launcher, pageRect);

        if (launcher.getWorkspace().getNormalChildWidth() <= 0 || pageRect.isEmpty()) {
            return super.getWorkspaceScaleAndTranslation(launcher);
        }

        float overlap = 0;
        if (rv.getCurrentPage() >= rv.getFirstTaskIndex()) {
            overlap = launcher.getResources().getDimension(R.dimen.workspace_overview_offset_x);
        }
        return getScaleAndTranslationForPageRect(launcher, overlap, pageRect);
        return getScaleAndTranslationForPageRect(launcher, pageRect);
    }

    @Override
@@ -94,8 +88,7 @@ public class OverviewState extends LauncherState {
        };
    }

    public static float[] getScaleAndTranslationForPageRect(Launcher launcher, float offsetX,
            Rect pageRect) {
    public static float[] getScaleAndTranslationForPageRect(Launcher launcher, Rect pageRect) {
        Workspace ws = launcher.getWorkspace();
        float childWidth = ws.getNormalChildWidth();

@@ -106,18 +99,6 @@ public class OverviewState extends LauncherState {
        float childTop = halfHeight - scale * (halfHeight - ws.getPaddingTop() - insets.top);
        float translationY = pageRect.top - childTop;

        // Align the workspace horizontally centered with the task rect
        float halfWidth = ws.getExpectedWidth() / 2;
        float childCenter = halfWidth -
                scale * (halfWidth - ws.getPaddingLeft() - insets.left - childWidth / 2);
        float translationX = pageRect.centerX() - childCenter;

        if (launcher.<RecentsView>getOverviewPanel().isRtl()) {
            translationX -= offsetX / scale;
        } else {
            translationX += offsetX / scale;
        }

        return new float[] {scale, translationX, translationY};
        return new float[] {scale, 0, translationY};
    }
}
+0 −4
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@ public class RecentsViewStateController implements StateHandler {

    @Override
    public void setState(LauncherState state) {
        mWorkspaceCard.setWorkspaceScrollingEnabled(state.overviewUi);
        setVisibility(state.overviewUi);
        setTransitionProgress(state.overviewUi ? 1 : 0);
        if (state.overviewUi) {
@@ -78,8 +77,6 @@ public class RecentsViewStateController implements StateHandler {
            .getBoolean("pref_scroll_to_first_task_default_true", true);
        mIsRecentsScrollingToFirstTask = mLauncher.isInState(NORMAL) && toState == OVERVIEW
                && settingEnabled;
        // TODO: Instead of animating the workspace translationX, move the contents
        mWorkspaceCard.setWorkspaceScrollingEnabled(mIsRecentsScrollingToFirstTask);

        // Scroll to the workspace card before changing to the NORMAL state.
        int currPage = mRecentsView.getCurrentPage();
@@ -100,7 +97,6 @@ public class RecentsViewStateController implements StateHandler {

            @Override
            public void onAnimationSuccess(Animator animator) {
                mWorkspaceCard.setWorkspaceScrollingEnabled(toState.overviewUi);
                mRecentsView.setCurrentPage(mRecentsView.getPageNearestToCenterOfScreen());
            }
        });
+0 −74
Original line number Diff line number Diff line
@@ -16,34 +16,19 @@
package com.android.launcher3.uioverrides;

import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.quickstep.RecentsView.SCROLL_TYPE_WORKSPACE;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;

import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.Workspace;
import com.android.quickstep.RecentsView;
import com.android.quickstep.RecentsView.PageCallbacks;
import com.android.quickstep.RecentsView.ScrollState;

public class WorkspaceCard extends View implements PageCallbacks, OnClickListener {

    private final Rect mTempRect = new Rect();

    private Launcher mLauncher;
    private Workspace mWorkspace;

    private float mLinearInterpolationForPage2 = 1;
    private float mTranslateXPage0, mTranslateXPage1;
    private float mExtraScrollShift;

    private boolean mIsWorkspaceScrollingEnabled;

    public WorkspaceCard(Context context) {
        this(context, null);
@@ -64,30 +49,6 @@ public class WorkspaceCard extends View implements PageCallbacks, OnClickListene
    @Override
    public void draw(Canvas canvas) { }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);

        // Initiate data
        // TODO: can remove most of this as workspace card is no longer scrolling
        mLinearInterpolationForPage2 = RecentsView.getScaledDownPageRect(
                mLauncher.getDeviceProfile(), mLauncher, mTempRect);

        float[] scale = OverviewState.getScaleAndTranslationForPageRect(mLauncher, 0, mTempRect);
        mTranslateXPage0 = scale[1];
        mTranslateXPage1 = OverviewState
                .getScaleAndTranslationForPageRect(mLauncher,
                        getResources().getDimension(R.dimen.workspace_overview_offset_x) / scale[0],
                        mTempRect)[1];

        mExtraScrollShift = 0;
        if (mWorkspace != null && getWidth() > 0) {
            float workspaceWidth = mWorkspace.getNormalChildWidth() * scale[0];
            mExtraScrollShift = (workspaceWidth - getWidth()) / 2;
            setScaleX(workspaceWidth / getWidth());
        }
    }

    @Override
    public void onClick(View view) {
        mLauncher.getStateManager().goToState(NORMAL);
@@ -95,40 +56,5 @@ public class WorkspaceCard extends View implements PageCallbacks, OnClickListene

    public void setup(Launcher launcher) {
        mLauncher = launcher;
        mWorkspace = mLauncher.getWorkspace();
    }

    public void setWorkspaceScrollingEnabled(boolean isEnabled) {
        // TODO can remove
        mIsWorkspaceScrollingEnabled = isEnabled;
    }

    @Override
    public int onPageScroll(ScrollState scrollState) {
        // TODO: can remove
        if (true) {
            return SCROLL_TYPE_WORKSPACE;
        }

        float factor = scrollState.linearInterpolation;
        float translateX = scrollState.distanceFromScreenCenter;
        if (mIsWorkspaceScrollingEnabled) {
            float shift = factor * (mTranslateXPage1 - mTranslateXPage0);
            mWorkspace.setTranslationX(shift + mTranslateXPage0);
            translateX += shift;
        }

        setTranslationX(translateX);

        // If the workspace card is still the first page, shift all the other pages.
        if (scrollState.linearInterpolation > mLinearInterpolationForPage2) {
            scrollState.prevPageExtraWidth = 0;
        } else if (mLinearInterpolationForPage2 > 0) {
            scrollState.prevPageExtraWidth = mExtraScrollShift *
                    (1 - scrollState.linearInterpolation / mLinearInterpolationForPage2);
        } else {
            scrollState.prevPageExtraWidth = mExtraScrollShift;
        }
        return SCROLL_TYPE_WORKSPACE;
    }
}
+10 −54
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@
package com.android.quickstep;

import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.quickstep.TaskView.CURVE_FACTOR;
import static com.android.quickstep.TaskView.CURVE_INTERPOLATOR;

import android.animation.LayoutTransition;
import android.animation.LayoutTransition.TransitionListener;
@@ -70,10 +68,6 @@ public class RecentsView extends PagedView implements Insettable, OnSharedPrefer

    private static final Rect sTempStableInsets = new Rect();

    public static final int SCROLL_TYPE_NONE = 0;
    public static final int SCROLL_TYPE_TASK = 1;
    public static final int SCROLL_TYPE_WORKSPACE = 2;

    private static final String PREF_FLIP_RECENTS = "pref_flip_recents";

    private final Launcher mLauncher;
@@ -150,7 +144,6 @@ public class RecentsView extends PagedView implements Insettable, OnSharedPrefer
                mIsRtl = !mIsRtl;
            }
            setLayoutDirection(mIsRtl ? View.LAYOUT_DIRECTION_RTL : View.LAYOUT_DIRECTION_LTR);
            mScrollState.isRtl = mIsRtl;
        }
    }

@@ -405,33 +398,6 @@ public class RecentsView extends PagedView implements Insettable, OnSharedPrefer
        return padding;
    }

    /**
     * Sets the {@param outRect} to match the position of the first tile such that it is scaled
     * down to match the 2nd taskView.
     * @return returns the factor which determines the scaling factor for the second task.
     */
    public static float getScaledDownPageRect(DeviceProfile dp, Context context, Rect outRect) {
        getPageRect(dp, context, outRect);

        int pageSpacing = context.getResources()
                .getDimensionPixelSize(R.dimen.recents_page_spacing);
        float halfScreenWidth = dp.widthPx * 0.5f;
        float halfPageWidth = outRect.width() * 0.5f;
        float pageCenter = outRect.right + pageSpacing + halfPageWidth;
        float distanceFromCenter = Math.abs(halfScreenWidth - pageCenter);
        float distanceToReachEdge = halfScreenWidth + halfPageWidth + pageSpacing;
        float linearInterpolation = Math.min(1, distanceFromCenter / distanceToReachEdge);

        float scale = 1 - CURVE_INTERPOLATOR.getInterpolation(linearInterpolation) * CURVE_FACTOR;

        int topMargin = context.getResources()
                .getDimensionPixelSize(R.dimen.task_thumbnail_top_margin);
        outRect.top -= topMargin;
        Utilities.scaleRectAboutCenter(outRect, scale);
        outRect.top += (int) (scale * topMargin);
        return linearInterpolation;
    }

    public static void getPageRect(DeviceProfile grid, Context context, Rect outRect) {
        Rect targetPadding = getPadding(grid, context);
        Rect insets = grid.getInsets();
@@ -472,8 +438,7 @@ public class RecentsView extends PagedView implements Insettable, OnSharedPrefer
        if (getPageCount() == 0 || getPageAt(0).getMeasuredWidth() == 0) {
            return;
        }
        final int halfPageWidth = mScrollState.halfPageWidth = getNormalChildWidth() / 2;
        mScrollState.lastScrollType = SCROLL_TYPE_NONE;
        final int halfPageWidth = getNormalChildWidth() / 2;
        final int screenCenter = mInsets.left + getPaddingLeft() + getScrollX() + halfPageWidth;
        final int halfScreenWidth = getMeasuredWidth() / 2;
        final int pageSpacing = mPageSpacing;
@@ -482,11 +447,11 @@ public class RecentsView extends PagedView implements Insettable, OnSharedPrefer
        for (int i = 0; i < pageCount; i++) {
            View page = getPageAt(i);
            int pageCenter = page.getLeft() + halfPageWidth;
            mScrollState.distanceFromScreenCenter = screenCenter - pageCenter;
            float distanceFromScreenCenter = screenCenter - pageCenter;
            float distanceToReachEdge = halfScreenWidth + halfPageWidth + pageSpacing;
            mScrollState.linearInterpolation = Math.min(1,
                    Math.abs(mScrollState.distanceFromScreenCenter) / distanceToReachEdge);
            mScrollState.lastScrollType = ((PageCallbacks) page).onPageScroll(mScrollState);
                    Math.abs(distanceFromScreenCenter) / distanceToReachEdge);
            ((PageCallbacks) page).onPageScroll(mScrollState);
        }
    }

@@ -635,29 +600,20 @@ public class RecentsView extends PagedView implements Insettable, OnSharedPrefer
        canvas.restoreToCount(saveCount);
    }

    // TODO: can remove
    public interface PageCallbacks {

        /**
         * Updates the page UI based on scroll params and returns the type of scroll
         * effect performed.
         *
         * @see #SCROLL_TYPE_NONE
         * @see #SCROLL_TYPE_TASK
         * @see #SCROLL_TYPE_WORKSPACE
         * Updates the page UI based on scroll params.
         */
        int onPageScroll(ScrollState scrollState);
        default void onPageScroll(ScrollState scrollState) {};
    }

    public static class ScrollState {

        public boolean isRtl;
        public int lastScrollType;

        public int halfPageWidth;
        public float distanceFromScreenCenter;
        /**
         * The progress from 0 to 1, where 0 is the center
         * of the screen and 1 is the edge of the screen.
         */
        public float linearInterpolation;

        public float prevPageExtraWidth;
    }
}
Loading