public class

DragSortController

extends SimpleFloatViewManager
implements GestureDetector.OnGestureListener View.OnTouchListener
java.lang.Object
   ↳ com.mobeta.android.dslv.SimpleFloatViewManager
     ↳ com.mobeta.android.dslv.DragSortController

Class Overview

Class that starts and stops item drags on a DragSortListView based on touch gestures. This class also inherits from SimpleFloatViewManager, which provides basic float View creation. An instance of this class is meant to be passed to the methods DragSortListView#setTouchListener() and DragSortListView#setFloatViewManager() of your DragSortListView instance.

Summary

Constants
int CLICK_REMOVE Remove mode enum.
int FLING_REMOVE
int MISS
int ON_DOWN Drag init mode enum.
int ON_DRAG
int ON_LONG_PRESS
Public Constructors
DragSortController(DragSortListView dslv)
Calls #DragSortController(DragSortListView, int) with a 0 drag handle id, FLING_RIGHT_REMOVE remove mode, and ON_DOWN drag init.
DragSortController(DragSortListView dslv, int dragHandleId, int dragInitMode, int removeMode)
DragSortController(DragSortListView dslv, int dragHandleId, int dragInitMode, int removeMode, int clickRemoveId)
DragSortController(DragSortListView dslv, int dragHandleId, int dragInitMode, int removeMode, int clickRemoveId, int flingHandleId)
By default, sorting is enabled, and removal is disabled.
Public Methods
int dragHandleHitPosition(MotionEvent ev)
Checks for the touch of an item's drag handle (specified by setDragHandleId(int)), and returns that item's position if a drag handle touch was detected.
int flingHandleHitPosition(MotionEvent ev)
int getDragInitMode()
int getRemoveMode()
boolean isRemoveEnabled()
boolean isSortEnabled()
boolean onDown(MotionEvent ev)
void onDragFloatView(View floatView, Point position, Point touch)
Overrides to provide fading when slide removal is enabled.
final boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
void onLongPress(MotionEvent e)
boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
void onShowPress(MotionEvent ev)
boolean onSingleTapUp(MotionEvent ev)
boolean onTouch(View v, MotionEvent ev)
void setClickRemoveId(int id)
Set the resource id for the View that represents click removal button.
void setDragHandleId(int id)
Set the resource id for the View that represents the drag handle in a list item.
void setDragInitMode(int mode)
Set how a drag is initiated.
void setFlingHandleId(int id)
Set the resource id for the View that represents the fling handle in a list item.
void setRemoveEnabled(boolean enabled)
Enable/Disable item removal without affecting remove mode.
void setRemoveMode(int mode)
One of CLICK_REMOVE, FLING_RIGHT_REMOVE, FLING_LEFT_REMOVE, SLIDE_RIGHT_REMOVE, or SLIDE_LEFT_REMOVE.
void setSortEnabled(boolean enabled)
Enable/Disable list item sorting.
boolean startDrag(int position, int deltaX, int deltaY)
Sets flags to restrict certain motions of the floating View based on DragSortController settings (such as remove mode).
int startDragPosition(MotionEvent ev)
Get the position to start dragging based on the ACTION_DOWN MotionEvent.
int startFlingPosition(MotionEvent ev)
int viewIdHitPosition(MotionEvent ev, int id)
[Expand]
Inherited Methods
From class com.mobeta.android.dslv.SimpleFloatViewManager
From class java.lang.Object
From interface android.view.GestureDetector.OnGestureListener
From interface android.view.View.OnTouchListener
From interface com.mobeta.android.dslv.DragSortListView.FloatViewManager

Constants

public static final int CLICK_REMOVE

Remove mode enum.

Constant Value: 0 (0x00000000)

public static final int FLING_REMOVE

Constant Value: 1 (0x00000001)

public static final int MISS

Constant Value: -1 (0xffffffff)

public static final int ON_DOWN

Drag init mode enum.

Constant Value: 0 (0x00000000)

public static final int ON_DRAG

Constant Value: 1 (0x00000001)

public static final int ON_LONG_PRESS

