com.operators.swipes
Class SwipesView

java.lang.Object
  extended by android.view.View
      extended by android.view.ViewGroup
          extended by android.widget.AdapterView<SwipesAdapter>
              extended by com.operators.swipes.SwipesView
All Implemented Interfaces:
Drawable.Callback, AccessibilityEventSource, KeyEvent.Callback, ViewManager, ViewParent

public class SwipesView
extends AdapterView<SwipesAdapter>

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));
  

Author:
christopher
See Also:
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
 
Nested classes/interfaces inherited from class android.view.View
View.AccessibilityDelegate, View.BaseSavedState, View.DragShadowBuilder, View.MeasureSpec, View.OnAttachStateChangeListener, View.OnClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnGenericMotionListener, View.OnHoverListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnSystemUiVisibilityChangeListener, View.OnTouchListener
 
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
 
Fields inherited from class android.view.View
ALPHA, DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, FIND_VIEWS_WITH_CONTENT_DESCRIPTION, FIND_VIEWS_WITH_TEXT, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, GONE, HAPTIC_FEEDBACK_ENABLED, IMPORTANT_FOR_ACCESSIBILITY_AUTO, IMPORTANT_FOR_ACCESSIBILITY_NO, IMPORTANT_FOR_ACCESSIBILITY_YES, INVISIBLE, KEEP_SCREEN_ON, LAYER_TYPE_HARDWARE, LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, NO_ID, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCREEN_STATE_OFF, SCREEN_STATE_ON, SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT, SCROLLBAR_POSITION_RIGHT, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SOUND_EFFECTS_ENABLED, STATUS_BAR_HIDDEN, STATUS_BAR_VISIBLE, SYSTEM_UI_FLAG_FULLSCREEN, SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LOW_PROFILE, SYSTEM_UI_FLAG_VISIBLE, SYSTEM_UI_LAYOUT_FLAGS, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_VIEW_END, TEXT_ALIGNMENT_VIEW_START, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TRANSLATION_X, TRANSLATION_Y, VISIBLE, X, Y
 
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 android.widget.AdapterView
addView, addView, addView, addView, dispatchPopulateAccessibilityEvent, getCount, getEmptyView, getFirstVisiblePosition, getItemAtPosition, getItemIdAtPosition, getLastVisiblePosition, getOnItemClickListener, getOnItemLongClickListener, getOnItemSelectedListener, getPositionForView, getSelectedItem, getSelectedItemId, getSelectedItemPosition, onInitializeAccessibilityEvent, onInitializeAccessibilityNodeInfo, onRequestSendAccessibilityEvent, performItemClick, removeAllViews, removeView, removeViewAt, setEmptyView, setFocusable, setFocusableInTouchMode, setOnClickListener, setOnItemClickListener, setOnItemLongClickListener, setOnItemSelectedListener
 
Methods inherited from class android.view.ViewGroup
addChildrenForAccessibility, addFocusables, addStatesFromChildren, addTouchables, addView, bringChildToFront, childDrawableStateChanged, clearChildFocus, clearDisappearingChildren, clearFocus, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchSetActivated, dispatchSetSelected, dispatchSystemUiVisibilityChanged, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchWindowFocusChanged, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, endViewTransition, findFocus, findViewsWithText, focusableViewAvailable, focusSearch, gatherTransparentRegion, getChildAt, getChildCount, getChildMeasureSpec, getChildVisibleRect, getClipChildren, getDescendantFocusability, getFocusedChild, getLayoutAnimation, getLayoutAnimationListener, getLayoutMode, getLayoutTransition, getOverlay, getPersistentDrawingCache, hasFocus, hasFocusable, indexOfChild, invalidateChild, invalidateChildInParent, isAlwaysDrawnWithCacheEnabled, isAnimationCacheEnabled, isMotionEventSplittingEnabled, jumpDrawablesToCurrentState, layout, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, onInterceptHoverEvent, onInterceptTouchEvent, recomputeViewAttributes, removeAllViewsInLayout, removeViewInLayout, removeViews, removeViewsInLayout, requestChildFocus, requestChildRectangleOnScreen, requestDisallowInterceptTouchEvent, requestFocus, requestSendAccessibilityEvent, requestTransparentRegion, scheduleLayoutAnimation, setAddStatesFromChildren, setAlwaysDrawnWithCacheEnabled, setAnimationCacheEnabled, setClipChildren, setClipToPadding, setDescendantFocusability, setLayoutAnimation, setLayoutAnimationListener, setLayoutMode, setLayoutTransition, setMotionEventSplittingEnabled, setOnHierarchyChangeListener, setPersistentDrawingCache, shouldDelayChildPressedState, showContextMenuForChild, startActionModeForChild, startLayoutAnimation, startViewTransition, updateViewLayout
 
