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.
See also 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 the bounds.
|
boolean |
animateStateTo(State endState)
Animates current state to provided end state.
|
Settings |
getSettings()
Returns settings that can be updated.
|
State |
getState()
Current state.
|
StateController |
getStateController() |
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) |
boolean |
onInterceptTouch(android.view.View view,
android.view.MotionEvent event) |
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 boolean |
onTouchInternal(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 |
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(@Nullable
GestureController.OnGestureListener listener)
listener - Gestures listenerGestureController.OnGestureListenerpublic void setOnStateSourceChangeListener(@Nullable
GestureController.OnStateSourceChangeListener listener)
listener - State's source changes listenerGestureController.OnStateSourceChangeListenerpublic void addOnStateChangeListener(@NonNull
GestureController.OnStateChangeListener listener)
listener - State changes listenerGestureController.OnStateChangeListenerpublic void removeOnStateChangeListener(@NonNull
GestureController.OnStateChangeListener listener)
listener - State changes listener to be removedaddOnStateChangeListener(OnStateChangeListener)@NonNull public Settings getSettings()
Note: call updateState(), resetState() or animateKeepInBounds()
after settings was changed to correctly apply state restrictions.
@NonNull public State getState()
If this state is changed from outside you should call
updateState() or animateKeepInBounds()
to properly apply changes.
@NonNull public StateController getStateController()
public void updateState()
GestureController.OnStateChangeListener listeners.public void resetState()
GestureController.OnStateChangeListener listeners.
Should be called when image size is changed.
public void setPivot(float pivotX,
float pivotY)
pivotX - Pivot point's X coordinatepivotY - Pivot point's Y coordinateanimateKeepInBounds(),
animateStateTo(State)public boolean animateKeepInBounds()
true if animation started, false otherwise. Animation may
not be started if image already withing the bounds.public boolean animateStateTo(@Nullable
State endState)
endState - End statetrue 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 onInterceptTouch(@NonNull
android.view.View view,
@NonNull
android.view.MotionEvent event)
public boolean onTouch(@NonNull
android.view.View view,
@NonNull
android.view.MotionEvent event)
onTouch in interface android.view.View.OnTouchListenerprotected boolean onTouchInternal(@NonNull
android.view.View view,
@NonNull
android.view.MotionEvent event)
protected boolean shouldDisallowInterceptTouch(android.view.MotionEvent event)
protected boolean onDown(@NonNull
android.view.MotionEvent event)
protected void onUpOrCancel(@NonNull
android.view.MotionEvent event)
protected boolean onSingleTapUp(@NonNull
android.view.MotionEvent event)
protected void onLongPress(@NonNull
android.view.MotionEvent event)
protected boolean onScroll(@NonNull
android.view.MotionEvent e1,
@NonNull
android.view.MotionEvent e2,
float dx,
float dy)
protected boolean onFling(@NonNull
android.view.MotionEvent e1,
@NonNull
android.view.MotionEvent e2,
float vx,
float vy)
protected boolean onFlingScroll(int dx,
int dy)
dx - Current X offset in the fling scrolldy - Current Y offset in the fling scrollprotected 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)