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

Commit dff855e7 authored by Ats Jenk's avatar Ats Jenk Committed by Android (Google) Code Review
Browse files

Merge "Update bubble bar stash and unstash animation" into main

parents 669445f7 9ab2b8c7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -437,6 +437,7 @@
    <dimen name="bubblebar_stashed_handle_width">55dp</dimen>
    <dimen name="bubblebar_stashed_size">@dimen/transient_taskbar_stashed_height</dimen>
    <dimen name="bubblebar_stashed_handle_height">@dimen/taskbar_stashed_handle_height</dimen>
    <dimen name="bubblebar_stashed_handle_spring_velocity_dp_per_s">@dimen/transient_taskbar_stash_spring_velocity_dp_per_s</dimen>
    <!-- this is a pointer height minus 1dp to ensure the pointer overlaps with the bubblebar
    background appropriately when close to the rounded corner -->
    <dimen name="bubblebar_pointer_visible_size">9dp</dimen>
+1 −1
Original line number Diff line number Diff line
@@ -283,7 +283,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
            TaskbarHotseatDimensionsProvider dimensionsProvider =
                    new DeviceProfileDimensionsProviderAdapter(this);
            BubbleStashController bubbleStashController = isTransientTaskbar
                    ? new TransientBubbleStashController(dimensionsProvider, getResources())
                    ? new TransientBubbleStashController(dimensionsProvider, this)
                    : new PersistentBubbleStashController(dimensionsProvider);
            bubbleControllersOptional = Optional.of(new BubbleControllers(
                    new BubbleBarController(this, bubbleBarView),
+38 −12
Original line number Diff line number Diff line
@@ -80,12 +80,14 @@ public class BubbleBarViewController {

    // These are exposed to {@link BubbleStashController} to animate for stashing/un-stashing
    private final MultiValueAlpha mBubbleBarAlpha;
    private final AnimatedFloat mBubbleBarScale = new AnimatedFloat(this::updateScale);
    private final AnimatedFloat mBubbleBarScaleY = new AnimatedFloat(this::updateScaleY);
    private final AnimatedFloat mBubbleBarTranslationY = new AnimatedFloat(
            this::updateTranslationY);

    // Modified when swipe up is happening on the bubble bar or task bar.
    private float mBubbleBarSwipeUpTranslationY;
    // Modified when bubble bar is springing back into the stash handle.
    private float mBubbleBarStashTranslationY;

    // Whether the bar is hidden for a sysui state.
    private boolean mHiddenForSysui;
@@ -125,7 +127,7 @@ public class BubbleBarViewController {
        onBubbleBarConfigurationChanged(/* animate= */ false);
        mActivity.addOnDeviceProfileChangeListener(
                dp -> onBubbleBarConfigurationChanged(/* animate= */ true));
        mBubbleBarScale.updateValue(1f);
        mBubbleBarScaleY.updateValue(1f);
        mBubbleClickListener = v -> onBubbleClicked((BubbleView) v);
        mBubbleBarClickListener = v -> expandBubbleBar();
        mBubbleDragController.setupBubbleBarView(mBarView);
@@ -255,8 +257,8 @@ public class BubbleBarViewController {
        return mBubbleBarAlpha;
    }

    public AnimatedFloat getBubbleBarScale() {
        return mBubbleBarScale;
    public AnimatedFloat getBubbleBarScaleY() {
        return mBubbleBarScaleY;
    }

    public AnimatedFloat getBubbleBarTranslationY() {
@@ -267,6 +269,27 @@ public class BubbleBarViewController {
        return mBarView.getBubbleBarCollapsedHeight();
    }

    /**
     * @see BubbleBarView#getRelativePivotX()
     */
    public float getBubbleBarRelativePivotX() {
        return mBarView.getRelativePivotX();
    }

    /**
     * @see BubbleBarView#getRelativePivotY()
     */
    public float getBubbleBarRelativePivotY() {
        return mBarView.getRelativePivotY();
    }

    /**
     * @see BubbleBarView#setRelativePivot(float, float)
     */
    public void setBubbleBarRelativePivot(float x, float y) {
        mBarView.setRelativePivot(x, y);
    }

    /**
     * Whether the bubble bar is visible or not.
     */
@@ -474,17 +497,20 @@ public class BubbleBarViewController {
        updateTranslationY();
    }

    /**
     * Sets the translation of the bubble bar during the stash animation.
     */
    public void setTranslationYForStash(float transY) {
        mBubbleBarStashTranslationY = transY;
        updateTranslationY();
    }

    private void updateTranslationY() {
        mBarView.setTranslationY(mBubbleBarTranslationY.value
                + mBubbleBarSwipeUpTranslationY);
        mBarView.setTranslationY(mBubbleBarTranslationY.value + mBubbleBarSwipeUpTranslationY
                + mBubbleBarStashTranslationY);
    }

    /**
     * Applies scale properties for the entire bubble bar.
     */
    private void updateScale() {
        float scale = mBubbleBarScale.value;
        mBarView.setScaleX(scale);
    private void updateScaleY(float scale) {
        mBarView.setScaleY(scale);
    }

+75 −44
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.view.View.VISIBLE;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.Nullable;
import android.content.res.Resources;
import android.graphics.Outline;
import android.graphics.Rect;
@@ -28,6 +29,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewOutlineProvider;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.anim.RevealOutlineAnimation;
import com.android.launcher3.anim.RoundedRectRevealOutlineProvider;
@@ -49,23 +51,29 @@ public class BubbleStashedHandleViewController {
    private final TaskbarActivityContext mActivity;
    private final StashedHandleView mStashedHandleView;
    private final MultiValueAlpha mStashedHandleAlpha;
    private float mTranslationForSwipeY;
    private float mTranslationForStashY;

    // Initialized in init.
    private BubbleBarViewController mBarViewController;
    private BubbleStashController mBubbleStashController;
    private RegionSamplingHelper mRegionSamplingHelper;
    private int mBarSize;
    private int mStashedTaskbarHeight;
    // Height of the area for the stash handle. Handle will be drawn in the center of this.
    // This is also the area where touch is handled on the handle.
    private int mStashedBubbleBarHeight;
    private int mStashedHandleWidth;
    private int mStashedHandleHeight;

    // The bounds we want to clip to in the settled state when showing the stashed handle.
    // The bounds of the stashed handle in settled state.
    private final Rect mStashedHandleBounds = new Rect();
    private float mStashedHandleRadius;

    // When the reveal animation is cancelled, we can assume it's about to create a new animation,
    // which should start off at the same point the cancelled one left off.
    private float mStartProgressForNextRevealAnim;
    private boolean mWasLastRevealAnimReversed;
    // Use a nullable boolean to handle initial case where the last animation direction is not known
    @Nullable
    private Boolean mWasLastRevealAnimReversed = null;

    // XXX: if there are more of these maybe do state flags instead
    private boolean mHiddenForSysui;
@@ -77,6 +85,7 @@ public class BubbleStashedHandleViewController {
        mActivity = activity;
        mStashedHandleView = stashedHandleView;
        mStashedHandleAlpha = new MultiValueAlpha(mStashedHandleView, 1);
        mStashedHandleAlpha.setUpdateVisibility(true);
    }

    /** Initialize controller. */
@@ -84,26 +93,31 @@ public class BubbleStashedHandleViewController {
        mBarViewController = bubbleControllers.bubbleBarViewController;
        mBubbleStashController = bubbleControllers.bubbleStashController;

        DeviceProfile deviceProfile = mActivity.getDeviceProfile();
        Resources resources = mActivity.getResources();
        mStashedHandleHeight = resources.getDimensionPixelSize(
                R.dimen.bubblebar_stashed_handle_height);
        mStashedHandleWidth = resources.getDimensionPixelSize(
                R.dimen.bubblebar_stashed_handle_width);
        mBarSize = resources.getDimensionPixelSize(R.dimen.bubblebar_size);

        final int bottomMargin = resources.getDimensionPixelSize(
                R.dimen.transient_taskbar_bottom_margin);
        mStashedHandleView.getLayoutParams().height = mBarSize + bottomMargin;
        int barSize = resources.getDimensionPixelSize(R.dimen.bubblebar_size);
        // Use the max translation for bubble bar whether it is on the home screen or in app.
        // Use values directly from device profile to avoid referencing other bubble controllers
        // during init flow.
        int maxTy = Math.max(deviceProfile.hotseatBarBottomSpacePx,
                deviceProfile.taskbarBottomMargin);
        // Adjust handle view size to accommodate the handle morphing into the bubble bar
        mStashedHandleView.getLayoutParams().height = barSize + maxTy;

        mStashedHandleAlpha.get(0).setValue(0);

        mStashedTaskbarHeight = resources.getDimensionPixelSize(
        mStashedBubbleBarHeight = resources.getDimensionPixelSize(
                R.dimen.bubblebar_stashed_size);
        mStashedHandleView.setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                float stashedHandleRadius = view.getHeight() / 2f;
                outline.setRoundRect(mStashedHandleBounds, stashedHandleRadius);
                mStashedHandleRadius = view.getHeight() / 2f;
                outline.setRoundRect(mStashedHandleBounds, mStashedHandleRadius);
            }
        });

@@ -132,28 +146,25 @@ public class BubbleStashedHandleViewController {
    private void updateBounds(BubbleBarLocation bubbleBarLocation) {
        // As more bubbles get added, the icon bounds become larger. To ensure a consistent
        // handle bar position, we pin it to the edge of the screen.
        final int stashedCenterY = mStashedHandleView.getHeight() - mStashedTaskbarHeight / 2;
        final int stashedCenterY = mStashedHandleView.getHeight() - mStashedBubbleBarHeight / 2;
        final int stashedCenterX;
        if (bubbleBarLocation.isOnLeft(mStashedHandleView.isLayoutRtl())) {
            final int left = mBarViewController.getHorizontalMargin();
            mStashedHandleBounds.set(
                    left,
                    stashedCenterY - mStashedHandleHeight / 2,
                    left + mStashedHandleWidth,
                    stashedCenterY + mStashedHandleHeight / 2);
            mStashedHandleView.setPivotX(0);
            stashedCenterX = left + mStashedHandleWidth / 2;
        } else {
            final int right =
                    mActivity.getDeviceProfile().widthPx - mBarViewController.getHorizontalMargin();
                    mStashedHandleView.getRight() - mBarViewController.getHorizontalMargin();
            stashedCenterX = right - mStashedHandleWidth / 2;
        }
        mStashedHandleBounds.set(
                    right - mStashedHandleWidth,
                stashedCenterX - mStashedHandleWidth / 2,
                stashedCenterY - mStashedHandleHeight / 2,
                    right,
                    stashedCenterY + mStashedHandleHeight / 2);
            mStashedHandleView.setPivotX(mStashedHandleView.getWidth());
        }

                stashedCenterX + mStashedHandleWidth / 2,
                stashedCenterY + mStashedHandleHeight / 2
        );
        mStashedHandleView.updateSampledRegion(mStashedHandleBounds);
        mStashedHandleView.setPivotY(mStashedHandleView.getHeight() - mStashedTaskbarHeight / 2f);
        mStashedHandleView.setPivotX(stashedCenterX);
        mStashedHandleView.setPivotY(stashedCenterY);
    }

    public void onDestroy() {
@@ -168,13 +179,6 @@ public class BubbleStashedHandleViewController {
        return mStashedHandleHeight;
    }

    /**
     * Returns the height when the bubble bar is unstashed (so the height of the bubble bar).
     */
    public int getUnstashedHeight() {
        return mBarSize;
    }

    /**
     * Called when system ui state changes. Bubbles don't show when the device is locked.
     */
@@ -242,7 +246,20 @@ public class BubbleStashedHandleViewController {
     * Sets the translation of the stashed handle during the swipe up gesture.
     */
    public void setTranslationYForSwipe(float transY) {
        mStashedHandleView.setTranslationY(transY);
        mTranslationForSwipeY = transY;
        updateTranslationY();
    }

    /**
     * Sets the translation of the stashed handle during the spring on stash animation.
     */
    public void setTranslationYForStash(float transY) {
        mTranslationForStashY = transY;
        updateTranslationY();
    }

    private void updateTranslationY() {
        mStashedHandleView.setTranslationY(mTranslationForSwipeY + mTranslationForStashY);
    }

    /** Returns the translation of the stashed handle. */
@@ -263,18 +280,17 @@ public class BubbleStashedHandleViewController {
     * the size of where the bubble bar icons will be.
     */
    public Animator createRevealAnimToIsStashed(boolean isStashed) {
        Rect bubbleBarBounds = new Rect(mBarViewController.getBubbleBarBounds());
        Rect bubbleBarBounds = getLocalBubbleBarBounds();

        // Account for the full visual height of the bubble bar
        int heightDiff = (mBarSize - bubbleBarBounds.height()) / 2;
        bubbleBarBounds.top -= heightDiff;
        bubbleBarBounds.bottom += heightDiff;
        float stashedHandleRadius = mStashedHandleView.getHeight() / 2f;
        float bubbleBarRadius = bubbleBarBounds.height() / 2f;
        final RevealOutlineAnimation handleRevealProvider = new RoundedRectRevealOutlineProvider(
                stashedHandleRadius, stashedHandleRadius, bubbleBarBounds, mStashedHandleBounds);
                bubbleBarRadius, mStashedHandleRadius, bubbleBarBounds, mStashedHandleBounds);

        boolean isReversed = !isStashed;
        boolean changingDirection = mWasLastRevealAnimReversed != isReversed;
        // We are only changing direction when mWasLastRevealAnimReversed is set at least once
        boolean changingDirection =
                mWasLastRevealAnimReversed != null && mWasLastRevealAnimReversed != isReversed;

        mWasLastRevealAnimReversed = isReversed;
        if (changingDirection) {
            mStartProgressForNextRevealAnim = 1f - mStartProgressForNextRevealAnim;
@@ -291,6 +307,21 @@ public class BubbleStashedHandleViewController {
        return revealAnim;
    }

    /**
     * Get bounds for the bubble bar in the space of the handle view
     */
    private Rect getLocalBubbleBarBounds() {
        // Position the bubble bar bounds to the space of handle view
        Rect bubbleBarBounds = new Rect(mBarViewController.getBubbleBarBounds());
        // Start by moving bubble bar bounds to the bottom of handle view
        int height = bubbleBarBounds.height();
        bubbleBarBounds.bottom = mStashedHandleView.getHeight();
        bubbleBarBounds.top = bubbleBarBounds.bottom - height;
        // Then apply translation that is applied to the bubble bar
        bubbleBarBounds.offset(0, (int) mBubbleStashController.getBubbleBarTranslationY());
        return bubbleBarBounds;
    }

    /** Checks that the stash handle is visible and that the motion event is within bounds. */
    public boolean isEventOverHandle(MotionEvent ev) {
        if (mStashedHandleView.getVisibility() != VISIBLE) {
@@ -299,7 +330,7 @@ public class BubbleStashedHandleViewController {

        // the bounds of the handle only include the visible part, so we check that the Y coordinate
        // is anywhere within the stashed height of bubble bar (same as taskbar stashed height).
        final int top = mActivity.getDeviceProfile().heightPx - mStashedTaskbarHeight;
        final int top = mActivity.getDeviceProfile().heightPx - mStashedBubbleBarHeight;
        final float x = ev.getRawX();
        return ev.getRawY() >= top && x >= mStashedHandleBounds.left
                && x <= mStashedHandleBounds.right;
+3 −3
Original line number Diff line number Diff line
@@ -179,10 +179,10 @@ interface BubbleStashController {
        /** How long to stash/unstash. */
        const val BAR_STASH_DURATION = InsetsController.ANIMATION_DURATION_RESIZE.toLong()

        const val BAR_STASH_ALPHA_DURATION = 50L
        const val BAR_STASH_ALPHA_DELAY = 33L

        /** How long to translate Y coordinate of the BubbleBar. */
        const val BAR_TRANSLATION_DURATION = 300L

        /** The scale bubble bar animates to when being stashed. */
        const val STASHED_BAR_SCALE = 0.5f
    }
}
Loading