public class

VisualRowReorderer

extends Object
implements ItemDragDetector.OnItemDragListener RowReorderDetector.OnRowReorderListener
java.lang.Object
   ↳ com.shinobicontrols.grids.supplement.VisualRowReorderer

Class Overview

Visualizes the reordering of rows within the ShinobiGridView. Specifically, the items in the row being reordered appear to be pulled out from the grid and move up and down in-sync with the user's finger until the gesture ends with the user lifting their finger.

This class is one of many that are used by the RowColumnReorderManager to enable row reordering on the ShinobiGridView. In general, the RowColumnReorderManager provides a more convenient way of achieving this. However, for more specialized situations this class can be leveraged in conjunction with other classes to provide the same visual feedback during row reordering.

In order to provide this visual feedback, the VisualRowReorderer must be added as a listener to both an ItemDragDetector and a RowReorderDetector.

This VisualRowReorderer will not perform any reordering actions on the grid's backing data; the responsibility for this is left up to the user and any such reordering operations should be done through a separate RowReorderDetector.OnRowReorderListener added to this VisualRowReorderer via the addOnRowReorderListener(RowReorderDetector.OnRowReorderListener) method.

By default the positions of selected and hidden items in the ShinobiGridView will not be updated to reflect the row reorder event. If you want to preserve selected and hidden item positions you can also add an ItemStateManager via the addOnRowReorderListener(RowReorderDetector.OnRowReorderListener) method.

By adding RowReorderDetector.OnRowReorderListeners to this VisualRowReorderer (instead of to the related RowReorderDetector) it will ensure that their callback methods are called at an appropriate time with respect to the visual feedback provided by this class.

Summary

Public Constructors
VisualRowReorderer()

Constructs a new VisualRowReorderer.

Public Methods
final void addOnRowReorderListener(RowReorderDetector.OnRowReorderListener listener)

Adds an RowReorderDetector.OnRowReorderListener to this VisualRowReorderer's list of listeners.

void onItemDrag(ItemDragDetector itemDragDetector, float x, float y, GridRecyclerView gridRecyclerView)

The callback method to be invoked while a drag gesture is being performed over items in the grid.

