news

Snippet to show a text box that, when long-pressed, allows Chrome to be dropped into a split-screen.

// Inspired by Launcher3:
// https://cs.android.com/android/platform/superproject/+/35157974d49e70f03687edb9408e5897d04ff845:packages/apps/Launcher3/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java;l=293

// Jetpack Compose view with interoperability:
// https://developer.android.com/jetpack/compose/interop/interop-apis
AndroidView(factory = { context ->
    TextView(context).apply {
        text = "Drag me!"

        // Drag and drop listener; see:
        // https://developer.android.com/develop/ui/views/touch-and-input/drag-drop#StartDrag
        setOnLongClickListener { v ->
            // Intent source:
            // https://cs.android.com/android/platform/superproject/+/35157974d49e70f03687edb9408e5897d04ff845:frameworks/base/services/core/java/com/android/server/pm/LauncherAppsService.java;l=1224;drc=a673c2e9218d29c87af12b123b53c26d0e444315;bpv=1;bpt=1
            val intent = Intent().apply {
                val launchIntent = Intent(Intent.ACTION_MAIN).apply {
                    component = ComponentName("com.android.chrome", "com.google.android.apps.chrome.Main")
                    addCategory(Intent.CATEGORY_LAUNCHER)
                    addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
                }
                // Not yet visible in SDK; source:
                // https://cs.android.com/android/platform/superproject/+/35157974d49e70f03687edb9408e5897d04ff845:frameworks/base/core/java/android/content/ClipDescription.java;drc=a673c2e9218d29c87af12b123b53c26d0e444315;l=116
                putExtra(
                    "android.intent.extra.PENDING_INTENT",
                    PendingIntent.getActivity(
                        this@MainActivity,
                        0,
                        launchIntent,
                        PendingIntent.FLAG_MUTABLE,
                    )
                )
                putExtra(Intent.EXTRA_USER, android.os.Process.myUserHandle())
            }
            val clipDescription = ClipDescription(
                "Chrome",
                // Not yet visible in SDK; source:
                // https://cs.android.com/android/platform/superproject/+/35157974d49e70f03687edb9408e5897d04ff845:frameworks/base/core/java/android/content/ClipDescription.java;drc=a673c2e9218d29c87af12b123b53c26d0e444315;l=82
                arrayOf("application/vnd.android.activity"),
            )
            val clipData = ClipData(clipDescription, ClipData.Item(intent))

            v.startDragAndDrop(
                clipData,
                MyDragShadowBuilder(this),
                null,
                // Without these flags, nothing happens:
                // https://cs.android.com/android/platform/superproject/+/35157974d49e70f03687edb9408e5897d04ff845:packages/apps/Launcher3/quickstep/src/com/android/launcher3/taskbar/TaskbarDragController.java;l=371
                View.DRAG_FLAG_GLOBAL or View.DRAG_FLAG_OPAQUE,
            )

            true
        }
    }
})

Related posts

Sharon Osborne hospitalizada para emergência médica não revelada

admin

নেইমার ছাড়াও এগিয়ে থাকবে ব্রাজিল

admin

‘Scream VI’ Teaser: Ghostface Takes Manhattan

admin

Leave a Comment