More accessibility improvements

Add missing content description and increase tap target sizes.

Fixes: 129216367
Fixes: 129226741
Fixes: 129216366
Change-Id: I0692891f720cfd963fc58a834d43ff7c9d5ad157
diff --git a/res/layout/clock_preview_card.xml b/res/layout/clock_preview_card.xml
index 63c55e1..5128dda 100644
--- a/res/layout/clock_preview_card.xml
+++ b/res/layout/clock_preview_card.xml
@@ -18,7 +18,8 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     style="@style/FullContentPreviewCard"
     android:layout_width="match_parent"
-    android:layout_height="match_parent">
+    android:layout_height="match_parent"
+    android:focusable="true">
 
     <ImageView
         android:id="@+id/clock_preview_image"
diff --git a/res/layout/fragment_theme_picker.xml b/res/layout/fragment_theme_picker.xml
index e20c5f9..ffc2d7b 100644
--- a/res/layout/fragment_theme_picker.xml
+++ b/res/layout/fragment_theme_picker.xml
@@ -51,6 +51,7 @@
                 android:layout_height="wrap_content"
                 android:layout_alignParentStart="true"
                 android:layout_centerVertical="true"
+                android:minHeight="@dimen/min_taptarget_height"
                 android:text="@string/keep_my_wallpaper"/>
             <Button
                 android:id="@+id/apply_button"
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index d27b142..f17f344 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -87,4 +87,6 @@
 
     <!-- For a corner radius of this size or larger, we'll preview a rounded qsb widget. -->
     <dimen name="roundCornerThreshold">16dp</dimen>
+
+    <dimen name="min_taptarget_height">48dp</dimen>
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index db85aaa..28adb79 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -60,6 +60,9 @@
     <!-- Sample text used to show a preview of a selected font [CHAR LIMIT=3] -->
     <string name="theme_font_example">ABC</string>
 
+    <!-- Content description for previewing a style, describing each of their components. [CHAR_LIMIT=NONE] -->
+    <string name="theme_description">Font: <xliff:g name="font_name">%1$s</xliff:g>, icons: <xliff:g name="icon_name">%2$s</xliff:g>, shape: <xliff:g name="shape_name">%3$s</xliff:g>, color: <xliff:g name="color_name">%4$s</xliff:g> </string>
+
     <!-- Plus sign used to indicate that the user can add a custom theme -->
     <string name="add_custom_theme" translatable="false">+</string>
 
@@ -167,4 +170,7 @@
         instead of their customly defined one. The button dismisses the dialog and goes back to the
         previous screen. [CHAR_LIMIT=16]  -->
     <string name="no_thanks">No, thanks</string>
+
+    <!-- Content description for a screen showing the preview of a clock face. [CHAR_LIMIT=NONE] -->
+    <string name="clock_preview_content_description"><xliff:g name="clock_name">%1$s</xliff:g> clock preview</string>
 </resources>
diff --git a/src/com/android/customization/model/theme/ThemeBundle.java b/src/com/android/customization/model/theme/ThemeBundle.java
index 67b085a..e13efb5 100644
--- a/src/com/android/customization/model/theme/ThemeBundle.java
+++ b/src/com/android/customization/model/theme/ThemeBundle.java
@@ -15,9 +15,14 @@
  */
 package com.android.customization.model.theme;
 
+import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR;
+import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_FONT;
+import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_ICON_ANDROID;
+import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SHAPE;
 import static com.android.customization.model.ResourceConstants.PATH_SIZE;
 
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.graphics.Path;
@@ -40,6 +45,7 @@
 
 import com.android.customization.model.CustomizationManager;
 import com.android.customization.model.CustomizationOption;
+import com.android.customization.model.theme.custom.CustomTheme;
 import com.android.customization.widget.DynamicAdaptiveIconDrawable;
 import com.android.wallpaper.R;
 import com.android.wallpaper.asset.Asset;
@@ -72,6 +78,7 @@
     @Nullable private final WallpaperInfo mWallpaperInfo;
     private WallpaperInfo mOverrideWallpaper;
     private Asset mOverrideWallpaperAsset;
+    private CharSequence mContentDescription;
 
     protected ThemeBundle(String title, Map<String, String> overlayPackages,
             boolean isDefault, @Nullable WallpaperInfo wallpaperInfo,
@@ -106,6 +113,7 @@
             ((ImageView) view.findViewById(R.id.theme_option_icon)).setImageDrawable(
                     icon);
         }
+        view.setContentDescription(getContentDescription(view.getContext()));
     }
 
     @Override
@@ -204,6 +212,35 @@
         }
     }
 
+    protected CharSequence getContentDescription(Context context) {
+        if (mContentDescription == null) {
+            CharSequence defaultName = context.getString(R.string.default_theme_title);
+            if (isDefault()) {
+                mContentDescription = defaultName;
+            } else {
+                PackageManager pm = context.getPackageManager();
+                CharSequence fontName = getOverlayName(pm, OVERLAY_CATEGORY_FONT);
+                CharSequence iconName = getOverlayName(pm, OVERLAY_CATEGORY_ICON_ANDROID);
+                CharSequence shapeName = getOverlayName(pm, OVERLAY_CATEGORY_SHAPE);
+                CharSequence colorName = getOverlayName(pm, OVERLAY_CATEGORY_COLOR);
+                mContentDescription = context.getString(R.string.theme_description,
+                        TextUtils.isEmpty(fontName) ? defaultName : fontName,
+                        TextUtils.isEmpty(iconName) ? defaultName : iconName,
+                        TextUtils.isEmpty(shapeName) ? defaultName : shapeName,
+                        TextUtils.isEmpty(colorName) ? defaultName : colorName);
+            }
+        }
+        return mContentDescription;
+    }
+
+    private CharSequence getOverlayName(PackageManager pm, String overlayCategoryFont) {
+        try {
+            return pm.getApplicationInfo(
+                    mPackagesByCategory.get(overlayCategoryFont), 0).loadLabel(pm);
+        } catch (PackageManager.NameNotFoundException e) {
+            return "";
+        }
+    }
 
     public static class PreviewInfo {
         public final Typeface bodyFontFamily;
@@ -259,7 +296,6 @@
         protected Map<String, String> mPackages = new HashMap<>();
         private List<Drawable> mAppIcons = new ArrayList<>();
 
-
         public ThemeBundle build(Context context) {
             return new ThemeBundle(mTitle, mPackages, mIsDefault, mWallpaperInfo,
                     createPreviewInfo(context));
diff --git a/src/com/android/customization/picker/clock/ClockFragment.java b/src/com/android/customization/picker/clock/ClockFragment.java
index 87f6b20..73a8af4 100644
--- a/src/com/android/customization/picker/clock/ClockFragment.java
+++ b/src/com/android/customization/picker/clock/ClockFragment.java
@@ -29,7 +29,6 @@
 
 import com.android.customization.model.CustomizationManager.Callback;
 import com.android.customization.model.clock.BaseClockManager;
-import com.android.customization.model.clock.ClockManager;
 import com.android.customization.model.clock.Clockface;
 import com.android.customization.module.ThemesUserEventLogger;
 import com.android.customization.picker.BasePreviewAdapter;
@@ -146,6 +145,8 @@
                     100 /* transitionDurationMillis */,
                     null /* drawableLoadedListener */,
                     res.getColor(android.R.color.transparent, null) /* placeholderColor */);
+            card.setContentDescription(card.getResources().getString(
+                    R.string.clock_preview_content_description, title));
         }
     }