askerov/DynamicGrid

Does not drag and drop properly on Android 2.3

GrahamBriggs opened this issue · 4 comments

I got dynamicgrid working just fine on Android 4.x.

I am having trouble getting it to work on Android 2.3.

I have a breakpoint in the startEditMode, and this point is always reached. However, on Android 2.3 the drag and drop mechanism is broken.

I will see one of two things.

  1. The item will actually visually drag on the screen (you can see it move) and the other items are reordered when you drag it into another cell. However, my drop listener is never called in this scenario. I put a breakpoint in DynamicGridView.java in the onTouchEvent function. In the code below, mHoverCell is always null in this case:
case MotionEvent.ACTION_UP:
            touchEventsEnded();

            if (mUndoSupportEnabled) {
                if (mCurrentModification != null && !mCurrentModification.getTransitions().isEmpty()) {
                    mModificationStack.push(mCurrentModification);
                    mCurrentModification = new DynamicGridModification();
                }
            }

            if (mHoverCell != null) {
                if (mDropListener != null) {
                    mDropListener.onActionDrop();
                }
            }
  1. The item does not appear to drag around the grid view (you can never see its icon move) and the other items do not reorder as you move it around the grid view. However, if you drop it on another cell then I do hit the onTouchEvent code, and in this case mHoverCell is not null, and onActionDrop is called. However, in this case, my onActionDrop gets the list out of the adapter, and it has not been updated. Neither are the items in the grid view. Therefore, any action I take in onActionDrop is moot because the list has not been updated by the grid view ?

The hard part is that the behavior is not predictable. Sometimes I see case (1) and the item is dragged visually, but onActionDrop is never called. Other times I don’t see any dragging visually and the grid view never reorders itself, but onActionDrop is called, but with the original list still intact? It never works properly, it is always defect 1 or 2.

I have already spent some time trying to debug this problem on an Android 2.3 phone (not emulator). I would be happy to see if I can help to solve this problem, but I would need some advice or suggestions about what may be wrong.

That's embarrassing. Is it reproducible only on a phone, not emulator? Out of curiosity you can take a look at #26 and a pull request for it - it addresses the issue that may be of the same kind

Denis

Thank you for the quick reply.

I have not tried it on an emulator. In general I only work with actual devices, the emulators are very slow and often don’t work like a real device anyway.

I examined #26 before I wrote up this one. I don’t think it is the same thing. BTW, I have seen the behavior described in 26 when running the code on my version 4.x android devices, so I believe this bug is real. I have noticed that when an item disappears, leaving a blank spot in the grid view, if you rearrange the items again, it will reappear. Therefore, it does not appear that it is dropped from the list, simply not drawn in the spot where it should be. BTW, the list of objects in my grid are of a complex type, with a title, int index, and other meta data, so I don’t think it is related to number #25 either?

Let me know if you think of anything.

Best Regards

GB
=-=-=-=-=-=-=
Graham Briggs
LittleBytesOfPi.com

On Oct 27, 2014, at 1:48 PM, Denis Kniazhev notifications@github.com wrote:

That's embarrassing. Is it reproducible only on a phone, not emulator? Out of curiosity you can take a look at #26 and a pull request for it - it addresses the issue that may be of the same kind


Reply to this email directly or view it on GitHub.

fhur commented

I am also experiencing the same issue as @GrahamBriggs onActionDrop() is never being called.

Same problem here, as described by GrahamBriggs case 1.
In MotionEvent.ACTION_UP you call touchEventsEnded(); in this method you call reset(mobileView) if Version <= HONEYCOMB (DynamicGridView.java line 569) and in reset method mHoverCell is set to null (line 621) so actionDrop will never be called for api <= HONEYCOMB.
Remove line 621 and add mHoverCell = null after others reset(..) calls (lines 646 and 611).

Best Regards
Davide