Merge "Apply styling to grid" into sc-dev
diff --git a/res/layout/fragment_grid_picker.xml b/res/layout/fragment_grid_picker.xml
index 99fb04c..f34d013 100644
--- a/res/layout/fragment_grid_picker.xml
+++ b/res/layout/fragment_grid_picker.xml
@@ -34,47 +34,27 @@
             <FrameLayout
                 android:id="@+id/preview_card_container"
                 android:layout_width="match_parent"
-                android:layout_height="0dp"
-                android:paddingTop="@dimen/preview_content_padding_top"
-                android:paddingBottom="@dimen/preview_content_padding_bottom"
-                android:clipToPadding="false"
-                app:layout_constrainedHeight="true"
-                app:layout_constraintStart_toStartOf="parent"
-                app:layout_constraintEnd_toEndOf="parent"
-                app:layout_constraintTop_toTopOf="parent"
-                app:layout_constraintBottom_toTopOf="@id/options_title"
-                app:layout_constraintHeight_max="@dimen/preview_pager_max_height"
-                app:layout_constraintVertical_bias="0.0"
-                app:layout_constraintHeight_percent="@dimen/preview_pager_maximum_height_ratio">
-                <include layout="@layout/grid_preview_card"/>
-            </FrameLayout>
-
-            <TextView
-                android:id="@+id/options_title"
-                android:layout_width="match_parent"
                 android:layout_height="wrap_content"
-                android:background="?android:colorPrimary"
-                android:gravity="center"
-                android:paddingVertical="18dp"
-                android:lineHeight="24dp"
-                android:singleLine="true"
-                android:text="@string/grid_options_title"
-                android:textAppearance="@style/TitleTextAppearance"
-                app:layout_constraintStart_toStartOf="parent"
+                android:clipToPadding="false"
+                android:paddingTop="@dimen/preview_page_top_margin"
+                android:paddingBottom="@dimen/preview_page_bottom_margin"
+                app:layout_constrainedHeight="true"
+                app:layout_constraintBottom_toTopOf="@+id/options_container"
                 app:layout_constraintEnd_toEndOf="parent"
-                app:layout_constraintTop_toBottomOf="@id/preview_card_container"
-                app:layout_constraintBottom_toTopOf="@id/options_container" />
+                app:layout_constraintStart_toStartOf="parent"
+                app:layout_constraintTop_toTopOf="parent">
+
+                <include layout="@layout/grid_preview_card" />
+            </FrameLayout>
 
             <androidx.recyclerview.widget.RecyclerView
                 android:id="@+id/options_container"
                 android:layout_width="match_parent"
-                android:layout_height="0dp"
-                android:background="?android:colorPrimary"
-                app:layout_constraintStart_toStartOf="parent"
-                app:layout_constraintEnd_toEndOf="parent"
-                app:layout_constraintTop_toBottomOf="@id/options_title"
+                android:layout_height="@dimen/options_container_height"
+
                 app:layout_constraintBottom_toBottomOf="parent"
-                app:layout_constraintVertical_bias="1.0" />
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintStart_toStartOf="parent" />
         </androidx.constraintlayout.widget.ConstraintLayout>
 
         <androidx.core.widget.ContentLoadingProgressBar
diff --git a/res/layout/fragment_theme_picker.xml b/res/layout/fragment_theme_picker.xml
index 893be46..0ecfdd0 100644
--- a/res/layout/fragment_theme_picker.xml
+++ b/res/layout/fragment_theme_picker.xml
@@ -53,7 +53,6 @@
                 android:layout_height="0dp"
                 android:layout_gravity="bottom|center_horizontal"
                 android:layout_marginTop="10dp"
-                android:background="?android:colorPrimary"
                 app:layout_constraintStart_toStartOf="parent"
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintTop_toBottomOf="@+id/preview_card_container"
diff --git a/res/layout/grid_option.xml b/res/layout/grid_option.xml
index d06ff60..221f353 100644
--- a/res/layout/grid_option.xml
+++ b/res/layout/grid_option.xml
@@ -23,13 +23,6 @@
     android:clipToPadding="false"
     android:orientation="vertical">
 
-    <TextView
-        android:id="@+id/option_label"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="center_horizontal"
-        android:layout_marginBottom="@dimen/theme_option_label_margin"
-        android:textAppearance="@style/OptionTitleTextAppearance"/>
     <FrameLayout
         android:id="@+id/option_tile"
         android:layout_width="@dimen/option_tile_width"
