From af5a393f883dcf0a6afe1835ff5a7ffb44dd448a Mon Sep 17 00:00:00 2001 From: Ats Jenk Date: Wed, 29 May 2024 16:43:06 -0700 Subject: [PATCH] Fix bubble position when dragged to dismiss view When moving a bubble to dismiss view, use the drag translation x methods to set the translation x values. When bubble is moved to the dismiss view, the container will animate back to the initial position. And we need to account for this while bubble is in the dismiss view. Bug: 339659499 Flag: com.android.wm.shell.enable_bubble_bar Test: manual, drag bubble to other side and then to dismiss view, observe that bar moves back to original side and bubble is at the center of the dismiss view Change-Id: I4c6e1be2dcd1180d985ceafccfc0f18466549347 --- .../bubbles/BubbleDismissController.java | 3 +- .../taskbar/bubbles/BubbleDragAnimator.java | 22 +------------ .../taskbar/bubbles/BubbleDragController.java | 32 +++++++++++++++++++ .../launcher3/taskbar/bubbles/BubbleView.java | 21 ------------ 4 files changed, 35 insertions(+), 43 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDismissController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDismissController.java index 0e6fa3c5e8..a6096e229c 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDismissController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDismissController.java @@ -169,7 +169,8 @@ public class BubbleDismissController { private void setupMagnetizedObject(@NonNull View magnetizedView) { mMagnetizedObject = new MagnetizedObject<>(mActivity.getApplicationContext(), - magnetizedView, DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y) { + magnetizedView, BubbleDragController.DRAG_TRANSLATION_X, + DynamicAnimation.TRANSLATION_Y) { @Override public float getWidth(@NonNull View underlyingObject) { return underlyingObject.getWidth() * underlyingObject.getScaleX(); diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragAnimator.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragAnimator.java index 287e9067bf..7aed2d2abe 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragAnimator.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragAnimator.java @@ -60,7 +60,6 @@ public class BubbleDragAnimator { private final float mBubbleFocusedScale; private final float mBubbleCapturedScale; private final float mDismissCapturedScale; - private final FloatPropertyCompat mTranslationXProperty; /** * Should be initialised for each dragged view @@ -82,28 +81,9 @@ public class BubbleDragAnimator { if (view instanceof BubbleBarView) { mBubbleFocusedScale = SCALE_BUBBLE_BAR_FOCUSED; mBubbleCapturedScale = mDismissCapturedScale; - mTranslationXProperty = DynamicAnimation.TRANSLATION_X; } else { mBubbleFocusedScale = SCALE_BUBBLE_FOCUSED; mBubbleCapturedScale = SCALE_BUBBLE_CAPTURED; - // Wrap BubbleView.DRAG_TRANSLATION_X as it can't be cast to FloatPropertyCompat - mTranslationXProperty = new FloatPropertyCompat<>( - BubbleView.DRAG_TRANSLATION_X.getName()) { - @Override - public float getValue(View object) { - if (object instanceof BubbleView bubbleView) { - return BubbleView.DRAG_TRANSLATION_X.get(bubbleView); - } - return 0; - } - - @Override - public void setValue(View object, float value) { - if (object instanceof BubbleView bubbleView) { - BubbleView.DRAG_TRANSLATION_X.setValue(bubbleView, value); - } - } - }; } } @@ -140,7 +120,7 @@ public class BubbleDragAnimator { mBubbleAnimator .spring(DynamicAnimation.SCALE_X, 1f) .spring(DynamicAnimation.SCALE_Y, 1f) - .spring(mTranslationXProperty, restingPosition.x, velocity.x, + .spring(BubbleDragController.DRAG_TRANSLATION_X, restingPosition.x, velocity.x, mTranslationConfig) .spring(DynamicAnimation.TRANSLATION_Y, restingPosition.y, velocity.y, mTranslationConfig) diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragController.java index e04c1b1020..fbd1b88693 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleDragController.java @@ -24,6 +24,7 @@ import android.view.ViewConfiguration; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.dynamicanimation.animation.FloatPropertyCompat; import com.android.launcher3.taskbar.TaskbarActivityContext; import com.android.wm.shell.common.bubbles.BaseBubblePinController.LocationChangeListener; @@ -38,6 +39,37 @@ import com.android.wm.shell.common.bubbles.BubbleBarLocation; * Restores initial position of dragged view if released outside of the dismiss target. */ public class BubbleDragController { + + /** + * Property to update dragged bubble x-translation value. + *

+ * When applied to {@link BubbleView}, will use set the translation through + * {@link BubbleView#getDragTranslationX()} and {@link BubbleView#setDragTranslationX(float)} + * methods. + *

+ * When applied to {@link BubbleBarView}, will use {@link View#getTranslationX()} and + * {@link View#setTranslationX(float)}. + */ + public static final FloatPropertyCompat DRAG_TRANSLATION_X = new FloatPropertyCompat<>( + "dragTranslationX") { + @Override + public float getValue(View view) { + if (view instanceof BubbleView bubbleView) { + return bubbleView.getDragTranslationX(); + } + return view.getTranslationX(); + } + + @Override + public void setValue(View view, float value) { + if (view instanceof BubbleView bubbleView) { + bubbleView.setDragTranslationX(value); + } else { + view.setTranslationX(value); + } + } + }; + private final TaskbarActivityContext mActivity; private BubbleBarController mBubbleBarController; private BubbleBarViewController mBubbleBarViewController; diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java index 61a6bceca1..2e37dc7695 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleView.java @@ -22,13 +22,11 @@ import android.graphics.Canvas; import android.graphics.Outline; import android.graphics.Rect; import android.util.AttributeSet; -import android.util.FloatProperty; import android.view.LayoutInflater; import android.view.View; import android.view.ViewOutlineProvider; import android.widget.ImageView; -import androidx.annotation.NonNull; import androidx.constraintlayout.widget.ConstraintLayout; import com.android.launcher3.R; @@ -48,25 +46,6 @@ public class BubbleView extends ConstraintLayout { public static final int DEFAULT_PATH_SIZE = 100; - /** - * Property to update drag translation value. - * - * @see BubbleView#getDragTranslationX() - * @see BubbleView#setDragTranslationX(float) - */ - public static final FloatProperty DRAG_TRANSLATION_X = new FloatProperty<>( - "dragTranslationX") { - @Override - public void setValue(@NonNull BubbleView bubbleView, float value) { - bubbleView.setDragTranslationX(value); - } - - @Override - public Float get(BubbleView bubbleView) { - return bubbleView.getDragTranslationX(); - } - }; - /** * Flags that suppress the visibility of the 'new' dot or the app badge, for one reason or * another. If any of these flags are set, the dot will not be shown.