patch DragSortListView to support setOnTouchListener calls.
This enables users of a DSLV to call setOnTouchListener without breaking the drag functionality.
This commit is contained in:
parent
597d704e4e
commit
7ffd0169b3
@ -81,6 +81,11 @@ public class DragSortController extends SimpleFloatViewManager implements View.O
|
||||
private DragSortListView mDslv;
|
||||
private int mPositionX;
|
||||
|
||||
/**
|
||||
* Class which will receive onTouch events
|
||||
*/
|
||||
private View.OnTouchListener mSecondaryOnTouchListener;
|
||||
|
||||
/**
|
||||
* Calls {@link #DragSortController(DragSortListView, int)} with a
|
||||
* 0 drag handle id, FLING_RIGHT_REMOVE remove mode,
|
||||
@ -236,6 +241,10 @@ public class DragSortController extends SimpleFloatViewManager implements View.O
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent ev) {
|
||||
if (mSecondaryOnTouchListener != null) {
|
||||
mSecondaryOnTouchListener.onTouch(v, ev);
|
||||
}
|
||||
|
||||
if (!mDslv.isDragEnabled() || mDslv.listViewIntercepted()) {
|
||||
return false;
|
||||
}
|
||||
@ -279,6 +288,15 @@ public class DragSortController extends SimpleFloatViewManager implements View.O
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We consume onTouch events: ALSO dispatch them to the listener
|
||||
* if requested.
|
||||
*/
|
||||
@Override
|
||||
public void setSecondaryOnTouchListener(View.OnTouchListener l) {
|
||||
mSecondaryOnTouchListener = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position to start dragging based on the ACTION_DOWN
|
||||
* MotionEvent. This function simply calls
|
||||
|
@ -530,7 +530,8 @@ public class DragSortListView extends ListView {
|
||||
controller.setBackgroundColor(bgColor);
|
||||
|
||||
mFloatViewManager = controller;
|
||||
setOnTouchListener(controller);
|
||||
// must register this on ListView (super), not 'this'.
|
||||
super.setOnTouchListener(controller);
|
||||
}
|
||||
|
||||
a.recycle();
|
||||
@ -570,6 +571,18 @@ public class DragSortListView extends ListView {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* DragSortListView registers the the controler as an onTouch listener.
|
||||
* We implement this method to ensure that users of this listview can also
|
||||
* register their own onTouch listener without disabling our own registration.
|
||||
*/
|
||||
@Override
|
||||
public void setOnTouchListener(View.OnTouchListener l) {
|
||||
if (mFloatViewManager != null) {
|
||||
mFloatViewManager.setSecondaryOnTouchListener(l);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Usually called from a FloatViewManager. The float alpha
|
||||
* will be reset to the xml-defined value every time a drag
|
||||
@ -2468,6 +2481,11 @@ public class DragSortListView extends ListView {
|
||||
* {@link #onCreateFloatView(int)}.
|
||||
*/
|
||||
public void onDestroyFloatView(View floatView);
|
||||
|
||||
/**
|
||||
* Register a class which will get onTouch events.
|
||||
*/
|
||||
public void setSecondaryOnTouchListener(View.OnTouchListener l);
|
||||
}
|
||||
|
||||
public void setFloatViewManager(FloatViewManager manager) {
|
||||
|
@ -85,5 +85,9 @@ public class SimpleFloatViewManager implements DragSortListView.FloatViewManager
|
||||
mFloatBitmap = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSecondaryOnTouchListener(View.OnTouchListener l) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user