Merging ub-launcher3-qt-r1-dev, build 5706291
am: 70528c08dc

Change-Id: I09964df1efaf4977a408ffc263cc17e5a206d622
diff --git a/res/drawable/ic_colorize_24px.xml b/res/drawable/ic_colorize_24px.xml
index 8363683..fb70972 100644
--- a/res/drawable/ic_colorize_24px.xml
+++ b/res/drawable/ic_colorize_24px.xml
@@ -14,8 +14,8 @@
      limitations under the License.
 -->
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
-    android:width="32dp"
-    android:height="32dp"
+    android:width="24dp"
+    android:height="24dp"
     android:viewportWidth="24"
     android:viewportHeight="24">
     <path
diff --git a/res/drawable/ic_font.xml b/res/drawable/ic_font.xml
index 6ce8308..f5df7ba 100644
--- a/res/drawable/ic_font.xml
+++ b/res/drawable/ic_font.xml
@@ -14,8 +14,8 @@
      limitations under the License.
 -->
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
-    android:width="32dp"
-    android:height="32dp"
+    android:width="24dp"
+    android:height="24dp"
     android:viewportWidth="24"
     android:viewportHeight="24">
     <!-- This path represents a square with rounded corners -->
diff --git a/res/drawable/ic_nav_wallpaper.xml b/res/drawable/ic_nav_wallpaper.xml
index a884a44..c935666 100644
--- a/res/drawable/ic_nav_wallpaper.xml
+++ b/res/drawable/ic_nav_wallpaper.xml
@@ -15,8 +15,8 @@
 -->
 <!-- Represents the wallpaper icon (a "landscape" shape in a box) -->
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
-    android:width="32dp"
-    android:height="32dp"
+    android:width="24dp"
+    android:height="24dp"
     android:viewportWidth="24"
     android:viewportHeight="24">
     <path
diff --git a/res/drawable/ic_shapes_24px.xml b/res/drawable/ic_shapes_24px.xml
index 6debc53..525f757 100644
--- a/res/drawable/ic_shapes_24px.xml
+++ b/res/drawable/ic_shapes_24px.xml
@@ -14,8 +14,8 @@
      limitations under the License.
 -->
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
-    android:width="32dp"
-    android:height="32dp"
+    android:width="24dp"
+    android:height="24dp"
     android:viewportWidth="24"
     android:viewportHeight="24">
     <path
diff --git a/res/drawable/ic_wifi_24px.xml b/res/drawable/ic_wifi_24px.xml
index 64834e0..0e27c57 100644
--- a/res/drawable/ic_wifi_24px.xml
+++ b/res/drawable/ic_wifi_24px.xml
@@ -14,8 +14,8 @@
      limitations under the License.
 -->
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
-    android:width="32dp"
-    android:height="32dp"
+    android:width="24dp"
+    android:height="24dp"
     android:viewportWidth="24"
     android:viewportHeight="24">
     <path
diff --git a/res/values-land/dimens.xml b/res/values-land/dimens.xml
index ddf84e8..985987f 100644
--- a/res/values-land/dimens.xml
+++ b/res/values-land/dimens.xml
@@ -18,6 +18,7 @@
 <resources>
     <dimen name="card_title_text_size">12sp</dimen>
     <dimen name="card_cover_title_text_size">14sp</dimen>
+    <dimen name="card_header_icon_size">24dp</dimen>
     <dimen name="card_header_top_margin">6dp</dimen>
     <dimen name="preview_card_padding">8dp</dimen>
     <dimen name="preview_card_top_padding">6dp</dimen>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 5c98fda..b6aac0b 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -66,6 +66,7 @@
 
     <dimen name="card_title_text_size">16sp</dimen>
     <dimen name="card_cover_title_text_size">24sp</dimen>
+    <dimen name="card_header_icon_size">32dp</dimen>
     <dimen name="card_header_top_margin">0dp</dimen>
     <dimen name="preview_pager_max_height">450dp</dimen>
     <dimen name="preview_pager_min_height">350dp</dimen>
diff --git a/src/com/android/customization/model/theme/DefaultThemeProvider.java b/src/com/android/customization/model/theme/DefaultThemeProvider.java
index 9fdb0c9..ce12d35 100644
--- a/src/com/android/customization/model/theme/DefaultThemeProvider.java
+++ b/src/com/android/customization/model/theme/DefaultThemeProvider.java
@@ -35,7 +35,6 @@
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.ResolveInfo;
-import android.content.res.Resources;
 import android.content.res.Resources.NotFoundException;
 import android.service.wallpaper.WallpaperService;
 import android.text.TextUtils;
