Configuration reference

This documentation was generated with the assistance of AI. Please report any inaccuracies.

Every GestureBitmapView setting, its XML attribute (if any), its default value and its constraints. Defaults come from the constants in GestureBitmapView.Companion and the property initializers.

Properties

Property Type Default Description

bitmap

Bitmap?

null

Bitmap to display; null while an imageSource is set. Setting it resets the transformation; the previously held bitmap is recycled. See also setBitmap(bitmap, resetMatrices) and setDrawable(drawable).

imageSource

ImageSource?

null

Source of the image, decoded by regions. Setting it replaces any bitmap or source and resets the transformation; the previous source is closed, and so is this one when it is replaced. See Large images.

regionDecodingEnabled

Boolean

true

Whether images set through an ImageSource are decoded by regions at several resolutions (true) or whole at full resolution (false). Changing it reconfigures the current image.

hardwareBitmapsEnabled

Boolean

true

Whether decoded images are hardware bitmaps. They are only used when the view is hardware accelerated. Changing it reconfigures the current image.

cachedLevelsMemoryBudget

Long

DEFAULT_CACHED_LEVELS_MEMORY_BUDGET

Bytes for the decoded resolution levels. The default means 4 times the pixels of the view, 4 bytes each; 0 keeps only the preview. Negative values throw IllegalArgumentException.

imageLoadListener

OnImageLoadListener?

null

Notified when the preview and details are decoded, or decoding fails.

imageOverlayDrawer

ImageOverlayDrawer?

null

Draws on top of the image, on a canvas expressed in upright image pixels and clipped to the image.

displayType

DisplayType

FIT_X_CENTER

How the bitmap is initially fitted into the view. Changing it keeps the current on-screen display.

animationDurationMillis

Long

200

Duration of the scale, scroll and rotate-and-translate animations, in milliseconds. Also used to compute the fling distance.

scrollEnabled

Boolean

true

Whether scroll and fling gestures move the bitmap.

twoFingerScrollEnabled

Boolean

true

Whether scrolling can be done with two fingers.

exclusiveTwoFingerScrollEnabled

Boolean

false

When true with scrollEnabled and twoFingerScrollEnabled, scrolling requires two fingers. When true with twoFingerScrollEnabled = false, scrolling requires exactly one finger.

scaleEnabled

Boolean

true

Whether pinch gestures scale the bitmap.

doubleTapEnabled

Boolean

true

Whether a double tap jumps in scale.

rotationEnabled

Boolean

true

Whether two-finger rotation gestures rotate the bitmap.

rotationFlingEnabled

Boolean

true

Whether a rotation gesture that ends while still rotating makes the bitmap keep rotating, decelerating until it stops. Only applies when rotationEnabled is true.

minScale

Float

1.0

Minimum scale, relative to the initial display. Must be greater than 0, otherwise IllegalArgumentException.

maxScale

Float

10.0

Maximum scale, relative to the initial display. Must be greater than 0, otherwise IllegalArgumentException.

scaleFactorJump

Float

3.0

Amount added to the scale on each double tap. Must be at least 1, otherwise IllegalArgumentException.

minScaleMargin

Float

0.1

How far below minScale a pinch can go before bouncing back.

maxScaleMargin

Float

1.0

How far above maxScale a pinch can go before bouncing back.

leftScrollMargin

Float

100.0

Overshoot allowed past the left limit while scrolling, in pixels. Must not be negative, otherwise IllegalArgumentException.

topScrollMargin

Float

100.0

Overshoot allowed past the top limit, in pixels. Must not be negative.

rightScrollMargin

Float

100.0

Overshoot allowed past the right limit, in pixels. Must not be negative.

bottomScrollMargin

Float

100.0

Overshoot allowed past the bottom limit, in pixels. Must not be negative.

scrollTensionEnabled

Boolean

true

Whether dragging past a scroll limit is progressively slowed down, approaching the margin asymptotically, instead of following the finger 1:1 until a hard stop at the margin.

scrollTension

Float

1.0