@@ -43,4 +36,13 @@
             android:layout_width="match_parent"
             android:layout_height="match_parent"/>
     </FrameLayout>
+
+    <TextView
+        android:id="@+id/option_label"
+        android:layout_width="wrap_content"
+        android:layout_height="24dp"
+        android:layout_gravity="center_horizontal"
+        android:layout_marginTop="@dimen/theme_option_label_margin"
+        android:gravity="center"
+        android:textAppearance="@style/OptionTitleTextAppearance" />
 </LinearLayout>
diff --git a/res/layout/grid_preview_card.xml b/res/layout/grid_preview_card.xml
index e824460..62da6b4 100644
--- a/res/layout/grid_preview_card.xml
+++ b/res/layout/grid_preview_card.xml
@@ -26,8 +26,7 @@
     <ImageView
         android:id="@+id/wallpaper_preview_image"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
-        android:background="@color/primary_color" />
+        android:layout_height="match_parent" />
 
     <SurfaceView
         android:id="@+id/wallpaper_preview_surface"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index abc2c6a..e5bba8c 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -29,7 +29,7 @@
     <dimen name="component_preview_page_bottom_margin">16dp</dimen>
 
     <!-- Dimensions for the customization option tiles -->
-    <dimen name="options_container_height">120dp</dimen>
+    <dimen name="options_container_height">124dp</dimen>
     <dimen name="options_container_width">0dp</dimen>
     <dimen name="option_tile_width">88dp</dimen>
     <dimen name="option_icon_size">16dp</dimen>
@@ -41,8 +41,8 @@
     <dimen name="theme_option_font_sample_width">52dp</dimen>
     <dimen name="theme_option_sample_margin">10dp</dimen>
     <!-- Note, using dp instead of sp as this is just the "+" symbol, not text -->
-    <dimen name="option_tile_padding_vertical">18dp</dimen>
-    <dimen name="option_tile_padding_horizontal">18dp</dimen>
+    <dimen name="option_tile_padding_vertical">12dp</dimen>
+    <dimen name="option_tile_padding_horizontal">12dp</dimen>
 
     <dimen name="option_bottom_margin">8dp</dimen>
     <dimen name="option_padding_horizontal">2dp</dimen>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 1ed2970..406a637 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -20,8 +20,6 @@
     <style name="CustomizationTheme" parent="@android:style/Theme.DeviceDefault.Settings">
         <item name="colorPrimary">?android:colorPrimary</item>
 
-        <item name="android:statusBarColor">?android:colorPrimary</item>
-
         <item name="android:navigationBarColor">?android:colorPrimaryDark</item>
         <item name="android:navigationBarDividerColor">@android:color/transparent</item>
 
diff --git a/src/com/android/customization/model/grid/GridOption.java b/src/com/android/customization/model/grid/GridOption.java
index 43afee4..13c2b68 100644
--- a/src/com/android/customization/model/grid/GridOption.java
+++ b/src/com/android/customization/model/grid/GridOption.java
@@ -28,6 +28,7 @@
 
 import com.android.customization.model.CustomizationManager;
 import com.android.customization.model.CustomizationOption;
+import com.android.customization.util.ResourceUtils;
 import com.android.customization.widget.GridTileDrawable;
 import com.android.wallpaper.R;
 
@@ -91,8 +92,10 @@
     public void bindThumbnailTile(View view) {
         Context context = view.getContext();
 
-        mTileDrawable.setColorFilter(context.getResources().getColor(
-                R.color.material_grey500, null), Mode.ADD);
+        int colorFilter = ResourceUtils.getColorAttr(context,
+                mIsCurrent ? android.R.attr.textColorPrimary :
+                android.R.attr.textColorTertiary);
+        mTileDrawable.setColorFilter(colorFilter, Mode.SRC_ATOP);
         ((ImageView) view.findViewById(R.id.grid_option_thumbnail))
                 .setImageDrawable(mTileDrawable);
     }
@@ -138,4 +141,13 @@
         parcel.writeParcelable(previewImageUri, i);
         parcel.writeInt(previewPagesCount);
     }
