uk.co.jasonfry.android.tools.ui
Class SwipeView

java.lang.Object
  extended by android.view.View
      extended by android.view.ViewGroup
          extended by android.widget.FrameLayout
              extended by android.widget.HorizontalScrollView
                  extended by uk.co.jasonfry.android.tools.ui.SwipeView
All Implemented Interfaces:
Drawable.Callback, AccessibilityEventSource, KeyEvent.Callback, ViewManager, ViewParent

public class SwipeView
extends HorizontalScrollView


Nested Class Summary
static interface SwipeView.OnPageChangedListener
          Implement this listener to listen for page change events
 
Nested classes/interfaces inherited from class android.widget.FrameLayout
FrameLayout.LayoutParams
 
Nested classes/interfaces inherited from class android.view.ViewGroup
ViewGroup.MarginLayoutParams, ViewGroup.OnHierarchyChangeListener
 
Nested classes/interfaces inherited from class android.view.View
View.BaseSavedState, View.MeasureSpec, View.OnClickListener, View.OnCreateContextMenuListener, View.OnFocusChangeListener, View.OnKeyListener, View.OnLongClickListener, View.OnTouchListener
 
Field Summary
 
Fields inherited from class android.view.ViewGroup
FOCUS_AFTER_DESCENDANTS, FOCUS_BEFORE_DESCENDANTS, FOCUS_BLOCK_DESCENDANTS, PERSISTENT_ALL_CACHES, PERSISTENT_ANIMATION_CACHE, PERSISTENT_NO_CACHE, PERSISTENT_SCROLLING_CACHE
 
Fields inherited from class android.view.View
DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, GONE, HAPTIC_FEEDBACK_ENABLED, INVISIBLE, KEEP_SCREEN_ON, NO_ID, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SOUND_EFFECTS_ENABLED, VISIBLE
 
Constructor Summary
SwipeView(Context context)
           
SwipeView(Context context, AttributeSet attrs)
           
SwipeView(Context context, AttributeSet attrs, int defStyle)
           
 
Method Summary
 void addView(View child)
           
 void addView(View child, int index)
           
 void addView(View child, int index, ViewGroup.LayoutParams params)
           
 void addView(View child, ViewGroup.LayoutParams params)
           
 int calculatePageSize(ViewGroup.MarginLayoutParams childLayoutParams)
          Set the width of each page by using the layout parameters of a child.
 LinearLayout getChildContainer()
          Get the View object that contains all the children of this SwipeView.
 int getCurrentPage()
          Get the current page the SwipeView is on
 SwipeView.OnPageChangedListener getOnPageChangedListener()
          Get the current OnPageChangeListsner
 PageControl getPageControl()
          Return the current PageControl object
 int getPageCount()
          Return the number of pages in this SwipeView
 int getPageWidth()
          Return the current width of each page
 int getSwipeThreshold()
          Get the swiping threshold distance to make the screens change
 boolean onInterceptTouchEvent(MotionEvent ev)
           
 boolean onTrackballEvent(MotionEvent event)
           
 void scrollToPage(int page)
          Go directly to the specified page
 void setOnPageChangedListener(SwipeView.OnPageChangedListener onPageChangedListener)
          Set the current OnPageChangedListsner
 void setOnTouchListener(View.OnTouchListener onTouchListener)
           
 void setPageControl(PageControl pageControl)
          Assign a PageControl object to this SwipeView.
 int setPageWidth(int pageWidth)
          Set the width of each page.
 void setSwipeThreshold(int swipeThreshold)
          Set the swiping threshold distance to make the screens change
 void smoothScrollToPage(int page)
          Animate a scroll to the specified page
 
Methods inherited from class android.widget.HorizontalScrollView
arrowScroll, computeScroll, dispatchKeyEvent, executeKeyEvent, fling, fullScroll, getMaxScrollAmount, isFillViewport, isSmoothScrollingEnabled, onTouchEvent, pageScroll, requestChildFocus, requestChildRectangleOnScreen, requestLayout, scrollTo, setFillViewport, setSmoothScrollingEnabled, smoothScrollBy, smoothScrollTo
 
