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
This commit is contained in:
Ats Jenk
2024-05-29 16:43:06 -07:00
parent 348ac13cfe
commit af5a393f88
4 changed files with 35 additions and 43 deletions

View File

@@ -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();

View File

@@ -60,7 +60,6 @@ public class BubbleDragAnimator {
private final float mBubbleFocusedScale;
private final float mBubbleCapturedScale;
private final float mDismissCapturedScale;
private final FloatPropertyCompat<View> 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<View>
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)

View File

@@ -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.
* <p>
* When applied to {@link BubbleView}, will use set the translation through
* {@link BubbleView#getDragTranslationX()} and {@link BubbleView#setDragTranslationX(float)}
* methods.
* <p>
* When applied to {@link BubbleBarView}, will use {@link View#getTranslationX()} and
* {@link View#setTranslationX(float)}.
*/
public static final FloatPropertyCompat<View> 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;

View File

@@ -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<BubbleView> 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.