|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectandroid.view.View
android.view.ViewGroup
android.widget.AdapterView<SwipesAdapter>
com.operators.swipes.SwipesView
public class SwipesView
The Swipes View is a new implementation of Android's AdapterView
specifically made for
4 directional swiping. This implementation is loosely based upon Tinder's Like/Nope Swiping action.
As in the example below, to pass data to the
SwipesView
, the SwipesAdapter
needs to be subclassed and passed to setAdapter(SwipesAdapter)
.
SwipesView sv = new SwipesView(context); sv.setAdapter(new BasicExampleSwipesAdapter(context, R.layout.card_item));
setAdapter(SwipesAdapter)
Nested Class Summary | |
---|---|
static class |
SwipesView.Directions
The Directions are abstractions of typical 4 directional swipe operations. |
static interface |
SwipesView.OnSwipeListener
Listener that updates on swipe threshold and direction. |
Nested classes/interfaces inherited from class android.widget.AdapterView |
---|
AdapterView.AdapterContextMenuInfo, AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener, AdapterView.OnItemSelectedListener |
Nested classes/interfaces inherited from class android.view.ViewGroup |
---|
ViewGroup.LayoutParams, ViewGroup.MarginLayoutParams, ViewGroup.OnHierarchyChangeListener |
Field Summary |
---|
Fields inherited from class android.widget.AdapterView |
---|
INVALID_POSITION, INVALID_ROW_ID, ITEM_VIEW_TYPE_HEADER_OR_FOOTER, ITEM_VIEW_TYPE_IGNORE |
Fields inherited from class android.view.ViewGroup |
---|
FOCUS_AFTER_DESCENDANTS, FOCUS_BEFORE_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS, LAYOUT_MODE_CLIP_BOUNDS, LAYOUT_MODE_OPTICAL_BOUNDS, PERSISTENT_ALL_CACHES, PERSISTENT_ANIMATION_CACHE, PERSISTENT_NO_CACHE, PERSISTENT_SCROLLING_CACHE |
Constructor Summary | |
---|---|
SwipesView(Context context)
Constructs the Swipes View, but just in Java source code. |
|
SwipesView(Context context,
AttributeSet attrs)
Constructs the Swipes View in Java source code or Android XML. |
|
SwipesView(Context context,
AttributeSet attrs,
int defStyle)
Constructs the Swipes View in Java source code or Android XML. |
Method Summary | |
---|---|
static void |
addSwipesListener(SwipesView.OnSwipeListener mListener)
The collection setter for Swipe Listener changes. |
ViewGroup.LayoutParams |
generateLayoutParams(AttributeSet attrs)
Returns the layout params for this widget. |
SwipesAdapter |
getAdapter()
Returns the adapter currently associated with this widget. |
float |
getRotation()
The rotation value that the swipes are limited to. |
View |
getSelectedView()
The currently visible view (or card). |
boolean |
isAllowed(SwipesView.Directions direction)
Checks whether a swipe direction change is allowed. |
void |
onDirectionChange(SwipesView.Directions direction)
Provides updates on swipe direction changes. |
void |
onThresholdChange(float threshold)
Provides updates on swipe threshold. |
static boolean |
onTouch(MotionEvent event)
This method allows Children Views to pass on touches (or Swipe Actions) to the SwipesView. |
void |
performSwipeDown()
The down swipe callback that performs the swipe operation. |
void |
performSwipeLeft()
The left swipe callback that performs the swipe operation. |
void |
performSwipeRight()
The right swipe callback that performs the swipe operation. |
void |
performSwipeUp()
The up swipe callback that performs the swipe operation. |
void |
setAdapter(SwipesAdapter adapter)
Sets the data for the views represented in this widget. |
void |
setAllowedDirections(SwipesView.Directions... allowed)
Sets the horizontal and vertical swiping directions enabled, and is automatically called when set in xml layout via the "directions" property. |
void |
setMaxVisibleCards(int cards)
Sets the maximum number of visible cards (defaults to 3), and can also be set in xml layout via the "max_visible_cards" property. |
void |
setSelection(int position)
Overrides parent implementation of setSelection. |
void |
setSwipeRotation(float rotation)
Sets the degree rotation for the swiping action, and can also be set in xml layout via the "swipe_rotation" property. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface android.view.ViewParent |
---|
createContextMenu, getParent, getParentForAccessibility, isLayoutRequested, requestFitSystemWindows, requestLayout |
Constructor Detail |
---|
public SwipesView(Context context)
context
- The activity context use for creation.public SwipesView(Context context, AttributeSet attrs)
context
- The activity context use for creation.attrs
- The attribute set typically used in android xml.public SwipesView(Context context, AttributeSet attrs, int defStyle)
context
- The activity context use for creation.attrs
- The attribute set typically used in android xml.defStyle
- The android style definition id.Method Detail |
---|
public static void addSwipesListener(SwipesView.OnSwipeListener mListener)
public void setAllowedDirections(SwipesView.Directions... allowed)
mSwipesView.setAllowedDirections(Directions.RIGHT, Directions.DOWN ...)XML Usage Example:
<com.operators.swipes.SwipesView
...
swipes:directions="right|down" />
SwipesView.Directions
public void setSwipeRotation(float rotation)
<com.operators.swipes.SwipesView
...
swipes:swipe_rotation="17.5" />
getRotation()
public void setMaxVisibleCards(int cards)
<com.operators.swipes.SwipesView
...
swipes:max_visible_cards="7" />
mMaxVisibleCards
public void setSelection(int position)
setSelection
in class AdapterView<SwipesAdapter>
position
- The passed position of the item to be selected.public View getSelectedView()
getSelectedView
in class AdapterView<SwipesAdapter>
public SwipesAdapter getAdapter()
getAdapter
in class AdapterView<SwipesAdapter>
public void setAdapter(SwipesAdapter adapter)
SwipesAdapter
:
class BasicExampleSwipesAdapter extends SwipesAdapter<Integer>
{
ArrayList<Integer>
mInts = new ArrayList<Integer>
(Arrays.asList(new Integer[]{
1, 11, 111
}));
public BasicExampleSwipesAdapter(Context context, int resource) {
super(context, resource);
}
@Override public View getView (int position, View convertView, ViewGroup parent) {
View inflatedResource = super.getView(position, convertView, parent);
TextView card_text = (TextView) inflatedResource.findViewById(R.id.card_text);
card_text.setText(getItem(position).toString());
return inflatedResource;
}
@Override public Integer getItem(int position) { return mInts.get(position); }
@Override public void removeItem(int position) { mInts.remove(position); }
@Override public int getCount() { return mInts.size(); }
}
The BasicExampleSwipesAdapter should be passed to the setAdapter(SwipesAdapter)
:
SwipesView sv = new SwipesView(context); sv.setAdapter(new BasicExampleSwipesAdapter(context, R.layout.card_item));
setAdapter
in class AdapterView<SwipesAdapter>
adapter
- The adapter used to create this view's content.SwipesAdapter
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)
generateLayoutParams
in class ViewGroup
FrameLayout.LayoutParams
public float getRotation()
getRotation
in class View
public void performSwipeLeft()
public void performSwipeDown()
public void performSwipeRight()
public void performSwipeUp()
public boolean isAllowed(SwipesView.Directions direction)
public void onDirectionChange(SwipesView.Directions direction)
public void onThresholdChange(float threshold)
public static boolean onTouch(MotionEvent event)
public boolean onTouchEvent(MotionEvent event) { SwipesView.onTouch(event); return super.onTouchEvent(event); }
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |