summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Bill Lin <lbill@google.com> 2018-11-30 21:51:47 +0800
committer Bill Lin <lbill@google.com> 2019-01-09 19:56:13 +0800
commit49bef2960b58d63528b69003cf15c8f2d1f5999d (patch)
tree8b975d7322b33ec97023f39cbee82776cee6157b
parentef377a052a59eeb3d1ce5892673f32867f08e594 (diff)
Update colored icons for mimeTypes (1/N)
1.Refactor root icons to use mimetype icons If docsui can't identify it, use system default mimetype icon Allow OEMs to customize vector drawable (drawable/drawable-night) 2.Remove duplicate ic_doc_xxx icons from docsui, load from system Test: atest DocumentsTests Test: atest IconUtilsTest.java Bug: 117956209 Change-Id: I938fa537a397b58faee12a2e38cf81592daf6e8b
-rw-r--r--res/color/item_action_icon.xml4
-rw-r--r--res/color/item_root_icon.xml2
-rw-r--r--res/drawable/ic_doc_album.xml24
-rw-r--r--res/drawable/ic_doc_audio.xml24
-rw-r--r--res/drawable/ic_doc_folder.xml24
-rw-r--r--res/drawable/ic_doc_generic.xml24
-rw-r--r--res/drawable/ic_doc_image.xml24
-rw-r--r--res/drawable/ic_doc_text.xml24
-rw-r--r--res/drawable/ic_doc_video.xml24
-rw-r--r--res/drawable/ic_eject.xml2
-rw-r--r--res/drawable/ic_root_documents.xml24
-rw-r--r--res/drawable/ic_root_download.xml2
-rw-r--r--res/drawable/ic_root_recent.xml4
-rw-r--r--res/drawable/ic_root_smartphone.xml2
-rw-r--r--res/drawable/ic_sd_storage.xml2
-rw-r--r--res/layout/item_dir_grid.xml3
-rw-r--r--res/menu/activity.xml1
-rw-r--r--res/values-night/colors.xml2
-rw-r--r--res/values/colors.xml1
-rw-r--r--res/values/drawables.xml5
-rw-r--r--src/com/android/documentsui/DragAndDropManager.java3
-rw-r--r--src/com/android/documentsui/DropBadgeView.java4
-rw-r--r--src/com/android/documentsui/IconUtils.java17
-rw-r--r--src/com/android/documentsui/base/MimeTypes.java1
-rw-r--r--src/com/android/documentsui/base/RootInfo.java36
-rw-r--r--src/com/android/documentsui/dirlist/GridDirectoryHolder.java4
-rw-r--r--tests/unit/com/android/documentsui/IconUtilsTest.java58
27 files changed, 121 insertions, 224 deletions
diff --git a/res/color/item_action_icon.xml b/res/color/item_action_icon.xml
index a96ff3400..2f0497889 100644
--- a/res/color/item_action_icon.xml
+++ b/res/color/item_action_icon.xml
@@ -17,6 +17,6 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:alpha="@dimen/root_icon_disabled_alpha"
- android:color="?android:textColorPrimary" />
- <item android:color="?android:textColorPrimary" />
+ android:color="@color/root_icon_color" />
+ <item android:color="@color/root_icon_color" />
</selector>
diff --git a/res/color/item_root_icon.xml b/res/color/item_root_icon.xml
index 593518e66..8055e0474 100644
--- a/res/color/item_root_icon.xml
+++ b/res/color/item_root_icon.xml
@@ -17,7 +17,7 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_activated="false"
- android:color="?android:textColorPrimary" />
+ android:color="@color/root_icon_color" />
<item
android:state_activated="true"
android:color="@color/root_activated_color" />
diff --git a/res/drawable/ic_doc_album.xml b/res/drawable/ic_doc_album.xml
deleted file mode 100644
index 49608b0cd..000000000
--- a/res/drawable/ic_doc_album.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<!--
-Copyright (C) 2015 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.
--->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="?android:textColorSecondary"
- android:pathData="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10,-4.48 10,-10S17.52 2 12 2zm0 14.5c-2.49 0,-4.5,-2.01,-4.5,-4.5S9.51 7.5 12 7.5s4.5 2.01 4.5 4.5,-2.01 4.5,-4.5 4.5zm0,-5.5c-.55 0,-1 .45,-1 1s.45 1 1 1 1,-.45 1,-1,-.45,-1,-1,-1z"/>
-</vector>
diff --git a/res/drawable/ic_doc_audio.xml b/res/drawable/ic_doc_audio.xml
deleted file mode 100644
index d0fbe6c56..000000000
--- a/res/drawable/ic_doc_audio.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<!--
-Copyright (C) 2017 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.
--->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="?android:textColorSecondary"
- android:pathData="M19 3H5c-1.1 0,-2 .9,-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2,-.9 2,-2V5c0,-1.1,-.9,-2,-2,-2zM7.2 18c-.66 0,-1.2,-.54,-1.2,-1.2V12c0,-3.31 2.69,-6 6,-6s6 2.69 6 6v4.8c0 .66,-.54 1.2,-1.2 1.2H14v-4h2v-2c0,-2.21,-1.79,-4,-4,-4s-4 1.79,-4 4v2h2v4H7.2z"/>
-</vector>
diff --git a/res/drawable/ic_doc_folder.xml b/res/drawable/ic_doc_folder.xml
deleted file mode 100644
index 48c562e52..000000000
--- a/res/drawable/ic_doc_folder.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<!--
-Copyright (C) 2015 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.
--->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="?android:textColorSecondary"
- android:pathData="M10 4H4c-1.1 0,-1.99.9,-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2,-.9 2,-2V8c0,-1.1,-.9,-2,-2,-2h-8l-2,-2z"/>
-</vector>
diff --git a/res/drawable/ic_doc_generic.xml b/res/drawable/ic_doc_generic.xml
deleted file mode 100644
index 9662ad196..000000000
--- a/res/drawable/ic_doc_generic.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<!--
-Copyright (C) 2017 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.
--->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="?android:textColorSecondary"
- android:pathData="M6 2c-1.1 0,-1.99.9,-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2,-.9 2,-2V8l-6,-6H6zm7 7V3.5L18.5 9H13z"/>
-</vector>
diff --git a/res/drawable/ic_doc_image.xml b/res/drawable/ic_doc_image.xml
deleted file mode 100644
index 88b97a3dd..000000000
--- a/res/drawable/ic_doc_image.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<!--
-Copyright (C) 2017 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.
--->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="?android:textColorSecondary"
- android:pathData="M21 19V5c0,-1.1,-.9,-2,-2,-2H5c-1.1 0,-2 .9,-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2,-.9 2,-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5,-4.5z"/>
-</vector>
diff --git a/res/drawable/ic_doc_text.xml b/res/drawable/ic_doc_text.xml
deleted file mode 100644
index 510d4ee1b..000000000
--- a/res/drawable/ic_doc_text.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<!--
-Copyright (C) 2015 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.
--->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="?android:textColorSecondary"
- android:pathData="M14 2H6c-1.1 0,-1.99.9,-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2,-.9 2,-2V8l-6,-6zm2 16H8v-2h8v2zm0,-4H8v-2h8v2zm-3,-5V3.5L18.5 9H13z"/>
-</vector>
diff --git a/res/drawable/ic_doc_video.xml b/res/drawable/ic_doc_video.xml
deleted file mode 100644
index 65a69310a..000000000
--- a/res/drawable/ic_doc_video.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<!--
-Copyright (C) 2017 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.
--->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="?android:textColorSecondary"
- android:pathData="M18 4l2 4h-3l-2,-4h-2l2 4h-3l-2,-4H8l2 4H7L5 4H4c-1.1 0,-1.99.9,-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2,-.9 2,-2V4h-4z"/>
-</vector>
diff --git a/res/drawable/ic_eject.xml b/res/drawable/ic_eject.xml
index 5b6b1c718..b94daebe7 100644
--- a/res/drawable/ic_eject.xml
+++ b/res/drawable/ic_eject.xml
@@ -19,6 +19,6 @@ Copyright (C) 2016 The Android Open Source Project
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="?android:textColorSecondary"
+ android:fillColor="@color/root_icon_color"
android:pathData="M5 17h14v2H5zm7-12L5.33 15h13.34z"/>
</vector> \ No newline at end of file
diff --git a/res/drawable/ic_root_documents.xml b/res/drawable/ic_root_documents.xml
deleted file mode 100644
index 48c562e52..000000000
--- a/res/drawable/ic_root_documents.xml
+++ /dev/null
@@ -1,24 +0,0 @@
-<!--
-Copyright (C) 2015 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.
--->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:viewportWidth="24.0"
- android:viewportHeight="24.0">
- <path
- android:fillColor="?android:textColorSecondary"
- android:pathData="M10 4H4c-1.1 0,-1.99.9,-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2,-.9 2,-2V8c0,-1.1,-.9,-2,-2,-2h-8l-2,-2z"/>
-</vector>
diff --git a/res/drawable/ic_root_download.xml b/res/drawable/ic_root_download.xml
index 83dce15a0..5f156a4f9 100644
--- a/res/drawable/ic_root_download.xml
+++ b/res/drawable/ic_root_download.xml
@@ -20,6 +20,6 @@
android:viewportHeight="24"
android:viewportWidth="24">
<path
- android:fillColor="?android:textColorSecondary"
+ android:fillColor="@color/root_icon_color"
android:pathData="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z" />
</vector>
diff --git a/res/drawable/ic_root_recent.xml b/res/drawable/ic_root_recent.xml
index 14e30dd9a..f45d01ff0 100644
--- a/res/drawable/ic_root_recent.xml
+++ b/res/drawable/ic_root_recent.xml
@@ -21,11 +21,11 @@
android:viewportHeight="24">
<path
- android:fillColor="?android:textColorSecondary"
+ android:fillColor="@color/root_icon_color"
android:pathData="M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2
11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z" />
<path
- android:fillColor="?android:textColorSecondary"
+ android:fillColor="@color/root_icon_color"
android:pathData="M12.5 7H11v6l5.25 3.15 .75 -1.23-4.5-2.67z" />
</vector> \ No newline at end of file
diff --git a/res/drawable/ic_root_smartphone.xml b/res/drawable/ic_root_smartphone.xml
index cadb1a700..956ea29dd 100644
--- a/res/drawable/ic_root_smartphone.xml
+++ b/res/drawable/ic_root_smartphone.xml
@@ -19,6 +19,6 @@ Copyright (C) 2015 The Android Open Source Project
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="?android:textColorSecondary"
+ android:fillColor="@color/root_icon_color"
android:pathData="M17 1.01L7 1c-1.1 0,-2 .9,-2 2v18c0 1.1.9 2 2 2h10c1.1 0 2,-.9 2,-2V3c0,-1.1,-.9,-1.99,-2,-1.99zM17 19H7V5h10v14z"/>
</vector>
diff --git a/res/drawable/ic_sd_storage.xml b/res/drawable/ic_sd_storage.xml
index 0c2208420..f711a5f86 100644
--- a/res/drawable/ic_sd_storage.xml
+++ b/res/drawable/ic_sd_storage.xml
@@ -19,6 +19,6 @@ Copyright (C) 2015 The Android Open Source Project
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="?android:textColorSecondary"
+ android:fillColor="@color/root_icon_color"
android:pathData="M18 2h-8L4.02 8 4 20c0 1.1.9 2 2 2h12c1.1 0 2,-.9 2,-2V4c0,-1.1,-.9,-2,-2,-2zm-6 6h-2V4h2v4zm3 0h-2V4h2v4zm3 0h-2V4h2v4z"/>
</vector>
diff --git a/res/layout/item_dir_grid.xml b/res/layout/item_dir_grid.xml
index 000790e12..56077e656 100644
--- a/res/layout/item_dir_grid.xml
+++ b/res/layout/item_dir_grid.xml
@@ -62,8 +62,7 @@
android:layout_height="@dimen/grid_item_icon_size"
android:layout_gravity="center"
android:contentDescription="@null"
- android:scaleType="centerInside"
- android:src="@drawable/ic_doc_folder"/>
+ android:scaleType="centerInside"/>
<ImageView
android:id="@+id/icon_check"
diff --git a/res/menu/activity.xml b/res/menu/activity.xml
index 778e7acba..d9b509bd8 100644
--- a/res/menu/activity.xml
+++ b/res/menu/activity.xml
@@ -60,7 +60,6 @@
<item
android:id="@+id/option_menu_create_dir"
android:title="@string/menu_create_dir"
- android:icon="@drawable/ic_menu_new_folder"
android:alphabeticShortcut="e"
android:visible="false"
app:showAsAction="never"/>
diff --git a/res/values-night/colors.xml b/res/values-night/colors.xml
index 9acc28059..1303d1255 100644
--- a/res/values-night/colors.xml
+++ b/res/values-night/colors.xml
@@ -13,8 +13,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
<resources>
+ <color name="root_icon_color">#9AA0A6</color>
<color name="chip_stroke_color">@android:color/transparent</color>
<color name="chip_selected_background_color">#FF3D4657</color>
<color name="chip_ripple_color">#FF5195EA</color>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 9cd64c1f5..5d78cf5e0 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -43,6 +43,7 @@
<color name="band_select_border">#44000000</color>
<color name="root_title_color">#de000000</color>
+ <color name="root_icon_color">#5F6368</color>
<color name="root_activated_color">#ff127beb</color>
<color name="root_details_color">#8a000000</color>
<color name="root_focus_color">?android:attr/colorControlHighlight</color>
diff --git a/res/values/drawables.xml b/res/values/drawables.xml
index ab7a48f44..c0575e0e7 100644
--- a/res/values/drawables.xml
+++ b/res/values/drawables.xml
@@ -17,9 +17,4 @@
<resources>
<item name="app_icon" type="drawable">@mipmap/ic_app_icon</item>
<item name="launcher_icon" type="drawable">@mipmap/ic_app_icon</item>
- <item name="image_root_icon" type="drawable">@drawable/ic_doc_image</item>
- <item name="video_root_icon" type="drawable">@drawable/ic_doc_video</item>
- <item name="audio_root_icon" type="drawable">@drawable/ic_doc_audio</item>
- <item name="generic_doc_icon" type="drawable">@drawable/ic_doc_generic</item>
- <item name="ic_menu_new_folder" type="drawable">@drawable/ic_doc_folder</item>
</resources> \ No newline at end of file
diff --git a/src/com/android/documentsui/DragAndDropManager.java b/src/com/android/documentsui/DragAndDropManager.java
index 5f5876c41..55dff381a 100644
--- a/src/com/android/documentsui/DragAndDropManager.java
+++ b/src/com/android/documentsui/DragAndDropManager.java
@@ -31,6 +31,7 @@ import android.view.View;
import com.android.documentsui.MenuManager.SelectionDetails;
import com.android.documentsui.base.DocumentInfo;
import com.android.documentsui.base.DocumentStack;
+import com.android.documentsui.base.MimeTypes;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.clipping.DocumentClipper;
import com.android.documentsui.dirlist.IconHelper;
@@ -186,7 +187,7 @@ public interface DragAndDropManager {
context.getApplicationContext(),
clipper,
new DragShadowBuilder(context),
- context.getDrawable(R.drawable.ic_doc_generic));
+ IconUtils.loadMimeIcon(context, MimeTypes.GENERIC_TYPE));
}
@VisibleForTesting
diff --git a/src/com/android/documentsui/DropBadgeView.java b/src/com/android/documentsui/DropBadgeView.java
index 6f71d018e..552e2ecd3 100644
--- a/src/com/android/documentsui/DropBadgeView.java
+++ b/src/com/android/documentsui/DropBadgeView.java
@@ -17,6 +17,7 @@
package com.android.documentsui;
import com.android.documentsui.DragAndDropManager.State;
+import com.android.documentsui.base.MimeTypes;
import android.content.Context;
import android.graphics.drawable.Drawable;
@@ -45,8 +46,7 @@ public final class DropBadgeView extends ImageView {
final int iconSize = context.getResources().getDimensionPixelSize(R.dimen.root_icon_size);
Drawable okBadge = context.getResources().getDrawable(R.drawable.drop_badge_states, null);
- Drawable defaultIcon = context.getResources()
- .getDrawable(R.drawable.ic_doc_generic, null);
+ Drawable defaultIcon = IconUtils.loadMimeIcon(context, MimeTypes.GENERIC_TYPE);
Drawable[] list = {defaultIcon, okBadge};
mBackground = new LayerDrawable(list);
diff --git a/src/com/android/documentsui/IconUtils.java b/src/com/android/documentsui/IconUtils.java
index 7b6678d6b..4a67375b5 100644
--- a/src/com/android/documentsui/IconUtils.java
+++ b/src/com/android/documentsui/IconUtils.java
@@ -20,9 +20,10 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.graphics.drawable.Drawable;
-import android.provider.DocumentsContract.Document;
import android.util.TypedValue;
+import com.android.documentsui.base.MimeTypes;
+
public class IconUtils {
public static Drawable loadPackageIcon(Context context, String authority, int icon) {
if (icon != 0) {
@@ -41,19 +42,25 @@ public class IconUtils {
public static Drawable loadMimeIcon(
Context context, String mimeType, String authority, String docId, int mode) {
- if (Document.MIME_TYPE_DIR.equals(mimeType)) {
- return context.getDrawable(R.drawable.ic_doc_folder);
- }
-
return loadMimeIcon(context, mimeType);
}
+ /**
+ * Load mime type drawable from system MimeIconUtils.
+ * @param context activity context to obtain resource
+ * @param mimeType specific mime type string of file
+ * @return drawable of mime type files from system default
+ */
public static Drawable loadMimeIcon(Context context, String mimeType) {
return context.getContentResolver().getTypeDrawable(mimeType);
}
public static Drawable applyTintColor(Context context, int drawableId, int tintColorId) {
final Drawable icon = context.getDrawable(drawableId);
+ return applyTintColor(context, icon, tintColorId);
+ }
+
+ public static Drawable applyTintColor(Context context, Drawable icon, int tintColorId) {
icon.mutate();
icon.setTintList(context.getColorStateList(tintColorId));
return icon;
diff --git a/src/com/android/documentsui/base/MimeTypes.java b/src/com/android/documentsui/base/MimeTypes.java
index 52818749f..fca097d3d 100644
--- a/src/com/android/documentsui/base/MimeTypes.java
+++ b/src/com/android/documentsui/base/MimeTypes.java
@@ -25,6 +25,7 @@ public final class MimeTypes {
private MimeTypes() {}
public static final String APK_TYPE = "application/vnd.android.package-archive";
+ public static final String GENERIC_TYPE = "application/*";
public static final String IMAGE_PREFIX = "image";
public static final String AUDIO_PREFIX = "audio";
diff --git a/src/com/android/documentsui/base/RootInfo.java b/src/com/android/documentsui/base/RootInfo.java
index 0f0a64ef2..61e9acae3 100644
--- a/src/com/android/documentsui/base/RootInfo.java
+++ b/src/com/android/documentsui/base/RootInfo.java
@@ -52,6 +52,7 @@ import java.util.Objects;
public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> {
private static final String TAG = "RootInfo";
+ private static final int LOAD_FROM_CONTENT_RESOLVER = -1;
// private static final int VERSION_INIT = 1; // Not used anymore
private static final int VERSION_DROP_TYPE = 2;
@@ -200,7 +201,7 @@ public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> {
if (isExternalStorageHome()) {
derivedType = TYPE_LOCAL;
- derivedIcon = R.drawable.ic_root_documents;
+ derivedIcon = LOAD_FROM_CONTENT_RESOLVER;
} else if (isMtp()) {
derivedType = TYPE_MTP;
derivedIcon = R.drawable.ic_usb_storage;
@@ -218,13 +219,13 @@ public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> {
derivedIcon = R.drawable.ic_root_download;
} else if (isImages()) {
derivedType = TYPE_IMAGES;
- derivedIcon = R.drawable.image_root_icon;
+ derivedIcon = LOAD_FROM_CONTENT_RESOLVER;
} else if (isVideos()) {
derivedType = TYPE_VIDEO;
- derivedIcon = R.drawable.video_root_icon;
+ derivedIcon = LOAD_FROM_CONTENT_RESOLVER;
} else if (isAudio()) {
derivedType = TYPE_AUDIO;
- derivedIcon = R.drawable.audio_root_icon;
+ derivedIcon = LOAD_FROM_CONTENT_RESOLVER;
} else if (isRecents()) {
derivedType = TYPE_RECENTS;
} else {
@@ -343,8 +344,28 @@ public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> {
return (flags & Root.FLAG_REMOVABLE_USB) != 0;
}
+ private Drawable loadMimeTypeIcon(Context context) {
+
+ if (isExternalStorageHome()) {
+ return IconUtils.loadMimeIcon(context, DocumentsContract.Document.MIME_TYPE_DIR);
+ }
+
+ switch (derivedType) {
+ case TYPE_IMAGES:
+ return IconUtils.loadMimeIcon(context, MimeTypes.IMAGE_PREFIX);
+ case TYPE_AUDIO:
+ return IconUtils.loadMimeIcon(context, MimeTypes.AUDIO_PREFIX);
+ case TYPE_VIDEO:
+ return IconUtils.loadMimeIcon(context, MimeTypes.VIDEO_PREFIX);
+ default:
+ return IconUtils.loadMimeIcon(context, MimeTypes.GENERIC_TYPE);
+ }
+ }
+
public Drawable loadIcon(Context context) {
- if (derivedIcon != 0) {
+ if (derivedIcon == LOAD_FROM_CONTENT_RESOLVER) {
+ return loadMimeTypeIcon(context);
+ } else if (derivedIcon != 0) {
return context.getDrawable(derivedIcon);
} else {
return IconUtils.loadPackageIcon(context, authority, icon);
@@ -352,7 +373,10 @@ public class RootInfo implements Durable, Parcelable, Comparable<RootInfo> {
}
public Drawable loadDrawerIcon(Context context) {
- if (derivedIcon != 0) {
+ if (derivedIcon == LOAD_FROM_CONTENT_RESOLVER) {
+ return IconUtils.applyTintColor(context, loadMimeTypeIcon(context),
+ R.color.item_root_icon);
+ } else if (derivedIcon != 0) {
return IconUtils.applyTintColor(context, derivedIcon, R.color.item_root_icon);
} else {
return IconUtils.loadPackageIcon(context, authority, icon);
diff --git a/src/com/android/documentsui/dirlist/GridDirectoryHolder.java b/src/com/android/documentsui/dirlist/GridDirectoryHolder.java
index f5f54edbf..807af4dd8 100644
--- a/src/com/android/documentsui/dirlist/GridDirectoryHolder.java
+++ b/src/com/android/documentsui/dirlist/GridDirectoryHolder.java
@@ -20,6 +20,7 @@ import static com.android.documentsui.base.DocumentInfo.getCursorString;
import android.content.Context;
import android.database.Cursor;
+import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Document;
import android.view.MotionEvent;
import android.view.View;
@@ -27,6 +28,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
+import com.android.documentsui.IconUtils;
import com.android.documentsui.R;
import com.android.documentsui.ui.Views;
@@ -45,6 +47,8 @@ final class GridDirectoryHolder extends DocumentHolder {
mTitle = (TextView) itemView.findViewById(android.R.id.title);
mIconMime = (ImageView) itemView.findViewById(R.id.icon_mime_sm);
mIconCheck = (ImageView) itemView.findViewById(R.id.icon_check);
+ mIconMime.setImageDrawable(
+ IconUtils.loadMimeIcon(context, DocumentsContract.Document.MIME_TYPE_DIR));
}
@Override
diff --git a/tests/unit/com/android/documentsui/IconUtilsTest.java b/tests/unit/com/android/documentsui/IconUtilsTest.java
new file mode 100644
index 000000000..f5547bd64
--- /dev/null
+++ b/tests/unit/com/android/documentsui/IconUtilsTest.java
@@ -0,0 +1,58 @@
+package com.android.documentsui;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import androidx.test.InstrumentationRegistry;
+import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
+
+import android.content.Context;
+
+import org.junit.Before;
+import org.junit.Test;
+
+@SmallTest
+public class IconUtilsTest {
+ private static final String AUDIO_MIME_TYPE = "audio";
+ private static final String IMAGE_MIME_TYPE = "image";
+ private static final String TEXT_MIME_TYPE = "text";
+ private static final String VIDEO_MIME_TYPE = "video";
+ private static final String GENERIC_MIME_TYPE = "generic";
+
+ private Context mTargetContext;
+
+ @Before
+ public void setUp() throws Exception {
+ mTargetContext = InstrumentationRegistry.getTargetContext();
+ }
+
+ @Test
+ public void testLoadMimeIcon_isAudioMimeType() {
+ assertThat(IconUtils.loadMimeIcon(mTargetContext, AUDIO_MIME_TYPE)).isNotNull();
+ }
+
+ @Test
+ public void testLoadMimeIcon_isImageMimeType() {
+ assertThat(IconUtils.loadMimeIcon(mTargetContext, IMAGE_MIME_TYPE)).isNotNull();
+ }
+
+ @Test
+ public void testLoadMimeIcon_isGenericMimeType() {
+ assertThat(IconUtils.loadMimeIcon(mTargetContext, GENERIC_MIME_TYPE)).isNotNull();
+ }
+
+ @Test
+ public void testLoadMimeIcon_isVideoMimeType() {
+ assertThat(IconUtils.loadMimeIcon(mTargetContext, VIDEO_MIME_TYPE)).isNotNull();
+ }
+
+ @Test
+ public void testLoadMimeIcon_isTextMimeType() {
+ assertThat(IconUtils.loadMimeIcon(mTargetContext, TEXT_MIME_TYPE)).isNotNull();
+ }
+
+ @Test
+ public void testLoadMimeIcon_isMimeTypeNull_shouldReturnNull() {
+ assertThat(IconUtils.loadMimeIcon(mTargetContext, null)).isNull();
+ }
+}