void onItemReleaseDrag(ItemDragDetector itemDragDetector, float x, float y, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a drag gesture is completed.

void onItemStartDrag(ItemDragDetector itemDragDetector, float x, float y, GridRecyclerView gridRecyclerView)

The callback method to be invoked when the start of a drag gesture is performed on an item in the grid.

void onRowIndexChanged(int rowIndex, int fromRowIndex, int toRowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked during a reorder event when a row has been moved enough for it to have been deemed to have changed places with an adjacent row.

void onRowReorderCancelled(int rowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a reorder event is cancelled.

void onRowReorderEnded(int rowIndex, int endRowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a reorder event that is performed on a row in the grid has ended.

void onRowReorderStarted(int rowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a reorder event is started on a row in the grid.

final void removeOnRowReorderListener(RowReorderDetector.OnRowReorderListener listener)

Adds an RowReorderDetector.OnRowReorderListener from this VisualRowReorderer's list of listeners.

[Expand]
Inherited Methods
From class java.lang.Object
From interface com.shinobicontrols.grids.supplement.ItemDragDetector.OnItemDragListener
From interface com.shinobicontrols.grids.supplement.RowReorderDetector.OnRowReorderListener

Public Constructors

public VisualRowReorderer ()

Constructs a new VisualRowReorderer.

Public Methods

public final void addOnRowReorderListener (RowReorderDetector.OnRowReorderListener listener)

Adds an RowReorderDetector.OnRowReorderListener to this VisualRowReorderer's list of listeners.

The onRowReorderStarted(int, GridRecyclerView) method of each listener is guaranteed to be called before the visual feedback aspects of the row reorder event begins. Likewise, the onRowReorderEnded(int, int, GridRecyclerView) method of each listener is guaranteed to be called after the visual feedback aspects of the row reorder event ends.

Parameters
listener the listener to add

public void onItemDrag (ItemDragDetector itemDragDetector, float x, float y, GridRecyclerView gridRecyclerView)

The callback method to be invoked while a drag gesture is being performed over items in the grid. More specifically, this will be called at the end of each move gesture once a drag has been initiated by means of a long press. The given x and y values can be used with the getItemPosition(RecyclerView, float, float) method to obtain the position of the item in the ShinobiGridView at those co-ordinates.

To translate this position into a column index or a row index use the getColumnIndexForPosition(int) and getRowIndexForPosition(int) methods.

Parameters
itemDragDetector the ItemDragDetector detecting the drag gesture
x the x coordinate of the pointer at the end of the move event
y the y coordinate of the pointer at the end of the move event
gridRecyclerView the RecyclerView on which the drag gesture is performed

public void onItemReleaseDrag (ItemDragDetector itemDragDetector, float x, float y, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a drag gesture is completed. More specifically, this will be called when the gesture is released at the end of a drag. The given x and y values can be used with the getItemPosition(RecyclerView, float, float) method to obtain the position of the item in the ShinobiGridView at those co-ordinates.

To translate this position into a column index or a row index use the getColumnIndexForPosition(int) and getRowIndexForPosition(int) methods.

Parameters
itemDragDetector the ItemDragDetector detecting the drag gesture
x the x coordinate of the pointer at the end of the drag gesture
y the y coordinate of the pointer at the end of the drag gesture
gridRecyclerView the GridRecyclerView on which the drag gesture is performed

public void onItemStartDrag (ItemDragDetector itemDragDetector, float x, float y, GridRecyclerView gridRecyclerView)

The callback method to be invoked when the start of a drag gesture is performed on an item in the grid. More specifically, this will be called on the end of a long press gesture. The given x and y values can be used with the getItemPosition(RecyclerView, float, float) method to obtain the position of the item in the ShinobiGridView at those co-ordinates.

To translate this position into a column index or a row index use the getColumnIndexForPosition(int) and getRowIndexForPosition(int) methods.

Parameters
itemDragDetector the ItemDragDetector detecting the drag gesture
x the x coordinate of the pointer at the start of the drag gesture
y the y coordinate of the pointer at the start of the drag gesture
gridRecyclerView the GridRecyclerView on which the drag gesture is performed

public void onRowIndexChanged (int rowIndex, int fromRowIndex, int toRowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked during a reorder event when a row has been moved enough for it to have been deemed to have changed places with an adjacent row. This will be called multiple times as the user drags their finger vertically across the ShinobiGridView.

Parameters
rowIndex the index of the row that is being reordered
fromRowIndex the index that the row being reordered has moved from due to dragging
toRowIndex the index that the row being reordered has moved to due to dragging
gridRecyclerView the GridRecyclerView on which the reordering event was initiated

public void onRowReorderCancelled (int rowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a reorder event is cancelled. More specifically, this is when the row has been dragged to somewhere deemed invalid for the grid, for example, out of its bounds.

Parameters
rowIndex the index of the row that was being reordered
gridRecyclerView the GridRecyclerView on which the reordering event was initiated

public void onRowReorderEnded (int rowIndex, int endRowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a reorder event that is performed on a row in the grid has ended. More specifically, this will be called at the end of a drag gesture, that is when the user lifts up their finger.

If at the end of the drag gesture the row has not been dragged far enough from its original position this method will be called with both parameters being the same value.

Parameters
rowIndex the index of the row that is being reordered
endRowIndex the index that the row being reordered has moved to at the end of the reorder event
gridRecyclerView the GridRecyclerView on which the reordering event was initiated

public void onRowReorderStarted (int rowIndex, GridRecyclerView gridRecyclerView)

The callback method to be invoked when a reorder event is started on a row in the grid. More specifically, this will be called when the user long presses a row. For the rest of the reorder event this row will be used as the reference point.

Parameters
rowIndex the index of the row that is being reordered
gridRecyclerView the GridRecyclerView on which the reordering event was initiated

public final void removeOnRowReorderListener (RowReorderDetector.OnRowReorderListener listener)

Adds an RowReorderDetector.OnRowReorderListener from this VisualRowReorderer's list of listeners.

Parameters
listener the listener to remove