Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullptr fix #130

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
----
Expand Down
2 changes: 1 addition & 1 deletion demo/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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/
2 changes: 1 addition & 1 deletion library/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

android.library=true
# Project target.
target=android-7
target=android-20
44 changes: 37 additions & 7 deletions library/src/com/mobeta/android/dslv/DragSortController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down