Bubble v2 animation changes.

Including:
- expanded view expands/collapses from top of itself
- small icon on avatar shows on left side when bubble is on right side
- when expand on bottom, bubble move up a bit so that expanded view doesn't go off screen. It also go back to previous position when collapse.
- remove animation for collapse when move expanded bubble

This change should not enable bubble v2 for anyone.

Bug: 67605985
Test: manual
PiperOrigin-RevId: 177974562
Change-Id: Id83f3f744b717d51fbe58e58769ac2cd2810d2b5
diff --git a/java/com/android/newbubble/NewMoveHandler.java b/java/com/android/newbubble/NewMoveHandler.java
index 189ad84..9cb1f1e 100644
--- a/java/com/android/newbubble/NewMoveHandler.java
+++ b/java/com/android/newbubble/NewMoveHandler.java
@@ -48,6 +48,8 @@
   private final int maxX;
   private final int maxY;
   private final int bubbleSize;
+  private final int bubbleShadowPaddingHorizontal;
+  private final int bubbleExpandedViewWidth;
   private final float touchSlopSquared;
 
   private boolean clickable = true;
@@ -70,8 +72,14 @@
         @Override
         public float getValue(LayoutParams windowParams) {
           int realX = windowParams.x;
-          realX = realX + bubbleSize / 2;
+          // Get bubble center position from real position
+          if (bubble.getDrawerVisibility() == View.INVISIBLE) {
+            realX += bubbleExpandedViewWidth / 2 + bubbleShadowPaddingHorizontal * 2;
+          } else {
+            realX += bubbleSize / 2 + bubbleShadowPaddingHorizontal;
+          }
           if (relativeToRight(windowParams)) {
+            // If gravity is right, get distant from bubble center position to screen right edge
             int displayWidth = context.getResources().getDisplayMetrics().widthPixels;
             realX = displayWidth - realX;
           }
@@ -88,12 +96,19 @@
           } else {
             onRight = (gravityOverride & Gravity.RIGHT) == Gravity.RIGHT;
           }
-          int centeringOffset = bubbleSize / 2;
+          // Get real position from bubble center position
+          int centeringOffset;
+          if (bubble.getDrawerVisibility() == View.INVISIBLE) {
+            centeringOffset = bubbleExpandedViewWidth / 2 + bubbleShadowPaddingHorizontal * 2;
+          } else {
+            centeringOffset = bubbleSize / 2 + bubbleShadowPaddingHorizontal;
+          }
           windowParams.x =
               (int) (onRight ? (displayWidth - value - centeringOffset) : value - centeringOffset);
           windowParams.gravity = Gravity.TOP | (onRight ? Gravity.RIGHT : Gravity.LEFT);
           if (bubble.isVisible()) {
             windowManager.updateViewLayout(bubble.getRootView(), windowParams);
+            bubble.onLeftRightSwitch(onRight);
           }
         }
       };
@@ -120,8 +135,13 @@
     windowManager = context.getSystemService(WindowManager.class);
 
     bubbleSize = context.getResources().getDimensionPixelSize(R.dimen.bubble_size);
+    bubbleShadowPaddingHorizontal =
+        context.getResources().getDimensionPixelSize(R.dimen.bubble_shadow_padding_size_horizontal);
+    bubbleExpandedViewWidth =
+        context.getResources().getDimensionPixelSize(R.dimen.bubble_expanded_width);
+    // The following value is based on bubble center
     minX =
-        context.getResources().getDimensionPixelOffset(R.dimen.bubble_safe_margin_horizontal)
+        context.getResources().getDimensionPixelOffset(R.dimen.bubble_off_screen_size_horizontal)
             + bubbleSize / 2;
     minY =
         context.getResources().getDimensionPixelOffset(R.dimen.bubble_safe_margin_vertical)
@@ -156,6 +176,12 @@
     moveYAnimation.animateToFinalPosition(yProperty.getValue(bubble.getWindowParams()));
   }
 
+  public int getMoveUpDistance(int deltaAllowed) {
+    int currentY = (int) yProperty.getValue(bubble.getWindowParams());
+    int currentDelta = maxY - currentY;
+    return currentDelta >= deltaAllowed ? 0 : deltaAllowed - currentDelta;
+  }
+
   @Override
   public boolean onTouch(View v, MotionEvent event) {
     float eventX = event.getRawX();
@@ -222,6 +248,14 @@
       moveXAnimation = new SpringAnimation(bubble.getWindowParams(), xProperty);
       moveXAnimation.setSpring(new SpringForce());
       moveXAnimation.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY);
+      // Moving when expanded makes expanded view INVISIBLE, and the whole view is not at the
+      // boundary. It's time to create a viewHolder.
+      moveXAnimation.addEndListener(
+          (animation, canceled, value, velocity) -> {
+            if (!isMoving && bubble.getDrawerVisibility() == View.INVISIBLE) {
+              bubble.replaceViewHolder();
+            }
+          });
     }
 
     if (moveYAnimation == null) {