Let the selected wallpaper can be seen on the collapsed wallpaper tiles page.

Video: https://drive.google.com/a/google.com/file/d/1-IkXGSXKijl-PZo-79Kkffd8V6kb8_7z/view?usp=sharing

Bug: 151286561
Change-Id: Iec53c5839d501da1da41bf7828fe0eb87942df3c
diff --git a/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java b/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
index 506f3a0..a2b13a0 100755
--- a/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
+++ b/src/com/android/wallpaper/picker/individual/IndividualPickerFragment.java
@@ -158,6 +158,18 @@
         void onDestinationSet(@Destination int destination);
     }
 
+    /**
+     * The listener which will be notified when the wallpaper is selected.
+     */
+    public interface WallpaperSelectedListener {
+        /**
+         * Called when the wallpaper is selected.
+         *
+         * @param position the position of the selected wallpaper
+         */
+        void onWallpaperSelected(int position);
+    }
+
     WallpaperPreferences mWallpaperPreferences;
     WallpaperChangedNotifier mWallpaperChangedNotifier;
     RecyclerView mImageGrid;
@@ -247,6 +259,7 @@
     private WallpaperInfo mAppliedWallpaperInfo;
     private WallpaperManager mWallpaperManager;
     private int mWallpaperDestination;
+    private WallpaperSelectedListener mWallpaperSelectedListener;
 
     public static IndividualPickerFragment newInstance(String collectionId) {
         Bundle args = new Bundle();
@@ -445,7 +458,7 @@
 
             mBottomActionBar.setActionClickListener(CANCEL, unused -> {
                 if (mSelectedWallpaperInfo != null) {
-                    onWallpaperSelected(null);
+                    onWallpaperSelected(null, 0);
                     return;
                 }
                 getActivity().onBackPressed();
@@ -638,6 +651,29 @@
         mWallpapersUiContainer = uiContainer;
     }
 
+    public void setOnWallpaperSelectedListener(
+            WallpaperSelectedListener wallpaperSelectedListener) {
+        mWallpaperSelectedListener = wallpaperSelectedListener;
+    }
+
+    /**
+     * Resizes the layout's height.
+     */
+    public void resizeLayout(int height) {
+        mImageGrid.getLayoutParams().height = height;
+        mImageGrid.requestLayout();
+    }
+
+    /**
+     * Scrolls to the specific item.
+     *
+     * @param position the position of the item
+     */
+    public void scrollToPosition(int position) {
+        ((GridLayoutManager) mImageGrid.getLayoutManager())
+                .scrollToPositionWithOffset(position, /* offset= */ 0);
+    }
+
     /**
      * Enable a test mode of operation -- in which certain UI features are disabled to allow for
      * UI tests to run correctly. Works around issue in ProgressDialog currently where the dialog
@@ -891,7 +927,8 @@
         wallpaperDestinationCallback.onDestinationSet(destination);
     }
 
-    private void onWallpaperSelected(@Nullable WallpaperInfo newSelectedWallpaperInfo) {
+    private void onWallpaperSelected(@Nullable WallpaperInfo newSelectedWallpaperInfo,
+                                     int position) {
         if (mSelectedWallpaperInfo == newSelectedWallpaperInfo) {
             return;
         }
@@ -908,8 +945,12 @@
         // Populate wallpaper info to bottom sheet page.
         if (mSelectedWallpaperInfo != null) {
             mBottomActionBar.populateInfoPage(
-                mSelectedWallpaperInfo.getAttributions(getContext()),
-                shouldShowMetadataInPreview(mSelectedWallpaperInfo));
+                    mSelectedWallpaperInfo.getAttributions(getContext()),
+                    shouldShowMetadataInPreview(mSelectedWallpaperInfo));
+        }
+
+        if (mWallpaperSelectedListener != null) {
+            mWallpaperSelectedListener.onWallpaperSelected(position);
         }
     }
 
@@ -1337,7 +1378,7 @@
                 holder.itemView.findViewById(R.id.check_circle).setVisibility(
                         isWallpaperApplied ? View.VISIBLE : View.GONE);
                 holder.itemView.findViewById(R.id.tile).setOnClickListener(
-                        view -> onWallpaperSelected(wallpaper));
+                        view -> onWallpaperSelected(wallpaper, position));
             }
         }
     }