Bubble v2 dismiss.

Drag and drop bubble to bottom to hide or end call. Flinging to bottom does not trigger the actions. Color/text is not final. Navigation bar is not hiden and the change will be in a following CL.

Bug: 67605985
Test: NewBubbleTest
PiperOrigin-RevId: 180608133
Change-Id: Iff4cb32226d8fbf0f8e5319f6876a1d74c336b4a
diff --git a/java/com/android/newbubble/NewBubble.java b/java/com/android/newbubble/NewBubble.java
index 469c15d..f5a036f 100644
--- a/java/com/android/newbubble/NewBubble.java
+++ b/java/com/android/newbubble/NewBubble.java
@@ -60,6 +60,7 @@
 import android.view.animation.OvershootInterpolator;
 import android.widget.ImageView;
 import android.widget.TextView;
+import android.widget.Toast;
 import android.widget.ViewAnimator;
 import com.android.dialer.common.LogUtil;
 import com.android.dialer.logging.DialerImpression;
@@ -830,6 +831,12 @@
    */
   void replaceViewHolder() {
     LogUtil.enterBlock("NewBubble.replaceViewHolder");
+    // Don't do it. If windowParams is null, either we haven't initialized it or we set it to null.
+    // There is no need to recreate bubble.
+    if (windowParams == null) {
+      return;
+    }
+
     ViewHolder oldViewHolder = viewHolder;
 
     // Create a new ViewHolder and copy needed info.
@@ -873,6 +880,27 @@
     return viewHolder.getExpandedView().getVisibility();
   }
 
+  void bottomActionDismiss() {
+    logBasicOrCallImpression(DialerImpression.Type.BUBBLE_V2_BOTTOM_ACTION_DISMISS);
+    // Create bubble at default location at next time
+    hideAndReset();
+    windowParams = null;
+  }
+
+  void bottomActionEndCall() {
+    logBasicOrCallImpression(DialerImpression.Type.BUBBLE_V2_BOTTOM_ACTION_END_CALL);
+    // Hide without animation
+    hideHelper(
+        () -> {
+          defaultAfterHidingAnimation();
+          DialerCall call = getCall();
+          if (call != null) {
+            call.disconnect();
+            Toast.makeText(context, R.string.incall_call_ended, Toast.LENGTH_SHORT).show();
+          }
+        });
+  }
+
   private boolean isDrawingFromRight() {
     return (windowParams.gravity & Gravity.RIGHT) == Gravity.RIGHT;
   }
@@ -896,11 +924,7 @@
   }
 
   private void logBasicOrCallImpression(DialerImpression.Type impressionType) {
-    // Bubble is shown for outgoing, active or background call
-    DialerCall call = CallList.getInstance().getOutgoingCall();
-    if (call == null) {
-      call = CallList.getInstance().getActiveOrBackgroundCall();
-    }
+    DialerCall call = getCall();
     if (call != null) {
       Logger.get(context)
           .logCallImpression(impressionType, call.getUniqueCallId(), call.getTimeAddedMs());
@@ -909,6 +933,15 @@
     }
   }
 
+  private DialerCall getCall() {
+    // Bubble is shown for outgoing, active or background call
+    DialerCall call = CallList.getInstance().getOutgoingCall();
+    if (call == null) {
+      call = CallList.getInstance().getActiveOrBackgroundCall();
+    }
+    return call;
+  }
+
   private void setPrimaryButtonAccessibilityAction(String description) {
     viewHolder
         .getPrimaryButton()