open class ZoomEngine : ZoomApi
A low level class that listens to touch events and posts zoom and pan updates. The most useful output is a Matrix that can be used to do pretty much everything, from canvas drawing to View hierarchies translations.
Users are required to:
interface Listener
An interface to listen for updates in the inner matrix. This will be called typically on animation frames. |
|
abstract class SimpleListener : Listener
A simple implementation of Listener that will extract the translation and scale values from the output matrix. |
ZoomEngine(context: Context, container: View)
Constructs an helper instance. ZoomEngine(context: Context, container: View, listener: Listener)
Constructs an helper instance. Deprecated: use addListener to add a listener. |
val containerHeight: Float
Returns the container height as passed to setContainerSize. |
|
val containerWidth: Float
Returns the container width as passed to setContainerSize. |
|
val contentHeight: Float
Returns the content height as passed to setContentSize. |
|
val contentWidth: Float
Returns the content width as passed to setContentSize. |
|
val matrix: Matrix
Returns the current matrix. This can be changed from the outside, but is not guaranteed to remain stable. |
|
open val pan: AbsolutePoint
The current pan as an AbsolutePoint. |
|
open val panX: Float
Returns the current horizontal pan value, in content absolute coordinates (that is, as if there was no zoom at all). |
|
open val panY: Float
Returns the current vertical pan value, in content absolute coordinates (that is, as if there was no zoom at all). |
|
open val realZoom: Float
Gets the current zoom value, including the base zoom that was eventually applied during the starting transformation, see setTransformation. This value will match the scaleX - scaleY values you get into the Matrix, and is the actual scale value of the content from its original size. |
|
open val scaledPan: ScaledPoint
The current pan as a ScaledPoint. |
|
open val scaledPanX: Float
Returns the current horizontal pan value, in content scaled coordinates (that is, including the current zoom). |
|
open val scaledPanY: Float
Returns the current vertical pan value, in content scaled coordinates (that is, including the current zoom). |
|
open val zoom: Float
Gets the current zoom value, which can be used as a reference when calling zoomTo or zoomBy. |
fun addListener(listener: Listener): Unit
Registers a new Listener to be notified of matrix updates. |
|
open fun cancelAnimations(): Boolean
Cancels all currently active animations triggered by either API calls with |
|
fun clear(): Unit
Clears the current state, and stops dispatching matrix events until the view is laid out again and ZoomEngine.setContentSize is called. |
|
fun computeHorizontalScrollOffset(): Int
Helper for implementing View.computeHorizontalScrollOffset in custom views. |
|
fun computeHorizontalScrollRange(): Int
Helper for implementing View.computeHorizontalScrollRange in custom views. |
|
fun computeVerticalScrollOffset(): Int
Helper for implementing View.computeVerticalScrollOffset in custom views. |
|
fun computeVerticalScrollRange(): Int
Helper for implementing View.computeVerticalScrollRange in custom views. |
|
open fun moveTo(zoom: Float, x: Float, y: Float, animate: Boolean): Unit
A low level API that can animate both zoom and pan at the same time. Zoom might not be the actual matrix scale, see ZoomApi.zoom and ZoomApi.realZoom. The coordinates are referred to the content size passed in setContentSize so they do not depend on current zoom. |
|
fun onInterceptTouchEvent(ev: MotionEvent): Boolean
This is required when the content is a View that has clickable hierarchies inside. If true is returned, implementors should not pass the call to super. |
|
fun onTouchEvent(ev: MotionEvent): Boolean
Process the given touch event. If true is returned, implementors should not pass the call to super. |
|
open fun panBy(dx: Float, dy: Float, animate: Boolean): Unit
Pans the content by the given quantity in dx-dy values. These are referred to the content size passed in setContentSize, so they do not depend on current zoom. |
|
open fun panTo(x: Float, y: Float, animate: Boolean): Unit
Pans the content until the top-left coordinates match the given x-y values. These are referred to the content size passed in setContentSize, so they do not depend on current zoom. |
|
open fun realZoomTo(realZoom: Float, animate: Boolean): Unit
Animates the actual matrix zoom to the given value. |
|
fun removeListener(listener: Listener): Unit
Removes a previously registered listener. |
|
open fun setAlignment(alignment: Int): Unit
Sets the content alignment. Can be any of the constants defined in Alignment. The content will be aligned and forced to the specified side of the container. Defaults to ZoomApi.ALIGNMENT_DEFAULT. |
|
open fun setAllowFlingInOverscroll(allow: Boolean): Unit
Controls whether fling events are allowed when the view is in an overscrolled state. |
|
open fun setAnimationDuration(duration: Long): Unit
Sets the duration of animations triggered by zoom and pan APIs. Defaults to ZoomEngine.DEFAULT_ANIMATION_DURATION. |
|
fun setContainerSize(width: Float, height: Float, applyTransformation: Boolean = false): Unit
Sets the size of the container view. Normally you don't need to call this because the size is detected from the container passed to the constructor using a global layout listener. |
|
fun fun setContentSize(width: Float, height: Float, applyTransformation: Boolean = false): Unit
Notifies the helper of the content size (be it a child View, a Bitmap, or whatever else). This is needed for the helper to start working. |
|
open fun setFlingEnabled(enabled: Boolean): Unit
Controls whether fling gesture is enabled or not. |
|
open fun setHorizontalPanEnabled(enabled: Boolean): Unit
Controls whether horizontal panning using gestures is enabled. |
|
open fun setMaxZoom(maxZoom: Float, type: Int): Unit
Which is the max zoom that should be allowed. If setOverPinchable is set to true, this can be over-pinched for a brief time. |
|
open fun setMinZoom(minZoom: Float, type: Int): Unit
Which is the min zoom that should be allowed. If setOverPinchable is set to true, this can be over-pinched for a brief time. |
|
open fun setOneFingerScrollEnabled(enabled: Boolean): Unit
Controls whether one finger scroll gesture is enabled or not. |
|
open fun setOverPinchable(overPinchable: Boolean): Unit
Controls whether the content should be overPinchable. If it is, pinch events can change the zoom outside the safe bounds, than return to safe values. |
|
open fun setOverScrollHorizontal(overScroll: Boolean): Unit
Controls whether the content should be over-scrollable horizontally. If it is, drag and fling horizontal events can scroll the content outside the safe area, then return to safe values. |
|
open fun setOverScrollVertical(overScroll: Boolean): Unit
Controls whether the content should be over-scrollable vertically. If it is, drag and fling vertical events can scroll the content outside the safe area, then return to safe values. |
|
open fun setScrollEnabled(enabled: Boolean): Unit
Controls whether scroll gesture is enabled or not. |
|
open fun setThreeFingersScrollEnabled(enabled: Boolean): Unit
Controls whether three fingers scroll gesture is enabled or not. |
|
open fun setTransformation(transformation: Int, gravity: Int): Unit
Sets the base transformation to be applied to the content. Defaults to ZoomApi.TRANSFORMATION_CENTER_INSIDE with Gravity.CENTER, which means that the content will be zoomed so that it fits completely inside the container. |
|
open fun setTwoFingersScrollEnabled(enabled: Boolean): Unit
Controls whether two fingers scroll gesture is enabled or not. |
|
open fun setVerticalPanEnabled(enabled: Boolean): Unit
Controls whether vertical panning using gestures is enabled. |
|
open fun setZoomEnabled(enabled: Boolean): Unit
Controls whether zoom using pinch gesture is enabled or not. |
|
open fun zoomBy(zoomFactor: Float, animate: Boolean): Unit
Applies the given factor to the current zoom. |
|
open fun zoomIn(): Unit
Applies a small, animated zoom-in. Shorthand for zoomBy with factor 1.3. |
|
open fun zoomOut(): Unit
Applies a small, animated zoom-out. Shorthand for zoomBy with factor 0.7. |
|
open fun zoomTo(zoom: Float, animate: Boolean): Unit
Zooms to the given scale. This might not be the actual matrix zoom, see ZoomApi.zoom and ZoomApi.realZoom. |
open fun setTransformation(transformation: Int): Unit
Sets the base transformation to be applied to the content. See setTransformation. |
const val DEFAULT_ANIMATION_DURATION: Long
The default animation duration |