public class GestureController
extends java.lang.Object
implements android.view.View.OnTouchListener
State) based on current
setup (Settings).getSettings().Settings.
This class implements View.OnTouchListener to delegate touches from view to controller.
State can also be manipulated directly with getState(), updateState()
and resetState(). You can also access getStateController() for some additional
stuff.
State can be animated with animateStateTo(State) method.stopFlingAnimation(), stopStateAnimation()
and stopAllAnimations() methods.
All state changes will be passed to OnStateChangeListener.
See addOnStateChangeListener and
removeOnStateChangeListener methods.
Additional touch events can be listened with OnGestureListener and
SimpleOnGestureListener using
setOnGesturesListener method.
State source changes (whether state is being changed by user or by animation) can be
listened with GestureController.OnStateSourceChangeListener using
setOnStateSourceChangeListener(OnStateSourceChangeListener) method.| Modifier and Type | Class and Description |
|---|---|
static interface |
GestureController.OnGestureListener
Listener for different touch events.
|
static interface |
GestureController.OnStateChangeListener
State changes listener.
|
static interface |
GestureController.OnStateSourceChangeListener
State source changes listener.
|
static class |
GestureController.SimpleOnGestureListener
Simple implementation of
GestureController.OnGestureListener. |
static class |
GestureController.StateSource
Source of state changes.
|
| Constructor and Description |
|---|
GestureController(android.view.View view) |
| Modifier and Type | Method and Description |
|---|---|
void |
addOnStateChangeListener(GestureController.OnStateChangeListener listener)
Adds listener for state changes.
|
boolean |
animateKeepInBounds()
Animates to correct position withing bounds.
|
boolean |
animateStateTo(State endState)
Animates current state to provided end state.
|
Settings |
getSettings()
Returns settings that can be updated.
|
State |
getState()
Returns current state.
|
StateController |
getStateController()
Returns state controller that can be used externally.
|
boolean |
isAnimating() |
boolean |
isAnimatingFling() |
boolean |
isAnimatingState() |
protected void |
notifyStateReset() |
protected void |
notifyStateUpdated() |
protected boolean |
onDoubleTapEvent(android.view.MotionEvent event) |
protected boolean |
onDown(android.view.MotionEvent event) |
protected boolean |
onFling(android.view.MotionEvent e1,
android.view.MotionEvent e2,
float vx,
float vy) |
protected void |
onFlingAnimationFinished(boolean forced) |
protected boolean |
onFlingScroll(int dx,
int dy) |
protected void |
onLongPress(android.view.MotionEvent event) |
protected boolean |
onRotate(RotationGestureDetector detector) |
protected boolean |
onRotationBegin(RotationGestureDetector detector) |
protected void |
onRotationEnd(RotationGestureDetector detector) |
protected boolean |
onScale(android.view.ScaleGestureDetector detector) |
protected boolean |
onScaleBegin(android.view.ScaleGestureDetector detector) |
protected void |
onScaleEnd(android.view.ScaleGestureDetector detector) |
protected boolean |
onScroll(android.view.MotionEvent e1,
android.view.MotionEvent e2,
float dx,
float dy) |
protected boolean |
onSingleTapConfirmed(android.view.MotionEvent event) |
protected boolean |
onSingleTapUp(android.view.MotionEvent event) |
protected void |
onStateAnimationFinished(boolean forced) |
boolean |
onTouch(android.view.View view,
android.view.MotionEvent event) |
protected void |
onUpOrCancel(android.view.MotionEvent event) |
void |
removeOnStateChangeListener(GestureController.OnStateChangeListener listener)
Removes listener for state changes.
|
void |
resetState()
Resets to initial state (default position, min zoom level) and notifies
GestureController.OnStateChangeListener listeners. |
void |
setLongPressEnabled(boolean enabled)
Sets whether long press is enabled or not.
|
void |
setOnGesturesListener(GestureController.OnGestureListener listener)
Sets listener for basic touch events.
|
void |
setOnStateSourceChangeListener(GestureController.OnStateSourceChangeListener listener)
Sets listener for state source changes.
|
void |
setPivot(float pivotX,
float pivotY)
Sets pivot point for zooming when keeping image in bounds.
|
protected boolean |
shouldDisallowInterceptTouch(android.view.MotionEvent event) |
void |
stopAllAnimations() |
void |
stopFlingAnimation() |
void |
stopStateAnimation() |
void |
updateState()
Applies state restrictions and notifies
GestureController.OnStateChangeListener listeners. |
public void setOnGesturesListener(GestureController.OnGestureListener listener)
GestureController.OnGestureListenerpublic void setOnStateSourceChangeListener(GestureController.OnStateSourceChangeListener listener)
public void addOnStateChangeListener(GestureController.OnStateChangeListener listener)
GestureController.OnStateChangeListenerpublic void removeOnStateChangeListener(GestureController.OnStateChangeListener listener)
public void setLongPressEnabled(boolean enabled)
public Settings getSettings()
updateState(), resetState() or animateKeepInBounds()
after settings was changed to correctly apply state restrictions.public State getState()
StateController instead.
If current state was changed outside GestureController
you should call updateState() or animateKeepInBounds()
to properly apply changes.public StateController getStateController()
public void updateState()
GestureController.OnStateChangeListener listeners.public void resetState()
GestureController.OnStateChangeListener listeners.
Should be called when image size is changed.
See Settings.setImage(int, int).public void setPivot(float pivotX,
float pivotY)
animateKeepInBounds(),
animateStateTo(State)public boolean animateKeepInBounds()
true if animation started, false otherwise. Animation may
not be started if image already withing bounds.public boolean animateStateTo(State endState)
true if animation started, false otherwise. Animation may
not be started if end state is null or equals to current state (after bounds
restrictions are applied).public boolean isAnimatingState()
public boolean isAnimatingFling()
public boolean isAnimating()
public void stopStateAnimation()
public void stopFlingAnimation()
public void stopAllAnimations()
protected void onStateAnimationFinished(boolean forced)
protected void onFlingAnimationFinished(boolean forced)
protected void notifyStateUpdated()
protected void notifyStateReset()
public boolean onTouch(android.view.View view,
android.view.MotionEvent event)
onTouch in interface android.view.View.OnTouchListenerprotected boolean shouldDisallowInterceptTouch(android.view.MotionEvent event)
protected boolean onDown(android.view.MotionEvent event)
protected void onUpOrCancel(android.view.MotionEvent event)
protected boolean onSingleTapUp(android.view.MotionEvent event)
protected void onLongPress(android.view.MotionEvent event)
protected boolean onScroll(android.view.MotionEvent e1,
android.view.MotionEvent e2,
float dx,
float dy)
protected boolean onFling(android.view.MotionEvent e1,
android.view.MotionEvent e2,
float vx,
float vy)
protected boolean onFlingScroll(int dx,
int dy)
protected boolean onSingleTapConfirmed(android.view.MotionEvent event)
protected boolean onDoubleTapEvent(android.view.MotionEvent event)
protected boolean onScaleBegin(android.view.ScaleGestureDetector detector)
protected boolean onScale(android.view.ScaleGestureDetector detector)
protected void onScaleEnd(android.view.ScaleGestureDetector detector)
protected boolean onRotationBegin(RotationGestureDetector detector)
protected boolean onRotate(RotationGestureDetector detector)
protected void onRotationEnd(RotationGestureDetector detector)