Merge "Gets the wallpaper color to update the preview text/icon" into ub-launcher3-master
diff --git a/src/com/android/customization/model/theme/DefaultThemeProvider.java b/src/com/android/customization/model/theme/DefaultThemeProvider.java
index c0937b4..60eb66d 100644
--- a/src/com/android/customization/model/theme/DefaultThemeProvider.java
+++ b/src/com/android/customization/model/theme/DefaultThemeProvider.java
@@ -28,6 +28,7 @@
 import static com.android.customization.model.ResourceConstants.SYSUI_PACKAGE;
 
 import android.content.Context;
+import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.res.Resources.NotFoundException;
 import android.text.TextUtils;
@@ -212,6 +213,11 @@
             try {
                 builder.addShapePreviewIcon(
                         mContext.getPackageManager().getApplicationIcon(packageName));
+                // Add the shape icon app name.
+                ApplicationInfo appInfo = mContext.getPackageManager()
+                        .getApplicationInfo(packageName, /* flag= */ 0);
+                builder.addShapePreviewIconName(
+                        String.valueOf(mContext.getPackageManager().getApplicationLabel(appInfo)));
             } catch (NameNotFoundException e) {
                 Log.d(TAG, "Couldn't find app " + packageName + ", won't use it for icon shape"
                         + "preview");
diff --git a/src/com/android/customization/model/theme/OverlayThemeExtractor.java b/src/com/android/customization/model/theme/OverlayThemeExtractor.java
index 9c85fa4..f1698f6 100644
--- a/src/com/android/customization/model/theme/OverlayThemeExtractor.java
+++ b/src/com/android/customization/model/theme/OverlayThemeExtractor.java
@@ -8,6 +8,7 @@
 import android.content.Context;
 import android.content.om.OverlayInfo;
 import android.content.om.OverlayManager;
+import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.res.Resources;
 import android.content.res.Resources.NotFoundException;
@@ -102,6 +103,11 @@
                 builder.addShapePreviewIcon(
                         mContext.getPackageManager().getApplicationIcon(
                                 packageName));
+                // Add the shape icon app name.
+                ApplicationInfo appInfo = mContext.getPackageManager()
+                        .getApplicationInfo(packageName, /* flag= */ 0);
+                builder.addShapePreviewIconName(
+                        String.valueOf(mContext.getPackageManager().getApplicationLabel(appInfo)));
             } catch (NameNotFoundException e) {
                 Log.d(TAG, "Couldn't find app " + packageName
                         + ", won't use it for icon shape preview");
diff --git a/src/com/android/customization/model/theme/ThemeBundle.java b/src/com/android/customization/model/theme/ThemeBundle.java
index 14b2dcd..9928c76 100644
--- a/src/com/android/customization/model/theme/ThemeBundle.java
+++ b/src/com/android/customization/model/theme/ThemeBundle.java
@@ -251,12 +251,13 @@
         public final List<Drawable> icons;
         public final Drawable shapeDrawable;
         public final List<Drawable> shapeAppIcons;
+        public final List<String> shapeAppIconNames;
         @Dimension public final int bottomSheeetCornerRadius;
 
         private PreviewInfo(Context context, Typeface bodyFontFamily, Typeface headlineFontFamily,
                 int colorAccentLight, int colorAccentDark, List<Drawable> icons,
                 Drawable shapeDrawable, @Dimension int cornerRadius,
-                List<Drawable> shapeAppIcons) {
+                List<Drawable> shapeAppIcons, List<String> shapeAppIconNames) {
             this.bodyFontFamily = bodyFontFamily;
             this.headlineFontFamily = headlineFontFamily;
             this.colorAccentLight = colorAccentLight;
@@ -265,6 +266,7 @@
             this.shapeDrawable = shapeDrawable;
             this.bottomSheeetCornerRadius = cornerRadius;
             this.shapeAppIcons = shapeAppIcons;
+            this.shapeAppIconNames = shapeAppIconNames;
         }
 
         /**
@@ -292,6 +294,7 @@
         @Dimension private int mCornerRadius;
         protected Map<String, String> mPackages = new HashMap<>();
         private List<Drawable> mAppIcons = new ArrayList<>();
+        private List<String> mAppIconNames = new ArrayList<>();
 
         public ThemeBundle build(Context context) {
             return new ThemeBundle(mTitle, mPackages, mIsDefault, createPreviewInfo(context));
@@ -322,7 +325,8 @@
                 }
             }
             return new PreviewInfo(context, mBodyFontFamily, mHeadlineFontFamily, mColorAccentLight,
-                    mColorAccentDark, mIcons, shapeDrawable, mCornerRadius, shapeIcons);
+                    mColorAccentDark, mIcons, shapeDrawable, mCornerRadius, shapeIcons,
+                    mAppIconNames);
         }
 
         public Map<String, String> getPackages() {
@@ -388,6 +392,11 @@
             return this;
         }
 
+        public Builder addShapePreviewIconName(String appIconName) {
+            mAppIconNames.add(appIconName);
+            return this;
+        }
+
         public Builder setBottomSheetCornerRadius(@Dimension int radius) {
             mCornerRadius = radius;
             return this;
diff --git a/src/com/android/customization/picker/theme/ThemeOptionPreviewer.java b/src/com/android/customization/picker/theme/ThemeOptionPreviewer.java
index 4105f67..efaa38c 100644
--- a/src/com/android/customization/picker/theme/ThemeOptionPreviewer.java
+++ b/src/com/android/customization/picker/theme/ThemeOptionPreviewer.java
@@ -151,6 +151,7 @@
         setHeadlineFont(previewInfo.headlineFontFamily);
         setTopBarIcons(previewInfo.icons);
         setAppIconShape(previewInfo.shapeAppIcons);
+        setAppIconName(previewInfo.shapeAppIconNames);
         setColorAndIconsSection(previewInfo.icons, previewInfo.shapeDrawable,
                 previewInfo.resolveAccentColor(mContext.getResources()));
         setColorAndIconsBoxRadius(previewInfo.bottomSheeetCornerRadius);
@@ -198,20 +199,22 @@
     }
 
     private void setHeadlineFont(Typeface headlineFont) {
+        // Update font of status bar clock.
         mClock.setTypeface(headlineFont);
 
+        // Update font of the smart space date.
         TextView date = mContentView.findViewById(R.id.smart_space_date);
         date.setTypeface(headlineFont);
         // TODO(chihhangchuang): Use real date.
         date.setText("Friday, Nov 12");
 
-        // TODO(chihhangchuang): Query the app name for icon shapes, we can get package name from
-        // res/values/override.xml to query the app name.
+        // Update font of app names.
         for (int id : mShapeIconAppNameIds) {
             TextView appName = mContentView.findViewById(id);
             appName.setTypeface(headlineFont);
         }
 
+        // Update font of color/icons section title.
         TextView colorIconsSectionTitle = mContentView.findViewById(R.id.color_icons_section_title);
         colorIconsSectionTitle.setTypeface(headlineFont);
     }
@@ -237,6 +240,13 @@
         }
     }
 
+    private void setAppIconName(List<String> appIconNames) {
+        for (int i = 0; i < mShapeIconAppNameIds.length && i < appIconNames.size(); i++) {
+            TextView appName = mContentView.findViewById(mShapeIconAppNameIds[i]);
+            appName.setText(appIconNames.get(i));
+        }
+    }
+
     private void setColorAndIconsSection(List<Drawable> icons, Drawable shapeDrawable,
                                          int accentColor) {
         // Set QS icons and background.