diff --git a/app/src/main/java/com/tangem/tap/MainActivity.kt b/app/src/main/java/com/tangem/tap/MainActivity.kt index 89360fb5fd..c85354972d 100644 --- a/app/src/main/java/com/tangem/tap/MainActivity.kt +++ b/app/src/main/java/com/tangem/tap/MainActivity.kt @@ -216,6 +216,7 @@ class MainActivity : AppCompatActivity(), ActivityResultCallbackHolder { if (BuildConfig.TESTER_MENU_ENABLED) { lifecycle.addObserver(testerMenuLauncher.launchOnKeyEventObserver) + testerMenuLauncher.registerTesterMenuShortcut() } if (intent != null) { diff --git a/features/tester/api/src/main/java/com/tangem/features/tester/api/TesterMenuLauncher.kt b/features/tester/api/src/main/java/com/tangem/features/tester/api/TesterMenuLauncher.kt index b16f8b366d..b0602fce38 100644 --- a/features/tester/api/src/main/java/com/tangem/features/tester/api/TesterMenuLauncher.kt +++ b/features/tester/api/src/main/java/com/tangem/features/tester/api/TesterMenuLauncher.kt @@ -12,4 +12,10 @@ interface TesterMenuLauncher { * Implementations should handle key events and return true if the event was consumed. */ val launchOnKeyEventObserver: KeyEventObserver + + /** + * Registers an app launcher shortcut (shown on long tap of the app icon) that opens the tester menu. + * Must be called only for builds where the tester menu is available. + */ + fun registerTesterMenuShortcut() } \ No newline at end of file diff --git a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/navigation/DefaultTesterMenuLauncher.kt b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/navigation/DefaultTesterMenuLauncher.kt index 1c1fc90ee1..f5cbf78f8b 100644 --- a/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/navigation/DefaultTesterMenuLauncher.kt +++ b/features/tester/impl/src/main/java/com/tangem/feature/tester/presentation/navigation/DefaultTesterMenuLauncher.kt @@ -1,15 +1,44 @@ package com.tangem.feature.tester.presentation.navigation import android.content.Context +import android.content.Intent +import androidx.core.content.pm.ShortcutInfoCompat +import androidx.core.content.pm.ShortcutManagerCompat +import androidx.core.graphics.drawable.IconCompat +import com.tangem.feature.tester.impl.R +import com.tangem.feature.tester.presentation.TesterActivity import com.tangem.features.tester.api.TesterMenuLauncher /** * Default implementation of [TesterMenuLauncher] that listens for double-press events * of the volume down button. When a double press is detected, it opens the tester menu. + * Also publishes an app launcher shortcut (long tap on the app icon) that opens the tester menu. * - * @param context the application context used to launch the tester menu + * @param context the context used to launch the tester menu */ internal class DefaultTesterMenuLauncher(private val context: Context) : TesterMenuLauncher { override val launchOnKeyEventObserver = VolumeButtonDoublePressObserver(context) + + override fun registerTesterMenuShortcut() { + // An action is mandatory for a shortcut intent (ShortcutInfoCompat requires it), unlike the + // volume-button launch path which starts TesterActivity by explicit component only. + val intent = Intent(context, TesterActivity::class.java) + .setAction(Intent.ACTION_VIEW) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + + val label = context.getString(R.string.tester_menu) + val shortcut = ShortcutInfoCompat.Builder(context, SHORTCUT_ID) + .setShortLabel(label) + .setLongLabel(label) + .setIcon(IconCompat.createWithResource(context, com.tangem.core.ui.R.drawable.ic_gear_24)) + .setIntent(intent) + .build() + + ShortcutManagerCompat.pushDynamicShortcut(context, shortcut) + } + + private companion object { + const val SHORTCUT_ID = "tester_menu" + } } \ No newline at end of file