Methods inherited from class android.view.View
addFocusables, addOnAttachStateChangeListener, addOnLayoutChangeListener, animate, announceForAccessibility, bringToFront, buildDrawingCache, buildDrawingCache, buildLayer, callOnClick, cancelLongPress, canScrollHorizontally, canScrollVertically, checkInputConnectionProxy, clearAnimation, combineMeasuredStates, computeScroll, createAccessibilityNodeInfo, createContextMenu, destroyDrawingCache, dispatchGenericMotionEvent, draw, findViewById, findViewWithTag, focusSearch, forceLayout, generateViewId, getAccessibilityNodeProvider, getAlpha, getAnimation, getApplicationWindowToken, getBackground, getBaseline, getBottom, getCameraDistance, getClipBounds, getContentDescription, getContext, getDefaultSize, getDisplay, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getId, getImportantForAccessibility, getKeepScreenOn, getKeyDispatcherState, getLabelFor, getLayerType, getLayoutDirection, getLayoutParams, getLeft, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, getResources, getRight, getRootView, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSystemUiVisibility, getTag, getTag, getTextAlignment, getTextDirection, getTop, getTouchables, getTouchDelegate, getTranslationX, getTranslationY, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowId, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, hasOnClickListeners, hasOverlappingRendering, hasTransientState, hasWindowFocus, inflate, invalidate, invalidate, invalidate, invalidateDrawable, isActivated, isClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isInEditMode, isInLayout, isInTouchMode, isLayoutRequested, isLongClickable, isOpaque, isPaddingRelative, isPressed, isSaveEnabled, isSaveFromParentEnabled, isScrollbarFadingEnabled, isScrollContainer, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, measure, offsetLeftAndRight, offsetTopAndBottom, onCheckIsTextEditor, onCreateInputConnection, onDragEvent, onFilterTouchEventForSecurity, onFinishTemporaryDetach, onGenericMotionEvent, onHoverChanged, onHoverEvent, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onPopulateAccessibilityEvent, onRtlPropertiesChanged, onScreenStateChanged, onStartTemporaryDetach, onTouchEvent, onTrackballEvent, onWindowFocusChanged, onWindowSystemUiVisibilityChanged, performAccessibilityAction, performClick, performHapticFeedback, performHapticFeedback, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, postInvalidateOnAnimation, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, refreshDrawableState, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestFitSystemWindows, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resolveSize, resolveSizeAndState, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAccessibilityDelegate, setActivated, setAlpha, setAnimation, setBackground, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBottom, setCameraDistance, setClickable, setClipBounds, setContentDescription, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHovered, setId, setImportantForAccessibility, setKeepScreenOn, setLabelFor, setLayerPaint, setLayerType, setLayoutDirection, setLayoutParams, setLeft, setLongClickable, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOverScrollMode, setPadding, setPaddingRelative, setPivotX, setPivotY, setPressed, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollContainer, setScrollX, setScrollY, setSelected, setSoundEffectsEnabled, setSystemUiVisibility, setTag, setTag, setTextAlignment, setTextDirection, setTop, setTouchDelegate, setTranslationX, setTranslationY, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, showContextMenu, startActionMode, startAnimation, startDrag, toString, unscheduleDrawable, unscheduleDrawable, willNotCacheDrawing, willNotDraw
 
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

