library / com.otaliastudios.zoom / ZoomApi

ZoomApi

interface ZoomApi

An interface for zoom controls.

Annotations

AbsolutePan

annotation class AbsolutePan

Annotation to indicate an AbsolutePan value.

Alignment

annotation class Alignment

Defines the available alignments

RealZoom

annotation class RealZoom

Annotation to indicate a RealZoom value.

ScaledPan

annotation class ScaledPan

Annotation to indicate a ScaledPan value.

Transformation

annotation class Transformation

Defines the available transformation types

Zoom

annotation class Zoom

Annotation to indicate a zoom value.

ZoomType

annotation class ZoomType

Defines the available zoom types

Properties

pan

abstract val pan: AbsolutePoint

The current pan as an AbsolutePoint.

panX

abstract val panX: Float

Returns the current horizontal pan value, in content absolute coordinates (that is, as if there was no zoom at all).

panY

abstract val panY: Float

Returns the current vertical pan value, in content absolute coordinates (that is, as if there was no zoom at all).

realZoom

abstract val realZoom: Float

Gets the current zoom value, including the base zoom that was eventually applied when initializing to respect the "center inside" policy. This will match the scaleX - scaleY values you get into the Matrix, and is the actual scale value of the content from its original size.

scaledPan

abstract val scaledPan: ScaledPoint

The current pan as a ScaledPoint, that is, taking into account the current zoom. This basically returns the pan value multiplied by the current realZoom.

scaledPanX

abstract val scaledPanX: Float

Returns the current horizontal pan value, in content scaled coordinates (that is, including the current zoom). This is equivalent to panX multiplied by realZoom.

scaledPanY

abstract val scaledPanY: Float

Returns the current vertical pan value, in content scaled coordinates (that is, including the current zoom). This is equivalent to panY multiplied by realZoom.

zoom

abstract val zoom: Float

Gets the current zoom value, which can be used as a reference when calling ZoomApi.zoomTo or ZoomApi.zoomBy.

Functions

cancelAnimations

abstract fun cancelAnimations(): Boolean

Cancels all currently active animations triggered by either API calls with animate = true or touch input flings. If no animation is currently active this is a no-op.

moveTo

abstract 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 so they do not depend on current zoom.

panBy

abstract 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 so they do not depend on current zoom.

panTo

abstract 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 so they do not depend on current zoom.

realZoomTo

abstract fun realZoomTo(realZoom: Float, animate: Boolean): Unit

Animates the actual matrix zoom to the given value.

setAlignment

abstract fun setAlignment(alignment: Int): Unit

Sets the content alignment. Can be any of the constants defined in com.otaliastudios.zoom.Alignment. The content will be aligned and forced to the specified side of the container. Defaults to ALIGNMENT_DEFAULT.

setAllowFlingInOverscroll

abstract fun setAllowFlingInOverscroll(allow: Boolean): Unit

Controls whether fling events are allowed when the view is in an overscrolled state.

setAnimationDuration

abstract fun setAnimationDuration(duration: Long): Unit

Sets the duration of animations triggered by zoom and pan APIs. Defaults to ZoomEngine.DEFAULT_ANIMATION_DURATION.

setFlingEnabled

abstract fun setFlingEnabled(enabled: Boolean): Unit

Controls whether fling gesture is enabled or not.

setHorizontalPanEnabled

abstract fun setHorizontalPanEnabled(enabled: Boolean): Unit

Controls whether horizontal panning using gestures is enabled.

setMaxZoom

abstract fun setMaxZoom(maxZoom: Float, type: Int): Unit

Which is the max zoom that should be allowed. If ZoomApi.setOverPinchable is set to true, this can be over-pinched for a brief time.

setMinZoom

abstract fun setMinZoom(minZoom: Float, type: Int): Unit

Which is the min zoom that should be allowed. If ZoomApi.setOverPinchable is set to true, this can be over-pinched for a brief time.

setOneFingerScrollEnabled

abstract fun setOneFingerScrollEnabled(enabled: Boolean): Unit

Controls whether one finger scroll gesture is enabled or not.

setOverPinchable

abstract 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.

setOverScrollHorizontal

abstract 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.

setOverScrollVertical

abstract 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.

setScrollEnabled

abstract fun setScrollEnabled(enabled: Boolean): Unit

Controls whether scroll gesture is enabled or not.

