mrKlar / PagedDragDropGrid

An Android ViewGroup that implements a paged grid with drag'n'drop moveable items
406 stars 184 forks source link

Dragging Items in the grid causes graphical artifacts #23

Closed hjkatz closed 11 years ago

hjkatz commented 11 years ago

SOLVED SEE BELOW:


I fixed it. During your longClick method you handle jiggling the itmes and start the dragged and movingView. Then in your touchMove method you handle moving the dragged view (clear animation, start animation) and you manage swapping, edges, and delete. However, this is all fine and dandy (starting animation, stopping animation) until nothing in the parent view ( "this" ) is animating, thus stopping all drawing. So if no redraw is called, you get artifacts. To fix this simple add one line (like most problems =P) to invalidate "this" before handling animation and events. Below is the new touchMove()

private void touchMove( MotionEvent event )
{
    if ( movingView && aViewIsDragged() )
    {
        lastTouchX = (int) event.getX();
        lastTouchY = (int) event.getY();

        invalidate();
        moveDraggedView( lastTouchX, lastTouchY );
        manageSwapPosition( lastTouchX, lastTouchY );
        manageEdgeCoordinates( lastTouchX );
        manageDeleteZoneHover( lastTouchX, lastTouchY );
    }
}

If you'd like I'll make a pull request, add the one line (and the ability to disable the remove bar) and request a merge. Thanks!


When you move an item around, it leaves behind a trial. Here is my xml:

    <ca.laplanete.mobile.pageddragdropgrid.PagedDragDropGrid
            android:id="@+id/gridview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            />

And I have 2 pages, 4 items in each, both pages are 2 x 3 allowing for 6 items max per page.

When you move the items slowly from the top down, or near the edges, you get artifacts. And if you have only 1 item on a page it leaves a ton of trailing artifacts...

lkorth commented 11 years ago

Screenshot?

hjkatz commented 11 years ago

It's company code, let me make another project quickly, thanks for responding :D

hjkatz commented 11 years ago

screenshot_2013-05-02-12-26-31

There is a screenshot, my entire xml is below, I am compiling all code using 4.0.3:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
        >
    <LinearLayout
            android:id="@+id/main2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >
        <include
                android:layout_width="fill_parent"
                android:layout_gravity="center_horizontal"
                android:adjustViewBounds="true"
                layout="@layout/main_titlebar" />
        <ca.laplanete.mobile.pageddragdropgrid.PagedDragDropGrid
                android:id="@+id/gridview"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                />
    </LinearLayout >
    <include
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            layout="@layout/sync_account_leaf_loader" />
</FrameLayout >
hjkatz commented 11 years ago

OMG that's a freaking HUGE screenshot, my bad =\

lkorth commented 11 years ago

Haven't seen anything like that before. Have you tried forcing GPU rendering to see if it clears it up? What happens if you don't set a background?

hjkatz commented 11 years ago

gpu rendering does not help.

Note: On release the artifacts disappear immediately, Also The artifacts on appear when moving down, so I can make "zig-zags" by dragging slowly down left, back tracking (thus erasing all artifacts BELOW the dragged item), then proceeding down again (as shown in screenshot)

screenshot_2013-05-02-12-36-53

hjkatz commented 11 years ago

Adding no background does not change anything

hjkatz commented 11 years ago

I also, could not get this to happen using your layout, so I assume it's a problem with a FrameLayout perhaps?

lkorth commented 11 years ago

Sounds like a problem with FrameLayout then. You also probably shouldn't be using a FrameLayout for this/in this manner

hjkatz commented 11 years ago

So I removed everything and just have the gridview, still happens:

<?xml version="1.0" encoding="utf-8"?>
<ca.laplanete.mobile.pageddragdropgrid.PagedDragDropGrid         xmlns:android="http://schemas.android.com/apk/res/android"
                                                         android:id="@+id/main2"
                                                         android:layout_width="fill_parent"
                                                         android:layout_height="fill_parent"
        />
lkorth commented 11 years ago

Does it happen on other devices?

hjkatz commented 11 years ago

Yes it does

hjkatz commented 11 years ago

It also, now only happens when there is only 1 item in the entire adapter, not one per page, just 1. Strange...

hjkatz commented 11 years ago

You can get it to happen in the example project, only have 1 item total. Then drag slowly...

screenshot_2013-05-02-14-18-01

hjkatz commented 11 years ago

I fixed it. During your longClick method you handle jiggling the itmes and start the dragged and movingView. Then in your touchMove method you handle moving the dragged view (clear animation, start animation) and you manage swapping, edges, and delete. However, this is all fine and dandy (starting animation, stopping animation) until nothing in the parent view ( "this" ) is animating, thus stopping all drawing. So if no redraw is called, you get artifacts. To fix this simple add one line (like most problems =P) to invalidate "this" before handling animation and events. Below is the new touchMove()

private void touchMove( MotionEvent event )
{
    if ( movingView && aViewIsDragged() )
    {
        lastTouchX = (int) event.getX();
        lastTouchY = (int) event.getY();

        invalidate();
        moveDraggedView( lastTouchX, lastTouchY );
        manageSwapPosition( lastTouchX, lastTouchY );
        manageEdgeCoordinates( lastTouchX );
        manageDeleteZoneHover( lastTouchX, lastTouchY );
    }
}

If you'd like I'll make a pull request, add the one line (and the ability to disable the remove bar) and request a merge. Thanks!

mrKlar commented 11 years ago

Yes do a pull request for the fix + the optional remove bar and i will merge it.