MediaRouter: Don't animate dialog if the art is loaded quickly

When the controller dialog is popped up, expanding animation is always
fired even when loading image took very short time. If the loading time
is fast enough, expanding animation is unnecessary.

Bug: 28727905
Change-Id: Idf5e3888e915ae703a3aa10f02375fac9e8b1d74
diff --git a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
index f1e0af0..d414a57 100644
--- a/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
+++ b/v7/mediarouter/src/android/support/v7/app/MediaRouteControllerDialog.java
@@ -28,6 +28,7 @@
 import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.RemoteException;
+import android.os.SystemClock;
 import android.support.v4.media.MediaDescriptionCompat;
 import android.support.v4.media.MediaMetadataCompat;
 import android.support.v4.media.session.MediaControllerCompat;
@@ -1234,9 +1235,13 @@
     }
 
     private class FetchArtTask extends AsyncTask<Void, Void, Bitmap> {
-        final Bitmap mIconBitmap;
-        final Uri mIconUri;
-        int mBackgroundColor;
+        // Show animation only when fetching takes a long time.
+        private static final long SHOW_ANIM_TIME_THRESHOLD_MILLIS = 120L;
+
+        private final Bitmap mIconBitmap;
+        private final Uri mIconUri;
+        private int mBackgroundColor;
+        private long mStartTimeMillis;
 
         FetchArtTask() {
             mIconBitmap = mDescription == null ? null : mDescription.getIconBitmap();
@@ -1248,7 +1253,9 @@
             if (!isIconChanged()) {
                 // Already handled the current art.
                 cancel(true);
+                return;
             }
+            mStartTimeMillis = SystemClock.uptimeMillis();
         }
 
         @Override
@@ -1324,7 +1331,8 @@
 
                 mArtView.setImageBitmap(art);
                 mArtView.setBackgroundColor(mBackgroundColor);
-                updateLayoutHeight(true);
+                long elapsedTimeMillis = SystemClock.uptimeMillis() - mStartTimeMillis;
+                updateLayoutHeight(elapsedTimeMillis > SHOW_ANIM_TIME_THRESHOLD_MILLIS);
             }
         }