setThreeFingersScrollEnabled

abstract fun setThreeFingersScrollEnabled(enabled: Boolean): Unit

Controls whether three fingers scroll gesture is enabled or not.

setTransformation

open fun setTransformation(transformation: Int): Unit

Sets the base transformation to be applied to the content. See setTransformation.

abstract fun setTransformation(transformation: Int, gravity: Int): Unit

Sets the base transformation to be applied to the content. Defaults to TRANSFORMATION_CENTER_INSIDE with android.view.Gravity.CENTER, which means that the content will be zoomed so that it fits completely inside the container.

setTwoFingersScrollEnabled

abstract fun setTwoFingersScrollEnabled(enabled: Boolean): Unit

Controls whether two fingers scroll gesture is enabled or not.

setVerticalPanEnabled

abstract fun setVerticalPanEnabled(enabled: Boolean): Unit

Controls whether vertical panning using gestures is enabled.

setZoomEnabled

abstract fun setZoomEnabled(enabled: Boolean): Unit

Controls whether zoom using pinch gesture is enabled or not.

zoomBy

abstract fun zoomBy(zoomFactor: Float, animate: Boolean): Unit

Applies the given factor to the current zoom.

zoomIn

abstract fun zoomIn(): Unit

Applies a small, animated zoom-in.

zoomOut

abstract fun zoomOut(): Unit

Applies a small, animated zoom-out.

zoomTo

abstract 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.

Companion Object Properties

ALIGNMENT_DEFAULT

const val ALIGNMENT_DEFAULT: Int

The default value for setAlignment.

MAX_ZOOM_DEFAULT

const val MAX_ZOOM_DEFAULT: Float

The default setMaxZoom applied by the engine if none is specified.

MAX_ZOOM_DEFAULT_TYPE

const val MAX_ZOOM_DEFAULT_TYPE: Int

The default setMaxZoom type applied by the engine if none is specified.

MIN_ZOOM_DEFAULT

const val MIN_ZOOM_DEFAULT: Float

The default setMinZoom applied by the engine if none is specified.

MIN_ZOOM_DEFAULT_TYPE

const val MIN_ZOOM_DEFAULT_TYPE: Int

The default setMinZoom type applied by the engine if none is specified.

TRANSFORMATION_CENTER_CROP

const val TRANSFORMATION_CENTER_CROP: Int

Constant for ZoomApi.setTransformation. The content will be zoomed so that its smaller side fits exactly inside the container. The larger side will be partially cropped.

TRANSFORMATION_CENTER_INSIDE

const val TRANSFORMATION_CENTER_INSIDE: Int

Constant for ZoomApi.setTransformation. The content will be zoomed so that it fits completely inside the container.

TRANSFORMATION_GRAVITY_AUTO

const val TRANSFORMATION_GRAVITY_AUTO: Int

Constant for ZoomApi.setTransformation gravity. This means that the gravity will be inferred from the alignment or fallback to a reasonable default.

TRANSFORMATION_NONE

const val TRANSFORMATION_NONE: Int

Constant for ZoomApi.setTransformation. No transformation will be applied, which means that both ZoomApi.zoom and ZoomApi.realZoom will return the same value.

TYPE_REAL_ZOOM

const val TYPE_REAL_ZOOM: Int

Flag for zoom constraints and settings. With ZoomApi.TYPE_REAL_ZOOM the constraint is measured over the zoom in ZoomApi.realZoom, which is the actual scale you get in the matrix.

TYPE_ZOOM

const val TYPE_ZOOM: Int

Flag for zoom constraints and settings. With ZoomApi.TYPE_ZOOM the constraint is measured over the zoom in ZoomApi.zoom. This is not the actual matrix scale value.

Inheritors

ZoomEngine

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.

ZoomImageView

open class ZoomImageView : ImageView, ZoomApi

Uses ZoomEngine to allow zooming and pan events to the inner drawable.

ZoomLayout

open class ZoomLayout : FrameLayout, OnGlobalLayoutListener, ZoomApi

Uses ZoomEngine to allow zooming and pan events onto a view hierarchy. The hierarchy must be contained in a single view, added to this layout (like what you do with a ScrollView).

ZoomSurfaceView

open class ZoomSurfaceView : GLSurfaceView, ZoomApi, Renderer

Uses ZoomEngine to allow zooming and pan events onto a GL rendered surface.