public abstract class OverScrollBounceEffectDecoratorBase extends java.lang.Object implements IOverScrollDecor, android.view.View.OnTouchListener
IOverScrollDecoratorAdapter implementation exists / can be written
for that view type (e.g. RecyclerViewOverScrollDecorAdapter).
Design-wise, being a standalone class, this decorator powerfully provides the ability to add the over-scroll effect over any view without adjusting the view's implementation. In essence, this eliminates the need to repeatedly implement the effect per each view type (list-view, recycler-view, image-view, etc.). Therefore, using it is highly recommended compared to other more intrusive solutions.
Note that this class is abstract, having HorizontalOverScrollBounceEffectDecorator and
VerticalOverScrollBounceEffectDecorator providing concrete implementations that are
view-orientation specific.
At it's core, the class simply registers itself as a touch-listener over the decorated view and intercepts touch events as needed.
Internally, it delegates the over-scrolling calculations onto 3 state-based classes:
| Modifier and Type | Class and Description |
|---|---|
protected static class |
OverScrollBounceEffectDecoratorBase.AnimationAttributes |
protected class |
OverScrollBounceEffectDecoratorBase.BounceBackState
When entered, starts the bounce-back animation.
|
protected static interface |
OverScrollBounceEffectDecoratorBase.IDecoratorState
Interface of decorator-state delegation classes.
|
protected class |
OverScrollBounceEffectDecoratorBase.IdleState
Idle state: monitors move events, trying to figure out whether over-scrolling should be
initiated (i.e.
|
protected static class |
OverScrollBounceEffectDecoratorBase.MotionAttributes
Motion attributes: keeps data describing current motion event.
|
protected class |
OverScrollBounceEffectDecoratorBase.OverScrollingState
Handles the actual over-scrolling: thus translating the view according to configuration
and user interactions, dynamically.
|
protected static class |
OverScrollBounceEffectDecoratorBase.OverScrollStartAttributes |
| Modifier and Type | Field and Description |
|---|---|
static float |
DEFAULT_DECELERATE_FACTOR |
static float |
DEFAULT_TOUCH_DRAG_MOVE_RATIO_BCK |
static float |
DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD |
protected static int |
MAX_BOUNCE_BACK_DURATION_MS |
protected OverScrollBounceEffectDecoratorBase.BounceBackState |
mBounceBackState |
protected OverScrollBounceEffectDecoratorBase.IDecoratorState |
mCurrentState |
protected OverScrollBounceEffectDecoratorBase.IdleState |
mIdleState |
protected static int |
MIN_BOUNCE_BACK_DURATION_MS |
protected OverScrollBounceEffectDecoratorBase.OverScrollingState |
mOverScrollingState |
protected OverScrollBounceEffectDecoratorBase.OverScrollStartAttributes |
mStartAttr |
protected IOverScrollStateListener |
mStateListener |
protected IOverScrollUpdateListener |
mUpdateListener |
protected float |
mVelocity
When in over-scroll mode, keep track of dragging velocity to provide a smooth slow-down
for the bounce-back effect.
|
protected IOverScrollDecoratorAdapter |
mViewAdapter |
static java.lang.String |
TAG |
| Constructor and Description |
|---|
OverScrollBounceEffectDecoratorBase(IOverScrollDecoratorAdapter viewAdapter,
float decelerateFactor,
float touchDragRatioFwd,
float touchDragRatioBck) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
attach() |
protected abstract OverScrollBounceEffectDecoratorBase.AnimationAttributes |
createAnimationAttributes() |
protected abstract OverScrollBounceEffectDecoratorBase.MotionAttributes |
createMotionAttributes() |
void |
detach()
Detach the decorator from its associated view, thus disabling it entirely.
|
int |
getCurrentState()
Get the current decorator's runtime state, i.e.
|
android.view.View |
getView() |
protected void |
issueStateTransition(OverScrollBounceEffectDecoratorBase.IDecoratorState state) |
boolean |
onTouch(android.view.View v,
android.view.MotionEvent event) |
void |
setOverScrollStateListener(IOverScrollStateListener listener) |
void |
setOverScrollUpdateListener(IOverScrollUpdateListener listener) |
protected abstract void |
translateView(android.view.View view,
float offset) |
protected abstract void |
translateViewAndEvent(android.view.View view,
float offset,
android.view.MotionEvent event) |
public static final java.lang.String TAG
public static final float DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD
public static final float DEFAULT_TOUCH_DRAG_MOVE_RATIO_BCK
public static final float DEFAULT_DECELERATE_FACTOR
protected static final int MAX_BOUNCE_BACK_DURATION_MS
protected static final int MIN_BOUNCE_BACK_DURATION_MS
protected final OverScrollBounceEffectDecoratorBase.OverScrollStartAttributes mStartAttr
protected final IOverScrollDecoratorAdapter mViewAdapter
protected final OverScrollBounceEffectDecoratorBase.IdleState mIdleState
protected final OverScrollBounceEffectDecoratorBase.OverScrollingState mOverScrollingState
protected final OverScrollBounceEffectDecoratorBase.BounceBackState mBounceBackState
protected OverScrollBounceEffectDecoratorBase.IDecoratorState mCurrentState
protected IOverScrollStateListener mStateListener
protected IOverScrollUpdateListener mUpdateListener
protected float mVelocity
public OverScrollBounceEffectDecoratorBase(IOverScrollDecoratorAdapter viewAdapter, float decelerateFactor, float touchDragRatioFwd, float touchDragRatioBck)
public boolean onTouch(android.view.View v,
android.view.MotionEvent event)
onTouch in interface android.view.View.OnTouchListenerpublic void setOverScrollStateListener(IOverScrollStateListener listener)
setOverScrollStateListener in interface IOverScrollDecorpublic void setOverScrollUpdateListener(IOverScrollUpdateListener listener)
setOverScrollUpdateListener in interface IOverScrollDecorpublic int getCurrentState()
IOverScrollDecorIOverScrollState.getCurrentState in interface IOverScrollDecorpublic android.view.View getView()
getView in interface IOverScrollDecorprotected void issueStateTransition(OverScrollBounceEffectDecoratorBase.IDecoratorState state)
protected void attach()
public void detach()
IOverScrollDecorIt is best to call this only when over-scroll isn't currently in-effect - i.e. verify that
getCurrentState()==IOverScrollState.STATE_IDLE as a precondition, or otherwise
use a state listener previously installed using
IOverScrollDecor.setOverScrollStateListener(IOverScrollStateListener).
Note: Upon detachment completion, the view in question will return to the default
Android over-scroll configuration (i.e. View.OVER_SCROLL_ALWAYS mode). This can be
overridden by calling View.setOverScrollMode(mode) immediately thereafter.
detach in interface IOverScrollDecorprotected abstract OverScrollBounceEffectDecoratorBase.MotionAttributes createMotionAttributes()
protected abstract OverScrollBounceEffectDecoratorBase.AnimationAttributes createAnimationAttributes()
protected abstract void translateView(android.view.View view,
float offset)
protected abstract void translateViewAndEvent(android.view.View view,
float offset,
android.view.MotionEvent event)