@@ -53,6 +52,7 @@
 import com.android.wallpaper.model.LiveWallpaperInfo;
 
 import com.bumptech.glide.request.RequestOptions;
+import com.google.android.apps.wallpaper.asset.ThemeBundleThumbAsset;
 
 import org.json.JSONArray;
 import org.json.JSONException;
@@ -204,7 +204,7 @@
                         mStubApkResources.getIdentifier(WALLPAPER_ACTION_PREFIX + themeName,
                                 "string", mStubPackageName))
                         .setWallpaperAsset(wallpaperThumbnailResId != ID_NULL ?
-                                getDrawableResourceAsset(WALLPAPER_THUMB_PREFIX, themeName)
+                                getThumbAsset(WALLPAPER_THUMB_PREFIX, themeName)
                                 : getDrawableResourceAsset(WALLPAPER_PREFIX, themeName));
             } else {
                 // Try to see if it's a live wallpaper reference
@@ -234,7 +234,7 @@
                             LiveWallpaperInfo liveInfo = new LiveWallpaperInfo(wallpaperInfo);
                             builder.setLiveWallpaperInfo(liveInfo).setWallpaperAsset(
                                     wallpaperThumbnailResId != ID_NULL ?
-                                        getDrawableResourceAsset(WALLPAPER_THUMB_PREFIX, themeName)
+                                            getThumbAsset(WALLPAPER_THUMB_PREFIX, themeName)
                                         : liveInfo.getThumbAsset(mContext))
                                     .setWallpaperOptions(wallpaperOptions);
                         } catch (XmlPullParserException | IOException e) {
@@ -484,4 +484,11 @@
         return drawableResId == 0 ? null : new ResourceAsset(mStubApkResources, drawableResId,
                 RequestOptions.fitCenterTransform());
     }
+
+    private ThemeBundleThumbAsset getThumbAsset(String prefix, String themeName) {
+        int drawableResId = mStubApkResources.getIdentifier(prefix + themeName,
+                "drawable", mStubPackageName);
+        return drawableResId == 0 ? null : new ThemeBundleThumbAsset(mStubApkResources,
+                drawableResId);
+    }
 }
diff --git a/src/com/android/customization/model/theme/custom/ThemeComponentOption.java b/src/com/android/customization/model/theme/custom/ThemeComponentOption.java
index ff8da08..f918d8e 100644
--- a/src/com/android/customization/model/theme/custom/ThemeComponentOption.java
+++ b/src/com/android/customization/model/theme/custom/ThemeComponentOption.java
@@ -163,7 +163,13 @@
             @DrawableRes int headerIcon) {
         TextView header = container.findViewById(R.id.theme_preview_card_header);
         header.setText(headerTextResId);
-        header.setCompoundDrawablesWithIntrinsicBounds(0, headerIcon, 0, 0);
+
+        Context context = container.getContext();
+        Drawable icon = context.getResources().getDrawable(headerIcon, context.getTheme());
+        int size = context.getResources().getDimensionPixelSize(R.dimen.card_header_icon_size);
+        icon.setBounds(0, 0, size, size);
+
+        header.setCompoundDrawables(null, icon, null, null);
         header.setCompoundDrawableTintList(ColorStateList.valueOf(
                 header.getCurrentTextColor()));
     }
diff --git a/src/com/android/customization/picker/theme/ThemePreviewPage.java b/src/com/android/customization/picker/theme/ThemePreviewPage.java
index f00cd3f..0543b24 100644
--- a/src/com/android/customization/picker/theme/ThemePreviewPage.java
+++ b/src/com/android/customization/picker/theme/ThemePreviewPage.java
@@ -38,8 +38,7 @@
 
     @StringRes
     final int nameResId;
-    @DrawableRes
-    final int iconSrc;
+    final Drawable icon;
     @LayoutRes
     final int contentLayoutRes;
     @ColorInt
