Upgrade launcher icon and shortcuts to adaptive icon Bug: 62023774 Test: build, and runs, manual testing on marlin device am: a62e5047cb
am: 2c1b15d25a
Change-Id: I3579c0a9763cc32e0bef5f4471b33b36f27373c7
diff --git a/res/drawable/ic_images_shortcut.xml b/res/drawable/ic_images_shortcut.xml
index a60f27c..5e84369 100644
--- a/res/drawable/ic_images_shortcut.xml
+++ b/res/drawable/ic_images_shortcut.xml
@@ -15,16 +15,19 @@
~ limitations under the License.
-->
-<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item>
- <shape android:shape="oval">
- <solid android:color="@color/shortcut_background" />
- </shape>
- </item>
- <item
- android:drawable="@drawable/ic_images_white"
- android:top="16dp"
- android:right="16dp"
- android:bottom="16dp"
- android:left="16dp" />
-</layer-list>
\ No newline at end of file
+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
+ <background android:drawable="@color/shortcut_background" />
+ <foreground>
+ <inset android:inset="33%">
+ <vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportHeight="24"
+ android:viewportWidth="24">
+ <path
+ android:fillColor="@color/shortcut_foreground"
+ 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>
+ </inset>
+ </foreground>
+</adaptive-icon>
diff --git a/res/drawable/ic_images_white.xml b/res/drawable/ic_images_white.xml
deleted file mode 100644
index 35d0e3a..0000000
--- a/res/drawable/ic_images_white.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- 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:viewportHeight="24"
- android:viewportWidth="24">
- <path
- android:fillColor="#FFFFFFFF"
- 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/mipmap-anydpi/ic_app_icon.xml b/res/mipmap-anydpi/ic_app_icon.xml
new file mode 100644
index 0000000..cd4fa58
--- /dev/null
+++ b/res/mipmap-anydpi/ic_app_icon.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
+ <background android:drawable="@color/app_icon_background"/>
+ <foreground android:drawable="@mipmap/ic_launcher_icon_foreground"/>
+</adaptive-icon>
diff --git a/res/mipmap-anydpi/ic_launcher_downloads.xml b/res/mipmap-anydpi/ic_launcher_downloads.xml
new file mode 100644
index 0000000..296c9d7
--- /dev/null
+++ b/res/mipmap-anydpi/ic_launcher_downloads.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
+ <background android:drawable="@color/downloads_icon_background"/>
+ <foreground android:drawable="@mipmap/ic_launcher_downloads_foreground"/>
+</adaptive-icon>
diff --git a/res/mipmap-hdpi/ic_app_icon.png b/res/mipmap-hdpi/ic_app_icon.png
deleted file mode 100644
index 7b0d04f..0000000
--- a/res/mipmap-hdpi/ic_app_icon.png
+++ /dev/null
Binary files differ
diff --git a/res/mipmap-hdpi/ic_launcher_downloads.png b/res/mipmap-hdpi/ic_launcher_downloads.png
deleted file mode 100644
index f958bbd..0000000
--- a/res/mipmap-hdpi/ic_launcher_downloads.png
+++ /dev/null
Binary files differ
diff --git a/res/mipmap-hdpi/ic_launcher_downloads_foreground.png b/res/mipmap-hdpi/ic_launcher_downloads_foreground.png
new file mode 100644
index 0000000..d27d526
--- /dev/null
+++ b/res/mipmap-hdpi/ic_launcher_downloads_foreground.png
Binary files differ
diff --git a/res/mipmap-hdpi/ic_launcher_icon_foreground.png b/res/mipmap-hdpi/ic_launcher_icon_foreground.png
new file mode 100644
index 0000000..992c44e
--- /dev/null
+++ b/res/mipmap-hdpi/ic_launcher_icon_foreground.png
Binary files differ
diff --git a/res/mipmap-mdpi/ic_app_icon.png b/res/mipmap-mdpi/ic_app_icon.png
deleted file mode 100644
index 1747fb2..0000000
--- a/res/mipmap-mdpi/ic_app_icon.png
+++ /dev/null
Binary files differ
diff --git a/res/mipmap-mdpi/ic_launcher_downloads.png b/res/mipmap-mdpi/ic_launcher_downloads.png
deleted file mode 100644
index f2e9376..0000000
--- a/res/mipmap-mdpi/ic_launcher_downloads.png
+++ /dev/null
Binary files differ
diff --git a/res/mipmap-mdpi/ic_launcher_downloads_foreground.png b/res/mipmap-mdpi/ic_launcher_downloads_foreground.png
new file mode 100644
index 0000000..a462402
--- /dev/null
+++ b/res/mipmap-mdpi/ic_launcher_downloads_foreground.png
Binary files differ
diff --git a/res/mipmap-mdpi/ic_launcher_icon_foreground.png b/res/mipmap-mdpi/ic_launcher_icon_foreground.png
new file mode 100644
index 0000000..4639ff0
--- /dev/null
+++ b/res/mipmap-mdpi/ic_launcher_icon_foreground.png
Binary files differ
diff --git a/res/mipmap-xhdpi/ic_app_icon.png b/res/mipmap-xhdpi/ic_app_icon.png
deleted file mode 100644
index 8a461fc..0000000
--- a/res/mipmap-xhdpi/ic_app_icon.png
+++ /dev/null
Binary files differ
diff --git a/res/mipmap-xhdpi/ic_launcher_downloads.png b/res/mipmap-xhdpi/ic_launcher_downloads.png
deleted file mode 100644
index 4dc5336..0000000
--- a/res/mipmap-xhdpi/ic_launcher_downloads.png
+++ /dev/null
Binary files differ
diff --git a/res/mipmap-xhdpi/ic_launcher_downloads_foreground.png b/res/mipmap-xhdpi/ic_launcher_downloads_foreground.png
new file mode 100644
index 0000000..c637eb4
--- /dev/null
+++ b/res/mipmap-xhdpi/ic_launcher_downloads_foreground.png
Binary files differ
diff --git a/res/mipmap-xhdpi/ic_launcher_icon_foreground.png b/res/mipmap-xhdpi/ic_launcher_icon_foreground.png
new file mode 100644
index 0000000..b992944
--- /dev/null
+++ b/res/mipmap-xhdpi/ic_launcher_icon_foreground.png
Binary files differ
diff --git a/res/mipmap-xxhdpi/ic_app_icon.png b/res/mipmap-xxhdpi/ic_app_icon.png
deleted file mode 100644
index c8eff03..0000000
--- a/res/mipmap-xxhdpi/ic_app_icon.png
+++ /dev/null
Binary files differ
diff --git a/res/mipmap-xxhdpi/ic_launcher_downloads.png b/res/mipmap-xxhdpi/ic_launcher_downloads.png
deleted file mode 100644
index 8716290..0000000
--- a/res/mipmap-xxhdpi/ic_launcher_downloads.png
+++ /dev/null
Binary files differ
diff --git a/res/mipmap-xxhdpi/ic_launcher_downloads_foreground.png b/res/mipmap-xxhdpi/ic_launcher_downloads_foreground.png
new file mode 100644
index 0000000..6f31eef
--- /dev/null
+++ b/res/mipmap-xxhdpi/ic_launcher_downloads_foreground.png
Binary files differ
diff --git a/res/mipmap-xxhdpi/ic_launcher_icon_foreground.png b/res/mipmap-xxhdpi/ic_launcher_icon_foreground.png
new file mode 100644
index 0000000..ae44b2f
--- /dev/null
+++ b/res/mipmap-xxhdpi/ic_launcher_icon_foreground.png
Binary files differ
diff --git a/res/mipmap-xxxhdpi/ic_app_icon.png b/res/mipmap-xxxhdpi/ic_app_icon.png
deleted file mode 100644
index 2961a64..0000000
--- a/res/mipmap-xxxhdpi/ic_app_icon.png
+++ /dev/null
Binary files differ
diff --git a/res/mipmap-xxxhdpi/ic_launcher_downloads.png b/res/mipmap-xxxhdpi/ic_launcher_downloads.png
deleted file mode 100644
index f5be219..0000000
--- a/res/mipmap-xxxhdpi/ic_launcher_downloads.png
+++ /dev/null
Binary files differ
diff --git a/res/mipmap-xxxhdpi/ic_launcher_downloads_foreground.png b/res/mipmap-xxxhdpi/ic_launcher_downloads_foreground.png
new file mode 100644
index 0000000..4b033db
--- /dev/null
+++ b/res/mipmap-xxxhdpi/ic_launcher_downloads_foreground.png
Binary files differ
diff --git a/res/mipmap-xxxhdpi/ic_launcher_icon_foreground.png b/res/mipmap-xxxhdpi/ic_launcher_icon_foreground.png
new file mode 100644
index 0000000..85150eb
--- /dev/null
+++ b/res/mipmap-xxxhdpi/ic_launcher_icon_foreground.png
Binary files differ
diff --git a/res/values/colors.xml b/res/values/colors.xml
index ca66c5d..e7801b9 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -64,7 +64,10 @@
<color name="item_drag_shadow_background">@*android:color/white</color>
<color name="item_drag_shadow_container_background">@*android:color/transparent</color>
- <color name="shortcut_background">@*android:color/Blue_700</color>
+ <color name="downloads_icon_background">#ff4688f2</color>
+ <color name="app_icon_background">#ff4688f2</color>
+ <color name="shortcut_foreground">#ff3367d6</color>
+ <color name="shortcut_background">#fff5f5f5</color>
<color name="dialog_title">@*android:color/primary_text_default_material_light</color>
diff --git a/src/com/android/documentsui/files/FilesActivity.java b/src/com/android/documentsui/files/FilesActivity.java
index 13d3bb3..50ba2ff 100644
--- a/src/com/android/documentsui/files/FilesActivity.java
+++ b/src/com/android/documentsui/files/FilesActivity.java
@@ -21,7 +21,14 @@
import android.app.ActivityManager.TaskDescription;
import android.app.FragmentManager;
import android.content.Intent;
+import android.content.Context;
+import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.CallSuper;
@@ -188,12 +195,60 @@
int iconRes = intent.getIntExtra(LauncherActivity.TASK_ICON_RES, -1);
assert(iconRes > -1);
- BitmapDrawable drawable = (BitmapDrawable) getResources().getDrawable(
+ Drawable drawable = getResources().getDrawable(
iconRes,
null // we don't care about theme, since the supplier should have handled that.
);
- setTaskDescription(new TaskDescription(label, drawable.getBitmap()));
+ setTaskDescription(new TaskDescription(label, flattenDrawableToBitmap(drawable)));
+ }
+
+ // AdaptiveIconDrawable assumes that the consumer of the icon applies the shadow and
+ // recents assume that the provider of the task description handles these. Hence,
+ // we apply the shadow treatment same as Launcher3 implementation.
+ private Bitmap flattenDrawableToBitmap(Drawable d) {
+ // Percent of actual icon size
+ float ICON_SIZE_BLUR_FACTOR = 0.5f/48;
+ // Percent of actual icon size
+ float ICON_SIZE_KEY_SHADOW_DELTA_FACTOR = 1f/48;
+ int KEY_SHADOW_ALPHA = 61;
+ int AMBIENT_SHADOW_ALPHA = 30;
+ if (d instanceof BitmapDrawable) {
+ return ((BitmapDrawable) d).getBitmap();
+ } else if (d instanceof AdaptiveIconDrawable) {
+ AdaptiveIconDrawable aid = (AdaptiveIconDrawable) d;
+ int iconSize = getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
+ int shadowSize = Math.max(iconSize, aid.getIntrinsicHeight());
+ aid.setBounds(0, 0, shadowSize, shadowSize);
+
+ float blur = ICON_SIZE_BLUR_FACTOR * shadowSize;
+ float keyShadowDistance = ICON_SIZE_KEY_SHADOW_DELTA_FACTOR * shadowSize;
+
+ int bitmapSize = (int) (shadowSize + 2 * blur + keyShadowDistance);
+ Bitmap shadow = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888);
+
+ Canvas canvas = new Canvas(shadow);
+ canvas.translate(blur + keyShadowDistance / 2, blur);
+
+ Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ paint.setColor(Color.TRANSPARENT);
+
+ // Draw ambient shadow
+ paint.setShadowLayer(blur, 0, 0, AMBIENT_SHADOW_ALPHA << 24);
+ canvas.drawPath(aid.getIconMask(), paint);
+
+ // Draw key shadow
+ canvas.translate(0, keyShadowDistance);
+ paint.setShadowLayer(blur, 0, 0, KEY_SHADOW_ALPHA << 24);
+ canvas.drawPath(aid.getIconMask(), paint);
+
+ // Draw original drawable
+ aid.draw(canvas);
+
+ canvas.setBitmap(null);
+ return shadow;
+ }
+ return null;
}
private void presentFileErrors(Bundle icicle, final Intent intent) {