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

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

Merge changes I485f6346,I24b0c646 into main

* changes:
  Animate alpha for bubbles and background (3/n)
  Use a reveal animator for bubble icons (2/n)
parents 97db09db 332828b3
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
@@ -205,7 +205,6 @@ public class BubbleBarView extends FrameLayout {

    public BubbleBarView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        setAlpha(0);
        setVisibility(INVISIBLE);
        mIconOverlapAmount = getResources().getDimensionPixelSize(R.dimen.bubblebar_icon_overlap);
        mBubbleBarPadding = getResources().getDimensionPixelSize(R.dimen.bubblebar_icon_spacing);
@@ -319,6 +318,22 @@ public class BubbleBarView extends FrameLayout {
        mBubbleBarBackground.setScaleY(scaleY);
    }

    /**
     * Set alpha for bubble views
     */
    public void setBubbleAlpha(float alpha) {
        for (int i = 0; i < getChildCount(); i++) {
            getChildAt(i).setAlpha(alpha);
        }
    }

    /**
     * Set alpha for bar background
     */
    public void setBackgroundAlpha(float alpha) {
        mBubbleBarBackground.setAlpha((int) (255 * alpha));
    }

    /**
     * Sets new icon sizes and newBubbleBarPadding between icons and bubble bar borders.
     *
@@ -1029,7 +1044,7 @@ public class BubbleBarView extends FrameLayout {
                // where the bubble will end up when the animation ends
                final float targetX = expandedX + expandedBarShift;
                bv.setTranslationX(widthState * (targetX - collapsedX) + collapsedX);
                bv.setAlpha(1);
                bv.setVisibility(VISIBLE);
            } else {
                // If bar is on the right, account for bubble bar expanding and shifting left
                final float collapsedBarShift = onLeft ? 0 : currentWidth - collapsedWidth;
@@ -1039,9 +1054,9 @@ public class BubbleBarView extends FrameLayout {
                // the overflow.
                if (widthState == 0) {
                    if (bv.isOverflow() || i > MAX_VISIBLE_BUBBLES_COLLAPSED - 1) {
                        bv.setAlpha(0);
                        bv.setVisibility(INVISIBLE);
                    } else {
                        bv.setAlpha(1);
                        bv.setVisibility(VISIBLE);
                    }
                }
            }
@@ -1349,7 +1364,7 @@ public class BubbleBarView extends FrameLayout {
     * touch bounds.
     */
    public boolean isEventOverAnyItem(MotionEvent ev) {
        if (getVisibility() == View.VISIBLE) {
        if (getVisibility() == VISIBLE) {
            getBoundsOnScreen(mTempRect);
            return mTempRect.contains((int) ev.getX(), (int) ev.getY());
        }
+72 −0
Original line number Diff line number Diff line
@@ -18,6 +18,11 @@ package com.android.launcher3.taskbar.bubbles;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;

import static com.android.launcher3.taskbar.bubbles.BubbleView.STASH_TRANSLATION_Y;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.PointF;
@@ -34,6 +39,7 @@ import androidx.annotation.Nullable;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.R;
import com.android.launcher3.anim.AnimatedFloat;
import com.android.launcher3.anim.RoundedRectRevealOutlineProvider;
import com.android.launcher3.taskbar.TaskbarActivityContext;
import com.android.launcher3.taskbar.TaskbarControllers;
import com.android.launcher3.taskbar.TaskbarInsetsController;
@@ -80,6 +86,9 @@ public class BubbleBarViewController {

    // These are exposed to {@link BubbleStashController} to animate for stashing/un-stashing
    private final MultiValueAlpha mBubbleBarAlpha;
    private final AnimatedFloat mBubbleBarBubbleAlpha = new AnimatedFloat(this::updateBubbleAlpha);
    private final AnimatedFloat mBubbleBarBackgroundAlpha = new AnimatedFloat(
            this::updateBackgroundAlpha);
    private final AnimatedFloat mBubbleBarScaleX = new AnimatedFloat(this::updateScaleX);
    private final AnimatedFloat mBubbleBarScaleY = new AnimatedFloat(this::updateScaleY);
    private final AnimatedFloat mBubbleBarBackgroundScaleX = new AnimatedFloat(
@@ -262,6 +271,14 @@ public class BubbleBarViewController {
        return mBubbleBarAlpha;
    }

    public AnimatedFloat getBubbleBarBubbleAlpha() {
        return mBubbleBarBubbleAlpha;
    }

    public AnimatedFloat getBubbleBarBackgroundAlpha() {
        return mBubbleBarBackgroundAlpha;
    }

    public AnimatedFloat getBubbleBarScaleX() {
        return mBubbleBarScaleX;
    }
@@ -555,6 +572,14 @@ public class BubbleBarViewController {
        mBarView.setBackgroundScaleY(scale);
    }

    private void updateBubbleAlpha(float alpha) {
        mBarView.setBubbleAlpha(alpha);
    }

    private void updateBackgroundAlpha(float alpha) {
        mBarView.setBackgroundAlpha(alpha);
    }

    //
    // Manipulating the specific bubble views in the bar
    //
@@ -839,6 +864,53 @@ public class BubbleBarViewController {
        mBoundsChangeListener = listener;
    }

    /**
     * Create an animator for showing or hiding bubbles when stashed state changes
     *
     * @param isStashed {@code true} when bubble bar should be stashed to the handle
     */
    public Animator createRevealAnimatorForStashChange(boolean isStashed) {
        Rect stashedHandleBounds = new Rect();
        mBubbleStashController.getHandleBounds(stashedHandleBounds);
        int childCount = mBarView.getChildCount();
        float newChildWidth = (float) stashedHandleBounds.width() / childCount;
        float stashTranslationY = -mBubbleStashController.getBubbleBarTranslationY();
        AnimatorSet animatorSet = new AnimatorSet();
        for (int i = 0; i < childCount; i++) {
            BubbleView child = (BubbleView) mBarView.getChildAt(i);
            final float startTransY = isStashed ? 0f : stashTranslationY;
            final float endTransY = isStashed ? stashTranslationY : 0f;
            animatorSet.play(
                    ObjectAnimator.ofFloat(child, STASH_TRANSLATION_Y, startTransY, endTransY));
            animatorSet.play(
                    createRevealAnimForBubble(child, isStashed, stashedHandleBounds,
                            newChildWidth));
        }
        return animatorSet;
    }

    private Animator createRevealAnimForBubble(BubbleView bubbleView, boolean isStashed,
            Rect stashedHandleBounds, float newWidth) {
        Rect viewBounds = new Rect(0, 0, bubbleView.getWidth(), bubbleView.getHeight());

        int viewCenterY = viewBounds.centerY();
        int halfHandleHeight = stashedHandleBounds.height() / 2;
        int widthDelta = Math.max(0, (int) (viewBounds.width() - newWidth) / 2);

        Rect stashedViewBounds = new Rect(
                viewBounds.left + widthDelta,
                viewCenterY - halfHandleHeight,
                viewBounds.right - widthDelta,
                viewCenterY + halfHandleHeight
        );

        float viewRadius = 0f; // Use 0 to not clip the new message dot or the app icon
        float stashedRadius = stashedViewBounds.height() / 2f;

        return new RoundedRectRevealOutlineProvider(viewRadius, stashedRadius, viewBounds,
                stashedViewBounds).createRevealAnimator(bubbleView, !isStashed, 0);
    }

    /**
     * Listener to receive updates about bubble bar bounds changing
     */
+7 −0
Original line number Diff line number Diff line
@@ -186,6 +186,13 @@ public class BubbleStashedHandleViewController {
        return mStashedHandleHeight;
    }

    /**
     * Returns bounds of the stashed handle view
     */
    public void getBounds(Rect bounds) {
        bounds.set(mStashedHandleBounds);
    }

    /**
     * Called when system ui state changes. Bubbles don't show when the device is locked.
     */
+43 −4
Original line number Diff line number Diff line
@@ -20,12 +20,14 @@ import android.app.Notification;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.FloatProperty;
import android.view.LayoutInflater;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.ImageView;
@@ -48,12 +50,27 @@ public class BubbleView extends ConstraintLayout {

    public static final int DEFAULT_PATH_SIZE = 100;

    public static FloatProperty<BubbleView> STASH_TRANSLATION_Y = new FloatProperty<>(
            "stashTranslationY") {
        @Override
        public void setValue(BubbleView bubbleView, float transY) {
            bubbleView.setStashTranslationY(transY);
        }

        @Override
        public Float get(BubbleView bubbleView) {
            return bubbleView.mStashTranslationY;
        }
    };

    private final ImageView mBubbleIcon;
    private final ImageView mAppIcon;
    private int mBubbleSize;

    private float mDragTranslationX;
    private float mOffsetX;
    private float mTranslationY;
    private float mStashTranslationY;

    private DotRenderer mDotRenderer;
    private DotRenderer.DrawParams mDrawParams;
@@ -110,6 +127,10 @@ public class BubbleView extends ConstraintLayout {

        setFocusable(true);
        setClickable(true);

        // We manage the shadow ourselves when creating the bitmap
        setOutlineAmbientShadowColor(Color.TRANSPARENT);
        setOutlineSpotShadowColor(Color.TRANSPARENT);
    }

    private void updateBubbleSizeAndDotRender() {
@@ -152,16 +173,34 @@ public class BubbleView extends ConstraintLayout {
        applyDragTranslation();
    }

    private void applyDragTranslation() {
        setTranslationX(mDragTranslationX + mOffsetX);
    }

    /**
     * Set translation in y direction during stash and unstash from handle
     */
    public void setStashTranslationY(float translationY) {
        mStashTranslationY = translationY;
        applyTranslationY();
    }

    @Override
    public void setTranslationY(float translationY) {
        mTranslationY = translationY;
        applyTranslationY();
    }

    private void applyTranslationY() {
        super.setTranslationY(mTranslationY + mStashTranslationY);
    }

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

    private void applyDragTranslation() {
        setTranslationX(mDragTranslationX + mOffsetX);
    }

    @Override
    public void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
+4 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.launcher3.taskbar.bubbles.stashing

import android.graphics.Rect
import android.view.InsetsController
import android.view.MotionEvent
import android.view.View
@@ -146,6 +147,9 @@ interface BubbleStashController {
    /** Returns the translation of the handle. */
    fun getHandleTranslationY(): Float?

    /** Returns bounds of the handle */
    fun getHandleBounds(bounds: Rect)

    /**
     * Returns bubble bar Y position according to [isBubblesShowingOnHome] and
     * [isBubblesShowingOnOverview] values. Default implementation only analyse
Loading