Change launcher and shortcut icons to MaskableIconDrawable

Test: manual test on Launcher3
Bug: 33034275
Bug: 35431198

Change-Id: Ief9f49ec38ec95daa738799398fc4b458d634acc
This commit is contained in:
Hyunyoung Song
2017-02-14 10:40:58 -08:00
parent b4d6b4f7f8
commit 1f093dd94c
14 changed files with 116 additions and 52 deletions

View File

@@ -83,7 +83,7 @@
<uses-permission android:name="android.permission.DELETE_PACKAGES"/> <uses-permission android:name="android.permission.DELETE_PACKAGES"/>
<application android:label="@string/settings_label" <application android:label="@string/settings_label"
android:icon="@mipmap/ic_launcher_settings" android:icon="@drawable/ic_launcher_settings"
android:taskAffinity="" android:taskAffinity=""
android:theme="@style/Theme.Settings" android:theme="@style/Theme.Settings"
android:hardwareAccelerated="true" android:hardwareAccelerated="true"

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<maskable-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="?android:attr/colorAccent"/>
<foreground android:drawable="@mipmap/ic_launcher_settings"/>
</maskable-icon>

View File

@@ -14,17 +14,20 @@
~ See the License for the specific language governing permissions and ~ See the License for the specific language governing permissions and
~ limitations under the License ~ limitations under the License
--> -->
<vector <maskable-icon xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android" <background android:drawable="@color/shortcut_background"/>
android:width="80dp" <foreground>
android:height="80dp" <vector
android:viewportWidth="52.0" android:width="120dp"
android:viewportHeight="52.0" > android:height="120dp"
<path android:viewportWidth="78.0"
android:fillColor="#FFF5F5F5" android:viewportHeight="78.0">
android:pathData="M2,26a24,24 0 1,0 48,0a24,24 0 1,0 -48,0"/> <group android:translateX="13.0" android:translateY="13.0">
<path <path
android:fillColor="@*android:color/accent_device_default_light" android:fillColor="@*android:color/accent_device_default_light"
android:pathData="M29.67,18H28v-2h-4v2h-1.67C21.6,18,21,18.6,21,19.33v15.33C21,35.4,21.6,36,22.33,36h7.33 android:pathData="M29.67,18H28v-2h-4v2h-1.67C21.6,18,21,18.6,21,19.33v15.33C21,35.4,21.6,36,22.33,36h7.33
C30.4,36,31,35.4,31,34.67V19.33C31,18.6,30.4,18,29.67,18z"/> C30.4,36,31,35.4,31,34.67V19.33C31,18.6,30.4,18,29.67,18z"/>
</vector> </group>
</vector>
</foreground>
</maskable-icon>

View File

@@ -14,18 +14,21 @@
~ See the License for the specific language governing permissions and ~ See the License for the specific language governing permissions and
~ limitations under the License ~ limitations under the License
--> -->
<vector <maskable-icon xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android" <background android:drawable="@color/shortcut_background"/>
android:width="80dp" <foreground>
android:height="80dp" <vector
android:viewportWidth="52.0" android:width="120dp"
android:viewportHeight="52.0" > android:height="120dp"
<path android:viewportWidth="78.0"
android:fillColor="#FFF5F5F5" android:viewportHeight="78.0">
android:pathData="M2,26a24,24 0 1,0 48,0a24,24 0 1,0 -48,0"/> <group android:translateX="13.0" android:translateY="13.0">
<path <path
android:fillColor="@*android:color/accent_device_default_light" android:fillColor="@*android:color/accent_device_default_light"
android:pathData="M27,16.05v3.03c3.39,0.49,6,3.39,6,6.92c0,0.9-0.18,1.75-0.48,2.54l2.6,1.53C35.68,28.83,36,27.45,36,26 android:pathData="M27,16.05v3.03c3.39,0.49,6,3.39,6,6.92c0,0.9-0.18,1.75-0.48,2.54l2.6,1.53C35.68,28.83,36,27.45,36,26
C36,20.82,32.05,16.55,27,16.05z M26,33c-3.87,0-7-3.13-7-7c0-3.53,2.61-6.43,6-6.92v-3.03c-5.06,0.5-9,4.76-9,9.95 C36,20.82,32.05,16.55,27,16.05z M26,33c-3.87,0-7-3.13-7-7c0-3.53,2.61-6.43,6-6.92v-3.03c-5.06,0.5-9,4.76-9,9.95
c0,5.52,4.47,10,9.99,10c3.31,0,6.24-1.61,8.06-4.09l-2.6-1.53C30.17,31.98,28.21,33,26,33z"/> c0,5.52,4.47,10,9.99,10c3.31,0,6.24-1.61,8.06-4.09l-2.6-1.53C30.17,31.98,28.21,33,26,33z"/>
</vector> </group>
</vector>
</foreground>
</maskable-icon>

View File

@@ -14,16 +14,19 @@
~ See the License for the specific language governing permissions and ~ See the License for the specific language governing permissions and
~ limitations under the License ~ limitations under the License
--> -->
<vector <maskable-icon xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:android="http://schemas.android.com/apk/res/android" <background android:drawable="@color/shortcut_background"/>
android:width="80dp" <foreground>
android:height="80dp" <vector
android:viewportWidth="52.0" android:width="120dp"
android:viewportHeight="52.0" > android:height="120dp"
<path android:viewportWidth="78.0"
android:fillColor="#FFF5F5F5" android:viewportHeight="78.0">
android:pathData="M2,26a24,24 0 1,0 48,0a24,24 0 1,0 -48,0"/> <group android:translateX="13.0" android:translateY="13.0">
<path <path
android:fillColor="@*android:color/accent_device_default_light" android:fillColor="@*android:color/accent_device_default_light"
android:pathData="M26.01,35.49L37.64,21c-0.45-0.34-4.93-4-11.64-4c-6.72,0-11.19,3.66-11.64,4l11.63,14.49L26,35.5L26.01,35.49z"/> android:pathData="M26.01,35.49L37.64,21c-0.45-0.34-4.93-4-11.64-4c-6.72,0-11.19,3.66-11.64,4l11.63,14.49L26,35.5L26.01,35.49z"/>
</vector> </group>
</vector>
</foreground>
</maskable-icon>

