More material updates to DocumentsUI.

All assets cut as alpha variants so we apply desired tinting at
runtime.  Small script to automatically generate XML resources.

Bug: 15836082, 16658537
Change-Id: I803b3f0bf6f121194a5445fd1c6600fabaf28f60
diff --git a/src/com/android/documentsui/DirectoryFragment.java b/src/com/android/documentsui/DirectoryFragment.java
index 001cac4..0a7eedc 100644
--- a/src/com/android/documentsui/DirectoryFragment.java
+++ b/src/com/android/documentsui/DirectoryFragment.java
@@ -70,7 +70,6 @@
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.BaseAdapter;
-import android.widget.FrameLayout;
 import android.widget.GridView;
 import android.widget.ImageView;
 import android.widget.ListView;
@@ -705,11 +704,11 @@
             if (extras != null) {
                 final String info = extras.getString(DocumentsContract.EXTRA_INFO);
                 if (info != null) {
-                    mFooters.add(new MessageFooter(2, R.drawable.ic_dialog_info_dark, info));
+                    mFooters.add(new MessageFooter(2, R.drawable.ic_dialog_info, info));
                 }
                 final String error = extras.getString(DocumentsContract.EXTRA_ERROR);
                 if (error != null) {
-                    mFooters.add(new MessageFooter(3, R.drawable.ic_dialog_alert_dark, error));
+                    mFooters.add(new MessageFooter(3, R.drawable.ic_dialog_alert, error));
                 }
                 if (extras.getBoolean(DocumentsContract.EXTRA_LOADING, false)) {
                     mFooters.add(new LoadingFooter());
@@ -718,7 +717,7 @@
 
             if (result != null && result.exception != null) {
                 mFooters.add(new MessageFooter(
-                        3, R.drawable.ic_dialog_alert_dark, getString(R.string.query_error)));
+                        3, R.drawable.ic_dialog_alert, getString(R.string.query_error)));
             }
 
             if (isEmpty()) {
@@ -854,7 +853,7 @@
                 // be shown, so this will never block.
                 final RootInfo root = roots.getRootBlocking(docAuthority, docRootId);
                 if (state.derivedMode == MODE_GRID) {
-                    iconDrawable = root.loadLightIcon(context);
+                    iconDrawable = root.loadGridIcon(context);
                 } else {
                     iconDrawable = root.loadIcon(context);
                 }
@@ -883,8 +882,8 @@
                 // hint to remind user they're a directory.
                 if (Document.MIME_TYPE_DIR.equals(docMimeType) && state.derivedMode == MODE_GRID
                         && showThumbnail) {
-                    iconDrawable = context.getResources().getDrawable(
-                            R.drawable.ic_root_folder_light);
+                    iconDrawable = IconUtils.applyTint(context, R.drawable.ic_doc_folder,
+                            android.R.attr.textColorPrimaryInverse);
                 }
 
                 if (summary != null) {
diff --git a/src/com/android/documentsui/DocumentsActivity.java b/src/com/android/documentsui/DocumentsActivity.java
index a2e8432..29f8b9d 100644
--- a/src/com/android/documentsui/DocumentsActivity.java
+++ b/src/com/android/documentsui/DocumentsActivity.java
@@ -425,7 +425,8 @@
         final RootInfo root = getCurrentRoot();
         final boolean showRootIcon = mShowAsDialog || (mState.action == ACTION_MANAGE);
         if (showRootIcon) {
-            mToolbar.setNavigationIcon(root != null ? root.loadLightIcon(this) : null);
+            mToolbar.setNavigationIcon(
+                    root != null ? root.loadToolbarIcon(mToolbar.getContext()) : null);
             mToolbar.setNavigationOnClickListener(null);
         } else {
             mToolbar.setNavigationIcon(R.drawable.ic_hamburger);
diff --git a/src/com/android/documentsui/IconUtils.java b/src/com/android/documentsui/IconUtils.java
index eaa74eb..b7e1294 100644
--- a/src/com/android/documentsui/IconUtils.java
+++ b/src/com/android/documentsui/IconUtils.java
@@ -22,6 +22,7 @@
 import android.content.res.Resources;
 import android.graphics.drawable.Drawable;
 import android.provider.DocumentsContract.Document;
+import android.util.TypedValue;
 
 import com.google.android.collect.Maps;
 
@@ -45,7 +46,7 @@
         add("application/vnd.android.package-archive", icon);
 
         // Audio
-        icon = R.drawable.ic_doc_audio_dark;
+        icon = R.drawable.ic_doc_audio;
         add("application/ogg", icon);
         add("application/x-flac", icon);
 
@@ -132,7 +133,7 @@
         add("application/x-font-ttf", icon);
 
         // Image
-        icon = R.drawable.ic_doc_image_dark;
+        icon = R.drawable.ic_doc_image;
         add("application/vnd.oasis.opendocument.graphics", icon);
         add("application/vnd.oasis.opendocument.graphics-template", icon);
         add("application/vnd.oasis.opendocument.image", icon);
@@ -186,7 +187,7 @@
         add("application/x-kword", icon);
 
         // Video
-        icon = R.drawable.ic_doc_video_dark;
+        icon = R.drawable.ic_doc_video;
         add("application/x-quicktimeplayer", icon);
         add("application/x-shockwave-flash", icon);
     }
@@ -220,7 +221,7 @@
             if (mode == DocumentsActivity.State.MODE_GRID) {
                 return res.getDrawable(R.drawable.ic_grid_folder);
             } else {
-                return res.getDrawable(R.drawable.ic_root_folder_dark);
+                return res.getDrawable(R.drawable.ic_doc_folder);
             }
         }
 
@@ -231,8 +232,7 @@
         final Resources res = context.getResources();
 
         if (Document.MIME_TYPE_DIR.equals(mimeType)) {
-            // TODO: return a mipmap, since this is used for grid
-            return res.getDrawable(R.drawable.ic_root_folder_dark);
+            return res.getDrawable(R.drawable.ic_doc_folder);
         }
 
         // Look for exact match first
@@ -249,15 +249,27 @@
         // Otherwise look for partial match
         final String typeOnly = mimeType.split("/")[0];
         if ("audio".equals(typeOnly)) {
-            return res.getDrawable(R.drawable.ic_doc_audio_dark);
+            return res.getDrawable(R.drawable.ic_doc_audio);
         } else if ("image".equals(typeOnly)) {
-            return res.getDrawable(R.drawable.ic_doc_image_dark);
+            return res.getDrawable(R.drawable.ic_doc_image);
         } else if ("text".equals(typeOnly)) {
             return res.getDrawable(R.drawable.ic_doc_text);
         } else if ("video".equals(typeOnly)) {
-            return res.getDrawable(R.drawable.ic_doc_video_dark);
+            return res.getDrawable(R.drawable.ic_doc_video);
         } else {
             return res.getDrawable(R.drawable.ic_doc_generic);
         }
     }
