[ThemePicker 6/N] Create the theme tiles

Add a view for the tiles representing each option in the
theme section.

Bug: 120559294

Change-Id: If7590813b6509cc9e78d7ebca3123f24c8c07593
diff --git a/res/color/option_border_color.xml b/res/color/option_border_color.xml
new file mode 100644
index 0000000..1dd8d5f
--- /dev/null
+++ b/res/color/option_border_color.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2019 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item
+        android:state_selected="true"
+        android:color="?android:colorAccent" />
+    <item
+        android:state_selected="false"
+        android:color="@color/material_grey500" />
+    <item
+        android:color="@color/material_grey500"/>
+</selector>
\ No newline at end of file
diff --git a/res/color/option_title_color.xml b/res/color/option_title_color.xml
new file mode 100644
index 0000000..caa8dd9
--- /dev/null
+++ b/res/color/option_title_color.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2019 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.
+-->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item
+        android:state_selected="true"
+        android:color="?android:colorAccent" />
+    <item
+        android:state_selected="false"
+        android:color="?android:colorForeground" />
+    <item
+        android:color="?android:colorForeground"/>
+</selector>
\ No newline at end of file
diff --git a/res/drawable/option_border.xml b/res/drawable/option_border.xml
new file mode 100644
index 0000000..e715fcd
--- /dev/null
+++ b/res/drawable/option_border.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+     Copyright (C) 2019 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.
+-->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <stroke android:color="@color/option_border_color" android:width="2dp" />
+    <corners android:radius="4dp" />
+</shape>
diff --git a/res/drawable/option_color.xml b/res/drawable/option_color.xml
new file mode 100644
index 0000000..87e2532
--- /dev/null
+++ b/res/drawable/option_color.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2019 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.
+-->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <solid android:color="@android:color/black"  />
+    <corners android:radius="8dp" />
+</shape>
diff --git a/res/layout/fragment_theme_picker.xml b/res/layout/fragment_theme_picker.xml
index d88e1f7..95702f1 100644
--- a/res/layout/fragment_theme_picker.xml
+++ b/res/layout/fragment_theme_picker.xml
@@ -28,12 +28,14 @@
         android:id="@+id/options_section"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:padding="10dp"
         android:orientation="vertical">
 
         <androidx.recyclerview.widget.RecyclerView
             android:id="@+id/options_container"
             android:layout_width="match_parent"
-            android:layout_height="wrap_content"/>
+            android:layout_height="@dimen/options_container_height"
+            android:layout_gravity="center_horizontal"/>
 
         <RelativeLayout
             android:layout_width="match_parent"
diff --git a/res/layout/theme_option.xml b/res/layout/theme_option.xml
new file mode 100644
index 0000000..fc08f6b
--- /dev/null
+++ b/res/layout/theme_option.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2019 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="match_parent"
+    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"/>
+    <RelativeLayout
+        android:id="@+id/option_tile"
+        android:layout_width="@dimen/option_tile_width"
+        android:layout_height="@dimen/option_tile_width"
+        android:layout_gravity="center_horizontal"
+        android:paddingHorizontal="@dimen/option_tile_padding_horizontal"
+        android:paddingVertical="@dimen/option_tile_padding_vertical"
+        android:background="@drawable/option_border">
+        <TextView
+            android:id="@+id/theme_option_font"
+            android:layout_width="wrap_content"
+            android:layout_height="@dimen/theme_option_sample_height"
+            android:layout_alignParentTop="true"
+            android:layout_alignParentLeft="true"
+            android:gravity="center"
+            android:textSize="@dimen/theme_option_font_text_size"
+            android:text="@string/theme_font_example"/>
+        <ImageView
+            android:id="@+id/theme_option_shape"
+            android:layout_width="@dimen/theme_option_sample_right_width"
+            android:layout_height="@dimen/theme_option_sample_height"
+            android:layout_alignParentTop="true"
+            android:layout_alignParentRight="true"/>
+        <ImageView
+            android:id="@+id/theme_option_color"
+            android:layout_width="@dimen/theme_option_sample_left_width"
+            android:layout_height="@dimen/theme_option_sample_height"
+            android:layout_alignParentBottom="true"
+            android:layout_alignParentLeft="true"
+            android:src="@drawable/option_color"/>
+        <ImageView
+            android:id="@+id/theme_option_icon"
+            android:layout_width="@dimen/theme_option_sample_right_width"
+            android:layout_height="@dimen/theme_option_sample_height"
+            android:layout_alignParentBottom="true"
+            android:layout_alignParentRight="true"/>
+    </RelativeLayout>
+</LinearLayout>
\ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 5576e4c..985ef61 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -31,4 +31,17 @@
     <dimen name="preview_page_top_margin">16dp</dimen>
     <dimen name="preview_page_bottom_margin">2dp</dimen>
 
