Fix animation of first time showing dialpad FAB.

In order to correctly show animation, we have to ensure:
1. fab.scaleIn() is not called before dialpad is slide up.
2. fab is invisible before scaleIn is called.

Caveat:
This change is not tested on old UI (DialtactsActivity) since it's deprecated.
Test: manual
PiperOrigin-RevId: 189765153
Change-Id: Iada96b2789f96ca1612ae2048020a649f8b57b6b
diff --git a/java/com/android/dialer/dialpadview/DialpadFragment.java b/java/com/android/dialer/dialpadview/DialpadFragment.java
index 578f35e..833b91f 100644
--- a/java/com/android/dialer/dialpadview/DialpadFragment.java
+++ b/java/com/android/dialer/dialpadview/DialpadFragment.java
@@ -83,7 +83,6 @@
 import com.android.dialer.common.concurrent.DialerExecutor;
 import com.android.dialer.common.concurrent.DialerExecutor.Worker;
 import com.android.dialer.common.concurrent.DialerExecutorComponent;
-import com.android.dialer.common.concurrent.ThreadUtil;
 import com.android.dialer.location.GeoUtil;
 import com.android.dialer.logging.UiAction;
 import com.android.dialer.oem.MotorolaUtils;
@@ -648,6 +647,14 @@
     LogUtil.i("DialpadFragment.onStart", "first launch: %b", firstLaunch);
     Trace.beginSection(TAG + " onStart");
     super.onStart();
+    Resources res = getResources();
+    int iconId = R.drawable.quantum_ic_call_vd_theme_24;
+    if (MotorolaUtils.isWifiCallingAvailable(getContext())) {
+      iconId = R.drawable.ic_wifi_calling;
+    }
+    floatingActionButtonController.changeIcon(
+        getContext(), iconId, res.getString(R.string.description_dial_button));
+
     // if the mToneGenerator creation fails, just continue without it.  It is
     // a local audio signal, and is not as important as the dtmf tone itself.
     final long start = System.currentTimeMillis();
@@ -676,14 +683,6 @@
     Trace.beginSection(TAG + " onResume");
     super.onResume();
 
-    Resources res = getResources();
-    int iconId = R.drawable.quantum_ic_call_vd_theme_24;
-    if (MotorolaUtils.isWifiCallingAvailable(getContext())) {
-      iconId = R.drawable.ic_wifi_calling;
-    }
-    floatingActionButtonController.changeIcon(
-        getContext(), iconId, res.getString(R.string.description_dial_button));
-
     dialpadQueryListener = FragmentUtils.getParentUnsafe(this, OnDialpadQueryChangedListener.class);
 
     final StopWatch stopWatch = StopWatch.start("Dialpad.onResume");
@@ -1247,19 +1246,14 @@
       if (dialpadView != null) {
         LogUtil.i("DialpadFragment.showDialpadChooser", "mDialpadView not null");
         dialpadView.setVisibility(View.VISIBLE);
-        floatingActionButtonController.scaleIn();
+        if (isDialpadSlideUp()) {
+          floatingActionButtonController.scaleIn();
+        }
       } else {
         LogUtil.i("DialpadFragment.showDialpadChooser", "mDialpadView null");
         digits.setVisibility(View.VISIBLE);
       }
 
-      // mFloatingActionButtonController must also be 'scaled in', in order to be visible after
-      // 'scaleOut()' hidden method.
-      if (!floatingActionButtonController.isVisible()) {
-        // Just call 'scaleIn()' method if the mFloatingActionButtonController was not already
-        // previously visible.
-        floatingActionButtonController.scaleIn();
-      }
       dialpadChooser.setVisibility(View.GONE);
     }
   }
@@ -1475,18 +1469,8 @@
       if (animate) {
         dialpadView.animateShow();
       }
-      ThreadUtil.getUiThreadHandler()
-          .postDelayed(
-              () -> {
-                if (!isDialpadChooserVisible()) {
-                  floatingActionButtonController.scaleIn();
-                }
-              },
-              animate ? dialpadSlideInDuration : 0);
       FragmentUtils.getParentUnsafe(this, DialpadListener.class).onDialpadShown();
       digits.requestFocus();
-    } else if (hidden) {
-      floatingActionButtonController.scaleOut();
     }
   }
 
@@ -1549,6 +1533,7 @@
     slideDown.setAnimationListener(listener);
     slideDown.setDuration(animate ? dialpadSlideInDuration : 0);
     getView().startAnimation(slideDown);
+    floatingActionButtonController.scaleOut();
   }
 
   /** Animate the dialpad up onto the screen. */
@@ -1564,6 +1549,19 @@
     Animation slideUp = AnimationUtils.loadAnimation(getContext(), animation);
     slideUp.setInterpolator(AnimUtils.EASE_IN);
     slideUp.setDuration(animate ? dialpadSlideInDuration : 0);
