Add adaptive icon for shortcut
This commit is contained in:
parent
ddf00ab488
commit
a2dc826a82
5 changed files with 79 additions and 4 deletions
|
|
@ -3,9 +3,14 @@ package com.kabouzeid.gramophone.appshortcuts;
|
|||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.AdaptiveIconDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.graphics.drawable.ScaleDrawable;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.graphics.drawable.shapes.RectShape;
|
||||
import android.graphics.drawable.shapes.Shape;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.util.TypedValue;
|
||||
|
|
@ -53,11 +58,16 @@ public final class AppShortcutIconGenerator {
|
|||
Drawable vectorDrawable = Util.getTintedVectorDrawable(context, iconId, foregroundColor);
|
||||
Drawable backgroundDrawable = Util.getTintedVectorDrawable(context, R.drawable.ic_app_shortcut_background, backgroundColor);
|
||||
|
||||
// Squash the two drawables together
|
||||
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{backgroundDrawable, vectorDrawable});
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
|
||||
AdaptiveIconDrawable adaptiveIconDrawable = new AdaptiveIconDrawable(backgroundDrawable, vectorDrawable);
|
||||
return Icon.createWithAdaptiveBitmap(drawableToBitmap(adaptiveIconDrawable));
|
||||
} else {
|
||||
// Squash the two drawables together
|
||||
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{backgroundDrawable, vectorDrawable});
|
||||
|
||||
// Return as an Icon
|
||||
return Icon.createWithBitmap(drawableToBitmap(layerDrawable));
|
||||
// Return as an Icon
|
||||
return Icon.createWithBitmap(drawableToBitmap(layerDrawable));
|
||||
}
|
||||
}
|
||||
|
||||
private static Bitmap drawableToBitmap(Drawable drawable) {
|
||||
|
|
|
|||
11
app/src/main/res/drawable-v26/ic_app_shortcut_background.xml
Normal file
11
app/src/main/res/drawable-v26/ic_app_shortcut_background.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:name="ic_app_shortcut_background"
|
||||
android:fillColor="#000"
|
||||
android:pathData="M0,0 108,0 108,108 0,108" />
|
||||
</vector>
|
||||
18
app/src/main/res/drawable-v26/ic_app_shortcut_last_added.xml
Normal file
18
app/src/main/res/drawable-v26/ic_app_shortcut_last_added.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="176"
|
||||
android:viewportWidth="176">
|
||||
|
||||
<group
|
||||
android:scaleX="0.45"
|
||||
android:scaleY="0.45"
|
||||
android:translateX="45"
|
||||
android:translateY="45">
|
||||
<path
|
||||
android:name="ic_app_shortcut_last_added_ic"
|
||||
android:fillColor="#000"
|
||||
android:pathData="M124.35,92h-16.2v16.2h-8.1V92H83.85v-8.1h16.2V67.65h8.1v16.2h16.2M128.4,55.5H79.8a8.1,8.1,0,0,0-8.1,8.1v48.6a8.1,8.1,0,0,0,8.1,8.1h48.6a8.1,8.1,0,0,0,8.1-8.1V63.6a8.1,8.1,0,0,0-8.1-8.1M63.6,71.7H55.5v56.7a8.1,8.1,0,0,0,8.1,8.1h56.7v-8.1H63.6Z" />
|
||||
</group>
|
||||
</vector>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="176"
|
||||
android:viewportWidth="176">
|
||||
|
||||
<group
|
||||
android:scaleX="0.45"
|
||||
android:scaleY="0.45"
|
||||
android:translateX="45"
|
||||
android:translateY="45">
|
||||
<path
|
||||
android:name="ic_app_shortcut_shuffle_ic"
|
||||
android:fillColor="#000"
|
||||
android:pathData="M110.15,103l-7,7,15.65,15.65L108.5,136H136V108.5l-10.2,10.2L110.15,103M108.5,56l10.2,10.2L56,128.95l7,7L125.8,73.3,136,83.5V56M89,81.85,63.05,56l-7,7L81.85,88.9Z" />
|
||||
</group>
|
||||
</vector>
|
||||
18
app/src/main/res/drawable-v26/ic_app_shortcut_top_tracks.xml
Normal file
18
app/src/main/res/drawable-v26/ic_app_shortcut_top_tracks.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="176"
|
||||
android:viewportWidth="176">
|
||||
|
||||
<group
|
||||
android:scaleX="0.45"
|
||||
android:scaleY="0.45"
|
||||
android:translateX="45"
|
||||
android:translateY="45">
|
||||
<path
|
||||
android:name="ic_app_shortcut_top_tracks_ic"
|
||||
android:fillColor="#000"
|
||||
android:pathData="M113.7,69.45l10.13,10.13-21.59,21.59-17.7-17.7L51.75,116.31,58,122.55,84.54,96l17.7,17.7,27.88-27.83L140.25,96V69.45Z" />
|
||||
</group>
|
||||
</vector>
|
||||
Loading…
Add table
Add a link
Reference in a new issue