Simplifying drag and drop
At the most basic level, drag and drop is a gesture where a user can tap and hold an image, text string or other data element, then drag it into another app (or to another location in the same app) and release, where the data is incorporated in the new location. This gesture is usually a long press on touch screens or a click and drag when using a mouse.
While Android has long supported drag and drop (
DragEvent was introduced in Android 3.0, API level 11), integrating full support for handling gestures, events, permissions and callbacks has proven to be complex.
Today we’re introducing the Jetpack DragAndDrop library as an alpha release to make it easier for you to handle data dropped into your app.
Drag and drop is becoming increasingly relevant for large screen form factors: tablet and laptops, but especially also foldables, where split screen is used 7 times as often than on conventional phones. The ability to drag data from one app to another is a natural experience for users as they multitask more efficiently with their apps in split-screen or windowed modes.
While dragging text from
EditTexts is supported natively by the platform, we strongly recommend enabling users to drag any images, files or text from other components of your app. Just as importantly, we encourage allowing users to drop data into your apps as well.
DragStartHelper is a utility class in Jetpack core that detects gestures commonly used to start a drag, such as long pressing or click and dragging with a mouse.
DropHelper is a utility class that takes care of listeners and drop targets. Be sure to use
addInnerEditTexts() when building
DropHelper.Options to ensure that any nested
EditTexts inside your drop target don’t acquire focus instead.
user-interface-samples/DragAndDrop at main · android/user-interface-samples
An android application demonstrating basic Drag and Drop functionality using the Jetpack Drag and Drop Library . Allows…