Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 12744cca authored by Marcello Galhardo's avatar Marcello Galhardo Committed by Automerger Merge Worker
Browse files

Merge "Use notes role app icon as a shortcut badge" into udc-dev am: a9eab435

parents 740be1a1 a9eab435
Loading
Loading
Loading
Loading
+25 −1
Original line number Original line Diff line number Diff line
@@ -17,8 +17,10 @@
package com.android.systemui.notetask.shortcut
package com.android.systemui.notetask.shortcut


import android.app.Activity
import android.app.Activity
import android.app.role.RoleManager
import android.content.Intent
import android.content.Intent
import android.os.Bundle
import android.os.Bundle
import android.os.PersistableBundle
import androidx.activity.ComponentActivity
import androidx.activity.ComponentActivity
import androidx.annotation.DrawableRes
import androidx.annotation.DrawableRes
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutInfoCompat
@@ -36,7 +38,11 @@ import javax.inject.Inject
 *   href="https://developer.android.com/develop/ui/views/launch/shortcuts/creating-shortcuts#custom-pinned">Creating
 *   href="https://developer.android.com/develop/ui/views/launch/shortcuts/creating-shortcuts#custom-pinned">Creating
 *   a custom shortcut activity</a>
 *   a custom shortcut activity</a>
 */
 */
class CreateNoteTaskShortcutActivity @Inject constructor() : ComponentActivity() {
class CreateNoteTaskShortcutActivity
@Inject
constructor(
    private val roleManager: RoleManager,
) : ComponentActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        super.onCreate(savedInstanceState)
@@ -59,12 +65,19 @@ class CreateNoteTaskShortcutActivity @Inject constructor() : ComponentActivity()
        intent: Intent,
        intent: Intent,
        @DrawableRes iconResource: Int,
        @DrawableRes iconResource: Int,
    ): Intent {
    ): Intent {
        val extras = PersistableBundle()

        roleManager.getRoleHoldersAsUser(RoleManager.ROLE_NOTES, user).firstOrNull()?.let { name ->
            extras.putString(EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE, name)
        }

        val shortcutInfo =
        val shortcutInfo =
            ShortcutInfoCompat.Builder(this, id)
            ShortcutInfoCompat.Builder(this, id)
                .setIntent(intent)
                .setIntent(intent)
                .setShortLabel(shortLabel)
                .setShortLabel(shortLabel)
                .setLongLived(true)
                .setLongLived(true)
                .setIcon(IconCompat.createWithResource(this, iconResource))
                .setIcon(IconCompat.createWithResource(this, iconResource))
                .setExtras(extras)
                .build()
                .build()


        return ShortcutManagerCompat.createShortcutResultIntent(
        return ShortcutManagerCompat.createShortcutResultIntent(
@@ -75,5 +88,16 @@ class CreateNoteTaskShortcutActivity @Inject constructor() : ComponentActivity()


    private companion object {
    private companion object {
        private const val SHORTCUT_ID = "note-task-shortcut-id"
        private const val SHORTCUT_ID = "note-task-shortcut-id"

        /**
         * Shortcut extra which can point to a package name and can be used to indicate an alternate
         * badge info. Launcher only reads this if the shortcut comes from a system app.
         *
         * Duplicated from [com.android.launcher3.icons.IconCache].
         *
         * @see com.android.launcher3.icons.IconCache.EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE
         */
        private const val EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE =
            "extra_shortcut_badge_override_package"
    }
    }
}
}