public class ImageMatrixTouchHandler extends MultiTouchListener
The ImageMatrixTouchHandler
enables pinch-zoom, pinch-rotate and dragging on an ImageView
.
Registering an instance of this class to an ImageView
is the only thing you need to do.
Modifier and Type | Field and Description |
---|---|
static int |
DRAG |
static int |
MORPH |
static int |
NONE |
static int |
PINCH |
static java.lang.String |
TAG |
Constructor and Description |
---|
ImageMatrixTouchHandler(android.content.Context context) |
ImageMatrixTouchHandler(android.content.Context context,
ImageMatrixCorrector corrector) |
Modifier and Type | Method and Description |
---|---|
void |
animateZoom(float zoomFactor,
long duration)
Performs a zoom animation using the given
zoomFactor . |
void |
animateZoom(float zoomFactor,
long duration,
float x,
float y)
Performs a zoom animation using the given
zoomFactor and centerpoint coordinates. |
void |
animateZoom(float zoomFactor,
long duration,
float x,
float y,
android.view.animation.Interpolator interpolator)
Performs a zoom animation using the given
zoomFactor and centerpoint coordinates. |
void |
animateZoomOutToFit(long duration)
Performs a zoom out animation so that the image entirely fits within the view.
|
void |
animateZoomOutToFit(long duration,
float x,
float y)
Performs a zoom out animation so that the image entirely fits within the view using centerpoint coordinates.
|
void |
cancelAnimation()
Cancels any running animations.
|
ImageMatrixCorrector |
getImageMatrixCorrector()
Returns the
ImageMatrixCorrector that corrects the image matrix when altered. |
int |
getMode()
Returns the mode the handler is currently in.
|
boolean |
isAnimating()
Indicates whether the image is being animated.
|
boolean |
isDragOnPinchEnabled()
Indicates whether drag-on-pinch is enabled.
|
boolean |
isRotateEnabled()
Indicates whether rotation is enabled.
|
boolean |
isScaleEnabled()
Indicates whether scaling is enabled.
|
boolean |
isTranslateEnabled()
Indicates whether translation is enabled.
|
boolean |
onTouch(android.view.View view,
android.view.MotionEvent event) |
void |
setDoubleTapZoomDuration(long doubleTapZoomDuration)
Sets the double tap zoom animation duration.
|
void |
setDoubleTapZoomFactor(float doubleTapZoomFactor)
Sets the double tap zoom factor.
|
void |
setDoubleTapZoomOutFactor(float doubleTapZoomOutFactor)
Sets the minimum scale factor when double tapping zooms back out instead of in.
|
void |
setDragOnPinchEnabled(boolean dragOnPinchEnabled)
Sets whether drag-on-pinch is enabled.
|
void |
setFlingDuration(long flingDuration)
Sets the fling animation duration.
|
void |
setFlingExaggeration(float flingExaggeration)
Sets the fling animation exaggeration factor.
|
void |
setPinchVelocityWindow(long pinchVelocityWindow)
Sets the pinch velocity window in milliseconds for determining the pinch velocity.
|
void |
setRotateEnabled(boolean rotateEnabled)
Sets whether rotation is enabled.
|
void |
setScaleEnabled(boolean scaleEnabled)
Sets whether scaling is enabled.
|
void |
setTranslateEnabled(boolean translateEnabled)
Sets whether translation is enabled.
|
void |
setZoomReleaseDuration(long zoomReleaseDuration)
Sets the zoom release animation duration.
|
void |
setZoomReleaseExaggeration(float zoomReleaseExaggeration)
Sets the zoom release animation exaggeration factor.
|
void |
updateTouchState()
Updates the touch state during a touch event.
|
angle, getId, getIdArray, getStartPoint, getTouchCount, isTouching, midPoint, midPoint, pinchVelocity, point, spacing, startedLower, updateStartPoints
public static final int NONE
public static final int DRAG
public static final int PINCH
public static final int MORPH
public static final java.lang.String TAG
public ImageMatrixTouchHandler(android.content.Context context)
public ImageMatrixTouchHandler(android.content.Context context, ImageMatrixCorrector corrector)
public int getMode()
Returns the mode the handler is currently in.
public ImageMatrixCorrector getImageMatrixCorrector()
Returns the ImageMatrixCorrector
that corrects the image matrix when altered.
public void updateTouchState()
Updates the touch state during a touch event. That is, when touch mode is not NONE
.
Use this when the image in the ImageView
or its matrix has been changed.
public boolean isRotateEnabled()
Indicates whether rotation is enabled.
public void setRotateEnabled(boolean rotateEnabled)
Sets whether rotation is enabled.
rotateEnabled
- public boolean isScaleEnabled()
Indicates whether scaling is enabled.
public void setScaleEnabled(boolean scaleEnabled)
Sets whether scaling is enabled.
scaleEnabled
- public boolean isTranslateEnabled()
Indicates whether translation is enabled.
public void setTranslateEnabled(boolean translateEnabled)
Sets whether translation is enabled.
translateEnabled
- public boolean isDragOnPinchEnabled()
Indicates whether drag-on-pinch is enabled.
public void setDragOnPinchEnabled(boolean dragOnPinchEnabled)
Sets whether drag-on-pinch is enabled.
dragOnPinchEnabled
- public void setPinchVelocityWindow(long pinchVelocityWindow)
Sets the pinch velocity window in milliseconds for determining the pinch velocity.
Note: Only touch events in this temporal window are used to calculate pinch velocity.
pinchVelocityWindow
- public void setDoubleTapZoomDuration(long doubleTapZoomDuration)
Sets the double tap zoom animation duration. Setting the duration to 0
disables the animation altogether.
doubleTapZoomDuration
- public void setFlingDuration(long flingDuration)
Sets the fling animation duration. Setting the duration to 0
disables the animation altogether.
flingDuration
- public void setZoomReleaseDuration(long zoomReleaseDuration)
Sets the zoom release animation duration. Setting the duration to 0
disables the animation altogether.
zoomReleaseDuration
- public void setDoubleTapZoomFactor(float doubleTapZoomFactor)
Sets the double tap zoom factor.
doubleTapZoomFactor
- public void setDoubleTapZoomOutFactor(float doubleTapZoomOutFactor)
Sets the minimum scale factor when double tapping zooms back out instead of in.
doubleTapZoomOutFactor
- public void setFlingExaggeration(float flingExaggeration)
Sets the fling animation exaggeration factor.
flingExaggeration
- public void setZoomReleaseExaggeration(float zoomReleaseExaggeration)
Sets the zoom release animation exaggeration factor.
zoomReleaseExaggeration
- public boolean isAnimating()
Indicates whether the image is being animated.
public void cancelAnimation()
Cancels any running animations.
public boolean onTouch(android.view.View view, android.view.MotionEvent event)
onTouch
in interface android.view.View.OnTouchListener
onTouch
in class MultiTouchListener
public void animateZoom(float zoomFactor, long duration)
Performs a zoom animation using the given zoomFactor
.
zoomFactor
- duration
- public void animateZoom(float zoomFactor, long duration, float x, float y)
Performs a zoom animation using the given zoomFactor
and centerpoint coordinates.
zoomFactor
- duration
- x
- y
- public void animateZoom(float zoomFactor, long duration, float x, float y, android.view.animation.Interpolator interpolator)
Performs a zoom animation using the given zoomFactor
and centerpoint coordinates.
zoomFactor
- duration
- x
- y
- interpolator
- public void animateZoomOutToFit(long duration)
Performs a zoom out animation so that the image entirely fits within the view.
duration
- public void animateZoomOutToFit(long duration, float x, float y)
Performs a zoom out animation so that the image entirely fits within the view using centerpoint coordinates.
duration
- x
- y
-