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

Commit fb085e63 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Animate the position of the selected bubble arrow in the expanded bubble bar." into udc-dev

parents 0740b7fb 4e909d07
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -43,7 +43,8 @@ class BubbleBarBackground(context: TaskbarActivityContext, private val backgroun
    private var shadowBlur = 0f
    private var keyShadowDistance = 0f

    private var arrowPositionX: Float = 0f
    var arrowPositionX: Float = 0f
        private set
    private var showingArrow: Boolean = false
    private var arrowDrawable: ShapeDrawable

+30 −10
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.launcher3.taskbar.bubbles;

import android.animation.ValueAnimator;
import android.annotation.Nullable;
import android.content.Context;
import android.graphics.Rect;
@@ -64,6 +65,7 @@ public class BubbleBarView extends FrameLayout {
    // TODO: (b/273594744) calculate the amount of space we have and base the max on that
    //  if it's smaller than 5.
    private static final int MAX_BUBBLES = 5;
    private static final int ARROW_POSITION_ANIMATION_DURATION_MS = 200;

    private final TaskbarActivityContext mActivityContext;
    private final BubbleBarBackground mBubbleBarBackground;
@@ -209,14 +211,18 @@ public class BubbleBarView extends FrameLayout {
    /**
     * Sets which bubble view should be shown as selected.
     */
    // TODO: (b/273592694) animate it
    public void setSelectedBubble(BubbleView view) {
        mSelectedBubbleView = view;
        updateArrowForSelected();
        invalidate();
        updateArrowForSelected(/* shouldAnimate= */ true);
    }

    private void updateArrowForSelected() {
    /**
     * Update the arrow position to match the selected bubble.
     *
     * @param shouldAnimate whether or not to animate the arrow. If the bar was just expanded, this
     *                      should be set to {@code false}. Otherwise set this to {@code true}.
     */
    private void updateArrowForSelected(boolean shouldAnimate) {
        if (mSelectedBubbleView == null) {
            Log.w(TAG, "trying to update selection arrow without a selected view!");
            return;
@@ -224,7 +230,21 @@ public class BubbleBarView extends FrameLayout {
        final int index = indexOfChild(mSelectedBubbleView);
        // Find the center of the bubble when it's expanded, set the arrow position to it.
        final float tx = getPaddingStart() + index * (mIconSize + mIconSpacing) + mIconSize / 2f;

        if (shouldAnimate) {
            final float currentArrowPosition = mBubbleBarBackground.getArrowPositionX();
            ValueAnimator animator = ValueAnimator.ofFloat(currentArrowPosition, tx);
            animator.setDuration(ARROW_POSITION_ANIMATION_DURATION_MS);
            animator.addUpdateListener(animation -> {
                float x = (float) animation.getAnimatedValue();
                mBubbleBarBackground.setArrowPosition(x);
                invalidate();
            });
            animator.start();
        } else {
            mBubbleBarBackground.setArrowPosition(tx);
            invalidate();
        }
    }

    @Override
@@ -248,7 +268,7 @@ public class BubbleBarView extends FrameLayout {
    public void setExpanded(boolean isBarExpanded) {
        if (mIsBarExpanded != isBarExpanded) {
            mIsBarExpanded = isBarExpanded;
            updateArrowForSelected();
            updateArrowForSelected(/* shouldAnimate= */ false);
            setOrUnsetClickListener();
            if (!isBarExpanded && mReorderRunnable != null) {
                mReorderRunnable.run();