Package 

Class SubsamplingScaleImageView

  • All Implemented Interfaces:
    android.graphics.drawable.Drawable.Callback , android.view.KeyEvent.Callback , android.view.accessibility.AccessibilityEventSource

    
    public class SubsamplingScaleImageView
    extends View
                        

    Displays an image subsampled as necessary to avoid loading too much image data into memory. After zooming in, a set of image tiles subsampled at higher resolution are loaded and displayed over the base layer. During pan and zoom, tiles off screen or higher/lower resolution than required are discarded from memory.

    Tiles are no larger than the max supported bitmap size, so with large images tiling may be used even when zoomed out.

    v prefixes - coordinates, translations and distances measured in screen (view) pixels s prefixes - coordinates, translations and distances measured in rotated and cropped source image pixels (scaled) f prefixes - coordinates, translations and distances measured in original unrotated, uncropped source file pixels

    View project on GitHub

    • Method Summary

      Modifier and Type Method Description
      final void setHasBaseLayerTiles(boolean hasBaseLayerTiles) Set if the view should keep base layer titles which are always visible and not recycled if they leave the visible area.
      final void setDebug(boolean debug) Enables visual debugging, showing tile boundaries and sizes.
      final int getOrientation() Returns the orientation setting.
      final void setOrientation(int orientation) Sets the image orientation.
      float getMaxScale() Returns the maximum allowed scale.
      final void setMaxScale(float maxScale) Set the maximum scale allowed.
      final float getMinScale() Returns the minimum allowed scale.
      final void setMinScale(float minScale) Set the minimum scale allowed.
      void setMinimumTileDpi(int minimumTileDpi) By default, image tiles are at least as high resolution as the screen.
      final void setPanLimit(int panLimit) Set the pan limiting style.
      final void setMinimumScaleType(int scaleType) Set the minimum scale type.
      void setExecutor(@NonNull() Executor executor) Provide an Executor to be used for loading images.
      void setEagerLoadingEnabled(boolean eagerLoadingEnabled) Enable or disable eager loading of tiles that appear on screen during gestures or animations,while the gesture or animation is still in progress.
      final void setPanEnabled(boolean panEnabled) Enable or disable pan gesture detection.
      final void setZoomEnabled(boolean zoomEnabled) Enable or disable zoom gesture detection.
      final void setQuickScaleEnabled(boolean quickScaleEnabled) Enable or disable double tap & swipe to zoom.
      final void setDoubleTapZoomScale(float doubleTapZoomScale) Set the scale the image will zoom in to when double tapped.
      final void setDoubleTapZoomStyle(int doubleTapZoomStyle) Set the type of zoom animation to be used for double taps.
      final void setDoubleTapZoomDuration(int durationMs) Set the duration of the double tap zoom animation.
      final float getScale() Returns the current scale value.
      final int getSWidth() Get source width, ignoring orientation.
      final int getSHeight() Get source height, ignoring orientation.
      final void setBitmapDecoderFactory(@NonNull() DecoderFactory<out ImageDecoder> bitmapDecoderFactory) Swap the default bitmap decoder implementation for one of your own.
      final void setRegionDecoderFactory(@NonNull() DecoderFactory<out ImageRegionDecoder> regionDecoderFactory) Swap the default region decoder implementation for one of your own.
      void setOnImageEventListener(SubsamplingScaleImageView.OnImageEventListener onImageEventListener) Add a listener allowing notification of load and error events.
      void setOnStateChangedListener(SubsamplingScaleImageView.OnStateChangedListener onStateChangedListener) Add a listener for pan and zoom events.
      void setOnLongClickListener(View.OnLongClickListener onLongClickListener)
      static Bitmap.Config getPreferredBitmapConfig() Get the current preferred configuration for decoding bitmaps.
      static void setPreferredBitmapConfig(Bitmap.Config preferredBitmapConfig) Set a global preferred bitmap config shared by all view instances and applied to new instancesinitialised after the call is made.
      final void setImage(@NonNull() ImageSource imageSource) Set the image source from a bitmap, resource, asset, file or other URI.
      final void setImage(@NonNull() ImageSource imageSource, ImageViewState state) Set the image source from a bitmap, resource, asset, file or other URI, starting with a given orientationsetting, scale and center.
      final void setImage(@NonNull() ImageSource imageSource, ImageSource previewSource) Set the image source from a bitmap, resource, asset, file or other URI, providing a preview image to bedisplayed until the full size image is loaded.
      final void setImage(@NonNull() ImageSource imageSource, ImageSource previewSource, ImageViewState state) Set the image source from a bitmap, resource, asset, file or other URI, providing a preview image to bedisplayed until the full size image is loaded, starting with a given orientation setting, scale and center.This is the best method to use when you want scale and center to be restored after screen orientation change;it avoids any redundant loading of tiles in the wrong orientation.
      boolean onTouchEvent(@NonNull() MotionEvent event) Handle touch events.
      void setMaxTileSize(int maxPixels) By default the View automatically calculates the optimal tile size.
      void setMaxTileSize(int maxPixelsX, int maxPixelsY) By default the View automatically calculates the optimal tile size.
      void recycle() Releases all resources the view is using and resets the state, nulling any fields that use significant memory.After you have called this method, the view can be re-used by setting a new image.
      void viewToFileRect(Rect vRect, Rect fRect) Converts a rectangle within the view to the corresponding rectangle from the source file, takinginto account the current scale, translation, orientation and clipped region.
      void visibleFileRect(Rect fRect) Find the area of the source file that is currently visible on screen, taking into account thecurrent scale, translation, orientation and clipped region.
      final PointF viewToSourceCoord(PointF vxy) Convert screen coordinate to source coordinate.
      final PointF viewToSourceCoord(float vx, float vy) Convert screen coordinate to source coordinate.
      final PointF viewToSourceCoord(PointF vxy, @NonNull() PointF sTarget) Convert screen coordinate to source coordinate.
      final PointF viewToSourceCoord(float vx, float vy, @NonNull() PointF sTarget) Convert screen coordinate to source coordinate.
      final PointF sourceToViewCoord(PointF sxy) Convert source coordinate to view coordinate.
      final PointF sourceToViewCoord(float sx, float sy) Convert source coordinate to view coordinate.
      final PointF sourceToViewCoord(PointF sxy, @NonNull() PointF vTarget) Convert source coordinate to view coordinate.
      final PointF sourceToViewCoord(float sx, float sy, @NonNull() PointF vTarget) Convert source coordinate to view coordinate.
      final void setRegionDecoderClass(@NonNull() Class<out ImageRegionDecoder> regionDecoderClass) Swap the default region decoder implementation for one of your own.
      final void setBitmapDecoderClass(@NonNull() Class<out ImageDecoder> bitmapDecoderClass) Swap the default bitmap decoder implementation for one of your own.
      final void getPanRemaining(RectF vTarget) Calculate how much further the image can be panned in each direction.
      final void setMinimumDpi(int dpi) This is a screen density aware alternative to setMaxScale; it allows you to express the maximumallowed scale in terms of the minimum pixel density.
      final void setMaximumDpi(int dpi) This is a screen density aware alternative to setMinScale; it allows you to express the minimumallowed scale in terms of the maximum pixel density.
      final PointF getCenter() Returns the source point at the center of the view.
      final void setScaleAndCenter(float scale, @Nullable() PointF sCenter) Externally change the scale and translation of the source image.
      final void resetScaleAndCenter() Fully zoom out and return the image to the middle of the screen.
      final boolean isReady() Call to find whether the view is initialised, has dimensions, and will display an image onthe next draw.
      final boolean isImageLoaded() Call to find whether the main image (base layer tiles where relevant) have been loaded.
      final int getAppliedOrientation() Returns the actual orientation of the image relative to the source file.
      final ImageViewState getState() Get the current state of the view (scale, center, orientation) for restoration after rotate.
      final boolean isZoomEnabled() Returns true if zoom gesture detection is enabled.
      final boolean isQuickScaleEnabled() Returns true if double tap & swipe to zoom is enabled.
      final boolean isPanEnabled() Returns true if pan gesture detection is enabled.
      final void setTileBackgroundColor(int tileBgColor) Set a solid color to render behind tiles, useful for displaying transparent PNGs.
      final void setDoubleTapZoomDpi(int dpi) A density aware alternative to setDoubleTapZoomScale; this allows you to express the scale theimage will zoom in to when double tapped in terms of the image pixel density.
      boolean hasImage() Check if an image has been set.
      SubsamplingScaleImageView.AnimationBuilder animateCenter(PointF sCenter) Creates a panning animation builder, that when started will animate the image to place the given coordinates ofthe image in the center of the screen.
      SubsamplingScaleImageView.AnimationBuilder animateScale(float scale) Creates a scale animation builder, that when started will animate a zoom in or out.
      SubsamplingScaleImageView.AnimationBuilder animateScaleAndCenter(float scale, PointF sCenter) Creates a scale animation builder, that when started will animate a zoom in or out.
      • Methods inherited from class android.view.View

        addChildrenForAccessibility, addExtraDataToAccessibilityNodeInfo, addFocusables, addKeyboardNavigationClusters, addOnAttachStateChangeListener, addOnLayoutChangeListener, addOnUnhandledKeyEventListener, addTouchables, animate, announceForAccessibility, autofill, bringToFront, buildDrawingCache, buildLayer, callOnClick, canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, canScrollHorizontally, canScrollVertically, cancelDragAndDrop, cancelLongPress, cancelPendingInputEvents, checkInputConnectionProxy, clearAnimation, clearFocus, combineMeasuredStates, computeScroll, computeSystemWindowInsets, createAccessibilityNodeInfo, createContextMenu, destroyDrawingCache, dispatchApplyWindowInsets, dispatchCapturedPointerEvent, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchDrawableHotspotChanged, dispatchFinishTemporaryDetach, dispatchGenericMotionEvent, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchNestedFling, dispatchNestedPreFling, dispatchNestedPrePerformAccessibilityAction, dispatchNestedPreScroll, dispatchNestedScroll, dispatchPointerCaptureChanged, dispatchPopulateAccessibilityEvent, dispatchProvideAutofillStructure, dispatchProvideStructure, dispatchStartTemporaryDetach, dispatchSystemUiVisibilityChanged, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchWindowFocusChanged, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, draw, drawableHotspotChanged, findFocus, findViewById, findViewWithTag, findViewsWithText, focusSearch, forceHasOverlappingRendering, forceLayout, generateViewId, getAccessibilityClassName, getAccessibilityDelegate, getAccessibilityLiveRegion, getAccessibilityNodeProvider, getAccessibilityPaneTitle, getAccessibilityTraversalAfter, getAccessibilityTraversalBefore, getAlpha, getAnimation, getAnimationMatrix, getApplicationWindowToken, getAttributeResolutionStack, getAttributeSourceResourceMap, getAutofillHints, getAutofillId, getAutofillType, getAutofillValue, getBackground, getBackgroundTintBlendMode, getBackgroundTintList, getBackgroundTintMode, getBaseline, getBottom, getCameraDistance, getClipBounds, getClipBounds, getClipToOutline, getContentCaptureSession, getContentDescription, getContext, getDefaultFocusHighlightEnabled, getDefaultSize, getDisplay, getDrawableState, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getElevation, getExplicitStyle, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusable, getFocusables, getFocusedRect, getForeground, getForegroundGravity, getForegroundTintBlendMode, getForegroundTintList, getForegroundTintMode, getGlobalVisibleRect, getHandler, getHasOverlappingRendering, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarThumbDrawable, getHorizontalScrollbarTrackDrawable, getId, getImportantForAccessibility, getImportantForAutofill, getKeepScreenOn, getKeyDispatcherState, getLabelFor, getLayerType, getLayoutDirection, getLayoutParams, getLeft, getLocalVisibleRect, getLocationInSurface, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextClusterForwardId, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOutlineAmbientShadowColor, getOutlineProvider, getOutlineSpotShadowColor, getOverScrollMode, getOverlay, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, getPointerIcon, getResources, getRevealOnFocusHint, getRight, getRootView, getRootWindowInsets, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollIndicators, getScrollX, getScrollY, getSolidColor, getSourceLayoutResId, getStateListAnimator, getSystemGestureExclusionRects, getSystemUiVisibility, getTag, getTextAlignment, getTextDirection, getTooltipText, getTop, getTouchDelegate, getTouchables, getTransitionAlpha, getTransitionName, getTranslationX, getTranslationY, getTranslationZ, getUniqueDrawingId, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarThumbDrawable, getVerticalScrollbarTrackDrawable, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowId, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, getZ, hasExplicitFocusable, hasFocus, hasFocusable, hasNestedScrollingParent, hasOnClickListeners, hasOverlappingRendering, hasPointerCapture, hasTransientState, hasWindowFocus, inflate, invalidate, invalidateDrawable, invalidateOutline, isAccessibilityFocused, isAccessibilityHeading, isActivated, isAttachedToWindow, isClickable, isContextClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isFocusedByDefault, isForceDarkAllowed, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isImportantForAccessibility, isImportantForAutofill, isInEditMode, isInLayout, isInTouchMode, isKeyboardNavigationCluster, isLaidOut, isLayoutDirectionResolved, isLayoutRequested, isLongClickable, isNestedScrollingEnabled, isOpaque, isPaddingRelative, isPivotSet, isPressed, isSaveEnabled, isSaveFromParentEnabled, isScreenReaderFocusable, isScrollContainer, isScrollbarFadingEnabled, isSelected, isShown, isSoundEffectsEnabled, isTemporarilyDetached, isTextAlignmentResolved, isTextDirectionResolved, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVisibleToUserForAutofill, jumpDrawablesToCurrentState, keyboardNavigationClusterSearch, layout, measure, offsetLeftAndRight, offsetTopAndBottom, onApplyWindowInsets, onCancelPendingInputEvents, onCapturedPointerEvent, onCheckIsTextEditor, onCreateInputConnection, onDragEvent, onDrawForeground, onFilterTouchEventForSecurity, onFinishTemporaryDetach, onGenericMotionEvent, onHoverChanged, onHoverEvent, onInitializeAccessibilityEvent, onInitializeAccessibilityNodeInfo, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onPointerCaptureChange, onPopulateAccessibilityEvent, onProvideAutofillStructure, onProvideAutofillVirtualStructure, onProvideStructure, onProvideVirtualStructure, onResolvePointerIcon, onRtlPropertiesChanged, onScreenStateChanged, onStartTemporaryDetach, onTouchEvent, onTrackballEvent, onVisibilityAggregated, onWindowFocusChanged, onWindowSystemUiVisibilityChanged, performAccessibilityAction, performClick, performContextClick, performHapticFeedback, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidateDelayed, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, refreshDrawableState, releasePointerCapture, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, removeOnUnhandledKeyEventListener, requestApplyInsets, requestFitSystemWindows, requestFocus, requestFocusFromTouch, requestLayout, requestPointerCapture, requestRectangleOnScreen, requestUnbufferedDispatch, requireViewById, resetPivot, resolveSize, resolveSizeAndState, restoreDefaultFocus, restoreHierarchyState, saveAttributeDataForStyleable, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAccessibilityDelegate, setAccessibilityHeading, setAccessibilityLiveRegion, setAccessibilityPaneTitle, setAccessibilityTraversalAfter, setAccessibilityTraversalBefore, setActivated, setAlpha, setAnimation, setAnimationMatrix, setAutofillHints, setAutofillId, setBackground, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBackgroundTintBlendMode, setBackgroundTintList, setBackgroundTintMode, setBottom, setCameraDistance, setClickable, setClipBounds, setClipToOutline, setContentCaptureSession, setContentDescription, setContextClickable, setDefaultFocusHighlightEnabled, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setElevation, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusableInTouchMode, setFocusedByDefault, setForceDarkAllowed, setForeground, setForegroundGravity, setForegroundTintBlendMode, setForegroundTintList, setForegroundTintMode, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHorizontalScrollbarThumbDrawable, setHorizontalScrollbarTrackDrawable, setHovered, setId, setImportantForAccessibility, setImportantForAutofill, setKeepScreenOn, setKeyboardNavigationCluster, setLabelFor, setLayerPaint, setLayerType, setLayoutDirection, setLayoutParams, setLeft, setLeftTopRightBottom, setLongClickable, setMinimumHeight, setMinimumWidth, setNestedScrollingEnabled, setNextClusterForwardId, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnApplyWindowInsetsListener, setOnCapturedPointerListener, setOnClickListener, setOnContextClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnScrollChangeListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOutlineAmbientShadowColor, setOutlineProvider, setOutlineSpotShadowColor, setOverScrollMode, setPadding, setPaddingRelative, setPivotX, setPivotY, setPointerIcon, setPressed, setRevealOnFocusHint, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScreenReaderFocusable, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollBarSize, setScrollBarStyle, setScrollContainer, setScrollIndicators, setScrollX, setScrollY, setScrollbarFadingEnabled, setSelected, setSoundEffectsEnabled, setStateListAnimator, setSystemGestureExclusionRects, setSystemUiVisibility, setTag, setTextAlignment, setTextDirection, setTooltipText, setTop, setTouchDelegate, setTransitionAlpha, setTransitionName, setTransitionVisibility, setTranslationX, setTranslationY, setTranslationZ, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVerticalScrollbarThumbDrawable, setVerticalScrollbarTrackDrawable, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, setZ, showContextMenu, startActionMode, startAnimation, startDrag, startDragAndDrop, startNestedScroll, stopNestedScroll, toString, transformMatrixToGlobal, transformMatrixToLocal, unscheduleDrawable, updateDragShadow, willNotCacheDrawing, willNotDraw
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SubsamplingScaleImageView

        SubsamplingScaleImageView(Context context)
    • Method Detail

      • setHasBaseLayerTiles

         final void setHasBaseLayerTiles(boolean hasBaseLayerTiles)

        Set if the view should keep base layer titles which are always visible and not recycled if they leave the visible area.

        Parameters:
        hasBaseLayerTiles - Enable or disable base layer rendering
      • setDebug

         final void setDebug(boolean debug)

        Enables visual debugging, showing tile boundaries and sizes.

        Parameters:
        debug - true to enable debugging, false to disable.
      • setOrientation

         final void setOrientation(int orientation)

        Sets the image orientation. It's best to call this before setting the image file or asset, because it may wasteloading of tiles. However, this can be freely called at any time.

        Parameters:
        orientation - orientation to be set.
      • getMaxScale

         float getMaxScale()

        Returns the maximum allowed scale.

      • setMaxScale

         final void setMaxScale(float maxScale)

        Set the maximum scale allowed. A value of 1 means 1:1 pixels at maximum scale. You may wish to set this accordingto screen density - on a retina screen, 1:1 may still be too small. Consider using setMinimumDpi,which is density aware.

        Parameters:
        maxScale - maximum scale expressed as a source/view pixels ratio.
      • getMinScale

         final float getMinScale()

        Returns the minimum allowed scale.

      • setMinScale

         final void setMinScale(float minScale)

        Set the minimum scale allowed. A value of 1 means 1:1 pixels at minimum scale. You may wish to set this accordingto screen density. Consider using setMaximumDpi, which is density aware.

        Parameters:
        minScale - minimum scale expressed as a source/view pixels ratio.
      • setMinimumTileDpi

         void setMinimumTileDpi(int minimumTileDpi)

        By default, image tiles are at least as high resolution as the screen. For a retina screen this may not benecessary, and may increase the likelihood of an OutOfMemoryError. This method sets a DPI at which higherresolution tiles should be loaded. Using a lower number will on average use less memory but result in a lowerquality image. 160-240dpi will usually be enough. This should be called before setting the image source,because it affects which tiles get loaded. When using an untiled source image this method has no effect.

        Parameters:
        minimumTileDpi - Tile loading threshold.
      • setPanLimit

         final void setPanLimit(int panLimit)

        Set the pan limiting style. See static fields. Normally PAN_LIMIT_INSIDE is best, for image galleries.

        Parameters:
        panLimit - a pan limit constant.
      • setMinimumScaleType

         final void setMinimumScaleType(int scaleType)

        Set the minimum scale type. See static fields. Normally SCALE_TYPE_CENTER_INSIDE is best, for image galleries.

        Parameters:
        scaleType - a scale type constant.
      • setExecutor

         void setExecutor(@NonNull() Executor executor)

        Provide an Executor to be used for loading images. By default, THREAD_POOL_EXECUTOR is used to minimise contention with other background work the app is doing. You can also chooseto use SERIAL_EXECUTOR if you want to limit concurrent background tasks.Alternatively you can supply an Executor of your own to avoid any contention. It isstrongly recommended to use a single executor instance for the life of your application, notone per view instance.

        Warning: If you are using a custom implementation of ImageRegionDecoder, and yousupply an executor with more than one thread, you must make sure your implementation supportsmulti-threaded bitmap decoding or has appropriate internal synchronization. From SDK 21, Android's android.graphics.BitmapRegionDecoder uses an internal lock so it is thread safe butthere is no advantage to using multiple threads.

        Parameters:
        executor - an Executor for image loading.
      • setEagerLoadingEnabled

         void setEagerLoadingEnabled(boolean eagerLoadingEnabled)

        Enable or disable eager loading of tiles that appear on screen during gestures or animations,while the gesture or animation is still in progress. By default this is enabled to improveresponsiveness, but it can result in tiles being loaded and discarded more rapidly thannecessary and reduce the animation frame rate on old/cheap devices. Disable this on olderdevices if you see poor performance. Tiles will then be loaded only when gestures and animationsare completed.

        Parameters:
        eagerLoadingEnabled - true to enable loading during gestures, false to delay loading until gestures end
      • setPanEnabled

         final void setPanEnabled(boolean panEnabled)

        Enable or disable pan gesture detection. Disabling pan causes the image to be centered. Pancan still be changed from code.

        Parameters:
        panEnabled - true to enable panning, false to disable.
      • setZoomEnabled

         final void setZoomEnabled(boolean zoomEnabled)

        Enable or disable zoom gesture detection. Disabling zoom locks the the current scale.

        Parameters:
        zoomEnabled - true to enable zoom gestures, false to disable.
      • setQuickScaleEnabled

         final void setQuickScaleEnabled(boolean quickScaleEnabled)

        Enable or disable double tap & swipe to zoom.

        Parameters:
        quickScaleEnabled - true to enable quick scale, false to disable.
      • setDoubleTapZoomScale

         final void setDoubleTapZoomScale(float doubleTapZoomScale)

        Set the scale the image will zoom in to when double tapped. This also the scale point where a double tap is interpretedas a zoom out gesture - if the scale is greater than 90% of this value, a double tap zooms out. Avoid using valuesgreater than the max zoom.

        Parameters:
        doubleTapZoomScale - New value for double tap gesture zoom scale.
      • setDoubleTapZoomStyle

         final void setDoubleTapZoomStyle(int doubleTapZoomStyle)

        Set the type of zoom animation to be used for double taps. See static fields.

        Parameters:
        doubleTapZoomStyle - New value for zoom style.
      • setDoubleTapZoomDuration

         final void setDoubleTapZoomDuration(int durationMs)

        Set the duration of the double tap zoom animation.

        Parameters:
        durationMs - Duration in milliseconds.
      • getScale

         final float getScale()

        Returns the current scale value.

      • setBitmapDecoderFactory

         final void setBitmapDecoderFactory(@NonNull() DecoderFactory<out ImageDecoder> bitmapDecoderFactory)

        Swap the default bitmap decoder implementation for one of your own. You must do this before setting the image file orasset, and you cannot use a custom decoder when using layout XML to set an asset name.

        Parameters:
        bitmapDecoderFactory - The DecoderFactory implementation that produces ImageDecoder instances.
      • setPreferredBitmapConfig

         static void setPreferredBitmapConfig(Bitmap.Config preferredBitmapConfig)

        Set a global preferred bitmap config shared by all view instances and applied to new instancesinitialised after the call is made. This is a hint only; the bundled ImageDecoder and ImageRegionDecoder classes all respect this (except when they were constructed withan instance-specific config) but custom decoder classes will not.

        Parameters:
        preferredBitmapConfig - the bitmap configuration to be used by future instances of the view.
      • setImage

         final void setImage(@NonNull() ImageSource imageSource)

        Set the image source from a bitmap, resource, asset, file or other URI.

        Parameters:
        imageSource - Image source.
      • setImage

         final void setImage(@NonNull() ImageSource imageSource, ImageViewState state)

        Set the image source from a bitmap, resource, asset, file or other URI, starting with a given orientationsetting, scale and center. This is the best method to use when you want scale and center to be restoredafter screen orientation change; it avoids any redundant loading of tiles in the wrong orientation.

        Parameters:
        imageSource - Image source.
        state - State to be restored.
      • setImage

         final void setImage(@NonNull() ImageSource imageSource, ImageSource previewSource)

        Set the image source from a bitmap, resource, asset, file or other URI, providing a preview image to bedisplayed until the full size image is loaded.You must declare the dimensions of the full size image by calling dimensions on the imageSource object. The preview source will be ignored if you don't provide dimensions,and if you provide a bitmap for the full size image.

        Parameters:
        imageSource - Image source.
        previewSource - Optional source for a preview image to be displayed and allow interaction while the full size image loads.
      • setImage

         final void setImage(@NonNull() ImageSource imageSource, ImageSource previewSource, ImageViewState state)

        Set the image source from a bitmap, resource, asset, file or other URI, providing a preview image to bedisplayed until the full size image is loaded, starting with a given orientation setting, scale and center.This is the best method to use when you want scale and center to be restored after screen orientation change;it avoids any redundant loading of tiles in the wrong orientation.You must declare the dimensions of the full size image by calling dimensions on the imageSource object. The preview source will be ignored if you don't provide dimensions,and if you provide a bitmap for the full size image.

        Parameters:
        imageSource - Image source.
        previewSource - Optional source for a preview image to be displayed and allow interaction while the full size image loads.
        state - State to be restored.
      • setMaxTileSize

         void setMaxTileSize(int maxPixels)

        By default the View automatically calculates the optimal tile size. Set this to override this, and force an upper limit to the dimensions of the generated tiles. Passing TILE_SIZE_AUTO will re-enable the default behaviour.

        Parameters:
        maxPixels - Maximum tile size X and Y in pixels.
      • setMaxTileSize

         void setMaxTileSize(int maxPixelsX, int maxPixelsY)

        By default the View automatically calculates the optimal tile size. Set this to override this, and force an upper limit to the dimensions of the generated tiles. Passing TILE_SIZE_AUTO will re-enable the default behaviour.

        Parameters:
        maxPixelsX - Maximum tile width.
        maxPixelsY - Maximum tile height.
      • recycle

         void recycle()

        Releases all resources the view is using and resets the state, nulling any fields that use significant memory.After you have called this method, the view can be re-used by setting a new image. Settings are rememberedbut state (scale and center) is forgotten. You can restore these yourself if required.

      • viewToFileRect

         void viewToFileRect(Rect vRect, Rect fRect)

        Converts a rectangle within the view to the corresponding rectangle from the source file, takinginto account the current scale, translation, orientation and clipped region. This can be usedto decode a bitmap from the source file.This method will only work when the image has fully initialised, after isReady returnstrue. It is not guaranteed to work with preloaded bitmaps.The result is written to the fRect argument. Re-use a single instance for efficiency.

        Parameters:
        vRect - rectangle representing the view area to interpret.
        fRect - rectangle instance to which the result will be written.
      • visibleFileRect

         void visibleFileRect(Rect fRect)

        Find the area of the source file that is currently visible on screen, taking into account thecurrent scale, translation, orientation and clipped region. This is a convenience method; see viewToFileRect.

        Parameters:
        fRect - rectangle instance to which the result will be written.
      • viewToSourceCoord

        @Nullable() final PointF viewToSourceCoord(float vx, float vy)

        Convert screen coordinate to source coordinate.

        Parameters:
        vx - view X coordinate.
        vy - view Y coordinate.
      • viewToSourceCoord

        @Nullable() final PointF viewToSourceCoord(float vx, float vy, @NonNull() PointF sTarget)

        Convert screen coordinate to source coordinate.

        Parameters:
        vx - view X coordinate.
        vy - view Y coordinate.
        sTarget - target object for result.
      • sourceToViewCoord

        @Nullable() final PointF sourceToViewCoord(float sx, float sy)

        Convert source coordinate to view coordinate.

        Parameters:
        sx - source X coordinate.
        sy - source Y coordinate.
      • sourceToViewCoord

        @Nullable() final PointF sourceToViewCoord(float sx, float sy, @NonNull() PointF vTarget)

        Convert source coordinate to view coordinate.

        Parameters:
        sx - source X coordinate.
        sy - source Y coordinate.
        vTarget - target object for result.
      • setRegionDecoderClass

         final void setRegionDecoderClass(@NonNull() Class<out ImageRegionDecoder> regionDecoderClass)

        Swap the default region decoder implementation for one of your own. You must do this before setting the image file orasset, and you cannot use a custom decoder when using layout XML to set an asset name. Your class must have apublic default constructor.

        Parameters:
        regionDecoderClass - The ImageRegionDecoder implementation to use.
      • setBitmapDecoderClass

         final void setBitmapDecoderClass(@NonNull() Class<out ImageDecoder> bitmapDecoderClass)

        Swap the default bitmap decoder implementation for one of your own. You must do this before setting the image file orasset, and you cannot use a custom decoder when using layout XML to set an asset name. Your class must have apublic default constructor.

        Parameters:
        bitmapDecoderClass - The ImageDecoder implementation to use.
      • getPanRemaining

         final void getPanRemaining(RectF vTarget)

        Calculate how much further the image can be panned in each direction. The results are set onthe supplied RectF and expressed as screen pixels. For example, if the image cannot bepanned any further towards the left, the value of left will be set to 0.

        Parameters:
        vTarget - target object for results.
      • setMinimumDpi

         final void setMinimumDpi(int dpi)

        This is a screen density aware alternative to setMaxScale; it allows you to express the maximumallowed scale in terms of the minimum pixel density. This avoids the problem of 1:1 scale still beingtoo small on a high density screen. A sensible starting point is 160 - the default used by this view.

        Parameters:
        dpi - Source image pixel density at maximum zoom.
      • setMaximumDpi

         final void setMaximumDpi(int dpi)

        This is a screen density aware alternative to setMinScale; it allows you to express the minimumallowed scale in terms of the maximum pixel density.

        Parameters:
        dpi - Source image pixel density at minimum zoom.
      • setScaleAndCenter

         final void setScaleAndCenter(float scale, @Nullable() PointF sCenter)

        Externally change the scale and translation of the source image. This may be used with getCenter() and getScale()to restore the scale and zoom after a screen rotate.

        Parameters:
        scale - New scale to set.
        sCenter - New source image coordinate to center on the screen, subject to boundaries.
      • resetScaleAndCenter

         final void resetScaleAndCenter()

        Fully zoom out and return the image to the middle of the screen. This might be useful if you have a view pagerand want images to be reset when the user has moved to another page.

      • isReady

         final boolean isReady()

        Call to find whether the view is initialised, has dimensions, and will display an image onthe next draw. If a preview has been provided, it may be the preview that will be displayedand the full size image may still be loading. If no preview was provided, this is called oncethe base layer tiles of the full size image are loaded.

      • isImageLoaded

         final boolean isImageLoaded()

        Call to find whether the main image (base layer tiles where relevant) have been loaded. Beforethis event the view is blank unless a preview was provided.

      • getAppliedOrientation

         final int getAppliedOrientation()

        Returns the actual orientation of the image relative to the source file. This will be based on the source file'sEXIF orientation if you're using ORIENTATION_USE_EXIF. Values are 0, 90, 180, 270.

      • getState

        @Nullable() final ImageViewState getState()

        Get the current state of the view (scale, center, orientation) for restoration after rotate. Will return null ifthe view is not ready.

      • isZoomEnabled

         final boolean isZoomEnabled()

        Returns true if zoom gesture detection is enabled.

      • isQuickScaleEnabled

         final boolean isQuickScaleEnabled()

        Returns true if double tap & swipe to zoom is enabled.

      • isPanEnabled

         final boolean isPanEnabled()

        Returns true if pan gesture detection is enabled.

      • setTileBackgroundColor

         final void setTileBackgroundColor(int tileBgColor)

        Set a solid color to render behind tiles, useful for displaying transparent PNGs.

        Parameters:
        tileBgColor - Background color for tiles.
      • setDoubleTapZoomDpi

         final void setDoubleTapZoomDpi(int dpi)

        A density aware alternative to setDoubleTapZoomScale; this allows you to express the scale theimage will zoom in to when double tapped in terms of the image pixel density. Values lower than the max scale willbe ignored. A sensible starting point is 160 - the default used by this view.

        Parameters:
        dpi - New value for double tap gesture zoom scale.
      • hasImage

         boolean hasImage()

        Check if an image has been set. The image may not have been loaded and displayed yet.

      • animateCenter

        @Nullable() SubsamplingScaleImageView.AnimationBuilder animateCenter(PointF sCenter)

        Creates a panning animation builder, that when started will animate the image to place the given coordinates ofthe image in the center of the screen. If doing this would move the image beyond the edges of the screen, theimage is instead animated to move the center point as near to the center of the screen as is allowed - it'sguaranteed to be on screen.

        Parameters:
        sCenter - Target center point
      • animateScale

        @Nullable() SubsamplingScaleImageView.AnimationBuilder animateScale(float scale)

        Creates a scale animation builder, that when started will animate a zoom in or out. If this would move the imagebeyond the panning limits, the image is automatically panned during the animation.

        Parameters:
        scale - Target scale.
      • animateScaleAndCenter

        @Nullable() SubsamplingScaleImageView.AnimationBuilder animateScaleAndCenter(float scale, PointF sCenter)

        Creates a scale animation builder, that when started will animate a zoom in or out. If this would move the imagebeyond the panning limits, the image is automatically panned during the animation.

        Parameters:
        scale - Target scale.
        sCenter - Target source center.