+    slideUp.setAnimationListener(
+        new AnimationListener() {
+          @Override
+          public void onAnimationStart(Animation animation) {}
+
+          @Override
+          public void onAnimationEnd(Animation animation) {
+            floatingActionButtonController.scaleIn();
+          }
+
+          @Override
+          public void onAnimationRepeat(Animation animation) {}
+        });
     getView().startAnimation(slideUp);
   }
 
diff --git a/java/com/android/dialer/dialpadview/res/layout-land/dialpad_fragment.xml b/java/com/android/dialer/dialpadview/res/layout-land/dialpad_fragment.xml
index 6389853..a2fbbab 100644
--- a/java/com/android/dialer/dialpadview/res/layout-land/dialpad_fragment.xml
+++ b/java/com/android/dialer/dialpadview/res/layout-land/dialpad_fragment.xml
@@ -20,33 +20,33 @@
     android:layout_height="wrap_content">
 
   <LinearLayout
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:orientation="horizontal">
+      android:layout_width="match_parent"
+      android:layout_height="wrap_content"
+      android:orientation="horizontal">
 
     <!-- spacer view -->
     <View
-      android:id="@+id/spacer"
-      android:layout_width="0dp"
-      android:layout_height="match_parent"
-      android:layout_weight="4"
-      android:background="#00000000"/>
+        android:id="@+id/spacer"
+        android:layout_width="0dp"
+        android:layout_height="match_parent"
+        android:layout_weight="4"
+        android:background="#00000000"/>
 
     <!-- Dialpad shadow -->
     <View
-      android:layout_width="@dimen/shadow_length"
-      android:layout_height="match_parent"
-      android:background="@drawable/shadow_fade_left"/>
+        android:layout_width="@dimen/shadow_length"
+        android:layout_height="match_parent"
+        android:background="@drawable/shadow_fade_left"/>
 
     <RelativeLayout
-      android:layout_width="0dp"
-      android:layout_height="match_parent"
-      android:layout_weight="6">
+        android:layout_width="0dp"
+        android:layout_height="match_parent"
+        android:layout_weight="6">
 
       <include
-        layout="@layout/dialpad_view"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent"/>
+          layout="@layout/dialpad_view"
+          android:layout_width="match_parent"
+          android:layout_height="match_parent"/>
 
       <!-- "Dialpad chooser" UI, shown only when the user brings up the
                Dialer while a call is already in progress.
@@ -54,18 +54,18 @@
                (the textfield/button and the dialpad) are hidden. -->
 
       <ListView
-        android:id="@+id/dialpadChooser"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:background="@color/background_dialer_light"
-        android:visibility="gone"/>
+          android:id="@+id/dialpadChooser"
+          android:layout_width="match_parent"
+          android:layout_height="wrap_content"
+          android:background="@color/background_dialer_light"
+          android:visibility="gone"/>
 
       <!-- Margin bottom and alignParentBottom don't work well together, so use a Space instead. -->
       <Space
-        android:id="@+id/dialpad_floating_action_button_margin_bottom"
-        android:layout_width="match_parent"
-        android:layout_height="@dimen/floating_action_button_margin_bottom"
-        android:layout_alignParentBottom="true"/>
+          android:id="@+id/dialpad_floating_action_button_margin_bottom"
+          android:layout_width="match_parent"
+          android:layout_height="@dimen/floating_action_button_margin_bottom"
+          android:layout_alignParentBottom="true"/>
 
       <android.support.design.widget.FloatingActionButton
           android:id="@+id/dialpad_floating_action_button"
@@ -73,10 +73,11 @@
           android:layout_height="@dimen/floating_action_button_height"
           android:layout_above="@id/dialpad_floating_action_button_margin_bottom"
           android:layout_centerHorizontal="true"
-          android:src="@drawable/quantum_ic_call_white_24"
           android:contentDescription="@string/description_dial_button"
-          app:elevation="@dimen/floating_action_button_translation_z"
-          app:backgroundTint="@color/dialpad_fab_green"/>
+          android:src="@drawable/quantum_ic_call_white_24"
+          android:visibility="invisible"
+          app:backgroundTint="@color/dialpad_fab_green"
+          app:elevation="@dimen/floating_action_button_translation_z"/>
     </RelativeLayout>
   </LinearLayout>
 </view>
diff --git a/java/com/android/dialer/dialpadview/res/layout/dialpad_fragment.xml b/java/com/android/dialer/dialpadview/res/layout/dialpad_fragment.xml
index 2e6b6ec..4a8ac07 100644
--- a/java/com/android/dialer/dialpadview/res/layout/dialpad_fragment.xml
+++ b/java/com/android/dialer/dialpadview/res/layout/dialpad_fragment.xml
@@ -67,6 +67,7 @@
       android:contentDescription="@string/description_dial_button"
       android:src="@drawable/quantum_ic_call_vd_theme_24"
       android:tint="#ffffff"
+      android:visibility="invisible"
       app:backgroundTint="@color/dialpad_fab_green"
       app:colorControlNormal="#ffffff"
       app:elevation="@dimen/floating_action_button_translation_z"/>