mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-02-19 21:08:28 +00:00
parent
b7799b53d9
commit
e9b76b6aa5
@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ShortcutInfo
|
||||
import android.content.pm.ShortcutManager
|
||||
import android.graphics.drawable.Icon
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.getSystemService
|
||||
@ -13,6 +14,7 @@ import androidx.core.graphics.drawable.IconCompat
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.core.Const
|
||||
import com.topjohnwu.magisk.core.Info
|
||||
import com.topjohnwu.magisk.core.isRunningAsStub
|
||||
import com.topjohnwu.magisk.core.ktx.getBitmap
|
||||
|
||||
object Shortcuts {
|
||||
@ -29,20 +31,22 @@ object Shortcuts {
|
||||
val info = ShortcutInfoCompat.Builder(context, Const.Nav.HOME)
|
||||
.setShortLabel(context.getString(R.string.magisk))
|
||||
.setIntent(intent)
|
||||
.setIcon(context.getIconCompat(R.drawable.ic_launcher))
|
||||
.setIcon(IconCompat.createFromIcon(context, context.getIcon(R.drawable.ic_launcher)))
|
||||
.build()
|
||||
ShortcutManagerCompat.requestPinShortcut(context, info, null)
|
||||
}
|
||||
|
||||
private fun Context.getIconCompat(id: Int): IconCompat {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
IconCompat.createWithAdaptiveBitmap(getBitmap(id))
|
||||
else
|
||||
IconCompat.createWithBitmap(getBitmap(id))
|
||||
private fun Context.getIcon(id: Int): Icon {
|
||||
return if (isRunningAsStub) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
Icon.createWithAdaptiveBitmap(getBitmap(id))
|
||||
else
|
||||
Icon.createWithBitmap(getBitmap(id))
|
||||
} else {
|
||||
Icon.createWithResource(this, id)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Context.getIcon(id: Int) = getIconCompat(id).toIcon(this)
|
||||
|
||||
@RequiresApi(api = 25)
|
||||
private fun getShortCuts(context: Context): List<ShortcutInfo> {
|
||||
val intent = context.packageManager.getLaunchIntentForPackage(context.packageName)
|
||||
|
@ -2,4 +2,5 @@
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@drawable/ic_magisk_padded" />
|
||||
</adaptive-icon>
|
||||
<monochrome android:drawable="@drawable/ic_magisk_padded" />
|
||||
</adaptive-icon>
|
||||
|
@ -6,4 +6,9 @@
|
||||
android:drawable="@drawable/ic_extension"
|
||||
android:inset="30%" />
|
||||
</foreground>
|
||||
</adaptive-icon>
|
||||
<monochrome>
|
||||
<inset
|
||||
android:drawable="@drawable/ic_extension"
|
||||
android:inset="30%" />
|
||||
</monochrome>
|
||||
</adaptive-icon>
|
||||
|
@ -6,4 +6,9 @@
|
||||
android:drawable="@drawable/ic_superuser"
|
||||
android:inset="30%" />
|
||||
</foreground>
|
||||
</adaptive-icon>
|
||||
<monochrome>
|
||||
<inset
|
||||
android:drawable="@drawable/ic_superuser"
|
||||
android:inset="30%" />
|
||||
</monochrome>
|
||||
</adaptive-icon>
|
||||
|
Loading…
x
Reference in New Issue
Block a user