+    <!-- Dimensions for the customization option tiles -->
+    <dimen name="options_container_height">100dp</dimen>
+    <dimen name="option_tile_width">72dp</dimen>
+    <dimen name="option_tile_padding_vertical">16dp</dimen>
+    <dimen name="option_tile_padding_horizontal">10dp</dimen>
+    <!-- Note, using dp instead of sp as this text is more like a "snapshot" of the font -->
+    <dimen name="theme_option_font_text_size">10dp</dimen>
+
+    <dimen name="theme_option_sample_right_width">20dp</dimen>
+    <dimen name="theme_option_sample_height">18dp</dimen>
+    <dimen name="theme_option_sample_left_width">22dp</dimen>
+    <dimen name="option_tile_margin_horizontal">4dp</dimen>
+    <dimen name="theme_option_label_margin">4dp</dimen>
 </resources>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 613c481..abb2988 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -45,4 +45,6 @@
     <!-- Content description of the previous button to bring user to the previous preview page. [CHAR LIMIT=NONE] -->
     <string name="previous_page_content_description">Previous</string>
 
+    <!-- Sample text used to show a preview of a selected font [CHAR LIMIT=3] -->
+    <string name="theme_font_example">ABC</string>
 </resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index dfd7a4b..38e5bdd 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -50,4 +50,9 @@
     <style name="HeaderTextAppearance" parent="@android:style/TextAppearance.DeviceDefault.Widget.ActionBar.Title"/>
 
     <style name="ActionPrimaryButton" parent="android:Widget.DeviceDefault.Button.Colored"/>
+
+    <style name="OptionTitleTextAppearance" parent="@android:style/TextAppearance.Small">
+        <item name="android:textColor">@color/option_title_color</item>
+    </style>
+
 </resources>
\ No newline at end of file
diff --git a/src/com/android/customization/model/theme/ThemeBundle.java b/src/com/android/customization/model/theme/ThemeBundle.java
index 874e90d..9e6d2c5 100644
--- a/src/com/android/customization/model/theme/ThemeBundle.java
+++ b/src/com/android/customization/model/theme/ThemeBundle.java
@@ -15,15 +15,19 @@
  */
 package com.android.customization.model.theme;
 
+import android.content.res.ColorStateList;
 import android.graphics.Typeface;
 import android.graphics.drawable.Drawable;
 import android.view.View;
+import android.widget.ImageView;
+import android.widget.TextView;
 
 import androidx.annotation.ColorInt;
 import androidx.annotation.DrawableRes;
 import androidx.annotation.Nullable;
 
 import com.android.customization.model.CustomizationOption;
+import com.android.wallpaper.R;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -50,7 +54,10 @@
 
     @Override
     public void bindThumbnailTile(View view) {
-        //TODO(santie): implement
+        ((ImageView) view.findViewById(R.id.theme_option_color)).setImageTintList(
+                ColorStateList.valueOf(mPreviewInfo.colorAccentLight));
+        ((TextView) view.findViewById(R.id.theme_option_font)).setTypeface(
+                mPreviewInfo.headlineFontFamily);
     }
 
     @Override
@@ -60,7 +67,7 @@
 
     @Override
     public int getLayoutResId() {
-        return 0; //TODO(santie)
+        return R.layout.theme_option;
     }
 
     public PreviewInfo getPreviewInfo() {
diff --git a/src/com/android/customization/widget/HorizontalSpacerItemDecoration.java b/src/com/android/customization/widget/HorizontalSpacerItemDecoration.java
new file mode 100644
index 0000000..6d95c36
--- /dev/null
+++ b/src/com/android/customization/widget/HorizontalSpacerItemDecoration.java
@@ -0,0 +1,32 @@
+package com.android.customization.widget;
+
+import android.graphics.Rect;
+import android.view.View;
+
+import androidx.annotation.Dimension;
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.recyclerview.widget.RecyclerView.ItemDecoration;
+import androidx.recyclerview.widget.RecyclerView.State;
+
+/**
+ * RecyclerView ItemDecorator that adds a horizontal space of the given size between items
+ * (except the first and last)
+ */
+public class HorizontalSpacerItemDecoration extends ItemDecoration {
+
+    private final int mOffset;
+
+    public HorizontalSpacerItemDecoration(@Dimension int offset) {
+        mOffset = offset;
+    }
+
+    @Override
+    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view,
+            @NonNull RecyclerView parent, @NonNull State state) {
+        int position = parent.getChildAdapterPosition(view);
+        int left = position == 0 ? 0 : mOffset;
+        int right = (position == parent.getAdapter().getItemCount() - 1) ? 0 : mOffset;
+        outRect.set(left, 0, right, 0);
+    }
+}
diff --git a/src/com/android/customization/widget/OptionSelectorController.java b/src/com/android/customization/widget/OptionSelectorController.java
index 6ffa0e6..dc14cfc 100644
--- a/src/com/android/customization/widget/OptionSelectorController.java
+++ b/src/com/android/customization/widget/OptionSelectorController.java
@@ -15,6 +15,7 @@
  */
 package com.android.customization.widget;
 
+import android.content.res.Resources;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -118,6 +119,9 @@
 
         mContainer.setLayoutManager(new LinearLayoutManager(mContainer.getContext(),
                 LinearLayoutManager.HORIZONTAL, false));
+        Resources res = mContainer.getContext().getResources();
+        mContainer.addItemDecoration(new HorizontalSpacerItemDecoration(
+                res.getDimensionPixelOffset(R.dimen.option_tile_margin_horizontal)));
         mContainer.setAdapter(mAdapter);
     }