Constant Value: 2 (0x00000002)

Public Constructors

public DragSortController (DragSortListView dslv)

Calls #DragSortController(DragSortListView, int) with a 0 drag handle id, FLING_RIGHT_REMOVE remove mode, and ON_DOWN drag init. By default, sorting is enabled, and removal is disabled.

Parameters
dslv The DSLV instance

public DragSortController (DragSortListView dslv, int dragHandleId, int dragInitMode, int removeMode)

public DragSortController (DragSortListView dslv, int dragHandleId, int dragInitMode, int removeMode, int clickRemoveId)

public DragSortController (DragSortListView dslv, int dragHandleId, int dragInitMode, int removeMode, int clickRemoveId, int flingHandleId)

By default, sorting is enabled, and removal is disabled.

Parameters
dslv The DSLV instance
dragHandleId The resource id of the View that represents the drag handle in a list item.

Public Methods

public int dragHandleHitPosition (MotionEvent ev)

Checks for the touch of an item's drag handle (specified by setDragHandleId(int)), and returns that item's position if a drag handle touch was detected.

Parameters
ev The ACTION_DOWN MotionEvent.
Returns
  • The list position of the item whose drag handle was touched; MISS if unsuccessful.

public int flingHandleHitPosition (MotionEvent ev)

public int getDragInitMode ()

public int getRemoveMode ()

public boolean isRemoveEnabled ()

public boolean isSortEnabled ()

public boolean onDown (MotionEvent ev)

public void onDragFloatView (View floatView, Point position, Point touch)

Overrides to provide fading when slide removal is enabled.

Parameters
floatView The floating View.
position The location (top-left; relative to DSLV top-left) at which the float View would like to appear, given the current touch location and the offset provided in startDrag(int, View, int, int, int).
touch The current touch location (relative to DSLV top-left).

public final boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)

public void onLongPress (MotionEvent e)

public boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)

public void onShowPress (MotionEvent ev)

public boolean onSingleTapUp (MotionEvent ev)

public boolean onTouch (View v, MotionEvent ev)

public void setClickRemoveId (int id)

Set the resource id for the View that represents click removal button.

Parameters
id An android resource id.

public void setDragHandleId (int id)

Set the resource id for the View that represents the drag handle in a list item.

Parameters
id An android resource id.

public void setDragInitMode (int mode)

Set how a drag is initiated. Needs to be one of ON_DOWN, ON_DRAG, or ON_LONG_PRESS.

Parameters
mode The drag init mode.

public void setFlingHandleId (int id)

Set the resource id for the View that represents the fling handle in a list item.

Parameters
id An android resource id.

public void setRemoveEnabled (boolean enabled)

Enable/Disable item removal without affecting remove mode.

public void setRemoveMode (int mode)

One of CLICK_REMOVE, FLING_RIGHT_REMOVE, FLING_LEFT_REMOVE, SLIDE_RIGHT_REMOVE, or SLIDE_LEFT_REMOVE.

public void setSortEnabled (boolean enabled)

Enable/Disable list item sorting. Disabling is useful if only item removal is desired. Prevents drags in the vertical direction.

Parameters
enabled Set true to enable list item sorting.

public boolean startDrag (int position, int deltaX, int deltaY)

Sets flags to restrict certain motions of the floating View based on DragSortController settings (such as remove mode). Starts the drag on the DragSortListView.

Parameters
position The list item position (includes headers).
deltaX Touch x-coord minus left edge of floating View.
deltaY Touch y-coord minus top edge of floating View.
Returns
  • True if drag started, false otherwise.

public int startDragPosition (MotionEvent ev)

Get the position to start dragging based on the ACTION_DOWN MotionEvent. This function simply calls dragHandleHitPosition(MotionEvent). Override to change drag handle behavior; this function is called internally when an ACTION_DOWN event is detected.

Parameters
ev The ACTION_DOWN MotionEvent.
Returns
  • The list position to drag if a drag-init gesture is detected; MISS if unsuccessful.

public int startFlingPosition (MotionEvent ev)

public int viewIdHitPosition (MotionEvent ev, int id)