View File

@@ -0,0 +1,36 @@
<?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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/shortcut_size_maskable"
android:layout_height="@dimen/shortcut_size_maskable"
android:background="@color/shortcut_background">
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="22"/>
<ImageView
android:id="@android:id/icon"
android:layout_width="0dp"
android:layout_height="match_parent"
android:tint="@color/icon_accent"
android:scaleType="fitCenter"
android:layout_weight="16"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="22"/>
</LinearLayout>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File

@@ -114,4 +114,7 @@
<!-- Color for the background of the donut graph.--> <!-- Color for the background of the donut graph.-->
<color name="donut_background_grey">#ffd7d7d7</color> <color name="donut_background_grey">#ffd7d7d7</color>
<!-- Color for the background of the shortcut icons.-->
<color name="shortcut_background">#fff5f5f5</color>
</resources> </resources>

View File

@@ -245,7 +245,9 @@
<dimen name="mdm_app_name_padding_left">16dp</dimen> <dimen name="mdm_app_name_padding_left">16dp</dimen>
<dimen name="mdm_app_icon_width_height">56dp</dimen> <dimen name="mdm_app_icon_width_height">56dp</dimen>
<dimen name="shortcut_size_maskable">120dp</dimen>
<dimen name="shortcut_size">40dp</dimen> <dimen name="shortcut_size">40dp</dimen>
<dimen name="shortcut_icon_size">16dp</dimen>
<dimen name="badge_size">10dp</dimen> <dimen name="badge_size">10dp</dimen>
<!-- Admin support contact details dialog. --> <!-- Admin support contact details dialog. -->

View File

@@ -29,6 +29,7 @@ import android.graphics.Bitmap;
import android.graphics.Bitmap.Config; import android.graphics.Bitmap.Config;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.drawable.Icon; import android.graphics.drawable.Icon;
import android.graphics.drawable.MaskableIconDrawable;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.VisibleForTesting; import android.support.annotation.VisibleForTesting;
@@ -68,19 +69,22 @@ public class CreateShortcut extends LauncherActivity {
protected Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo, protected Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo,
CharSequence label) { CharSequence label) {
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
ShortcutManager sm = getSystemService(ShortcutManager.class);
ActivityInfo activityInfo = resolveInfo.activityInfo; ActivityInfo activityInfo = resolveInfo.activityInfo;
Bitmap icon = activityInfo.icon != 0 ? createIcon(activityInfo.icon) : null;
Icon maskableIcon = activityInfo.icon != 0 ? Icon.createWithMaskableBitmap(
createIcon(activityInfo.icon,
R.layout.shortcut_badge_maskable,
getResources().getDimensionPixelSize(R.dimen.shortcut_size_maskable))) :
Icon.createWithResource(this, R.drawable.ic_launcher_settings);
String shortcutId = SHORTCUT_ID_PREFIX + String shortcutId = SHORTCUT_ID_PREFIX +
shortcutIntent.getComponent().flattenToShortString(); shortcutIntent.getComponent().flattenToShortString();
ShortcutInfo info = new ShortcutInfo.Builder(this, shortcutId) ShortcutInfo info = new ShortcutInfo.Builder(this, shortcutId)
.setShortLabel(label) .setShortLabel(label)
.setIntent(shortcutIntent) .setIntent(shortcutIntent)
.setIcon(icon != null ? Icon.createWithBitmap(icon) : .setIcon(maskableIcon)
Icon.createWithResource(this, R.mipmap.ic_launcher_settings))
.build(); .build();
Intent intent = getSystemService(ShortcutManager.class).createShortcutResultIntent(info); Intent intent = sm.createShortcutResultIntent(info);
if (intent == null) { if (intent == null) {
intent = new Intent(); intent = new Intent();
} }
@@ -88,7 +92,12 @@ public class CreateShortcut extends LauncherActivity {
Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_settings)); Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_settings));
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
if (activityInfo.icon != 0) {
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, createIcon(activityInfo.icon,
R.layout.shortcut_badge,
getResources().getDimensionPixelSize(R.dimen.shortcut_size)));
}
return intent; return intent;
} }
@@ -101,12 +110,12 @@ public class CreateShortcut extends LauncherActivity {
info.activityInfo.name); info.activityInfo.name);
} }
private Bitmap createIcon(int resource) { private Bitmap createIcon(int resource, int layoutRes, int size) {
Context context = new ContextThemeWrapper(this, android.R.style.Theme_Material); Context context = new ContextThemeWrapper(this, android.R.style.Theme_Material);
View view = LayoutInflater.from(context).inflate(R.layout.shortcut_badge, null); View view = LayoutInflater.from(context).inflate(layoutRes, null);
((ImageView) view.findViewById(android.R.id.icon)).setImageResource(resource); ((ImageView) view.findViewById(android.R.id.icon)).setImageResource(resource);
int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); int spec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY);
view.measure(spec, spec); view.measure(spec, spec);
Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(),
Config.ARGB_8888); Config.ARGB_8888);