+
+    public static Drawable applyTint(Context context, int drawableId, int tintAttrId) {
+        final Resources res = context.getResources();
+
+        final TypedValue outValue = new TypedValue();
+        context.getTheme().resolveAttribute(tintAttrId, outValue, true);
+
+        final Drawable icon = res.getDrawable(drawableId);
+        icon.mutate();
+        icon.setTintList(res.getColorStateList(outValue.resourceId));
+        return icon;
+    }
 }
diff --git a/src/com/android/documentsui/RootsCache.java b/src/com/android/documentsui/RootsCache.java
index 1235c9b..a465ecd 100644
--- a/src/com/android/documentsui/RootsCache.java
+++ b/src/com/android/documentsui/RootsCache.java
@@ -103,8 +103,7 @@
         // Special root for recents
         mRecentsRoot.authority = null;
         mRecentsRoot.rootId = null;
-        mRecentsRoot.icon = R.drawable.ic_root_recent_dark;
-        mRecentsRoot.lightIcon = R.drawable.ic_root_recent_light;
+        mRecentsRoot.derivedIcon = R.drawable.ic_root_recent;
         mRecentsRoot.flags = Root.FLAG_LOCAL_ONLY | Root.FLAG_SUPPORTS_CREATE
                 | Root.FLAG_SUPPORTS_IS_CHILD;
         mRecentsRoot.title = mContext.getString(R.string.root_recent);
