3

Simplifying drag and drop

 2 years ago
source link: https://medium.com/androiddevelopers/simplifying-drag-and-drop-3713d6ef526e
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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.

A simple drag & drop sample.

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.

1*i2-hwIJhdhP0rfsXvIhJ4A.gif?q=20
simplifying-drag-and-drop-3713d6ef526e
Dragging from one app into another.

DropHelper, in combination with DragStartHelper, makes it much easier to take care of gesture support, callbacks, styling and pixel-perfect alignment.

DragStartHelper

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

The new 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.

Learn more

Read more in the Drag and drop guide on Android Developers, dive into the large screen sample to see DropHelper in practice and then try it out in alpha now to give us feedback.

Thanks to Florina,Ben and Nick!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK