Update user aspcet ratio settings button animation

Increase the fade in animation to 167ms. When showin the button, add a
scale animation going from 0.8 to 1 with a duration of 300ms.

Add a fade out animation with a duration of 167ms.

Fixes: 296563422
Fixes: 301934717
Test: Manual
Change-Id: I12d064a34302cf56abdc067150e8639020da0d82
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/UserAspectRatioSettingsLayout.java b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/UserAspectRatioSettingsLayout.java
index 5eeb3b6..b141beb 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/UserAspectRatioSettingsLayout.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/compatui/UserAspectRatioSettingsLayout.java
@@ -18,12 +18,16 @@
 
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
+import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
 import android.annotation.IdRes;
 import android.annotation.NonNull;
 import android.content.Context;
 import android.util.AttributeSet;
 import android.view.View;
+import android.view.animation.Interpolator;
+import android.view.animation.LinearInterpolator;
+import android.view.animation.PathInterpolator;
 import android.widget.ImageButton;
 import android.widget.LinearLayout;
 import android.widget.TextView;
@@ -36,14 +40,29 @@
  */
 public class UserAspectRatioSettingsLayout extends LinearLayout {
 
+    private static final Interpolator LINEAR_INTERPOLATOR = new LinearInterpolator();
+
+    private static final Interpolator PATH_INTERPOLATOR =
+            new PathInterpolator(0.2f, 0f, 0f, 1f);
+
     private static final float ALPHA_FULL_TRANSPARENT = 0f;
 
     private static final float ALPHA_FULL_OPAQUE = 1f;
 
-    private static final long VISIBILITY_ANIMATION_DURATION_MS = 50;
+    private static final float SCALE_START = 0.8f;
+
+    private static final float SCALE_END = 1f;
+
+    private static final long FADE_ANIMATION_DURATION_MS = 167;
+
+    private static final long SCALE_ANIMATION_DURATION_MS = 300;
 
     private static final String ALPHA_PROPERTY_NAME = "alpha";
 
+    private static final String SCALE_X_PROPERTY_NAME = "scaleX";
+
+    private static final String SCALE_Y_PROPERTY_NAME = "scaleY";
+
     private UserAspectRatioSettingsWindowManager mWindowManager;
 
     public UserAspectRatioSettingsLayout(Context context) {
@@ -88,7 +107,7 @@
         if (show) {
             showItem(view);
         } else {
-            view.setVisibility(visibility);
+            hideItem(view);
         }
     }
 
@@ -121,16 +140,40 @@
     }
 
     private void showItem(@NonNull View view) {
-        view.setVisibility(View.VISIBLE);
+        final AnimatorSet animatorSet = new AnimatorSet();
         final ObjectAnimator fadeIn = ObjectAnimator.ofFloat(view, ALPHA_PROPERTY_NAME,
                 ALPHA_FULL_TRANSPARENT, ALPHA_FULL_OPAQUE);
-        fadeIn.setDuration(VISIBILITY_ANIMATION_DURATION_MS);
-        fadeIn.addListener(new AnimatorListenerAdapter() {
+        fadeIn.setDuration(FADE_ANIMATION_DURATION_MS);
+        fadeIn.setInterpolator(LINEAR_INTERPOLATOR);
+        final ObjectAnimator scaleY =
+                ObjectAnimator.ofFloat(view, SCALE_Y_PROPERTY_NAME, SCALE_START, SCALE_END);
+        final ObjectAnimator scaleX =
+                ObjectAnimator.ofFloat(view, SCALE_X_PROPERTY_NAME, SCALE_START, SCALE_END);
+        scaleX.setDuration(SCALE_ANIMATION_DURATION_MS);
+        scaleX.setInterpolator(PATH_INTERPOLATOR);
+        scaleY.setDuration(SCALE_ANIMATION_DURATION_MS);
+        scaleY.setInterpolator(PATH_INTERPOLATOR);
+        animatorSet.addListener(new AnimatorListenerAdapter() {
             @Override
-            public void onAnimationEnd(Animator animation) {
+            public void onAnimationStart(Animator animation) {
                 view.setVisibility(View.VISIBLE);
             }
         });
-        fadeIn.start();
+        animatorSet.playTogether(fadeIn, scaleY, scaleX);
+        animatorSet.start();
+    }
+
+    private void hideItem(@NonNull View view) {
+        final ObjectAnimator fadeOut = ObjectAnimator.ofFloat(view, ALPHA_PROPERTY_NAME,
+                ALPHA_FULL_OPAQUE, ALPHA_FULL_TRANSPARENT);
+        fadeOut.setDuration(FADE_ANIMATION_DURATION_MS);
+        fadeOut.setInterpolator(LINEAR_INTERPOLATOR);
+        fadeOut.addListener(new AnimatorListenerAdapter() {
+            @Override
+            public void onAnimationEnd(Animator animation) {
+                view.setVisibility(View.GONE);
+            }
+        });
+        fadeOut.start();
     }
 }