diff options
| author | 2023-09-14 21:16:07 -0400 | |
|---|---|---|
| committer | 2023-09-14 22:19:08 -0400 | |
| commit | 6481f4e9371c9cd45878d06f8b9471883d81fd90 (patch) | |
| tree | 983c5a2cdcfc7fe9e4ea11049fad18604d17de04 /src | |
| parent | Merge pull request #11503 from t895/stateflow-patch (diff) | |
| download | yuzu-6481f4e9371c9cd45878d06f8b9471883d81fd90.tar.gz yuzu-6481f4e9371c9cd45878d06f8b9471883d81fd90.tar.xz yuzu-6481f4e9371c9cd45878d06f8b9471883d81fd90.zip | |
android: Use resource as shortcut intermediary
Fixes issue where the shortcut icon would appear cropped on certain devices
Diffstat (limited to 'src')
4 files changed, 43 insertions, 3 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt index 0013e8512..f9f88a1d2 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/adapters/GameAdapter.kt | |||
| @@ -4,7 +4,8 @@ | |||
| 4 | package org.yuzu.yuzu_emu.adapters | 4 | package org.yuzu.yuzu_emu.adapters |
| 5 | 5 | ||
| 6 | import android.content.Intent | 6 | import android.content.Intent |
| 7 | import android.graphics.drawable.BitmapDrawable | 7 | import android.graphics.Bitmap |
| 8 | import android.graphics.drawable.LayerDrawable | ||
| 8 | import android.net.Uri | 9 | import android.net.Uri |
| 9 | import android.text.TextUtils | 10 | import android.text.TextUtils |
| 10 | import android.view.LayoutInflater | 11 | import android.view.LayoutInflater |
| @@ -15,7 +16,10 @@ import android.widget.Toast | |||
| 15 | import androidx.appcompat.app.AppCompatActivity | 16 | import androidx.appcompat.app.AppCompatActivity |
| 16 | import androidx.core.content.pm.ShortcutInfoCompat | 17 | import androidx.core.content.pm.ShortcutInfoCompat |
| 17 | import androidx.core.content.pm.ShortcutManagerCompat | 18 | import androidx.core.content.pm.ShortcutManagerCompat |
| 19 | import androidx.core.content.res.ResourcesCompat | ||
| 18 | import androidx.core.graphics.drawable.IconCompat | 20 | import androidx.core.graphics.drawable.IconCompat |
| 21 | import androidx.core.graphics.drawable.toBitmap | ||
| 22 | import androidx.core.graphics.drawable.toDrawable | ||
| 19 | import androidx.documentfile.provider.DocumentFile | 23 | import androidx.documentfile.provider.DocumentFile |
| 20 | import androidx.lifecycle.ViewModelProvider | 24 | import androidx.lifecycle.ViewModelProvider |
| 21 | import androidx.navigation.findNavController | 25 | import androidx.navigation.findNavController |
| @@ -87,11 +91,24 @@ class GameAdapter(private val activity: AppCompatActivity) : | |||
| 87 | action = Intent.ACTION_VIEW | 91 | action = Intent.ACTION_VIEW |
| 88 | data = Uri.parse(holder.game.path) | 92 | data = Uri.parse(holder.game.path) |
| 89 | } | 93 | } |
| 94 | |||
| 95 | val layerDrawable = ResourcesCompat.getDrawable( | ||
| 96 | YuzuApplication.appContext.resources, | ||
| 97 | R.drawable.shortcut, | ||
| 98 | null | ||
| 99 | ) as LayerDrawable | ||
| 100 | layerDrawable.setDrawableByLayerId( | ||
| 101 | R.id.shortcut_foreground, | ||
| 102 | GameIconUtils.getGameIcon(holder.game).toDrawable(YuzuApplication.appContext.resources) | ||
| 103 | ) | ||
| 104 | val inset = YuzuApplication.appContext.resources | ||
| 105 | .getDimensionPixelSize(R.dimen.icon_inset) | ||
| 106 | layerDrawable.setLayerInset(1, inset, inset, inset, inset) | ||
| 90 | val shortcut = ShortcutInfoCompat.Builder(YuzuApplication.appContext, holder.game.path) | 107 | val shortcut = ShortcutInfoCompat.Builder(YuzuApplication.appContext, holder.game.path) |
| 91 | .setShortLabel(holder.game.title) | 108 | .setShortLabel(holder.game.title) |
| 92 | .setIcon( | 109 | .setIcon( |
| 93 | IconCompat.createWithBitmap( | 110 | IconCompat.createWithAdaptiveBitmap( |
| 94 | (holder.binding.imageGameScreen.drawable as BitmapDrawable).bitmap | 111 | layerDrawable.toBitmap(config = Bitmap.Config.ARGB_8888) |
| 95 | ) | 112 | ) |
| 96 | ) | 113 | ) |
| 97 | .setIntent(openIntent) | 114 | .setIntent(openIntent) |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameIconUtils.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameIconUtils.kt index c0fe596d7..9fe99fab1 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameIconUtils.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/GameIconUtils.kt | |||
| @@ -6,9 +6,11 @@ package org.yuzu.yuzu_emu.utils | |||
| 6 | import android.graphics.Bitmap | 6 | import android.graphics.Bitmap |
| 7 | import android.graphics.BitmapFactory | 7 | import android.graphics.BitmapFactory |
| 8 | import android.widget.ImageView | 8 | import android.widget.ImageView |
| 9 | import androidx.core.graphics.drawable.toBitmap | ||
| 9 | import androidx.core.graphics.drawable.toDrawable | 10 | import androidx.core.graphics.drawable.toDrawable |
| 10 | import coil.ImageLoader | 11 | import coil.ImageLoader |
| 11 | import coil.decode.DataSource | 12 | import coil.decode.DataSource |
| 13 | import coil.executeBlocking | ||
| 12 | import coil.fetch.DrawableResult | 14 | import coil.fetch.DrawableResult |
| 13 | import coil.fetch.FetchResult | 15 | import coil.fetch.FetchResult |
| 14 | import coil.fetch.Fetcher | 16 | import coil.fetch.Fetcher |
| @@ -74,4 +76,13 @@ object GameIconUtils { | |||
| 74 | .build() | 76 | .build() |
| 75 | imageLoader.enqueue(request) | 77 | imageLoader.enqueue(request) |
| 76 | } | 78 | } |
| 79 | |||
| 80 | fun getGameIcon(game: Game): Bitmap { | ||
| 81 | val request = ImageRequest.Builder(YuzuApplication.appContext) | ||
| 82 | .data(game) | ||
| 83 | .error(R.drawable.default_icon) | ||
| 84 | .build() | ||
| 85 | return imageLoader.executeBlocking(request) | ||
| 86 | .drawable!!.toBitmap(config = Bitmap.Config.ARGB_8888) | ||
| 87 | } | ||
| 77 | } | 88 | } |
diff --git a/src/android/app/src/main/res/drawable/shortcut.xml b/src/android/app/src/main/res/drawable/shortcut.xml new file mode 100644 index 000000000..c749e5d72 --- /dev/null +++ b/src/android/app/src/main/res/drawable/shortcut.xml | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| 3 | |||
| 4 | <item> | ||
| 5 | <color android:color="@android:color/white" /> | ||
| 6 | </item> | ||
| 7 | <item android:id="@+id/shortcut_foreground"> | ||
| 8 | <bitmap android:src="@drawable/default_icon" /> | ||
| 9 | </item> | ||
| 10 | |||
| 11 | </layer-list> | ||
diff --git a/src/android/app/src/main/res/values/dimens.xml b/src/android/app/src/main/res/values/dimens.xml index 00757e5e8..7b2296d95 100644 --- a/src/android/app/src/main/res/values/dimens.xml +++ b/src/android/app/src/main/res/values/dimens.xml | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | <dimen name="spacing_refresh_end">72dp</dimen> | 12 | <dimen name="spacing_refresh_end">72dp</dimen> |
| 13 | <dimen name="menu_width">256dp</dimen> | 13 | <dimen name="menu_width">256dp</dimen> |
| 14 | <dimen name="card_width">165dp</dimen> | 14 | <dimen name="card_width">165dp</dimen> |
| 15 | <dimen name="icon_inset">24dp</dimen> | ||
| 15 | 16 | ||
| 16 | <dimen name="dialog_margin">20dp</dimen> | 17 | <dimen name="dialog_margin">20dp</dimen> |
| 17 | <dimen name="elevated_app_bar">3dp</dimen> | 18 | <dimen name="elevated_app_bar">3dp</dimen> |