+
+    @Override
+    public String toString() {
+        return String.format(
+                "GridOption{mTitle='%s', mIsCurrent=%s, mTileDrawable=%s, name='%s', rows=%d, "
+                        + "cols=%d, previewImageUri=%s, previewPagesCount=%d}\n",
+                mTitle, mIsCurrent, mTileDrawable, name, rows, cols, previewImageUri,
+                previewPagesCount);
+    }
 }
diff --git a/src/com/android/customization/picker/grid/GridFragment.java b/src/com/android/customization/picker/grid/GridFragment.java
index deaa210..d29627e 100644
--- a/src/com/android/customization/picker/grid/GridFragment.java
+++ b/src/com/android/customization/picker/grid/GridFragment.java
@@ -190,7 +190,9 @@
             @Override
             public void onOptionsLoaded(List<GridOption> options) {
                 mLoading.hide();
-                mOptionsController = new OptionSelectorController<>(mOptionsContainer, options);
+                mOptionsController = new OptionSelectorController<>(
+                        mOptionsContainer, options, true,
+                        OptionSelectorController.CheckmarkStyle.CENTER);
                 mOptionsController.initOptions(mGridManager);
 
                 // Find the selected Grid option.
diff --git a/src/com/android/customization/util/ResourceUtils.java b/src/com/android/customization/util/ResourceUtils.java
new file mode 100644
index 0000000..d42dca9
--- /dev/null
+++ b/src/com/android/customization/util/ResourceUtils.java
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+package com.android.customization.util;
+
+import android.content.Context;
+import android.content.res.ColorStateList;
+import android.content.res.TypedArray;
+
+/**
+ * A set of common resource utilities.
+ */
+public class ResourceUtils {
+    /**
+     * Returns the default color for a given attribute.
+     */
+    public static int getColorAttr(Context context, int attr) {
+        TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
+        ColorStateList stateList = null;
+        try {
+            stateList = ta.getColorStateList(0);
+        } finally {
+            ta.recycle();
+        }
+        return stateList.getDefaultColor();
+    }
+}
diff --git a/src/com/android/customization/widget/GridTileDrawable.java b/src/com/android/customization/widget/GridTileDrawable.java
index c746aaf..5039cf6 100644
--- a/src/com/android/customization/widget/GridTileDrawable.java
+++ b/src/com/android/customization/widget/GridTileDrawable.java
@@ -19,8 +19,7 @@
 
     // Path is expected configuration in following dimension: [100 x 100]))
     private static final float PATH_SIZE = 100f;
-    // We want each "icon" using 80% of the available size, so there's 10% padding on each side
-    private static final float ICON_SCALE = .8f;
+    private static final float SPACE_BETWEEN_ICONS = 6f;
     private final int mCols;
     private final int mRows;
     private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
@@ -28,7 +27,6 @@
     private final Path mTransformedPath;
     private final Matrix mScaleMatrix;
     private float mCellSize = -1f;
-    private float mSpaceBetweenIcons;
 
     public GridTileDrawable(int cols, int rows, String path) {
         mCols = cols;
@@ -43,9 +41,8 @@
     protected void onBoundsChange(Rect bounds) {
         super.onBoundsChange(bounds);
         mCellSize = (float) bounds.height() / mRows;
-        mSpaceBetweenIcons = mCellSize * ((1 - ICON_SCALE) / 2);
 
-        float scaleFactor = (mCellSize * ICON_SCALE) / PATH_SIZE;
+        float scaleFactor = (mCellSize - 2 * SPACE_BETWEEN_ICONS) / PATH_SIZE;
         mScaleMatrix.setScale(scaleFactor, scaleFactor);
         mShapePath.transform(mScaleMatrix, mTransformedPath);
     }
@@ -55,8 +52,8 @@
         for (int r = 0; r < mRows; r++) {
             for (int c = 0; c < mCols; c++) {
                 int saveCount = canvas.save();
-                float x = (c * mCellSize) + mSpaceBetweenIcons;
-                float y = (r * mCellSize) + mSpaceBetweenIcons;
+                float x = (c * mCellSize) + SPACE_BETWEEN_ICONS;
+                float y = (r * mCellSize) + SPACE_BETWEEN_ICONS;
                 canvas.translate(x, y);
                 canvas.drawPath(mTransformedPath, mPaint);
                 canvas.restoreToCount(saveCount);