/** Overrides to provide fading when slide removal is enabled. */ @Override public void onDragFloatView(View floatView, Point position, Point touch) { if (mRemoveEnabled) { int x = touch.x; if (mRemoveMode == SLIDE_RIGHT_REMOVE) { int width = mDslv.getWidth(); int thirdWidth = width / 3; float alpha; if (x < thirdWidth) { alpha = 1.0f; } else if (x < width - thirdWidth) { alpha = ((float) (width - thirdWidth - x)) / ((float) thirdWidth); } else { alpha = 0.0f; } mDslv.setFloatAlpha(mOrigFloatAlpha * alpha); } else if (mRemoveMode == SLIDE_LEFT_REMOVE) { int width = mDslv.getWidth(); int thirdWidth = width / 3; float alpha; if (x < thirdWidth) { alpha = 0.0f; } else if (x < width - thirdWidth) { alpha = ((float) (x - thirdWidth)) / ((float) thirdWidth); } else { alpha = 1.0f; } mDslv.setFloatAlpha(mOrigFloatAlpha * alpha); } } }
@Override public boolean onTouch(View v, MotionEvent ev) { mDetector.onTouchEvent(ev); if (mRemoveEnabled && mDragging && (mRemoveMode == FLING_RIGHT_REMOVE || mRemoveMode == FLING_LEFT_REMOVE)) { 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: if (mRemoveEnabled) { final int x = (int) ev.getX(); int thirdW = mDslv.getWidth() / 3; int twoThirdW = mDslv.getWidth() - thirdW; if ((mRemoveMode == SLIDE_RIGHT_REMOVE && x > twoThirdW) || (mRemoveMode == SLIDE_LEFT_REMOVE && x < thirdW)) { mDslv.stopDrag(true); } } case MotionEvent.ACTION_CANCEL: mDragging = false; break; } return false; }
@Override public boolean onTouch(View v, MotionEvent ev) { if (!mDslv.isDragEnabled() || mDslv.listViewIntercepted()) { return false; } mDetector.onTouchEvent(ev); if (mRemoveEnabled && mDragging && mRemoveMode == FLING_REMOVE) { 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: if (mRemoveEnabled && mIsRemoving) { int x = mPositionX >= 0 ? mPositionX : -mPositionX; int removePoint = mDslv.getWidth() / 2; if (x > removePoint) { mDslv.stopDragWithVelocity(true, 0); } } case MotionEvent.ACTION_CANCEL: mIsRemoving = false; mDragging = false; break; } return false; }
@Override public final boolean onFling( MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // Log.d("mobeta", "on fling remove called"); if (mRemoveEnabled && mIsRemoving) { int w = mDslv.getWidth(); int minPos = w / 5; if (velocityX > mFlingSpeed) { if (mPositionX > -minPos) { mDslv.stopDragWithVelocity(true, velocityX); } } else if (velocityX < -mFlingSpeed) { if (mPositionX < minPos) { mDslv.stopDragWithVelocity(true, velocityX); } } mIsRemoving = false; } return false; }