Amount of tension when scrollTensionEnabled is true: exponent of the resistance factor (1 - overscroll / margin)^scrollTension. 1 is linear, larger values feel stiffer, values between 0 and 1 feel softer and 0 removes tension. Must not be negative, otherwise IllegalArgumentException.

isAntialiasingEnabled

Boolean

true

Whether the bitmap is drawn with antialiasing.

transformationParameters

MetricTransformationParameters

identity

Scale, rotation and translation applied on top of the base transformation. Setting it enforces no limits.

Read-only properties

Property Type Description

transformationMatrix

Matrix

Copy of the matrix form of transformationParameters.

baseTransformationParameters

MetricTransformationParameters

Transformation applied by displayType.

baseTransformationMatrix

Matrix

Copy of the matrix form of baseTransformationParameters.

displayTransformationParameters

MetricTransformationParameters

Overall transformation from bitmap to view coordinates (base and gesture transformations combined).

displayTransformationMatrix

Matrix

Copy of the matrix form of displayTransformationParameters.

displayRect

RectF?

Rectangle occupied by the bitmap in view coordinates, or null when no bitmap is set.

Listener properties

topBoundReachedListener, bottomBoundReachedListener, leftBoundReachedListener, rightBoundReachedListener, minScaleReachedListener, maxScaleReachedListener, scaleAnimationCompletedListener, scrollAnimationCompletedListener, rotateAndTranslateAnimationCompletedListener and doubleTapListener, all null by default. See Listeners. imageLoadListener (OnImageLoadListener: onPreviewLoaded(view), onDetailLoaded(view) and onImageLoadFailed(view, error)) and imageOverlayDrawer (ImageOverlayDrawer.onDrawOverImage(view, canvas)) are also null by default.

Methods

Method Description

setBitmap(bitmap: Bitmap?, resetMatrices: Boolean = true)

Sets the bitmap, recycling the previous one. With resetMatrices = false the current transformation is kept.

setDrawable(drawable: Drawable?)

Sets the bitmap from a drawable at its intrinsic size; bitmap drawables are never scaled up by screen density.

setImageSource(source: ImageSource?, resetMatrices: Boolean = true)

Sets the source of the image, decoded by regions. The view owns the source and closes it when replaced.

setImageResource(resId: Int, resetMatrices: Boolean = true)

Sets a raster drawable resource, decoded by regions. Throws IOException if it cannot be read.

setImageUri(uri: Uri, resetMatrices: Boolean = true)

Sets a content URI, decoded by regions. Throws IOException if it cannot be read.

setImageFile(file: File, resetMatrices: Boolean = true)

Sets a file, decoded by regions. Throws IOException if it cannot be read.

invalidateImage(region: Rect? = null)

Notifies that the image contents changed. region is in upright image pixels, null for the whole image. See Updating image contents.

mapViewToImage(x: Float, y: Float, result: PointF): Boolean

Maps a view point into upright image pixels. Returns false when there is no image or the display matrix cannot be inverted.

resetTransformationParameters()

Cancels animations and resets the gesture transformation, returning to the initial display.

XML attributes

Declared in lib/src/main/res/values/attrs.xml (styleable GestureBitmapView). Use them with the app: namespace (xmlns:app="http://schemas.android.com/apk/res-auto"). Each one sets the property of the same name.

Attribute Format Property / values

app:src

reference

Drawable passed to setDrawable. A raster resource (JPEG, PNG, WebP) is decoded by regions instead (EXIF applied, size of the file in pixels), unless regionDecodingEnabled is false.

app:displayType

enum

none, fit_if_bigger, fit_x_top, fit_x_bottom, fit_x_center, fit_y_left, fit_y_right, fit_y_center, center_crop (see display types).

app:animationDurationMillis

integer

animationDurationMillis

app:rotationEnabled

boolean

rotationEnabled

app:rotationFlingEnabled

boolean

rotationFlingEnabled

app:scaleEnabled

boolean

scaleEnabled

app:scrollEnabled

boolean

scrollEnabled

app:twoFingerScrollEnabled

boolean

twoFingerScrollEnabled

