Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 73f9ef98 authored by Ben Lin's avatar Ben Lin Committed by Android (Google) Code Review
Browse files

Merge "Always pass DragEvents to the underlying DirFragment's...

Merge "Always pass DragEvents to the underlying DirFragment's ItemDragListener." into nyc-andromeda-dev
parents 44667b85 7c5deaae
Loading
Loading
Loading
Loading
+3 −10
Original line number Diff line number Diff line
@@ -124,7 +124,6 @@ class DragHoverListener implements OnDragListener {

    @Override
    public boolean onDrag(View v, DragEvent event) {
        boolean handled = false;
        switch (event.getAction()) {
            case DragEvent.ACTION_DRAG_STARTED:
                mDragHappening = true;
@@ -132,21 +131,15 @@ class DragHoverListener implements OnDragListener {
            case DragEvent.ACTION_DRAG_ENDED:
                mDragHappening = false;
                break;
            case DragEvent.ACTION_DRAG_ENTERED:
                handled = insideDragZone();
                break;
            case DragEvent.ACTION_DRAG_LOCATION:
                handled = handleLocationEvent(v, event.getX(), event.getY());
                handleLocationEvent(v, event.getX(), event.getY());
                break;
            default:
                break;
        }

        if (!handled) {
            handled = mDragHandler.onDrag(v, event);
        }

        return handled;
        // Always forward events to the drag handler for item highlight, spring load, etc.
        return mDragHandler.onDrag(v, event);
    }

    private boolean handleLocationEvent(View v, float x, float y) {
+6 −14
Original line number Diff line number Diff line
@@ -104,6 +104,12 @@ public class DragScrollListenerTest {
        triggerDragLocationEvent(0, BOTTOM_Y_POINT);
        assertTrue(mDragHandler.mLastDropEvent.getAction() == DragEvent.ACTION_DRAG_LOCATION);

        triggerDragLocationEvent(0, TOP_Y_POINT);
        assertTrue(mDragHandler.mLastDropEvent.getAction() == DragEvent.ACTION_DRAG_LOCATION);

        triggerDragLocationEvent(0, BOTTOM_Y_POINT);
        assertTrue(mDragHandler.mLastDropEvent.getAction() == DragEvent.ACTION_DRAG_LOCATION);

        triggerDragEvent(DragEvent.ACTION_DRAG_ENDED);
    }

@@ -134,18 +140,6 @@ public class DragScrollListenerTest {
        triggerDragEvent(DragEvent.ACTION_DRAG_ENDED);
    }

    // Make sure given correct location/enter events, DragScrollListener handle them itself
    @Test
    public void testDragScrollEvent_Handled() {
        triggerDragLocationEvent(0, TOP_Y_POINT);
        triggerDragEvent(DragEvent.ACTION_DRAG_ENTERED);
        assertTrue(mDragHandler.mLastDropEvent == null);

        triggerDragLocationEvent(0, BOTTOM_Y_POINT);
        triggerDragEvent(DragEvent.ACTION_DRAG_ENTERED);
        assertTrue(mDragHandler.mLastDropEvent == null);
    }

    // A correct Auto-scroll happens in the sequence of:
    // Started -> LocationChanged -> Scroll -> Enter -> Exit
    // This test to make sure scroll actually happens in the right direction given correct sequence
@@ -155,14 +149,12 @@ public class DragScrollListenerTest {

        triggerDragLocationEvent(0, TOP_Y_POINT);
        triggerDragEvent(DragEvent.ACTION_DRAG_ENTERED);
        assertTrue(mDragHandler.mLastDropEvent.getAction() == DragEvent.ACTION_DRAG_STARTED);
        mActionDelegate.assertScrollNegative();

        triggerDragLocationEvent(0, BOTTOM_Y_POINT);
        triggerDragEvent(DragEvent.ACTION_DRAG_ENTERED);

        triggerDragEvent(DragEvent.ACTION_DRAG_ENDED);
        assertTrue(mDragHandler.mLastDropEvent.getAction() == DragEvent.ACTION_DRAG_ENDED);
        mActionDelegate.assertScrollPositive();
    }