@@ -51,7 +50,13 @@
             @ColorInt int accentColor) {
         super(null);
         this.nameResId = titleResId;
-        this.iconSrc = iconSrc;
+        if (iconSrc != Resources.ID_NULL) {
+            this.icon = context.getResources().getDrawable(iconSrc, context.getTheme());
+            int size = context.getResources().getDimensionPixelSize(R.dimen.card_header_icon_size);
+            icon.setBounds(0, 0, size, size);
+        } else {
+            this.icon = null;
+        }
         this.contentLayoutRes = contentLayoutRes;
         this.accentColor = accentColor;
         this.inflater = LayoutInflater.from(context);
@@ -61,7 +66,7 @@
     public void bindPreviewContent() {
         TextView header = card.findViewById(R.id.theme_preview_card_header);
         header.setText(nameResId);
-        header.setCompoundDrawablesWithIntrinsicBounds(0, iconSrc, 0, 0);
+        header.setCompoundDrawables(null, icon, null, null);
         header.setCompoundDrawableTintList(ColorStateList.valueOf(accentColor));
         card.findViewById(R.id.theme_preview_top_bar).setVisibility(View.GONE);
         card.findViewById(R.id.edit_label).setVisibility(View.GONE);
diff --git a/src/com/google/android/apps/wallpaper/asset/ThemeBundleThumbAsset.java b/src/com/google/android/apps/wallpaper/asset/ThemeBundleThumbAsset.java
new file mode 100644
index 0000000..bc5f309
--- /dev/null
+++ b/src/com/google/android/apps/wallpaper/asset/ThemeBundleThumbAsset.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.android.apps.wallpaper.asset;
+
+import android.app.Activity;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Rect;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.LayerDrawable;
+import android.os.AsyncTask;
+
+import androidx.annotation.Nullable;
+
+import com.android.wallpaper.asset.Asset;
+import com.android.wallpaper.module.DrawableLayerResolver;
+import com.android.wallpaper.module.InjectorProvider;
+
+public class ThemeBundleThumbAsset extends Asset {
+    private final Resources mRes;
+    private final int mResId;
+    private final DrawableLayerResolver mLayerResolver;
+
+    public ThemeBundleThumbAsset(Resources res, int resId) {
+        mRes = res;
+        mResId = resId;
+        mLayerResolver = InjectorProvider.getInjector().getDrawableLayerResolver();
+    }
+
+    @Override
+    public void decodeBitmap(int targetWidth, int targetHeight, BitmapReceiver receiver) {
+        // No scaling is needed, as the thumbnail is already a thumbnail.
+        LoadThumbnailTask task = new LoadThumbnailTask(mRes, mResId, mLayerResolver, receiver);
+        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+    }
+
+    @Override
+    public void decodeBitmapRegion(Rect rect, int targetWidth, int targetHeight,
+            BitmapReceiver receiver) {
+
+    }
+
+    @Override
+    public void decodeRawDimensions(@Nullable Activity activity, DimensionsReceiver receiver) {
+
+    }
+
+    @Override
+    public boolean supportsTiling() {
+        return false;
+    }
+
+    /**
+     * AsyncTask subclass which loads the live wallpaper's thumbnail bitmap off the main UI thread.
+     * Resolves with null if live wallpaper thumbnail is not a bitmap.
+     */
+    private static class LoadThumbnailTask extends AsyncTask<Void, Void, Bitmap> {
+        private final DrawableLayerResolver mLayerResolver;
+        private final Resources mResources;
+        private final int mResId;
+        private BitmapReceiver mReceiver;
+
+        public LoadThumbnailTask(Resources res, int resId, DrawableLayerResolver resolver,
+                BitmapReceiver receiver) {
+            mLayerResolver = resolver;
+            mReceiver = receiver;
+            mResources = res;
+            mResId = resId;
+        }
+
+        @Override
+        protected Bitmap doInBackground(Void... unused) {
+            Drawable thumb = mResources.getDrawable(mResId, null);
+
+            // Live wallpaper components may or may not specify a thumbnail drawable.
+            if (thumb instanceof BitmapDrawable) {
+                return ((BitmapDrawable) thumb).getBitmap();
+            } else if (thumb instanceof LayerDrawable) {
+                Drawable layer = mLayerResolver.resolveLayer((LayerDrawable) thumb);
+                if (layer instanceof BitmapDrawable) {
+                    return ((BitmapDrawable) layer).getBitmap();
+                }
+            }
+
+            // If no thumbnail was specified, return a null bitmap.
+            return null;
+        }
+
+        @Override
+        protected void onPostExecute(Bitmap bitmap) {
+            mReceiver.onBitmapDecoded(bitmap);
+        }
+    }
+}