Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drag and Drop icons to Home Screen

Update: to understand my question, here is what i need to achieve: Drag icon from App drawer to home screen (if possible not in a gridview) like in the pic,

enter image description here

Old (this just to learn how this works):

I'm trying to implement dragging clickable icons from a ListView to a customView with no container(Listview or Gridview...) inside the same Activity or another, here is a picture for you to understand more:

enter image description here

but when i put the icon in the right area i don't see the object, in the log i see: I/ViewRootImpl﹕ Reporting drop result: true

enter image description here

here my code:

class MyDragListener implements View.OnDragListener {
    @Override
    public boolean onDrag(View v, DragEvent event) {
        int action = event.getAction();
        switch (event.getAction()) {
            ...
            case DragEvent.ACTION_DROP:
                LinearLayoutAbsListView itemo = (LinearLayoutAbsListView)findViewById(R.id.paneko);
                View child = getLayoutInflater().inflate(R.layout.list_item, null);
                itemo.addView(child);
                break;
            case DragEvent.ACTION_DRAG_ENDED:
             default:
                break;
        }
        return true;
    }
}

My XML file:

...
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:background="@android:color/background_dark"
    android:orientation="horizontal" >

    <com.moapps.elfassimounir.simple.LinearLayoutAbsListView
        android:id="@+id/paneuj"
        android:background="@android:color/background_light"
        android:orientation="vertical"
        >

        <ListView
            android:id="@+id/listview1"
            android:layout_width="100dp"
            android:layout_height="wrap_content" />
    </com.moapps.elfassimounir.simple.LinearLayoutAbsListView>

    <com.moapps.elfassimounir.simple.LinearLayoutAbsListView
        android:id="@+id/paneko"
        android:background="@android:color/background_light"
        android:orientation="vertical" >

    </com.moapps.elfassimounir.simple.LinearLayoutAbsListView>
</LinearLayout>

 ...

Any infos or references (tutorials, docs...) would be very helpful

like image 767
Mounir Elfassi Avatar asked Apr 02 '15 10:04

Mounir Elfassi


1 Answers

Have a look at adding a view to the WindowManager(WM). When you long press on an item to be dragged, create your own bitmap of that item and add it to the WM, so that it can be moved without view boundary constraints. When you receive a ACTION_UP or an equivalent event, map your current x,y to the actual view that is directly below the dragged item (Rect classs might be helpful). You can then add this item to that particular view.

like image 195
Jignesh Shah Avatar answered Sep 29 '22 09:09

Jignesh Shah