Fix dismiss not working in landscape

In stack animation controller only one target would ever
be added so when the target is re-created after rotating
then it wouldn't be used.

Test: - have some bubbles, drag them around, rotate device, try to
        dismiss them => they can be dismissed in landscape
      - get more bubbles, rotate back to portrait, try to dismiss
        them => they can be dismissed in portrait
      - drag the stack around the edges of the screen and verify that
        the only magnetic spot is where the dismiss target is
Fixes: 193008696
Change-Id: I6b24b1f9d301d37749dc67c95392fd6c8451df00
This commit is contained in:
Mady Mellor
2021-07-14 13:15:19 -07:00
parent ce54693964
commit 5474359369
3 changed files with 17 additions and 18 deletions

View File

@@ -574,20 +574,17 @@ public class BubbleStackView extends FrameLayout
mBubbleContainer.setActiveController(mStackAnimationController); mBubbleContainer.setActiveController(mStackAnimationController);
hideFlyoutImmediate(); hideFlyoutImmediate();
if (!mPositioner.showingInTaskbar()) { if (mPositioner.showingInTaskbar()) {
// Also, save the magnetized stack so we can dispatch touch events to it.
mMagnetizedObject = mStackAnimationController.getMagnetizedStack(
mMagneticTarget);
mMagnetizedObject.setMagnetListener(mStackMagnetListener);
} else {
// In taskbar, the stack isn't draggable so we shouldn't dispatch touch events. // In taskbar, the stack isn't draggable so we shouldn't dispatch touch events.
mMagnetizedObject = null; mMagnetizedObject = null;
} else {
// Save the magnetized stack so we can dispatch touch events to it.
mMagnetizedObject = mStackAnimationController.getMagnetizedStack();
mMagnetizedObject.clearAllTargets();
mMagnetizedObject.addTarget(mMagneticTarget);
mMagnetizedObject.setMagnetListener(mStackMagnetListener);
} }
// Also, save the magnetized stack so we can dispatch touch events to it.
mMagnetizedObject = mStackAnimationController.getMagnetizedStack(mMagneticTarget);
mMagnetizedObject.setMagnetListener(mStackMagnetListener);
mIsDraggingStack = true; mIsDraggingStack = true;
// Cancel animations to make the stack temporarily invisible, since we're now // Cancel animations to make the stack temporarily invisible, since we're now
@@ -865,7 +862,6 @@ public class BubbleStackView extends FrameLayout
mRelativeStackPositionBeforeRotation = null; mRelativeStackPositionBeforeRotation = null;
} }
setUpDismissView();
if (mIsExpanded) { if (mIsExpanded) {
// Re-draw bubble row and pointer for new orientation. // Re-draw bubble row and pointer for new orientation.
beforeExpandedViewAnimation(); beforeExpandedViewAnimation();
@@ -1029,10 +1025,9 @@ public class BubbleStackView extends FrameLayout
contentResolver, "bubble_dismiss_radius", mBubbleSize * 2 /* default */); contentResolver, "bubble_dismiss_radius", mBubbleSize * 2 /* default */);
// Save the MagneticTarget instance for the newly set up view - we'll add this to the // Save the MagneticTarget instance for the newly set up view - we'll add this to the
// MagnetizedObjects. // MagnetizedObjects when the dismiss view gets shown.
mMagneticTarget = new MagnetizedObject.MagneticTarget( mMagneticTarget = new MagnetizedObject.MagneticTarget(
mDismissView.getCircle(), dismissRadius); mDismissView.getCircle(), dismissRadius);
mBubbleContainer.bringToFront(); mBubbleContainer.bringToFront();
} }

View File

@@ -1024,11 +1024,9 @@ public class StackAnimationController extends
} }
/** /**
* Returns the {@link MagnetizedObject} instance for the bubble stack, with the provided * Returns the {@link MagnetizedObject} instance for the bubble stack.
* {@link MagnetizedObject.MagneticTarget} added as a target.
*/ */
public MagnetizedObject<StackAnimationController> getMagnetizedStack( public MagnetizedObject<StackAnimationController> getMagnetizedStack() {
MagnetizedObject.MagneticTarget target) {
if (mMagnetizedStack == null) { if (mMagnetizedStack == null) {
mMagnetizedStack = new MagnetizedObject<StackAnimationController>( mMagnetizedStack = new MagnetizedObject<StackAnimationController>(
mLayout.getContext(), mLayout.getContext(),
@@ -1053,7 +1051,6 @@ public class StackAnimationController extends
loc[1] = (int) mStackPosition.y; loc[1] = (int) mStackPosition.y;
} }
}; };
mMagnetizedStack.addTarget(target);
mMagnetizedStack.setHapticsEnabled(true); mMagnetizedStack.setHapticsEnabled(true);
mMagnetizedStack.setFlingToTargetMinVelocity(FLING_TO_DISMISS_MIN_VELOCITY); mMagnetizedStack.setFlingToTargetMinVelocity(FLING_TO_DISMISS_MIN_VELOCITY);
} }

View File

@@ -302,6 +302,13 @@ abstract class MagnetizedObject<T : Any>(
associatedTargets.remove(target) associatedTargets.remove(target)
} }
/**
* Removes all associated targets from this object.
*/
fun clearAllTargets() {
associatedTargets.clear()
}
/** /**
* Provide this method with all motion events that move the magnetized object. If the * Provide this method with all motion events that move the magnetized object. If the
* location of the motion events moves within the magnetic field of a target, or indicate a * location of the motion events moves within the magnetic field of a target, or indicate a