Restore our concept of a swipe listener

pull/14/head
Tim Su 14 years ago
parent c228e33b0e
commit 108a4efbb8

@ -24,7 +24,6 @@ import android.graphics.PixelFormat;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.Gravity; import android.view.Gravity;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@ -45,9 +44,10 @@ public class TouchListView extends ListView {
private int mFirstDragPos; // where was the dragged item originally private int mFirstDragPos; // where was the dragged item originally
private int mDragPoint; // at what offset inside the item did the user grab it private int mDragPoint; // at what offset inside the item did the user grab it
private int mCoordOffset; // the difference between screen coordinates and coordinates in this view private int mCoordOffset; // the difference between screen coordinates and coordinates in this view
private int mDragStartX;
private DragListener mDragListener; private DragListener mDragListener;
private DropListener mDropListener; private DropListener mDropListener;
private RemoveListener mRemoveListener; private SwipeListener mSwipeListener;
private int mUpperBound; private int mUpperBound;
private int mLowerBound; private int mLowerBound;
private int mHeight; private int mHeight;
@ -115,31 +115,6 @@ public class TouchListView extends ListView {
@Override @Override
public boolean onInterceptTouchEvent(MotionEvent ev) { public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mRemoveListener != null && mGestureDetector == null) {
if (mRemoveMode == FLING) {
mGestureDetector = new GestureDetector(getContext(), new SimpleOnGestureListener() {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (mDragView != null) {
if (velocityX > 1000) {
Rect r = mTempRect;
mDragView.getDrawingRect(r);
if ( e2.getX() > r.right * 2 / 3) {
// fast fling right with release near the right edge of the screen
stopDragging();
mRemoveListener.remove(mFirstDragPos);
unExpandViews(true);
}
}
// flinging while dragging should have no effect
return true;
}
return false;
}
});
}
}
if (mDragListener != null || mDropListener != null) { if (mDragListener != null || mDropListener != null) {
switch (ev.getAction()) { switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
@ -336,16 +311,15 @@ public class TouchListView extends ListView {
Rect r = mTempRect; Rect r = mTempRect;
mDragView.getDrawingRect(r); mDragView.getDrawingRect(r);
stopDragging(); stopDragging();
if (mDragPos == mFirstDragPos && ev.getX() > mDragStartX + 20) {
if (mRemoveMode == SLIDE_RIGHT && ev.getX() > r.left+(r.width()*3/4)) { if (mSwipeListener!= null) {
if (mRemoveListener != null) { mSwipeListener.swipeRight(mFirstDragPos);
mRemoveListener.remove(mFirstDragPos);
} }
unExpandViews(true); unExpandViews(true);
} else if (mRemoveMode == SLIDE_LEFT && ev.getX() < r.left+(r.width()/4)) { } else if (mDragPos == mFirstDragPos && ev.getX() < mDragStartX - 20) {
if (mRemoveListener != null) { if (mSwipeListener!= null) {
mRemoveListener.remove(mFirstDragPos); mSwipeListener.swipeLeft(mFirstDragPos);
} }
unExpandViews(true); unExpandViews(true);
} else { } else {
if (mDropListener != null && mDragPos >= 0 && mDragPos < getCount()) { if (mDropListener != null && mDragPos >= 0 && mDragPos < getCount()) {
@ -467,8 +441,8 @@ public class TouchListView extends ListView {
mDropListener = l; mDropListener = l;
} }
public void setRemoveListener(RemoveListener l) { public void setSwipeListener(SwipeListener l) {
mRemoveListener = l; mSwipeListener = l;
} }
public interface DragListener { public interface DragListener {
@ -477,7 +451,8 @@ public class TouchListView extends ListView {
public interface DropListener { public interface DropListener {
void drop(int from, int to); void drop(int from, int to);
} }
public interface RemoveListener { public interface SwipeListener {
void remove(int which); void swipeLeft(int which);
void swipeRight(int which);
} }
} }

@ -1,4 +1,4 @@
<resources> <resources xmlns:android="http://schemas.android.com/apk/res/android">
<declare-styleable name="TouchListView"> <declare-styleable name="TouchListView">
<attr name="normal_height" format="dimension" /> <attr name="normal_height" format="dimension" />
<attr name="expanded_height" format="dimension" /> <attr name="expanded_height" format="dimension" />

Loading…
Cancel
Save