SwipesView

public SwipesView(Context context)
Constructs the Swipes View, but just in Java source code.

Parameters:
context - The activity context use for creation.

SwipesView

public SwipesView(Context context,
                  AttributeSet attrs)
Constructs the Swipes View in Java source code or Android XML.

Parameters:
context - The activity context use for creation.
attrs - The attribute set typically used in android xml.

SwipesView

public SwipesView(Context context,
                  AttributeSet attrs,
                  int defStyle)
Constructs the Swipes View in Java source code or Android XML.

Parameters:
context - The activity context use for creation.
attrs - The attribute set typically used in android xml.
defStyle - The android style definition id.
Method Detail

addSwipesListener

public static void addSwipesListener(SwipesView.OnSwipeListener mListener)
The collection setter for Swipe Listener changes.

This method (and the related collection) allows for multiple listeners for the OnSwipeListener


setAllowedDirections

public 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.

Java Usage Example:
 mSwipesView.setAllowedDirections(Directions.RIGHT, Directions.DOWN ...) 
XML Usage Example:
  <com.operators.swipes.SwipesView
        ...
        swipes:directions="right|down" />
 

See Also:
SwipesView.Directions

setSwipeRotation

public 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.

XML Usage Example:
  <com.operators.swipes.SwipesView
        ...
        swipes:swipe_rotation="17.5" />
 

See Also:
getRotation()

setMaxVisibleCards

public 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.

XML Usage Example:
  <com.operators.swipes.SwipesView
        ...
        swipes:max_visible_cards="7" />
 

See Also:
mMaxVisibleCards

setSelection

public void setSelection(int position)
Overrides parent implementation of setSelection.

Specified by:
setSelection in class AdapterView<SwipesAdapter>
Parameters:
position - The passed position of the item to be selected.

getSelectedView

public View getSelectedView()
The currently visible view (or card).

Specified by:
getSelectedView in class AdapterView<SwipesAdapter>

getAdapter

public SwipesAdapter getAdapter()
Returns the adapter currently associated with this widget.

Specified by:
getAdapter in class AdapterView<SwipesAdapter>
Returns:
The adapter used to provide this view's content.

setAdapter

public void setAdapter(SwipesAdapter adapter)
Sets the data for the views represented in this widget.
The following is a basic implementation of 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));
  

Specified by:
setAdapter in class AdapterView<SwipesAdapter>
Parameters:
adapter - The adapter used to create this view's content.
See Also:
SwipesAdapter

generateLayoutParams

public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)
Returns the layout params for this widget.

Overrides:
generateLayoutParams in class ViewGroup
Returns:
adapter The layout params for this widget's views.
See Also:
FrameLayout.LayoutParams

getRotation

public float getRotation()
The rotation value that the swipes are limited to.

Overrides:
getRotation in class View

performSwipeLeft

public void performSwipeLeft()
The left swipe callback that performs the swipe operation.


performSwipeDown

public void performSwipeDown()
The down swipe callback that performs the swipe operation.


performSwipeRight

public void performSwipeRight()
The right swipe callback that performs the swipe operation.


performSwipeUp

public void performSwipeUp()
The up swipe callback that performs the swipe operation.


isAllowed

public boolean isAllowed(SwipesView.Directions direction)
Checks whether a swipe direction change is allowed.


onDirectionChange

public void onDirectionChange(SwipesView.Directions direction)
Provides updates on swipe direction changes.


onThresholdChange

public void onThresholdChange(float threshold)
Provides updates on swipe threshold.


onTouch

public static boolean onTouch(MotionEvent event)
This method allows Children Views to pass on touches (or Swipe Actions) to the SwipesView.

An Example call to this method should be used in your Child View's onTouchEvent method like follows:
  public boolean onTouchEvent(MotionEvent event) {
    SwipesView.onTouch(event);
    return super.onTouchEvent(event);
  }