Configure an App to Enable Drag and Drop in Multi-Window
configure an app to enable drag and drop in multi-window objective learn how to implement drag and drop on a note-taking app when in multi-window mode overview in galaxy fold and it's latest versions, the advantage of its larger display is to split its screen and simultaneously use up to three apps in multi-window mode, you can split the screen with one window being the main focus, and the other two windows off to the side all three windows are active, not just the largest one you can multitask in either landscape or portrait mode, giving you even more flexibility when using multi-window, drag & drop is one of the useful features when multitasking drag and drop allows you to easily move data from one app to another to provide users with better multitasking experience on samsung's foldable devices, developers need to optimize their apps to work on multi-window mode set up your environment you will need the following java se development kit jdk 8 or later android studio latest version recommended samsung galaxy fold, z fold2, z fold3, or newer remote test lab if physical device is not available requirements samsung account java runtime environment jre 7 or later with java web start internet environment where port 2600 is available sample code here is a sample code for you to start coding in this code lab download it and start your learning experience! multi-window drag & drop sample code 19 27 mb start your project open android studio and click open an existing project locate the downloaded android project simplenotes_dragdrop from the directory and click ok make the app resizable to ensure that the app works in multi-window mode, you need to add an attribute in the manifest’s <activity> element if you set android resizeableactivity to true, the activity can be launched in multi-window or in pop-up view, and adapt different screen size android resizeableactivity= "true" noteif this attribute is set to true, the activity can be launched in split-screen and freeform modes otherwise, it will disable multi-window display remember to handle the changes required to fit your ux in small windows when in multi-window mode for this code lab, you do not need to worry about the ux as it is already handled register a drag event listener in newnote kt, register a drag event listener object by calling setondraglistener for both title and description view of the app title setondraglistener ondraglistener desc setondraglistener ondraglistenerdescription store the action type to a variable declare a variable to store the action type for the incoming event val action int = event getaction get and drop the text data inside the dragevent action_drop, get the item from clipdata and check the mime type if the mime type is set to text/plain, get the text value from the item object and allow the operation of drop otherwise, simply show a toast message val item item = event getclipdata getitemat 0 var mtype = event clipdescription getmimetype 0 if mtype == "text/plain" || mtype== "text/html" { // gets the text data from the item dragdata = item text tostring }else{ toast maketext applicationcontext,"operation not allowed"+mtype,toast length_long show return@ondraglistener true } tipin this code lab, to simplify the demonstration of implementing drag and drop, mime type or media type is set to plain text only run the app after building the apk, you can run the optimized note-taking app and start dragging and dropping texts between apps in multi-window mode if you don’t have any physical device, you can also test it on a remote test lab device notewatch this tutorial video and know how to easily test your app via remote test lab you're done! congratulations! you have successfully achieved the goal of this code lab now, you can implement drag and drop in your app for your foldable device by yourself! if you're having trouble, you may download this file multi-window drag & drop complete code 19 33 mb to learn more about developing apps for galaxy foldable devices, visit www developer samsung com/galaxy-z