diff --git a/README.md b/README.md index ee09da8..8afc6ff 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,7 @@ DragSortListView ================ -# NOTICE: No longer maintained. - -I do not have much time to devote to this project so I am -dropping support for the time being. Sorry everybody! +# NOTICE: maintained to serve the purposes of KeepSafe Software. Nevertheless, please contribute issues and we will gladly take a look at fixing them News ---- diff --git a/demo/project.properties b/demo/project.properties index 488ad44..9f0b607 100644 --- a/demo/project.properties +++ b/demo/project.properties @@ -11,5 +11,5 @@ #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt # Project target. -target=android-16 +target=android-20 android.library.reference.1=../library/ diff --git a/library/project.properties b/library/project.properties index 0eb624c..6cd1f6a 100644 --- a/library/project.properties +++ b/library/project.properties @@ -12,4 +12,4 @@ android.library=true # Project target. -target=android-7 +target=android-20 diff --git a/library/src/com/mobeta/android/dslv/DragSortController.java b/library/src/com/mobeta/android/dslv/DragSortController.java index 41d477e..8af4839 100644 --- a/library/src/com/mobeta/android/dslv/DragSortController.java +++ b/library/src/com/mobeta/android/dslv/DragSortController.java @@ -47,9 +47,12 @@ public class DragSortController extends SimpleFloatViewManager implements View.O private boolean mIsRemoving = false; private GestureDetector mDetector; - + private boolean mDetectorSawMotionEventDown; + private GestureDetector mFlingRemoveDetector; + private boolean mFlingDetectorSawMotionEventDown; + private int mTouchSlop; public static final int MISS = -1; @@ -113,8 +116,12 @@ public DragSortController(DragSortListView dslv, int dragHandleId, int dragInitM super(dslv); mDslv = dslv; mDetector = new GestureDetector(dslv.getContext(), this); + mDetectorSawMotionEventDown = false; + mFlingRemoveDetector = new GestureDetector(dslv.getContext(), mFlingRemoveListener); mFlingRemoveDetector.setIsLongpressEnabled(false); + mFlingDetectorSawMotionEventDown = false; + mTouchSlop = ViewConfiguration.get(dslv.getContext()).getScaledTouchSlop(); mDragHandleId = dragHandleId; mClickRemoveId = clickRemoveId; @@ -235,23 +242,46 @@ public boolean startDrag(int position, int deltaX, int deltaY) { } @Override - public boolean onTouch(View v, MotionEvent ev) { - if (!mDslv.isDragEnabled() || mDslv.listViewIntercepted()) { + public boolean onTouch(View v, MotionEvent ev) { + if (!mDslv.isDragEnabled() || mDslv.listViewIntercepted()) { return false; } - - mDetector.onTouchEvent(ev); + + int action = ev.getAction() & MotionEvent.ACTION_MASK; + + // If detected an ACTION_DOWN motion event, remember that + if (action == MotionEvent.ACTION_DOWN) + mDetectorSawMotionEventDown = true; + + // Only propagate Touch events to the gesture detector if received at least one ACTION_DOWN + // event. Otherwise, the GestureDetector will crash our control by calling our onScroll + // method with a null first MotionEvent. + if (mDetectorSawMotionEventDown) + mDetector.onTouchEvent(ev); + if (mRemoveEnabled && mDragging && mRemoveMode == FLING_REMOVE) { - mFlingRemoveDetector.onTouchEvent(ev); + // If detected an ACTION_DOWN motion event, remember that + if (action == MotionEvent.ACTION_DOWN) + mFlingDetectorSawMotionEventDown = true; + + // Only propagate Touch events to the gesture detector if received at least one ACTION_DOWN + // event. Otherwise, the GestureDetector will crash our control by calling our onScroll + // method with a null first MotionEvent. + if (mFlingDetectorSawMotionEventDown) + mFlingRemoveDetector.onTouchEvent(ev); } - int action = ev.getAction() & MotionEvent.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mCurrX = (int) ev.getX(); mCurrY = (int) ev.getY(); break; case MotionEvent.ACTION_UP: + + // Make sure we won't be parsing gestures until a DOWN event is received + mDetectorSawMotionEventDown = false; + mFlingDetectorSawMotionEventDown = false; + if (mRemoveEnabled && mIsRemoving) { int x = mPositionX >= 0 ? mPositionX : -mPositionX; int removePoint = mDslv.getWidth() / 2;