Use Glide for thumbnail and image loading

Use Glide for thumbnail loading. This helps us preview GIF without any
extra work.

Bug: 185801129
Test: Manual, video with the bug

Change-Id: If687ef26433886627f5f5ad7c04f9ce1df7f0aeb
Merged-In: If687ef26433886627f5f5ad7c04f9ce1df7f0aeb
(cherry picked from commit c70976a4b537b7d770f10696d67b08e8800fc7bb)
diff --git a/Android.bp b/Android.bp
index 60688a5..022dab4 100644
--- a/Android.bp
+++ b/Android.bp
@@ -29,6 +29,7 @@
         "com.google.android.material_material",
         "guava",
         "modules-utils-build",
+        "glide-prebuilt",
     ],
 
     libs: [
diff --git a/src/com/android/providers/media/photopicker/ui/ImageLoader.java b/src/com/android/providers/media/photopicker/ui/ImageLoader.java
index 1101444..2519a37 100644
--- a/src/com/android/providers/media/photopicker/ui/ImageLoader.java
+++ b/src/com/android/providers/media/photopicker/ui/ImageLoader.java
@@ -17,27 +17,18 @@
 package com.android.providers.media.photopicker.ui;
 
 import android.content.Context;
-
-import android.graphics.Bitmap;
-import android.graphics.ImageDecoder;
-import android.graphics.drawable.BitmapDrawable;
-import android.util.Log;
-import android.util.Size;
 import android.widget.ImageView;
 
-import com.android.providers.media.R;
+import com.bumptech.glide.Glide;
+
 import com.android.providers.media.photopicker.data.model.Item;
 
-import java.io.IOException;
-
-
 /**
  * A class to assist with loading and managing the Images (i.e. thumbnails and preview) associated
  * with item.
  */
 public class ImageLoader {
 
-    private static final String TAG = "ImageLoader";
     private final Context mContext;
 
     public ImageLoader(Context context) {
@@ -45,32 +36,17 @@
     }
 
     public void loadPhotoThumbnail(Item item, ImageView imageView) {
-        int thumbSize = getThumbSize();
-        final Size size = new Size(thumbSize, thumbSize);
-        try {
-            Bitmap bitmap = mContext.getContentResolver().loadThumbnail(item.getContentUri(),
-                    size, null);
-            imageView.setImageDrawable(new BitmapDrawable(mContext.getResources(), bitmap));
-        } catch (IOException ex) {
-            Log.d(TAG, "Loading icon failed", ex);
-            imageView.setImageDrawable(null);
-        }
+        Glide.with(mContext)
+                .load(item.getContentUri())
+                .thumbnail()
+                .into(imageView);
     }
 
     public void loadImagePreview(Item item, ImageView imageView) {
-       // TODO(b/185801129): Use Glide for image loading
        // TODO(b/185801129): Load image in background thread. Loading the image blocks loading the
        // layout now.
-        try {
-            imageView.setImageBitmap(ImageDecoder.decodeBitmap(ImageDecoder.createSource(
-                    mContext.getContentResolver(), item.getContentUri())));
-        } catch (IOException e) {
-            Log.d(TAG, "Failed loading image for uri " + item.getContentUri(), e);
-            imageView.setImageBitmap(null);
-        }
-    }
-
-    private int getThumbSize() {
-        return mContext.getResources().getDimensionPixelSize(R.dimen.picker_photo_size);
+        Glide.with(mContext)
+                .load(item.getContentUri())
+                .into(imageView);
     }
 }
diff --git a/tests/Android.bp b/tests/Android.bp
index 693fe69..508a19a 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -131,6 +131,7 @@
         "androidx.test.espresso.contrib",
         "androidx.test.core",
         "androidx.arch.core_core-runtime",
+        "glide-prebuilt",
     ],
 
     certificate: "media",