Merge "Refine Style/Grid picker recyclerview layout" into ub-launcher3-master
diff --git a/res/values/styles.xml b/res/values/styles.xml
index dd0f2a3..b4e1971 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -103,6 +103,7 @@
         <item name="android:paddingBottom">16dp</item>
         <item name="android:paddingStart">12dp</item>
         <item name="android:paddingEnd">12dp</item>
+        <item name="android:textAlignment">viewStart</item>
         <item name="android:textColor">@color/edittext_text_color</item>
         <item name="android:inputType">text</item>
         <item name="android:maxLength">100</item>
diff --git a/src/com/android/customization/model/theme/ThemeBundle.java b/src/com/android/customization/model/theme/ThemeBundle.java
index 43b07ff..4ede59e 100644
--- a/src/com/android/customization/model/theme/ThemeBundle.java
+++ b/src/com/android/customization/model/theme/ThemeBundle.java
@@ -272,9 +272,9 @@
                 mAppName = appName;
             }
 
-            /** Returns the app icon drawable. */
-            public Drawable getDrawable() {
-                return mIconDrawable;
+            /** Returns a copy of app icon drawable. */
+            public Drawable getDrawableCopy() {
+                return mIconDrawable.getConstantState().newDrawable().mutate();
             }
 
             /** Returns the app name. */
@@ -340,7 +340,7 @@
                 shapeDrawable.setIntrinsicHeight((int) PATH_SIZE);
                 shapeDrawable.setIntrinsicWidth((int) PATH_SIZE);
                 for (ShapeAppIcon icon : mAppIcons) {
-                    Drawable drawable = icon.getDrawable();
+                    Drawable drawable = icon.mIconDrawable;
                     if (drawable instanceof AdaptiveIconDrawable) {
                         AdaptiveIconDrawable adaptiveIcon = (AdaptiveIconDrawable) drawable;
                         shapeIcons.add(new ShapeAppIcon(
diff --git a/src/com/android/customization/model/theme/custom/ThemeComponentOption.java b/src/com/android/customization/model/theme/custom/ThemeComponentOption.java
index 178098c..f93be44 100644
--- a/src/com/android/customization/model/theme/custom/ThemeComponentOption.java
+++ b/src/com/android/customization/model/theme/custom/ThemeComponentOption.java
@@ -504,7 +504,7 @@
             }
             for (int i = 0; i < mShapeIconIds.length && i < mAppIcons.size(); i++) {
                 ImageView iconView = cardBody.findViewById(mShapeIconIds[i]);
-                iconView.setBackground(mAppIcons.get(i).getDrawable());
+                iconView.setBackground(mAppIcons.get(i).getDrawableCopy());
             }
         }
 
diff --git a/src/com/android/customization/picker/theme/ThemeOptionPreviewer.java b/src/com/android/customization/picker/theme/ThemeOptionPreviewer.java
index 7b4d220..5c775dd 100644
--- a/src/com/android/customization/picker/theme/ThemeOptionPreviewer.java
+++ b/src/com/android/customization/picker/theme/ThemeOptionPreviewer.java
@@ -288,7 +288,7 @@
             ShapeAppIcon icon = appIcons.get(i);
             // Set app icon.
             ImageView iconView = mContentView.findViewById(mShapeAppIconIds[i]);
-            iconView.setBackground(icon.getDrawable());
+            iconView.setBackground(icon.getDrawableCopy());
             // Set app name.
             TextView appName = mContentView.findViewById(mShapeIconAppNameIds[i]);
             appName.setText(icon.getAppName());
diff --git a/src/com/android/customization/widget/DynamicAdaptiveIconDrawable.java b/src/com/android/customization/widget/DynamicAdaptiveIconDrawable.java
index 06d8392..afcb27c 100644
--- a/src/com/android/customization/widget/DynamicAdaptiveIconDrawable.java
+++ b/src/com/android/customization/widget/DynamicAdaptiveIconDrawable.java
@@ -3,7 +3,6 @@
 import android.content.res.ColorStateList;
 import android.content.res.Resources;
 import android.content.res.Resources.Theme;
-import android.content.res.TypedArray;
 import android.graphics.Bitmap;
 import android.graphics.BitmapShader;
 import android.graphics.Canvas;
@@ -27,8 +26,6 @@
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
-import com.android.wallpaper.R;
-
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
@@ -765,6 +762,8 @@
     }
 
     static class LayerState extends ConstantState {
+        private final DynamicAdaptiveIconDrawable mOwner;
+
         private int[] mThemeAttrs;
 
         final static int N_CHILDREN = 2;
@@ -791,6 +790,7 @@
 
         LayerState(@Nullable LayerState orig, @NonNull DynamicAdaptiveIconDrawable owner,
                 @Nullable Resources res) {
+            mOwner = owner;
             mChildren = new ChildDrawable[N_CHILDREN];
             if (orig != null) {
                 final ChildDrawable[] origChildDrawable = orig.mChildren;
@@ -800,7 +800,7 @@
 
                 for (int i = 0; i < N_CHILDREN; i++) {
                     final ChildDrawable or = origChildDrawable[i];
-                    mChildren[i] = new ChildDrawable(or, owner, res);
+                    mChildren[i] = new ChildDrawable(or, mOwner, res);
                 }
 
                 mCheckedOpacity = orig.mCheckedOpacity;
@@ -842,12 +842,13 @@
 
         @Override
         public Drawable newDrawable() {
-            return new DynamicAdaptiveIconDrawable(this, null, null);
+            return new DynamicAdaptiveIconDrawable(mOwner.getBackground(), mOwner.getForeground(),
+                    mOwner.mOriginalMask);
         }
 
         @Override
         public Drawable newDrawable(@Nullable Resources res) {
-            return new DynamicAdaptiveIconDrawable(this, res, null);
+            return newDrawable();
         }
 
         @Override
diff --git a/src/com/android/customization/widget/ThemeInfoView.java b/src/com/android/customization/widget/ThemeInfoView.java
index a733a40..b21b96f 100644
--- a/src/com/android/customization/widget/ThemeInfoView.java
+++ b/src/com/android/customization/widget/ThemeInfoView.java
@@ -72,7 +72,7 @@
 
             if (previewInfo.shapeAppIcons.get(SHAPE_PREVIEW_INDEX) != null) {
                 mAppPreviewImageView.setBackground(
-                        previewInfo.shapeAppIcons.get(SHAPE_PREVIEW_INDEX).getDrawable());
+                        previewInfo.shapeAppIcons.get(SHAPE_PREVIEW_INDEX).getDrawableCopy());
             }
 
             if (previewInfo.shapeDrawable != null) {