Methods inherited from class android.widget.FrameLayout
draw, gatherTransparentRegion, generateLayoutParams, getConsiderGoneChildrenWhenMeasuring, getForeground, setForeground, setForegroundGravity, setMeasureAllChildren
 
Methods inherited from class android.view.ViewGroup
addFocusables, addFocusables, addStatesFromChildren, addTouchables, addView, bringChildToFront, childDrawableStateChanged, clearChildFocus, clearDisappearingChildren, clearFocus, dispatchConfigurationChanged, dispatchDisplayHint, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEvent, dispatchSetSelected, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, findFocus, focusableViewAvailable, focusSearch, getChildAt, getChildCount, getChildMeasureSpec, getChildVisibleRect, getDescendantFocusability, getFocusedChild, getLayoutAnimation, getLayoutAnimationListener, getPersistentDrawingCache, hasFocus, hasFocusable, indexOfChild, invalidateChild, invalidateChildInParent, isAlwaysDrawnWithCacheEnabled, isAnimationCacheEnabled, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, recomputeViewAttributes, removeAllViews, removeAllViewsInLayout, removeView, removeViewAt, removeViewInLayout, removeViews, removeViewsInLayout, requestDisallowInterceptTouchEvent, requestFocus, requestTransparentRegion, scheduleLayoutAnimation, setAddStatesFromChildren, setAlwaysDrawnWithCacheEnabled, setAnimationCacheEnabled, setClipChildren, setClipToPadding, setDescendantFocusability, setLayoutAnimation, setLayoutAnimationListener, setOnHierarchyChangeListener, setPadding, setPersistentDrawingCache, showContextMenuForChild, startLayoutAnimation, updateViewLayout
 
Methods inherited from class android.view.View
bringToFront, buildDrawingCache, buildDrawingCache, cancelLongPress, checkInputConnectionProxy, clearAnimation, createContextMenu, destroyDrawingCache, findViewById, findViewWithTag, focusSearch, forceLayout, getAnimation, getApplicationWindowToken, getBackground, getBaseline, getBottom, getContentDescription, getContext, getDefaultSize, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getId, getKeepScreenOn, getKeyDispatcherState, getLayoutParams, getLeft, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMeasuredHeight, getMeasuredWidth, getNextFocusDownId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getParent, getResources, getRight, getRootView, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getTag, getTag, getTop, getTouchables, getTouchDelegate, getVerticalFadingEdgeLength, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, hasWindowFocus, inflate, invalidate, invalidate, invalidate, invalidateDrawable, isClickable, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHapticFeedbackEnabled, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isInEditMode, isInTouchMode, isLayoutRequested, isLongClickable, isOpaque, isPressed, isSaveEnabled, isScrollbarFadingEnabled, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, layout, measure, offsetLeftAndRight, offsetTopAndBottom, onCheckIsTextEditor, onCreateInputConnection, onFinishTemporaryDetach, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onStartTemporaryDetach, onWindowFocusChanged, performClick, performHapticFeedback, performHapticFeedback, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, refreshDrawableState, removeCallbacks, requestFocus, requestFocus, requestFocusFromTouch, requestRectangleOnScreen, requestRectangleOnScreen, resolveSize, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAnimation, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setClickable, setContentDescription, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFocusable, setFocusableInTouchMode, setHapticFeedbackEnabled, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setId, setKeepScreenOn, setLayoutParams, setLongClickable, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnFocusChangeListener, setOnKeyListener, setOnLongClickListener, setPressed, setSaveEnabled, setScrollbarFadingEnabled, setScrollBarStyle, setScrollContainer, setSelected, setSoundEffectsEnabled, setTag, setTag, setTouchDelegate, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVisibility, setWillNotCacheDrawing, setWillNotDraw, showContextMenu, startAnimation, unscheduleDrawable, unscheduleDrawable, willNotCacheDrawing, willNotDraw
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface android.view.ViewParent
createContextMenu, getParent, isLayoutRequested
 

