18

I am trying to develop custom launcher app (with unlimited number of home pages)and i need to implement Drag and Drop as done in Launcher2(android 4.2).

So i found two approaches

1) Drag and Drop framework
2) Use the android launcher2 way like implementation DragController, DragSource as explained here.

But i am struggling to understand why didn't Android guys didn't use the Drag and Drop framework developed by them in their own application. Can anyone brief regarding possible rationale behind their approach?( i mean in terms of memory/performance)

Thanks in advance.

manjusg
  • 2,275
  • 1
  • 22
  • 31

5 Answers5

3

The Android drag and drop framework is very basic as compared to the one used in the Launcher app.

The Launcher app has a myriad of "layers" and the drag and drop occurs accross these layers, namely the DragLayer, Workspace and the All Apps view etc. It uses window flags and dynamically adds/removes views to the DragLayer when a drag is in progress and a multitude of activities monitor the drag. For more details look at the DragLayer.java and Workspace.java files particularly.

Jignesh Shah
  • 599
  • 1
  • 5
  • 13
  • can you please explain more the mechanism of myriad of "layers", i have asked a question here: http://stackoverflow.com/questions/29410875/drag-and-drop-icons-to-home-screen – Mounir Elfassi Apr 15 '15 at 12:21
  • to be precise,i need to add apps to home screen (workspace) just like launcher3 – Mounir Elfassi Apr 15 '15 at 12:27
2

Drag and Drop in Android Launcher is done as Overlay drawing within the same ViewGroup and in same window . But android drag and drop approach creates a separate window with a separate window type altogether .

Resource and memory wise standard android drag and drop approach is costlier.

If performance is very critical my suggestion is go as per Android launcher way else prefer standard android approach its easy and simple.

manjusg
  • 2,275
  • 1
  • 22
  • 31
  • Can you please explain more "Overlay drawing within the same ViewGroup and in same window", here i'm asking a pretty similar question: http://stackoverflow.com/questions/29410875/drag-and-drop-icons-to-home-screen – Mounir Elfassi Apr 21 '15 at 10:50
  • Checkout dispatchDraw method in the ViewGroup.java. In your Layout just override the method dispatchdraw and draw your view bitmap after calling super.dispatchdraw(). This will render your bitmap on top. If you change the bitmap drawing positions according to user touch positions you will see Drag effect. – manjusg Apr 22 '15 at 13:21
0

Drag and Drop framework is sice api 11. My guess is, lot of code for launcher was written before that, and noone had time to refactor it yet. But api works similar like second approach.

snapix
  • 344
  • 2
  • 8
0

http://javapapers.com/android/android-drag-and-drop/. This is the best drag and drop example since i have implemented the same in my application. Note: It will support versions only above 11. The drag and drop feature will not support for version 10. Instead u have to move the fields in a absolute layout by settin X and Y positons. But Absolute layout is completely deprecated...

0

You should use WindowManaager to control Drag And Drop if in case your Application is not so much complex. This is easy to implement and work on Position changed. get the code Here

Suresh Sharma
  • 1,826
  • 22
  • 41