Snap for 7579381 from 369e082d737bb4fa0a9a6689536385ef0314b654 to sc-release

Change-Id: I167a95bcc9f025ba32f69f7b0465690ad83873b4
diff --git a/res/drawable/ic_check_wallpaper_24dp.xml b/res/drawable/ic_check_wallpaper_24dp.xml
new file mode 100644
index 0000000..eeee07e
--- /dev/null
+++ b/res/drawable/ic_check_wallpaper_24dp.xml
@@ -0,0 +1,25 @@
+<!--
+     Copyright (C) 2021 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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+  <path
+      android:fillColor="?androidprv:attr/textColorOnAccent"
+      android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41L9,16.17z"/>
+</vector>
diff --git a/res/drawable/wallpaper_check_circle_24dp.xml b/res/drawable/wallpaper_check_circle_24dp.xml
new file mode 100644
index 0000000..1249111
--- /dev/null
+++ b/res/drawable/wallpaper_check_circle_24dp.xml
@@ -0,0 +1,29 @@
+<!--
+     Copyright (C) 2021 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.
+-->
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android">
+    <item>
+        <shape android:shape="oval">
+            <size android:width="24dp" android:height="24dp" />
+            <solid android:color="?androidprv:attr/colorAccentPrimary" />
+        </shape>
+    </item>
+    <item
+        android:width="@dimen/grid_item_badge_indicator_size"
+        android:height="@dimen/grid_item_badge_indicator_size"
+        android:drawable="@drawable/ic_check_wallpaper_24dp"
+        android:gravity="center" />
+</layer-list>
diff --git a/res/layout/grid_item_image.xml b/res/layout/grid_item_image.xml
index 7a00b59..b4e2b1e 100755
--- a/res/layout/grid_item_image.xml
+++ b/res/layout/grid_item_image.xml
@@ -35,7 +35,7 @@
             android:layout_height="match_parent"
             android:foreground="@drawable/wallpaper_option_border">
 
-            <com.android.wallpaper.picker.individual.CustomShapeImageView
+            <ImageView
                 android:id="@+id/thumbnail"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
@@ -53,7 +53,6 @@
                 android:layout_height="wrap_content"
                 android:layout_alignParentBottom="true"
                 android:layout_alignParentEnd="true"
-                android:background="@drawable/ic_download_badge"
                 android:visibility="gone" />
 
             <FrameLayout
diff --git a/res/layout/grid_item_my_photos.xml b/res/layout/grid_item_my_photos.xml
index eab77dc..e88b21e 100755
--- a/res/layout/grid_item_my_photos.xml
+++ b/res/layout/grid_item_my_photos.xml
@@ -27,7 +27,7 @@
         android:focusable="true"
         android:foreground="?attr/selectableItemBackground">
 
-        <com.android.wallpaper.picker.individual.CustomShapeImageView
+        <ImageView
             android:id="@+id/thumbnail"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
diff --git a/res/layout/grid_item_rotation_desktop.xml b/res/layout/grid_item_rotation_desktop.xml
index 61502ae..85a6902 100755
--- a/res/layout/grid_item_rotation_desktop.xml
+++ b/res/layout/grid_item_rotation_desktop.xml
@@ -27,7 +27,7 @@
         android:focusable="true"
         android:foreground="?attr/selectableItemBackground">
 
-        <com.android.wallpaper.picker.individual.CustomShapeImageView
+        <ImageView
             android:id="@+id/thumbnail"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
diff --git a/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java b/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
index a7d1f5c..bb7a1d0 100755
--- a/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
+++ b/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
@@ -38,8 +38,11 @@
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.RelativeLayout;
 import android.widget.Toast;
 
+import androidx.annotation.DrawableRes;
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 import androidx.cardview.widget.CardView;
@@ -1068,6 +1071,7 @@
         startActivity(exploreIntent);
     }
 
+    // TODO: Dead code. Should remove this method in the future.
     private void updateActivatedStatus(WallpaperInfo wallpaperInfo, boolean isActivated) {
         if (wallpaperInfo == null) {
             return;
@@ -1077,14 +1081,14 @@
                 ? index + 1 : index;
         ViewHolder holder = mImageGrid.findViewHolderForAdapterPosition(index);
         if (holder != null) {
-            CustomShapeImageView thumbnail = holder.itemView.findViewById(R.id.thumbnail);
-            thumbnail.setClipped(isActivated);
+            holder.itemView.setActivated(isActivated);
         } else {
             // Item is not visible, make sure the item is re-bound when it becomes visible.
             mAdapter.notifyItemChanged(index);
         }
     }
 
+    // TODO: Dead code. Should remove this method in the future.
     private void updateAppliedStatus(WallpaperInfo wallpaperInfo, boolean isApplied) {
         if (wallpaperInfo == null) {
             return;
@@ -1093,7 +1097,9 @@
         index = (shouldShowRotationTile() || mCategory.supportsCustomPhotos())
                 ? index + 1 : index;
         ViewHolder holder = mImageGrid.findViewHolderForAdapterPosition(index);
-        if (holder == null) {
+        if (holder != null) {
+            mAdapter.showBadge(holder, R.drawable.wallpaper_check_circle_24dp, isApplied);
+        } else {
             // Item is not visible, make sure the item is re-bound when it becomes visible.
             mAdapter.notifyItemChanged(index);
         }
@@ -1436,7 +1442,7 @@
             WallpaperInfo wallpaper = mWallpapers.get(wallpaperIndex);
             wallpaper.computePlaceholderColor(holder.itemView.getContext());
             ((IndividualHolder) holder).bindWallpaper(wallpaper);
-            boolean isWallpaperApplied = mAppliedWallpaperIds.contains(wallpaper.getWallpaperId());
+            boolean isWallpaperApplied = isWallpaperApplied(wallpaper);
 
             if (isWallpaperApplied) {
                 mSelectedAdapterPosition = position;
@@ -1447,8 +1453,29 @@
             int radiusId = isFewerColumnLayout() ? R.dimen.grid_item_all_radius
                     : R.dimen.grid_item_all_radius_small;
             container.setRadius(getResources().getDimension(radiusId));
-            CustomShapeImageView thumbnail = holder.itemView.findViewById(R.id.thumbnail);
-            thumbnail.setClipped(isWallpaperApplied);
+            showBadge(holder, R.drawable.wallpaper_check_circle_24dp, isWallpaperApplied);
+        }
+
+        protected boolean isWallpaperApplied(WallpaperInfo wallpaper) {
+            return mAppliedWallpaperIds.contains(wallpaper.getWallpaperId());
+        }
+
+        protected void showBadge(ViewHolder holder, @DrawableRes int icon, boolean show) {
+            ImageView badge = holder.itemView.findViewById(R.id.indicator_icon);
+            if (show) {
+                final float margin = isFewerColumnLayout() ? getResources().getDimension(
+                        R.dimen.grid_item_badge_margin) : getResources().getDimension(
+                        R.dimen.grid_item_badge_margin_small);
+                final RelativeLayout.LayoutParams layoutParams =
+                        (RelativeLayout.LayoutParams) badge.getLayoutParams();
+                layoutParams.setMargins(/* left= */ (int) margin, /* top= */ (int) margin,
+                        /* right= */ (int) margin, /* bottom= */ (int) margin);
+                badge.setLayoutParams(layoutParams);
+                badge.setBackgroundResource(icon);
+                badge.setVisibility(View.VISIBLE);
+            } else {
+                badge.setVisibility(View.GONE);
+            }
         }
     }