Constructor Detail

SwipeView

public SwipeView(Context context)

SwipeView

public SwipeView(Context context,
                 AttributeSet attrs)

SwipeView

public SwipeView(Context context,
                 AttributeSet attrs,
                 int defStyle)
Method Detail

onTrackballEvent

public boolean onTrackballEvent(MotionEvent event)
Overrides:
onTrackballEvent in class View

addView

public void addView(View child)
Overrides:
addView in class HorizontalScrollView

addView

public void addView(View child,
                    int index)
Overrides:
addView in class HorizontalScrollView

addView

public void addView(View child,
                    ViewGroup.LayoutParams params)
Specified by:
addView in interface ViewManager
Overrides:
addView in class HorizontalScrollView

addView

public void addView(View child,
                    int index,
                    ViewGroup.LayoutParams params)
Overrides:
addView in class HorizontalScrollView

setOnTouchListener

public void setOnTouchListener(View.OnTouchListener onTouchListener)
Overrides:
setOnTouchListener in class View

getChildContainer

public LinearLayout getChildContainer()
Get the View object that contains all the children of this SwipeView. The same as calling getChildAt(0) A SwipeView behaves slightly differently from a normal ViewGroup, all the children of a SwipeView sit within a LinearLayout, which then sits within the SwipeView object.

Returns:
linearLayout The View object that contains all the children of this view

getSwipeThreshold

public int getSwipeThreshold()
Get the swiping threshold distance to make the screens change

Returns:
swipeThreshold The minimum distance the finger should move to allow the screens to change

setSwipeThreshold

public void setSwipeThreshold(int swipeThreshold)
Set the swiping threshold distance to make the screens change

Parameters:
swipeThreshold - The minimum distance the finger should move to allow the screens to change

getCurrentPage

public int getCurrentPage()
Get the current page the SwipeView is on

Returns:
The current page the SwipeView is on

getPageCount

public int getPageCount()
Return the number of pages in this SwipeView

Returns:
Returns the number of pages in this SwipeView

scrollToPage

public void scrollToPage(int page)
Go directly to the specified page

Parameters:
page - The page to scroll to

smoothScrollToPage

public void smoothScrollToPage(int page)
Animate a scroll to the specified page

Parameters:
page - The page to animate to

setPageWidth

public int setPageWidth(int pageWidth)
Set the width of each page. This function returns an integer that should be added to the left margin of the first child and the right margin of the last child. This enables all the children to appear to be central

Parameters:
pageWidth - The width you wish to assign for each page
Returns:
An integer to add to the left margin of the first child and the right margin of the last child

calculatePageSize

public int calculatePageSize(ViewGroup.MarginLayoutParams childLayoutParams)
Set the width of each page by using the layout parameters of a child. Call this function before you add the child to the SwipeView to maintain the child's size. This function returns an integer that should be added to the left margin of the first child and the right margin of the last child. This enables all the children to appear to be central

Parameters:
childLayoutParams - A child view that you have added / will add to the SwipeView
Returns:
An integer to add to the left margin of the first child and the right margin of the last child

getPageWidth

public int getPageWidth()
Return the current width of each page

Returns:
Returns t¤he width of each page

setPageControl

public void setPageControl(PageControl pageControl)
Assign a PageControl object to this SwipeView. Call after adding all the children

Parameters:
pageControl - The PageControl object to assign

getPageControl

public PageControl getPageControl()
Return the current PageControl object

Returns:
Returns the current PageControl object

setOnPageChangedListener

public void setOnPageChangedListener(SwipeView.OnPageChangedListener onPageChangedListener)
Set the current OnPageChangedListsner

Parameters:
onPageChangedListener - The OnPageChangedListener object

getOnPageChangedListener

public SwipeView.OnPageChangedListener getOnPageChangedListener()
Get the current OnPageChangeListsner

Returns:
The current OnPageChangedListener

onInterceptTouchEvent

public boolean onInterceptTouchEvent(MotionEvent ev)
Overrides:
onInterceptTouchEvent in class HorizontalScrollView