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
Modifier and Type | Class and Description |
---|---|
class |
SubsamplingScaleImageView.AnimationBuilder
Builder class used to set additional options for a scale animation.
|
static class |
SubsamplingScaleImageView.DefaultOnAnimationEventListener
Default implementation of
SubsamplingScaleImageView.OnAnimationEventListener for extension. |
static class |
SubsamplingScaleImageView.DefaultOnImageEventListener
Default implementation of
SubsamplingScaleImageView.OnImageEventListener for extension. |
static class |
SubsamplingScaleImageView.DefaultOnStateChangedListener
Default implementation of
SubsamplingScaleImageView.OnStateChangedListener . |
static interface |
SubsamplingScaleImageView.OnAnimationEventListener
An event listener for animations, allows events to be triggered when an animation completes,
is aborted by another animation starting, or is aborted by a touch event.
|
static interface |
SubsamplingScaleImageView.OnImageEventListener
An event listener, allowing subclasses and activities to be notified of significant events.
|
static interface |
SubsamplingScaleImageView.OnStateChangedListener
An event listener, allowing activities to be notified of pan and zoom events.
|
View.AccessibilityDelegate, View.BaseSavedState, View.DragShadowBuilder, View.MeasureSpec, View.OnApplyWindowInsetsListener, View.OnAttachStateChangeListener, View.OnCapturedPointerListener, View.OnClickListener, View.OnContextClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnGenericMotionListener, View.OnHoverListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnScrollChangeListener, View.OnSystemUiVisibilityChangeListener, View.OnTouchListener
Modifier and Type | Field and Description |
---|---|
static int |
EASE_IN_OUT_QUAD
Quadratic ease in and out.
|
static int |
EASE_OUT_QUAD
Quadratic ease out.
|
static int |
ORIENTATION_0
Display the image file in its native orientation.
|
static int |
ORIENTATION_180
Rotate the image 180 degrees.
|
static int |
ORIENTATION_270
Rotate the image 270 degrees clockwise.
|
static int |
ORIENTATION_90
Rotate the image 90 degrees clockwise.
|
static int |
ORIENTATION_USE_EXIF
Attempt to use EXIF information on the image to rotate it.
|
static int |
ORIGIN_ANIM
State change originated from animation.
|
static int |
ORIGIN_DOUBLE_TAP_ZOOM
State change originated from a double tap zoom anim.
|
static int |
ORIGIN_FLING
State change originated from a fling momentum anim.
|
static int |
ORIGIN_TOUCH
State change originated from touch gesture.
|
static int |
PAN_LIMIT_CENTER
Allows the image to be panned until a corner reaches the center of the screen but no further.
|
static int |
PAN_LIMIT_INSIDE
Don't allow the image to be panned off screen.
|
static int |
PAN_LIMIT_OUTSIDE
Allows the image to be panned until it is just off screen, but no further.
|
static int |
SCALE_TYPE_CENTER_CROP
Scale the image uniformly so that both dimensions of the image will be equal to or larger than the corresponding dimension of the view.
|
static int |
SCALE_TYPE_CENTER_INSIDE
Scale the image so that both dimensions of the image will be equal to or less than the corresponding dimension of the view.
|
static int |
SCALE_TYPE_CUSTOM
Scale the image so that both dimensions of the image will be equal to or less than the maxScale and equal to or larger than minScale.
|
static int |
SCALE_TYPE_START
Scale the image so that both dimensions of the image will be equal to or larger than the corresponding dimension of the view.
|
static int |
TILE_SIZE_AUTO |
static int |
ZOOM_FOCUS_CENTER
During zoom animation, move the point of the image that was tapped to the center of the screen.
|
static int |
ZOOM_FOCUS_CENTER_IMMEDIATE
Zoom in to and center the tapped point immediately without animating.
|
static int |
ZOOM_FOCUS_FIXED
During zoom animation, keep the point of the image that was tapped in the same place, and scale the image around it.
|
ACCESSIBILITY_LIVE_REGION_ASSERTIVE, ACCESSIBILITY_LIVE_REGION_NONE, ACCESSIBILITY_LIVE_REGION_POLITE, ALPHA, AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS, AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE, AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY, AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH, AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR, AUTOFILL_HINT_CREDIT_CARD_NUMBER, AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE, AUTOFILL_HINT_EMAIL_ADDRESS, AUTOFILL_HINT_NAME, AUTOFILL_HINT_PASSWORD, AUTOFILL_HINT_PHONE, AUTOFILL_HINT_POSTAL_ADDRESS, AUTOFILL_HINT_POSTAL_CODE, AUTOFILL_HINT_USERNAME, AUTOFILL_TYPE_DATE, AUTOFILL_TYPE_LIST, AUTOFILL_TYPE_NONE, AUTOFILL_TYPE_TEXT, AUTOFILL_TYPE_TOGGLE, DRAG_FLAG_GLOBAL, DRAG_FLAG_GLOBAL_PERSISTABLE_URI_PERMISSION, DRAG_FLAG_GLOBAL_PREFIX_URI_PERMISSION, DRAG_FLAG_GLOBAL_URI_READ, DRAG_FLAG_GLOBAL_URI_WRITE, DRAG_FLAG_OPAQUE, DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FIND_VIEWS_WITH_CONTENT_DESCRIPTION, FIND_VIEWS_WITH_TEXT, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLE, FOCUSABLE_AUTO, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, IMPORTANT_FOR_ACCESSIBILITY_AUTO, IMPORTANT_FOR_ACCESSIBILITY_NO, IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS, IMPORTANT_FOR_ACCESSIBILITY_YES, IMPORTANT_FOR_AUTOFILL_AUTO, IMPORTANT_FOR_AUTOFILL_NO, IMPORTANT_FOR_AUTOFILL_NO_EXCLUDE_DESCENDANTS, IMPORTANT_FOR_AUTOFILL_YES, IMPORTANT_FOR_AUTOFILL_YES_EXCLUDE_DESCENDANTS, INVISIBLE, KEEP_SCREEN_ON, LAYER_TYPE_HARDWARE, LAYER_TYPE_NONE, LAYER_TYPE_SOFTWARE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, NO_ID, NOT_FOCUSABLE, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCREEN_STATE_OFF, SCREEN_STATE_ON, SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_NONE, SCROLL_AXIS_VERTICAL, SCROLL_INDICATOR_BOTTOM, SCROLL_INDICATOR_END, SCROLL_INDICATOR_LEFT, SCROLL_INDICATOR_RIGHT, SCROLL_INDICATOR_START, SCROLL_INDICATOR_TOP, SCROLLBAR_POSITION_DEFAULT, SCROLLBAR_POSITION_LEFT, SCROLLBAR_POSITION_RIGHT, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, STATUS_BAR_HIDDEN, STATUS_BAR_VISIBLE, SYSTEM_UI_FLAG_FULLSCREEN, SYSTEM_UI_FLAG_HIDE_NAVIGATION, SYSTEM_UI_FLAG_IMMERSIVE, SYSTEM_UI_FLAG_IMMERSIVE_STICKY, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, SYSTEM_UI_FLAG_LAYOUT_STABLE, SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR, SYSTEM_UI_FLAG_LIGHT_STATUS_BAR, SYSTEM_UI_FLAG_LOW_PROFILE, SYSTEM_UI_FLAG_VISIBLE, SYSTEM_UI_LAYOUT_FLAGS, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_VIEW_END, TEXT_ALIGNMENT_VIEW_START, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_FIRST_STRONG_LTR, TEXT_DIRECTION_FIRST_STRONG_RTL, TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TRANSLATION_X, TRANSLATION_Y, TRANSLATION_Z, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y, Z
Constructor and Description |
---|
SubsamplingScaleImageView(Context context) |
SubsamplingScaleImageView(Context context,
AttributeSet attr) |
Modifier and Type | Method and Description |
---|---|
SubsamplingScaleImageView.AnimationBuilder |
animateCenter(PointF sCenter)
Creates a panning animation builder, that when started will animate the image to place the given coordinates of
the 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.
|
int |
getAppliedOrientation()
Returns the actual orientation of the image relative to the source file.
|
PointF |
getCenter()
Returns the source point at the center of the view.
|
float |
getMaxScale()
Returns the maximum allowed scale.
|
float |
getMinScale()
Returns the minimum allowed scale.
|
int |
getOrientation()
Returns the orientation setting.
|
void |
getPanRemaining(RectF vTarget)
Calculate how much further the image can be panned in each direction.
|
static Bitmap.Config |
getPreferredBitmapConfig()
Get the current preferred configuration for decoding bitmaps.
|
float |
getScale()
Returns the current scale value.
|
int |
getSHeight()
Get source height, ignoring orientation.
|
ImageViewState |
getState()
Get the current state of the view (scale, center, orientation) for restoration after rotate.
|
int |
getSWidth()
Get source width, ignoring orientation.
|
boolean |
hasImage()
Check if an image has been set.
|
boolean |
isImageLoaded()
Call to find whether the main image (base layer tiles where relevant) have been loaded.
|
boolean |
isPanEnabled()
Returns true if pan gesture detection is enabled.
|
boolean |
isQuickScaleEnabled()
Returns true if double tap & swipe to zoom is enabled.
|
boolean |
isReady()
Call to find whether the view is initialised, has dimensions, and will display an image on
the next draw.
|
boolean |
isZoomEnabled()
Returns true if zoom gesture detection is enabled.
|
protected void |
onDraw(Canvas canvas)
Draw method should not be called until the view has dimensions so the first calls are used as triggers to calculate
the scaling and tiling required.
|
protected void |
onImageLoaded()
Called once when the full size image or its base layer tiles have been loaded.
|
protected void |
onMeasure(int widthMeasureSpec,
int heightMeasureSpec)
Measures the width and height of the view, preserving the aspect ratio of the image displayed if wrap_content is
used.
|
protected void |
onReady()
Called once when the view is initialised, has dimensions, and will display an image on the
next draw.
|
protected void |
onSizeChanged(int w,
int h,
int oldw,
int oldh)
On resize, preserve center and scale.
|
boolean |
onTouchEvent(MotionEvent event)
Handle touch events.
|
void |
recycle()
Releases all resources the view is using and resets the state, nulling any fields that use significant memory.
|
void |
resetScaleAndCenter()
Fully zoom out and return the image to the middle of the screen.
|
void |
setBitmapDecoderClass(Class<? extends ImageDecoder> bitmapDecoderClass)
Swap the default bitmap decoder implementation for one of your own.
|
void |
setBitmapDecoderFactory(DecoderFactory<? extends ImageDecoder> bitmapDecoderFactory)
Swap the default bitmap decoder implementation for one of your own.
|
void |
setDebug(boolean debug)
Enables visual debugging, showing tile boundaries and sizes.
|
void |
setDoubleTapZoomDpi(int dpi)
A density aware alternative to
setDoubleTapZoomScale(float) ; this allows you to express the scale the
image will zoom in to when double tapped in terms of the image pixel density. |
void |
setDoubleTapZoomDuration(int durationMs)
Set the duration of the double tap zoom animation.
|
void |
setDoubleTapZoomScale(float doubleTapZoomScale)
Set the scale the image will zoom in to when double tapped.
|
void |
setDoubleTapZoomStyle(int doubleTapZoomStyle)
Set the type of zoom animation to be used for double taps.
|
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.
|
void |
setExecutor(Executor executor)
Provide an
Executor to be used for loading images. |
void |
setImage(ImageSource imageSource)
Set the image source from a bitmap, resource, asset, file or other URI.
|
void |
setImage(ImageSource imageSource,
ImageSource previewSource)
Set the image source from a bitmap, resource, asset, file or other URI, providing a preview image to be
displayed until the full size image is loaded.
|
void |
setImage(ImageSource imageSource,
ImageSource previewSource,
ImageViewState state)
Set the image source from a bitmap, resource, asset, file or other URI, providing a preview image to be
displayed until the full size image is loaded, starting with a given orientation setting, scale and center.
|
void |
setImage(ImageSource imageSource,
ImageViewState state)
Set the image source from a bitmap, resource, asset, file or other URI, starting with a given orientation
setting, scale and center.
|
void |
setMaximumDpi(int dpi)
This is a screen density aware alternative to
setMinScale(float) ; it allows you to express the minimum
allowed scale in terms of the maximum pixel density. |
void |
setMaxScale(float maxScale)
Set the maximum scale allowed.
|
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 |
setMinimumDpi(int dpi)
This is a screen density aware alternative to
setMaxScale(float) ; it allows you to express the maximum
allowed scale in terms of the minimum pixel density. |
void |
setMinimumScaleType(int scaleType)
Set the minimum scale type.
|
void |
setMinimumTileDpi(int minimumTileDpi)
By default, image tiles are at least as high resolution as the screen.
|
void |
setMinScale(float minScale)
Set the minimum scale allowed.
|
void |
setOnImageEventListener(SubsamplingScaleImageView.OnImageEventListener onImageEventListener)
Add a listener allowing notification of load and error events.
|
void |
setOnLongClickListener(View.OnLongClickListener onLongClickListener) |
void |
setOnStateChangedListener(SubsamplingScaleImageView.OnStateChangedListener onStateChangedListener)
Add a listener for pan and zoom events.
|
void |
setOrientation(int orientation)
Sets the image orientation.
|
void |
setPanEnabled(boolean panEnabled)
Enable or disable pan gesture detection.
|
void |
setPanLimit(int panLimit)
Set the pan limiting style.
|
static void |
setPreferredBitmapConfig(Bitmap.Config preferredBitmapConfig)
Set a global preferred bitmap config shared by all view instances and applied to new instances
initialised after the call is made.
|
void |
setQuickScaleEnabled(boolean quickScaleEnabled)
Enable or disable double tap & swipe to zoom.
|
void |
setRegionDecoderClass(Class<? extends ImageRegionDecoder> regionDecoderClass)
Swap the default region decoder implementation for one of your own.
|
void |
setRegionDecoderFactory(DecoderFactory<? extends ImageRegionDecoder> regionDecoderFactory)
Swap the default region decoder implementation for one of your own.
|
void |
setScaleAndCenter(float scale,
PointF sCenter)
Externally change the scale and translation of the source image.
|
void |
setTileBackgroundColor(int tileBgColor)
Set a solid color to render behind tiles, useful for displaying transparent PNGs.
|
void |
setZoomEnabled(boolean zoomEnabled)
Enable or disable zoom gesture detection.
|
PointF |
sourceToViewCoord(float sx,
float sy)
Convert source coordinate to view coordinate.
|
PointF |
sourceToViewCoord(float sx,
float sy,
PointF vTarget)
Convert source coordinate to view coordinate.
|
PointF |
sourceToViewCoord(PointF sxy)
Convert source coordinate to view coordinate.
|
PointF |
sourceToViewCoord(PointF sxy,
PointF vTarget)
Convert source coordinate to view coordinate.
|
void |
viewToFileRect(Rect vRect,
Rect fRect)
Converts a rectangle within the view to the corresponding rectangle from the source file, taking
into account the current scale, translation, orientation and clipped region.
|
PointF |
viewToSourceCoord(float vx,
float vy)
Convert screen coordinate to source coordinate.
|
PointF |
viewToSourceCoord(float vx,
float vy,
PointF sTarget)
Convert screen coordinate to source coordinate.
|
PointF |
viewToSourceCoord(PointF vxy)
Convert screen coordinate to source coordinate.
|
PointF |
viewToSourceCoord(PointF vxy,
PointF sTarget)
Convert screen coordinate to source coordinate.
|
void |
visibleFileRect(Rect fRect)
Find the area of the source file that is currently visible on screen, taking into account the
current scale, translation, orientation and clipped region.
|
addChildrenForAccessibility, addExtraDataToAccessibilityNodeInfo, addFocusables, addFocusables, addKeyboardNavigationClusters, addOnAttachStateChangeListener, addOnLayoutChangeListener, addTouchables, animate, announceForAccessibility, autofill, autofill, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, buildLayer, callOnClick, cancelDragAndDrop, cancelLongPress, cancelPendingInputEvents, canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, canScrollHorizontally, canScrollVertically, checkInputConnectionProxy, clearAnimation, clearFocus, combineMeasuredStates, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeSystemWindowInsets, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createAccessibilityNodeInfo, createContextMenu, destroyDrawingCache, dispatchApplyWindowInsets, dispatchCapturedPointerEvent, dispatchConfigurationChanged, dispatchDisplayHint, dispatchDragEvent, dispatchDraw, dispatchDrawableHotspotChanged, dispatchFinishTemporaryDetach, dispatchGenericFocusedEvent, dispatchGenericMotionEvent, dispatchGenericPointerEvent, dispatchHoverEvent, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchNestedFling, dispatchNestedPreFling, dispatchNestedPrePerformAccessibilityAction, dispatchNestedPreScroll, dispatchNestedScroll, dispatchPointerCaptureChanged, dispatchPopulateAccessibilityEvent, dispatchProvideAutofillStructure, dispatchProvideStructure, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchSystemUiVisibilityChanged, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, draw, drawableHotspotChanged, drawableStateChanged, findFocus, findViewById, findViewsWithText, findViewWithTag, fitSystemWindows, focusSearch, forceHasOverlappingRendering, forceLayout, generateViewId, getAccessibilityClassName, getAccessibilityLiveRegion, getAccessibilityNodeProvider, getAccessibilityTraversalAfter, getAccessibilityTraversalBefore, getAlpha, getAnimation, getApplicationWindowToken, getAutofillHints, getAutofillId, getAutofillType, getAutofillValue, getBackground, getBackgroundTintList, getBackgroundTintMode, getBaseline, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getCameraDistance, getClipBounds, getClipBounds, getClipToOutline, getContentDescription, getContext, getContextMenuInfo, getDefaultFocusHighlightEnabled, getDefaultSize, getDisplay, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getElevation, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusable, getFocusables, getFocusedRect, getForeground, getForegroundGravity, getForegroundTintList, getForegroundTintMode, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHasOverlappingRendering, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getId, getImportantForAccessibility, getImportantForAutofill, getKeepScreenOn, getKeyDispatcherState, getLabelFor, getLayerType, getLayoutDirection, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextClusterForwardId, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOutlineProvider, getOverlay, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getParentForAccessibility, getPivotX, getPivotY, getPointerIcon, getResources, getRevealOnFocusHint, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootView, getRootWindowInsets, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollIndicators, getScrollX, getScrollY, getSolidColor, getStateListAnimator, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getSystemUiVisibility, getTag, getTag, getTextAlignment, getTextDirection, getTooltipText, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchables, getTouchDelegate, getTransitionName, getTranslationX, getTranslationY, getTranslationZ, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowId, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, getZ, hasExplicitFocusable, hasFocus, hasFocusable, hasNestedScrollingParent, hasOnClickListeners, hasOverlappingRendering, hasPointerCapture, hasTransientState, hasWindowFocus, inflate, invalidate, invalidate, invalidate, invalidateDrawable, invalidateOutline, isAccessibilityFocused, isActivated, isAttachedToWindow, isClickable, isContextClickable, isDirty, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isFocusedByDefault, isHapticFeedbackEnabled, isHardwareAccelerated, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isImportantForAccessibility, isImportantForAutofill, isInEditMode, isInLayout, isInTouchMode, isKeyboardNavigationCluster, isLaidOut, isLayoutDirectionResolved, isLayoutRequested, isLongClickable, isNestedScrollingEnabled, isOpaque, isPaddingOffsetRequired, isPaddingRelative, isPressed, isSaveEnabled, isSaveFromParentEnabled, isScrollbarFadingEnabled, isScrollContainer, isSelected, isShown, isSoundEffectsEnabled, isTemporarilyDetached, isTextAlignmentResolved, isTextDirectionResolved, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, jumpDrawablesToCurrentState, keyboardNavigationClusterSearch, layout, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onAnimationEnd, onAnimationStart, onApplyWindowInsets, onAttachedToWindow, onCancelPendingInputEvents, onCapturedPointerEvent, onCheckIsTextEditor, onConfigurationChanged, onCreateContextMenu, onCreateDrawableState, onCreateInputConnection, onDetachedFromWindow, onDisplayHint, onDragEvent, onDrawForeground, onDrawScrollBars, onFilterTouchEventForSecurity, onFinishInflate, onFinishTemporaryDetach, onFocusChanged, onGenericMotionEvent, onHoverChanged, onHoverEvent, onInitializeAccessibilityEvent, onInitializeAccessibilityNodeInfo, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onLayout, onOverScrolled, onPointerCaptureChange, onPopulateAccessibilityEvent, onProvideAutofillStructure, onProvideAutofillVirtualStructure, onProvideStructure, onProvideVirtualStructure, onResolvePointerIcon, onRestoreInstanceState, onRtlPropertiesChanged, onSaveInstanceState, onScreenStateChanged, onScrollChanged, onSetAlpha, onStartTemporaryDetach, onTrackballEvent, onVisibilityAggregated, onVisibilityChanged, onWindowFocusChanged, onWindowSystemUiVisibilityChanged, onWindowVisibilityChanged, overScrollBy, performAccessibilityAction, performClick, performContextClick, performContextClick, performHapticFeedback, performHapticFeedback, performLongClick, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, postInvalidateOnAnimation, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, refreshDrawableState, releasePointerCapture, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestApplyInsets, requestFitSystemWindows, requestFocus, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestPointerCapture, requestRectangleOnScreen, requestRectangleOnScreen, requestUnbufferedDispatch, resolveSize, resolveSizeAndState, restoreDefaultFocus, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAccessibilityDelegate, setAccessibilityLiveRegion, setAccessibilityTraversalAfter, setAccessibilityTraversalBefore, setActivated, setAlpha, setAnimation, setAutofillHints, setBackground, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setBackgroundTintList, setBackgroundTintMode, setBottom, setCameraDistance, setClickable, setClipBounds, setClipToOutline, setContentDescription, setContextClickable, setDefaultFocusHighlightEnabled, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setElevation, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusable, setFocusableInTouchMode, setFocusedByDefault, setForeground, setForegroundGravity, setForegroundTintList, setForegroundTintMode, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHovered, setId, setImportantForAccessibility, setImportantForAutofill, setKeepScreenOn, setKeyboardNavigationCluster, setLabelFor, setLayerPaint, setLayerType, setLayoutDirection, setLayoutParams, setLeft, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNestedScrollingEnabled, setNextClusterForwardId, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnApplyWindowInsetsListener, setOnCapturedPointerListener, setOnClickListener, setOnContextClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnScrollChangeListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOutlineProvider, setOverScrollMode, setPadding, setPaddingRelative, setPivotX, setPivotY, setPointerIcon, setPressed, setRevealOnFocusHint, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollContainer, setScrollIndicators, setScrollIndicators, setScrollX, setScrollY, setSelected, setSoundEffectsEnabled, setStateListAnimator, setSystemUiVisibility, setTag, setTag, setTextAlignment, setTextDirection, setTooltipText, setTop, setTouchDelegate, setTransitionName, setTranslationX, setTranslationY, setTranslationZ, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVisibility, setWillNotCacheDrawing, setWillNotDraw, setX, setY, setZ, showContextMenu, showContextMenu, startActionMode, startActionMode, startAnimation, startDrag, startDragAndDrop, startNestedScroll, stopNestedScroll, toString, unscheduleDrawable, unscheduleDrawable, updateDragShadow, verifyDrawable, willNotCacheDrawing, willNotDraw
public static final int ORIENTATION_USE_EXIF
public static final int ORIENTATION_0
public static final int ORIENTATION_90
public static final int ORIENTATION_180
public static final int ORIENTATION_270
public static final int ZOOM_FOCUS_FIXED
public static final int ZOOM_FOCUS_CENTER
public static final int ZOOM_FOCUS_CENTER_IMMEDIATE
public static final int EASE_OUT_QUAD
public static final int EASE_IN_OUT_QUAD
public static final int PAN_LIMIT_INSIDE
public static final int PAN_LIMIT_OUTSIDE
public static final int PAN_LIMIT_CENTER
public static final int SCALE_TYPE_CENTER_INSIDE
public static final int SCALE_TYPE_CENTER_CROP
public static final int SCALE_TYPE_CUSTOM
public static final int SCALE_TYPE_START
public static final int ORIGIN_ANIM
public static final int ORIGIN_TOUCH
public static final int ORIGIN_FLING
public static final int ORIGIN_DOUBLE_TAP_ZOOM
public static int TILE_SIZE_AUTO
public SubsamplingScaleImageView(Context context, AttributeSet attr)
public SubsamplingScaleImageView(Context context)
public static Bitmap.Config getPreferredBitmapConfig()
ImageDecoder
and ImageRegionDecoder
instances can read this and use it when decoding images.public static void setPreferredBitmapConfig(Bitmap.Config preferredBitmapConfig)
ImageDecoder
and
ImageRegionDecoder
classes all respect this (except when they were constructed with
an instance-specific config) but custom decoder classes will not.preferredBitmapConfig
- the bitmap configuration to be used by future instances of the view. Pass null to restore the default.public final void setOrientation(int orientation)
orientation
- orientation to be set. See ORIENTATION_ static fields for valid values.public final void setImage(ImageSource imageSource)
imageSource
- Image source.public final void setImage(ImageSource imageSource, ImageViewState state)
imageSource
- Image source.state
- State to be restored. Nullable.public final void setImage(ImageSource imageSource, ImageSource previewSource)
ImageSource.dimensions(int, int)
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.imageSource
- Image source. Dimensions must be declared.previewSource
- Optional source for a preview image to be displayed and allow interaction while the full size image loads.public final void setImage(ImageSource imageSource, ImageSource previewSource, ImageViewState state)
ImageSource.dimensions(int, int)
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.imageSource
- Image source. Dimensions must be declared.previewSource
- Optional source for a preview image to be displayed and allow interaction while the full size image loads.state
- State to be restored. Nullable.protected void onSizeChanged(int w, int h, int oldw, int oldh)
onSizeChanged
in class View
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
public boolean onTouchEvent(@NonNull MotionEvent event)
onTouchEvent
in class View
protected void onDraw(Canvas canvas)
public void setMaxTileSize(int maxPixels)
TILE_SIZE_AUTO
will re-enable the default behaviour.maxPixels
- Maximum tile size X and Y in pixels.public void setMaxTileSize(int maxPixelsX, int maxPixelsY)
TILE_SIZE_AUTO
will re-enable the default behaviour.maxPixelsX
- Maximum tile width.maxPixelsY
- Maximum tile height.public void recycle()
public void viewToFileRect(Rect vRect, Rect fRect)
isReady()
returns
true. It is not guaranteed to work with preloaded bitmaps.
The result is written to the fRect argument. Re-use a single instance for efficiency.vRect
- rectangle representing the view area to interpret.fRect
- rectangle instance to which the result will be written. Re-use for efficiency.public void visibleFileRect(Rect fRect)
viewToFileRect(Rect, Rect)
.fRect
- rectangle instance to which the result will be written. Re-use for efficiency.public final PointF viewToSourceCoord(PointF vxy)
vxy
- view X/Y coordinate.public final PointF viewToSourceCoord(float vx, float vy)
vx
- view X coordinate.vy
- view Y coordinate.public final PointF viewToSourceCoord(PointF vxy, PointF sTarget)
vxy
- view coordinates to convert.sTarget
- target object for result. The same instance is also returned.public final PointF viewToSourceCoord(float vx, float vy, PointF sTarget)
vx
- view X coordinate.vy
- view Y coordinate.sTarget
- target object for result. The same instance is also returned.public final PointF sourceToViewCoord(PointF sxy)
sxy
- source coordinates to convert.public final PointF sourceToViewCoord(float sx, float sy)
sx
- source X coordinate.sy
- source Y coordinate.public final PointF sourceToViewCoord(PointF sxy, PointF vTarget)
sxy
- source coordinates to convert.vTarget
- target object for result. The same instance is also returned.public final PointF sourceToViewCoord(float sx, float sy, PointF vTarget)
sx
- source X coordinate.sy
- source Y coordinate.vTarget
- target object for result. The same instance is also returned.public final void setRegionDecoderClass(Class<? extends ImageRegionDecoder> regionDecoderClass)
regionDecoderClass
- The ImageRegionDecoder
implementation to use.public final void setRegionDecoderFactory(DecoderFactory<? extends ImageRegionDecoder> regionDecoderFactory)
regionDecoderFactory
- The DecoderFactory
implementation that produces ImageRegionDecoder
instances.public final void setBitmapDecoderClass(Class<? extends ImageDecoder> bitmapDecoderClass)
bitmapDecoderClass
- The ImageDecoder
implementation to use.public final void setBitmapDecoderFactory(DecoderFactory<? extends ImageDecoder> bitmapDecoderFactory)
bitmapDecoderFactory
- The DecoderFactory
implementation that produces ImageDecoder
instances.public final void getPanRemaining(RectF vTarget)
RectF
and expressed as screen pixels. For example, if the image cannot be
panned any further towards the left, the value of RectF.left
will be set to 0.vTarget
- target object for results. Re-use for efficiency.public final void setPanLimit(int panLimit)
PAN_LIMIT_INSIDE
is best, for image galleries.panLimit
- a pan limit constant. See static fields.public final void setMinimumScaleType(int scaleType)
SCALE_TYPE_CENTER_INSIDE
is best, for image galleries.scaleType
- a scale type constant. See static fields.public final void setMaxScale(float maxScale)
setMinimumDpi(int)
,
which is density aware.maxScale
- maximum scale expressed as a source/view pixels ratio.public final void setMinScale(float minScale)
setMaximumDpi(int)
, which is density aware.minScale
- minimum scale expressed as a source/view pixels ratio.public final void setMinimumDpi(int dpi)
setMaxScale(float)
; it allows you to express the maximum
allowed scale in terms of the minimum pixel density. This avoids the problem of 1:1 scale still being
too small on a high density screen. A sensible starting point is 160 - the default used by this view.dpi
- Source image pixel density at maximum zoom.public final void setMaximumDpi(int dpi)
setMinScale(float)
; it allows you to express the minimum
allowed scale in terms of the maximum pixel density.dpi
- Source image pixel density at minimum zoom.public float getMaxScale()
public final float getMinScale()
public void setMinimumTileDpi(int minimumTileDpi)
minimumTileDpi
- Tile loading threshold.public final PointF getCenter()
public final float getScale()
public final void setScaleAndCenter(float scale, PointF sCenter)
scale
- New scale to set.sCenter
- New source image coordinate to center on the screen, subject to boundaries.public final void resetScaleAndCenter()
public final boolean isReady()
protected void onReady()
SubsamplingScaleImageView.OnImageEventListener.onReady()
but
allows a subclass to receive this event without using a listener.public final boolean isImageLoaded()
protected void onImageLoaded()
public final int getSWidth()
getOrientation()
returns 90 or 270, you can use getSHeight()
for the apparent width.public final int getSHeight()
getOrientation()
returns 90 or 270, you can use getSWidth()
for the apparent height.public final int getOrientation()
ORIENTATION_USE_EXIF
, in which case it doesn't tell you
the applied orientation of the image. For that, use getAppliedOrientation()
.public final int getAppliedOrientation()
public final ImageViewState getState()
ImageViewState
instance representing the current position of the image. null if the view isn't ready.public final boolean isZoomEnabled()
public final void setZoomEnabled(boolean zoomEnabled)
zoomEnabled
- true to enable zoom gestures, false to disable.public final boolean isQuickScaleEnabled()
public final void setQuickScaleEnabled(boolean quickScaleEnabled)
quickScaleEnabled
- true to enable quick scale, false to disable.public final boolean isPanEnabled()
public final void setPanEnabled(boolean panEnabled)
panEnabled
- true to enable panning, false to disable.public final void setTileBackgroundColor(int tileBgColor)
tileBgColor
- Background color for tiles.public final void setDoubleTapZoomScale(float doubleTapZoomScale)
doubleTapZoomScale
- New value for double tap gesture zoom scale.public final void setDoubleTapZoomDpi(int dpi)
setDoubleTapZoomScale(float)
; this allows you to express the scale the
image will zoom in to when double tapped in terms of the image pixel density. Values lower than the max scale will
be ignored. A sensible starting point is 160 - the default used by this view.dpi
- New value for double tap gesture zoom scale.public final void setDoubleTapZoomStyle(int doubleTapZoomStyle)
doubleTapZoomStyle
- New value for zoom style.public final void setDoubleTapZoomDuration(int durationMs)
durationMs
- Duration in milliseconds.public void setExecutor(Executor executor)
Provide an Executor
to be used for loading images. By default, AsyncTask.THREAD_POOL_EXECUTOR
is used to minimise contention with other background work the app is doing. You can also choose
to use AsyncTask.SERIAL_EXECUTOR
if you want to limit concurrent background tasks.
Alternatively you can supply an Executor
of your own to avoid any contention. It is
strongly recommended to use a single executor instance for the life of your application, not
one per view instance.
Warning: If you are using a custom implementation of ImageRegionDecoder
, and you
supply an executor with more than one thread, you must make sure your implementation supports
multi-threaded bitmap decoding or has appropriate internal synchronization. From SDK 21, Android's
BitmapRegionDecoder
uses an internal lock so it is thread safe but
there is no advantage to using multiple threads.
executor
- an Executor
for image loading.public void setEagerLoadingEnabled(boolean eagerLoadingEnabled)
eagerLoadingEnabled
- true to enable loading during gestures, false to delay loading until gestures endpublic final void setDebug(boolean debug)
debug
- true to enable debugging, false to disable.public boolean hasImage()
public void setOnLongClickListener(View.OnLongClickListener onLongClickListener)
setOnLongClickListener
in class View
public void setOnImageEventListener(SubsamplingScaleImageView.OnImageEventListener onImageEventListener)
SubsamplingScaleImageView.DefaultOnImageEventListener
to simplify implementation.onImageEventListener
- an SubsamplingScaleImageView.OnImageEventListener
instance.public void setOnStateChangedListener(SubsamplingScaleImageView.OnStateChangedListener onStateChangedListener)
SubsamplingScaleImageView.DefaultOnStateChangedListener
to simplify
implementation.onStateChangedListener
- an SubsamplingScaleImageView.OnStateChangedListener
instance.public SubsamplingScaleImageView.AnimationBuilder animateCenter(PointF sCenter)
sCenter
- Target center pointSubsamplingScaleImageView.AnimationBuilder
instance. Call SubsamplingScaleImageView.AnimationBuilder.start()
to start the anim.public SubsamplingScaleImageView.AnimationBuilder animateScale(float scale)
scale
- Target scale.SubsamplingScaleImageView.AnimationBuilder
instance. Call SubsamplingScaleImageView.AnimationBuilder.start()
to start the anim.public SubsamplingScaleImageView.AnimationBuilder animateScaleAndCenter(float scale, PointF sCenter)
scale
- Target scale.sCenter
- Target source center.SubsamplingScaleImageView.AnimationBuilder
instance. Call SubsamplingScaleImageView.AnimationBuilder.start()
to start the anim.