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

Commit 3f82a06c authored by Federico Baron's avatar Federico Baron
Browse files

Remove delightful page indicator

Due to design changes, we are no longer going to use the  changes guarded under the flag SHOW_DELIIGHTFUL_PAGINATION, so we remove the flag and the code that was guarded by that flag

Bug: 261904707
Test: verify flag SHOW_DELIGHTFUL_PAGINATION no longer exists and that the regular pagination works without issues after removing all this code
Change-Id: I244b88b98df0357aa99a325a11988e8248a03206
parent 9898d790
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ import static com.android.launcher3.LauncherState.SPRING_LOADED;
import static com.android.launcher3.Utilities.postAsyncCallback;
import static com.android.launcher3.accessibility.LauncherAccessibilityDelegate.getSupportedActions;
import static com.android.launcher3.anim.Interpolators.EMPHASIZED;
import static com.android.launcher3.config.FeatureFlags.SHOW_DELIGHTFUL_PAGINATION;
import static com.android.launcher3.config.FeatureFlags.SHOW_DOT_PAGINATION;
import static com.android.launcher3.logging.StatsLogManager.EventEnum;
import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_BACKGROUND;
@@ -1280,8 +1279,7 @@ public class Launcher extends StatefulActivity<LauncherState>

    @Override
    public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
        if ((SHOW_DOT_PAGINATION.get() || SHOW_DELIGHTFUL_PAGINATION.get())
                && WorkspacePageIndicator.class.getName().equals(name)) {
        if ((SHOW_DOT_PAGINATION.get()) && WorkspacePageIndicator.class.getName().equals(name)) {
            return LayoutInflater.from(context).inflate(R.layout.page_indicator_dots,
                    (ViewGroup) parent, false);
        }
+0 −4
Original line number Diff line number Diff line
@@ -307,10 +307,6 @@ public final class FeatureFlags {
            "SCROLL_TOP_TO_RESET", false, "Bring up IME and focus on "
            + "input when scroll to top if 'Always show keyboard' is enabled or in prefix state");

    public static final BooleanFlag SHOW_DELIGHTFUL_PAGINATION = getDebugFlag(
            "SHOW_DELIGHTFUL_PAGINATION", false,
            "Enable showing the new 'delightful pagination' which is a brand"
                    + " new animation for folder pagination and workspace pagination");
    public static final BooleanFlag POPUP_MATERIAL_U = new DeviceFlag(
            "POPUP_MATERIAL_U", false, "Switch popup UX to use material U");

+21 −157
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.launcher3.pageindicators;

import static com.android.launcher3.config.FeatureFlags.SHOW_DELIGHTFUL_PAGINATION;
import static com.android.launcher3.config.FeatureFlags.SHOW_DOT_PAGINATION;

import android.animation.Animator;
@@ -32,7 +31,6 @@ import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
@@ -48,7 +46,6 @@ import androidx.annotation.Nullable;
import com.android.launcher3.Insettable;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.util.Themes;

/**
@@ -70,7 +67,6 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
    private static final int PAGE_INDICATOR_ALPHA = 255;
    private static final int DOT_ALPHA = 128;
    private static final int DOT_GAP_FACTOR = 3;
    private static final float DOT_GAP_FACTOR_FLOAT = 3.8f;
    private static final int VISIBLE_ALPHA = 1;
    private static final int INVISIBLE_ALPHA = 0;
    private Paint mPaginationPaint;
@@ -78,8 +74,6 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
    // This value approximately overshoots to 1.5 times the original size.
    private static final float ENTER_ANIMATION_OVERSHOOT_TENSION = 4.9f;

    private static final float INDICATOR_ROTATION = 180f;

    private static final RectF sTempRect = new RectF();

    private static final FloatProperty<PageIndicatorDots> CURRENT_POSITION =
@@ -112,11 +106,8 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
            };

    private final Handler mDelayedPaginationFadeHandler = new Handler(Looper.getMainLooper());
    private final Drawable mPageIndicatorDrawable;
    private final float mDotRadius;
    private final float mCircleGap;
    private final float mPageIndicatorSize;
    private final float mPageIndicatorRadius;
    private final boolean mIsRtl;

    private int mNumPages;
@@ -159,31 +150,14 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
        mPaginationPaint.setStyle(Style.FILL);
        mPaginationPaint.setColor(Themes.getAttrColor(context, R.attr.folderPaginationColor));
        mDotRadius = getResources().getDimension(R.dimen.page_indicator_dot_size) / 2;

        if (SHOW_DELIGHTFUL_PAGINATION.get()) {
            mPageIndicatorSize = getResources().getDimension(
                    R.dimen.page_indicator_size);
            mPageIndicatorRadius = mPageIndicatorSize / 2;
            mPageIndicatorDrawable = context.getDrawable(R.drawable.page_indicator);
            mPageIndicatorDrawable.setBounds(0, 0, (int) mPageIndicatorSize,
                    (int) mPageIndicatorSize);
            mCircleGap = DOT_GAP_FACTOR_FLOAT * mDotRadius;

        } else {
            mPageIndicatorSize = 0;
            mPageIndicatorRadius = 0;
            mPageIndicatorDrawable = null;
        mCircleGap = DOT_GAP_FACTOR * mDotRadius;
        }
        if (!SHOW_DELIGHTFUL_PAGINATION.get()) {
        setOutlineProvider(new MyOutlineProver());
        }
        mIsRtl = Utilities.isRtl(getResources());
    }

    @Override
    public void setScroll(int currentScroll, int totalScroll) {
        if (SHOW_DELIGHTFUL_PAGINATION.get() || SHOW_DOT_PAGINATION.get()) {
        if (SHOW_DOT_PAGINATION.get()) {
            animatePaginationToAlpha(VISIBLE_ALPHA);
        }

@@ -197,16 +171,6 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
        }

        mTotalScroll = totalScroll;
        if (SHOW_DELIGHTFUL_PAGINATION.get()) {
            mCurrentScroll = currentScroll;
            invalidate();

            if (mShouldAutoHide
                    && (getScrollPerPage() == 0 || mCurrentScroll % getScrollPerPage() == 0)) {
                hideAfterDelay();
            }
            return;
        }

        int scrollPerPage = totalScroll / (mNumPages - 1);
        int pageToLeft = currentScroll / scrollPerPage;
@@ -404,92 +368,23 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
            }
            for (int i = 0; i < mEntryAnimationRadiusFactors.length; i++) {
                mPaginationPaint.setAlpha(i == mActivePage ? PAGE_INDICATOR_ALPHA : DOT_ALPHA);
                if (SHOW_DELIGHTFUL_PAGINATION.get()) {
                    if (i != mActivePage) {
                        canvas.drawCircle(x, y, mDotRadius * mEntryAnimationRadiusFactors[i],
                                mPaginationPaint);
                    } else {
                        drawPageIndicator(canvas, mEntryAnimationRadiusFactors[i]);
                    }
                } else {
                canvas.drawCircle(x, y, mDotRadius * mEntryAnimationRadiusFactors[i],
                        mPaginationPaint);
                }
                x += circleGap;
            }
        } else {
            // Here we draw the dots
            mPaginationPaint.setAlpha(DOT_ALPHA);
            for (int i = 0; i < mNumPages; i++) {
                if (SHOW_DELIGHTFUL_PAGINATION.get()) {
                    canvas.drawCircle(x, y, getRadius(x), mPaginationPaint);
                } else {
                canvas.drawCircle(x, y, mDotRadius, mPaginationPaint);
                }
                x += circleGap;
            }

            // Here we draw the current page indicator
            mPaginationPaint.setAlpha(PAGE_INDICATOR_ALPHA);
            if (SHOW_DELIGHTFUL_PAGINATION.get()) {
                drawPageIndicator(canvas, 1);
            } else {
            canvas.drawRoundRect(getActiveRect(), mDotRadius, mDotRadius, mPaginationPaint);
        }
    }
    }

    /**
     * Draws the page indicator, denoting the currently selected page
     *
     * @param canvas is used to draw the page indicator and to rotate it as we scroll
     * @param scale  is used to set the scale of our canvas
     */
    private void drawPageIndicator(Canvas canvas, float scale) {
        RectF currRect = getActiveRect();

        // saves the canvas so we can later restore it to its original scale
        canvas.save();

        // Moves the canvas to start at the top left corner of the page indicator
        canvas.translate(currRect.left, currRect.top);

        // Scales the canvas in place to animate the indicator on entry
        canvas.scale(scale, scale, mPageIndicatorRadius, mPageIndicatorRadius);

        int scrollPerPage = getScrollPerPage();
        // This IF is to avoid division by 0
        if (scrollPerPage != 0) {
            int delta = mCurrentScroll % scrollPerPage;
            canvas.rotate((INDICATOR_ROTATION * delta) / scrollPerPage,
                    mPageIndicatorRadius, mPageIndicatorRadius);
        }

        mPageIndicatorDrawable.draw(canvas);
        canvas.restore();
    }

    /**
     * Returns the radius of the circle based on how close the page indicator is to it
     *
     * @param dotPositionX is the position the dot is located at in the x-axis
     */
    private float getRadius(float dotPositionX) {

        float startXIndicator =
                ((getWidth() - (mNumPages * mCircleGap) + mDotRadius) / 2) - getOffset();
        float indicatorPosition = startXIndicator + getIndicatorScrollDistance()
                + mPageIndicatorRadius;

        // If the indicator gets close enough to a dot then we change the radius
        // of the dot based on how close the indicator is to it.
        float dotDistance = Math.abs(indicatorPosition - dotPositionX);
        if (dotDistance <= mCircleGap) {
            return Utilities.mapToRange(dotDistance, 0, mCircleGap, 0f, mDotRadius,
                    Interpolators.LINEAR);
        }
        return mDotRadius;
    }

    private RectF getActiveRect() {
        float startCircle = (int) mCurrentPosition;
@@ -497,13 +392,6 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
        float diameter = 2 * mDotRadius;
        float startX;

        if (SHOW_DELIGHTFUL_PAGINATION.get()) {
            startX = ((getWidth() - (mNumPages * mCircleGap) + mDotRadius) / 2) - getOffset();
            sTempRect.top = (getHeight() - mPageIndicatorSize) * 0.5f;
            sTempRect.bottom = (getHeight() + mPageIndicatorSize) * 0.5f;
            sTempRect.left = startX + getIndicatorScrollDistance();
            sTempRect.right = sTempRect.left + mPageIndicatorSize;
        } else {
        startX = ((getWidth() - (mNumPages * mCircleGap) + mDotRadius) / 2);
        sTempRect.top = (getHeight() * 0.5f) - mDotRadius;
        sTempRect.bottom = (getHeight() * 0.5f) + mDotRadius;
@@ -520,7 +408,6 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
            delta -= SHIFT_PER_ANIMATION;
            sTempRect.left += delta * mCircleGap * 2;
        }
        }

        if (mIsRtl) {
            float rectWidth = sTempRect.width();
@@ -531,29 +418,6 @@ public class PageIndicatorDots extends View implements Insettable, PageIndicator
        return sTempRect;
    }

    /**
     * The offset between the radius of the dot and the midpoint of the indicator so that
     * the indicator is centered in with the indicator circles
     */
    private float getOffset() {
        return mPageIndicatorRadius - mDotRadius;
    }

    /**
     * Returns an int that is the amount we need to scroll per page
     */
    private int getScrollPerPage() {
        return mNumPages > 1 ? mTotalScroll / (mNumPages - 1) : 0;
    }

    /**
     * The current scroll adjusted for the distance the indicator needs to travel on the screen
     */
    private float getIndicatorScrollDistance() {
        int scrollPerPage = getScrollPerPage();
        return scrollPerPage != 0 ? ((float) mCurrentScroll / scrollPerPage) * mCircleGap : 0;
    }

    private class MyOutlineProver extends ViewOutlineProvider {

        @Override