app:exclusiveTwoFingerScrollEnabled

boolean

exclusiveTwoFingerScrollEnabled

app:doubleTapEnabled

boolean

doubleTapEnabled

app:minScale

float

minScale

app:maxScale

float

maxScale

app:scaleFactorJump

float

scaleFactorJump

app:minScaleMargin

float

minScaleMargin

app:maxScaleMargin

float

maxScaleMargin

app:leftScrollMargin

float

leftScrollMargin

app:topScrollMargin

float

topScrollMargin

app:rightScrollMargin

float

rightScrollMargin

app:bottomScrollMargin

float

bottomScrollMargin

app:scrollTensionEnabled

boolean

scrollTensionEnabled

app:scrollTension

float

scrollTension

app:regionDecodingEnabled

boolean

regionDecodingEnabled

app:hardwareBitmapsEnabled

boolean

hardwareBitmapsEnabled

app:cachedLevelsMemoryBudget

integer

cachedLevelsMemoryBudget

bitmap (other than through app:src), imageSource, isAntialiasingEnabled, transformationParameters, the listeners and imageOverlayDrawer can only be set from code.

Default constants

GestureBitmapView exposes its defaults as public constants in its companion object:

Constant Value

DEFAULT_ANIMATION_DURATION_MILLIS

200L

DEFAULT_MIN_SCALE

1.0f

DEFAULT_MAX_SCALE

10.0f

DEFAULT_SCALE_FACTOR_JUMP

3.0f

DEFAULT_MIN_SCALE_MARGIN

0.1f

DEFAULT_MAX_SCALE_MARGIN

1.0f

DEFAULT_SCROLL_MARGIN

100.0f

DEFAULT_CACHED_LEVELS_MEMORY_BUDGET

Long.MAX_VALUE (sentinel: 4 times the pixels of the view, 4 bytes each)

MetricTransformationParameters

data class MetricTransformationParameters(var scale: Double = 1.0, var rotationAngle: Double = 0.0, var horizontalTranslation: Double = 0.0, var verticalTranslation: Double = 0.0) : Serializable

rotationAngle is expressed in radians.

Member Description

fromMatrix(matrix, assumePositiveScale = true)

Fills this instance from a Matrix. Throws InvalidMatrixException if the matrix is not a metric transformation. assumePositiveScale resolves the sign ambiguity between scale and a 180-degree rotation.

toMatrix(result: Matrix) / toMatrix(): Matrix

Writes this instance into a matrix, or returns a new one.

MetricTransformationParameters.fromMatrix(matrix, result, assumePositiveScale = true)

Static form writing into result.

MetricTransformationParameters.fromMatrix(matrix, assumePositiveScale = true)

Static form returning a new instance.

MetricTransformationParameters.toMatrix(parameters, result) / toMatrix(parameters)

Static forms of toMatrix.

MetricTransformationParameters.MATRIX_VALUES_LENGTH

9, the number of values in a 3x3 Matrix.

val params = MetricTransformationParameters.fromMatrix(view.displayTransformationMatrix)
val matrix = MetricTransformationParameters(scale = 2.0).toMatrix()

InvalidMatrixException

class InvalidMatrixException : RuntimeException(). Thrown by MetricTransformationParameters.fromMatrix when the matrix has perspective terms, unequal scale on both axes, shear, or a zero homogeneous scale.

Image sources

Type Description

ImageSource

Interface extending Closeable: storedWidth, storedHeight, orientation (EXIF), decodeRegion(region, sampleSize, config, reuse) (worker thread) and contentChanged() (default no-op, called before decoding again after invalidateImage).

RegionDecoderImageSource

Source decoding regions with BitmapRegionDecoder from an opener () → InputStream. Used by the factories below.

ImageSources

Factories fromResource(resources, resId), fromAsset(assets, path), fromFile(file), fromUri(contentResolver, uri) and fromBytes(bytes).

BitmapImageSource

Source backed by a caller-owned bitmap held whole in memory, never recycled by the source. Synchronize on the bitmap while drawing on it.