diff --git a/src/com/android/documentsui/model/RootInfo.java b/src/com/android/documentsui/model/RootInfo.java
index 79cbf26..a358798 100644
--- a/src/com/android/documentsui/model/RootInfo.java
+++ b/src/com/android/documentsui/model/RootInfo.java
@@ -48,7 +48,6 @@
     public String rootId;
     public int flags;
     public int icon;
-    public int lightIcon;
     public String title;
     public String summary;
     public String documentId;
@@ -59,7 +58,6 @@
     public String derivedPackageName;
     public String[] derivedMimeTypes;
     public int derivedIcon;
-    public int derivedLightIcon;
 
     public RootInfo() {
         reset();
@@ -71,7 +69,6 @@
         rootId = null;
         flags = 0;
         icon = 0;
-        lightIcon = 0;
         title = null;
         summary = null;
         documentId = null;
@@ -81,7 +78,6 @@
         derivedPackageName = null;
         derivedMimeTypes = null;
         derivedIcon = 0;
-        derivedLightIcon = 0;
     }
 
     @Override
@@ -163,20 +159,15 @@
 
         // TODO: remove these special case icons
         if (isExternalStorage()) {
-            derivedIcon = R.drawable.ic_root_sdcard_dark;
-            derivedLightIcon = R.drawable.ic_root_sdcard_light;
+            derivedIcon = R.drawable.ic_root_sdcard;
         } else if (isDownloads()) {
-            derivedIcon = R.drawable.ic_root_download_dark;
-            derivedLightIcon = R.drawable.ic_root_download_light;
+            derivedIcon = R.drawable.ic_root_download;
         } else if (isImages()) {
-            derivedIcon = R.drawable.ic_doc_image_dark;
-            derivedLightIcon = R.drawable.ic_doc_image_light;
+            derivedIcon = R.drawable.ic_doc_image;
         } else if (isVideos()) {
-            derivedIcon = R.drawable.ic_doc_video_dark;
-            derivedLightIcon = R.drawable.ic_doc_video_light;
+            derivedIcon = R.drawable.ic_doc_video;
         } else if (isAudio()) {
-            derivedIcon = R.drawable.ic_doc_audio_dark;
-            derivedLightIcon = R.drawable.ic_doc_audio_light;
+            derivedIcon = R.drawable.ic_doc_audio;
         }
     }
 
@@ -220,13 +211,21 @@
         }
     }
 
-    public Drawable loadLightIcon(Context context) {
-        if (derivedLightIcon != 0) {
-            return context.getResources().getDrawable(derivedLightIcon);
-        } else if (lightIcon != 0) {
-            return IconUtils.loadPackageIcon(context, authority, lightIcon);
+    public Drawable loadGridIcon(Context context) {
+        if (derivedIcon != 0) {
+            return IconUtils.applyTint(context, derivedIcon,
+                    android.R.attr.textColorPrimaryInverse);
         } else {
-            return loadIcon(context);
+            return IconUtils.loadPackageIcon(context, authority, icon);
+        }
+    }
+
+    public Drawable loadToolbarIcon(Context context) {
+        if (derivedIcon != 0) {
+            return IconUtils.applyTint(context, derivedIcon,
+                    android.R.attr.colorControlNormal);
+        } else {
+            return IconUtils.loadPackageIcon(context, authority, icon);
         }
     }