-
- All Implemented Interfaces:
-
android.graphics.drawable.Drawable.Callback,android.opengl.GLSurfaceView.Renderer,android.view.KeyEvent.Callback,android.view.SurfaceHolder.Callback,android.view.SurfaceHolder.Callback2,android.view.accessibility.AccessibilityEventSource,com.otaliastudios.zoom.ZoomApi
@RequiresApi(value = 18) public class ZoomSurfaceView extends GLSurfaceView implements ZoomApi, GLSurfaceView.Renderer
Uses ZoomEngine to allow zooming and pan events onto a GL rendered surface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceZoomSurfaceView.CallbackA Callback to be notified of the surface lifecycle. All methods are invoked on the ui thread for convenience.
public classZoomSurfaceView.Companion
-
Field Summary
Fields Modifier and Type Field Description private Surfacesurfaceprivate SurfaceTexturesurfaceTextureprivate final ZoomEngineengineprivate final Floatzoomprivate final FloatrealZoomprivate final AbsolutePointpanprivate final FloatpanXprivate final FloatpanYprivate final ScaledPointscaledPanprivate final FloatscaledPanXprivate final FloatscaledPanY
-
Constructor Summary
Constructors Constructor Description ZoomSurfaceView(Context context, AttributeSet attrs)ZoomSurfaceView(Context context)
-
Method Summary
Modifier and Type Method Description final SurfacegetSurface()A Surface that can be consumed by some buffer provider. final UnitsetSurface(Surface surface)final SurfaceTexturegetSurfaceTexture()A SurfaceTexture that can be consumed by some buffer provider. final UnitsetSurfaceTexture(SurfaceTexture surfaceTexture)final ZoomEnginegetEngine()FloatgetZoom()Gets the current zoom value, which can be used as a reference when calling ZoomApi.zoomTo or ZoomApi.zoomBy. FloatgetRealZoom()Gets the current zoom value, including the base zoom that was eventually applied when initializing to respect the "center inside" policy. AbsolutePointgetPan()The current pan as an AbsolutePoint. FloatgetPanX()Returns the current horizontal pan value, in content absolute coordinates (that is, as if there was no zoom at all). FloatgetPanY()Returns the current vertical pan value, in content absolute coordinates (that is, as if there was no zoom at all). ScaledPointgetScaledPan()The current pan as a ScaledPoint, that is, taking into account the current zoom. FloatgetScaledPanX()Returns the current horizontal pan value, in content scaled coordinates (that is, including the current zoom). FloatgetScaledPanY()Returns the current vertical pan value, in content scaled coordinates (that is, including the current zoom). final UnitaddCallback(ZoomSurfaceView.Callback callback)Adds a new Callback to be notified of the surface state. final UnitremoveCallback(ZoomSurfaceView.Callback callback)Removes a Callback previously added with addCallback. UnitsetBackgroundColor(Integer color)If non transparent, we will draw this background color using GL before drawing the actual texture. final UnitsetContentSize(Float width, Float height)Sets the size of the content. BooleanonTouchEvent(MotionEvent ev)UnitonSurfaceCreated(GL10 gl, EGLConfig config)UnitonSurfaceChanged(GL10 gl, Integer width, Integer height)UnitonDrawFrame(GL10 gl)Performs the texture and background drawing. -
Methods inherited from class android.view.SurfaceView
addChildrenForAccessibility, addExtraDataToAccessibilityNodeInfo, addFocusables, addFocusables, addKeyboardNavigationClusters, addOnAttachStateChangeListener, addOnLayoutChangeListener, addOnUnhandledKeyEventListener, addTouchables, animate, announceForAccessibility, autofill, autofill, awakenScrollBars, awakenScrollBars, awakenScrollBars, bringToFront, buildDrawingCache, buildDrawingCache, buildLayer, callOnClick, canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, canScrollHorizontally, canScrollVertically, cancelDragAndDrop, cancelLongPress, cancelPendingInputEvents, checkInputConnectionProxy, clearAnimation, clearFocus, clearViewTranslationCallback, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeSystemWindowInsets, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createAccessibilityNodeInfo, createContextMenu, destroyDrawingCache, dispatchApplyWindowInsets, dispatchCapturedPointerEvent, dispatchConfigurationChanged, dispatchCreateViewTranslationRequest, dispatchDisplayHint, dispatchDragEvent, dispatchDrawableHotspotChanged, dispatchFinishTemporaryDetach, dispatchGenericFocusedEvent, dispatchGenericMotionEvent, dispatchGenericPointerEvent, dispatchHoverEvent, dispatchKeyEvent, dispatchKeyEventPreIme, dispatchKeyShortcutEvent, dispatchNestedFling, dispatchNestedPreFling, dispatchNestedPrePerformAccessibilityAction, dispatchNestedPreScroll, dispatchNestedScroll, dispatchPointerCaptureChanged, dispatchPopulateAccessibilityEvent, dispatchProvideAutofillStructure, dispatchProvideStructure, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchScrollCaptureSearch, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchSystemUiVisibilityChanged, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowInsetsAnimationEnd, dispatchWindowInsetsAnimationPrepare, dispatchWindowInsetsAnimationProgress, dispatchWindowInsetsAnimationStart, dispatchWindowSystemUiVisiblityChanged, dispatchWindowVisibilityChanged, drawableHotspotChanged, drawableStateChanged, findFocus, findViewById, findViewWithTag, findViewsWithText, fitSystemWindows, focusSearch, forceHasOverlappingRendering, forceLayout, generateDisplayHash, getAccessibilityClassName, getAccessibilityDelegate, getAccessibilityLiveRegion, getAccessibilityNodeProvider, getAccessibilityPaneTitle, getAccessibilityTraversalAfter, getAccessibilityTraversalBefore, getAlpha, getAnimation, getAnimationMatrix, getApplicationWindowToken, getAttributeResolutionStack, getAttributeSourceResourceMap, getAutofillHints, getAutofillId, getAutofillType, getAutofillValue, getBackground, getBackgroundTintBlendMode, getBackgroundTintList, getBackgroundTintMode, getBaseline, getBottom, getBottomFadingEdgeStrength, getBottomPaddingOffset, getCameraDistance, getClipBounds, getClipBounds, getClipToOutline, getContentCaptureSession, getContentDescription, getContext, getContextMenuInfo, getDefaultFocusHighlightEnabled, getDisplay, getDrawableState, getDrawingCache, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getElevation, getExplicitStyle, getFilterTouchesWhenObscured, getFitsSystemWindows, getFocusable, getFocusables, getFocusedRect, getForeground, getForegroundGravity, getForegroundTintBlendMode, getForegroundTintList, getForegroundTintMode, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHasOverlappingRendering, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getHorizontalScrollbarThumbDrawable, getHorizontalScrollbarTrackDrawable, getId, getImportantForAutofill, getImportantForContentCapture, getKeepScreenOn, getKeyDispatcherState, getLabelFor, getLayerType, getLayoutDirection, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLeftPaddingOffset, 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, getReceiveContentMimeTypes, getResources, getRevealOnFocusHint, getRight, getRightFadingEdgeStrength, getRightPaddingOffset, getRootSurfaceControl, getRootView, getRootWindowInsets, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollCaptureHint, getScrollIndicators, getScrollX, getScrollY, getSolidColor, getSourceLayoutResId, getStateDescription, getStateListAnimator, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getSystemGestureExclusionRects, getSystemUiVisibility, getTag, getTag, getTextAlignment, getTextDirection, getTooltipText, getTop, getTopFadingEdgeStrength, getTopPaddingOffset, getTouchDelegate, getTouchables, getTransitionAlpha, getTransitionName, getTranslationX, getTranslationY, getTranslationZ, getUniqueDrawingId, getVerticalFadingEdgeLength, getVerticalScrollbarPosition, getVerticalScrollbarThumbDrawable, getVerticalScrollbarTrackDrawable, getVerticalScrollbarWidth, getViewTranslationResponse, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowId, getWindowInsetsController, getWindowSystemUiVisibility, getWindowToken, getWindowVisibility, getWindowVisibleDisplayFrame, getX, getY, getZ, hasExplicitFocusable, hasFocus, hasFocusable, hasNestedScrollingParent, hasOnClickListeners, hasOnLongClickListeners, hasOverlappingRendering, hasPointerCapture, hasTransientState, hasWindowFocus, invalidate, invalidate, 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, isImportantForContentCapture, isInEditMode, isInLayout, isInTouchMode, isKeyboardNavigationCluster, isLaidOut, isLayoutDirectionResolved, isLayoutRequested, isLongClickable, isNestedScrollingEnabled, isOpaque, isPaddingOffsetRequired, isPaddingRelative, isPivotSet, isPressed, isSaveEnabled, isSaveFromParentEnabled, isScreenReaderFocusable, isScrollContainer, isScrollbarFadingEnabled, isSelected, isShowingLayoutBounds, isShown, isSoundEffectsEnabled, isTemporarilyDetached, isTextAlignmentResolved, isTextDirectionResolved, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVisibleToUserForAutofill, jumpDrawablesToCurrentState, keyboardNavigationClusterSearch, layout, measure, offsetLeftAndRight, offsetTopAndBottom, onAnimationEnd, onAnimationStart, onApplyWindowInsets, onCancelPendingInputEvents, onCapturedPointerEvent, onCheckIsTextEditor, onConfigurationChanged, onCreateContextMenu, onCreateDrawableState, onCreateInputConnection, onCreateViewTranslationRequest, onCreateVirtualViewTranslationRequests, onDisplayHint, onDragEvent, onDraw, onDrawForeground, onDrawScrollBars, onFilterTouchEventForSecurity, onFinishInflate, onFinishTemporaryDetach, onGenericMotionEvent, onHoverChanged, onHoverEvent, onInitializeAccessibilityEvent, onInitializeAccessibilityNodeInfo, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyPreIme, onKeyShortcut, onKeyUp, onLayout, onOverScrolled, onPointerCaptureChange, onPopulateAccessibilityEvent, onProvideAutofillStructure, onProvideAutofillVirtualStructure, onProvideContentCaptureStructure, onProvideStructure, onProvideVirtualStructure, onReceiveContent, onResolvePointerIcon, onRestoreInstanceState, onRtlPropertiesChanged, onSaveInstanceState, onScreenStateChanged, onScrollCaptureSearch, onScrollChanged, onSetAlpha, onSizeChanged, onStartTemporaryDetach, onTrackballEvent, onViewTranslationResponse, onVirtualViewTranslationResponses, onVisibilityAggregated, onVisibilityChanged, onWindowFocusChanged, onWindowSystemUiVisibilityChanged, overScrollBy, performAccessibilityAction, performClick, performContextClick, performContextClick, performHapticFeedback, performHapticFeedback, performLongClick, performLongClick, performReceiveContent, playSoundEffect, post, postDelayed, postInvalidate, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, postInvalidateOnAnimation, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, refreshDrawableState, releasePointerCapture, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, removeOnUnhandledKeyEventListener, requestApplyInsets, requestFitSystemWindows, requestFocus, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestPointerCapture, requestRectangleOnScreen, requestRectangleOnScreen, requestUnbufferedDispatch, requestUnbufferedDispatch, requireViewById, resetPivot, restoreDefaultFocus, restoreHierarchyState, saveAttributeDataForStyleable, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, sendAccessibilityEvent, sendAccessibilityEventUnchecked, setAccessibilityDelegate, setAccessibilityHeading, setAccessibilityLiveRegion, setAccessibilityPaneTitle, setAccessibilityTraversalAfter, setAccessibilityTraversalBefore, setActivated, setAllowClickWhenDisabled, setAnimation, setAnimationMatrix, setAutofillHints, setAutofillId, setBackground, setBackgroundDrawable, setBackgroundResource, setBackgroundTintBlendMode, setBackgroundTintList, setBackgroundTintMode, setBottom, setCameraDistance, setClickable, setClipToOutline, setContentCaptureSession, setContentDescription, setContextClickable, setDefaultFocusHighlightEnabled, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setElevation, setEnabled, setFadingEdgeLength, setFilterTouchesWhenObscured, setFitsSystemWindows, setFocusable, setFocusable, setFocusableInTouchMode, setFocusedByDefault, setForceDarkAllowed, setForeground, setForegroundGravity, setForegroundTintBlendMode, setForegroundTintList, setForegroundTintMode, setHapticFeedbackEnabled, setHasTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHorizontalScrollbarThumbDrawable, setHorizontalScrollbarTrackDrawable, setHovered, setId, setImportantForAccessibility, setImportantForAutofill, setImportantForContentCapture, setKeepScreenOn, setKeyboardNavigationCluster, setLabelFor, setLayerPaint, setLayerType, setLayoutDirection, setLayoutParams, setLeft, setLeftTopRightBottom, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNestedScrollingEnabled, setNextClusterForwardId, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnApplyWindowInsetsListener, setOnCapturedPointerListener, setOnClickListener, setOnContextClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnReceiveContentListener, setOnScrollChangeListener, setOnSystemUiVisibilityChangeListener, setOnTouchListener, setOutlineAmbientShadowColor, setOutlineProvider, setOutlineSpotShadowColor, setOverScrollMode, setPadding, setPaddingRelative, setPivotX, setPivotY, setPointerIcon, setPressed, setRenderEffect, setRevealOnFocusHint, setRight, setRotation, setRotationX, setRotationY, setSaveEnabled, setSaveFromParentEnabled, setScaleX, setScaleY, setScreenReaderFocusable, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollBarSize, setScrollBarStyle, setScrollCaptureCallback, setScrollCaptureHint, setScrollContainer, setScrollIndicators, setScrollIndicators, setScrollX, setScrollY, setScrollbarFadingEnabled, setSelected, setSoundEffectsEnabled, setStateDescription, setStateListAnimator, setSystemGestureExclusionRects, setSystemUiVisibility, setTag, setTag, setTextAlignment, setTextDirection, setTooltipText, setTop, setTouchDelegate, setTransitionAlpha, setTransitionName, setTransitionVisibility, setTranslationX, setTranslationY, setTranslationZ, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarPosition, setVerticalScrollbarThumbDrawable, setVerticalScrollbarTrackDrawable, setViewTranslationCallback, setWillNotCacheDrawing, setWillNotDraw, setWindowInsetsAnimationCallback, setX, setY, setZ, showContextMenu, showContextMenu, startActionMode, startActionMode, startAnimation, startDrag, startDragAndDrop, startNestedScroll, stopNestedScroll, toString, transformMatrixToGlobal, transformMatrixToLocal, unscheduleDrawable, unscheduleDrawable, updateDragShadow, verifyDrawable, willNotCacheDrawing, willNotDraw -
Methods inherited from class android.opengl.GLSurfaceView
dispatchDraw, draw, gatherTransparentRegion, getHolder, getHostToken, getImportantForAccessibility, getSurfaceControl, onFocusChanged, onWindowVisibilityChanged, setAlpha, setChildSurfacePackage, setClipBounds, setSecure, setVisibility, setZOrderMediaOverlay, setZOrderOnTop -
Methods inherited from class com.otaliastudios.zoom.ZoomSurfaceView
cancelAnimations, finalize, getDebugFlags, getMaxZoom, getMaxZoomType, getMinZoom, getMinZoomType, getPreserveEGLContextOnPause, getRenderMode, moveTo, moveToCenter, onAttachedToWindow, onPause, onResume, panBy, panTo, queueEvent, realZoomTo, requestRender, setAlignment, setAllowFlingInOverscroll, setAnimationDuration, setDebugFlags, setEGLConfigChooser, setEGLConfigChooser, setEGLConfigChooser, setEGLContextClientVersion, setEGLContextFactory, setEGLWindowSurfaceFactory, setFlingEnabled, setGLWrapper, setHorizontalPanEnabled, setMaxZoom, setMaxZoom, setMinZoom, setMinZoom, setOneFingerScrollEnabled, setOverPanRange, setOverPinchable, setOverScrollHorizontal, setOverScrollVertical, setOverZoomRange, setPreserveEGLContextOnPause, setRenderMode, setRenderer, setScrollEnabled, setThreeFingersScrollEnabled, setTransformation, setTransformation, setTwoFingersScrollEnabled, setVerticalPanEnabled, setZoomEnabled, surfaceChanged, surfaceCreated, surfaceDestroyed, surfaceRedrawNeeded, surfaceRedrawNeededAsync, zoomBy, zoomIn, zoomOut, zoomTo -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
ZoomSurfaceView
ZoomSurfaceView(Context context, AttributeSet attrs)
-
ZoomSurfaceView
ZoomSurfaceView(Context context)
-
-
Method Detail
-
getSurface
final Surface getSurface()
A Surface that can be consumed by some buffer provider. This will be non-null after Callback.onZoomSurfaceCreated and null again after Callback.onZoomSurfaceDestroyed.
This class cares about releasing this object when done.
-
setSurface
final Unit setSurface(Surface surface)
-
getSurfaceTexture
final SurfaceTexture getSurfaceTexture()
A SurfaceTexture that can be consumed by some buffer provider. This will be non-null after Callback.onZoomSurfaceCreated and null again after Callback.onZoomSurfaceDestroyed.
This class cares about releasing this object when done.
-
setSurfaceTexture
final Unit setSurfaceTexture(SurfaceTexture surfaceTexture)
-
getEngine
final ZoomEngine getEngine()
-
getZoom
Float getZoom()
Gets the current zoom value, which can be used as a reference when calling ZoomApi.zoomTo or ZoomApi.zoomBy.
This can be different than the actual scale you get in the matrix, because at startup we apply a base zoom to respect the "center inside" policy. All zoom calls, including min zoom and max zoom, refer to this axis, where zoom is set to 1 right after the initial transformation.
-
getRealZoom
Float getRealZoom()
Gets the current zoom value, including the base zoom that was eventually applied when initializing to respect the "center inside" policy. This will match the scaleX - scaleY values you get into the Matrix, and is the actual scale value of the content from its original size.
-
getPan
AbsolutePoint getPan()
The current pan as an AbsolutePoint.
-
getPanX
Float getPanX()
Returns the current horizontal pan value, in content absolute coordinates (that is, as if there was no zoom at all).
-
getPanY
Float getPanY()
Returns the current vertical pan value, in content absolute coordinates (that is, as if there was no zoom at all).
-
getScaledPan
ScaledPoint getScaledPan()
The current pan as a ScaledPoint, that is, taking into account the current zoom. This basically returns the pan value multiplied by the current realZoom.
-
getScaledPanX
Float getScaledPanX()
-
getScaledPanY
Float getScaledPanY()
-
addCallback
final Unit addCallback(ZoomSurfaceView.Callback callback)
Adds a new Callback to be notified of the surface state. Should be called as soon as possible.
-
removeCallback
final Unit removeCallback(ZoomSurfaceView.Callback callback)
Removes a Callback previously added with addCallback.
-
setBackgroundColor
Unit setBackgroundColor(Integer color)
If non transparent, we will draw this background color using GL before drawing the actual texture.
-
setContentSize
final Unit setContentSize(Float width, Float height)
Sets the size of the content. If this is not called, the size will be assumed to be that of the ZoomSurfaceView itself. In this case, make sure to measure ZoomSurfaceView correctly or the texture will be distorted.
-
onTouchEvent
Boolean onTouchEvent(MotionEvent ev)
-
onSurfaceCreated
@WorkerThread() Unit onSurfaceCreated(GL10 gl, EGLConfig config)
-
onSurfaceChanged
@WorkerThread() Unit onSurfaceChanged(GL10 gl, Integer width, Integer height)
-
onDrawFrame
@WorkerThread() Unit onDrawFrame(GL10 gl)
Performs the texture and background drawing.
An old version of this acted on surfaceTextureTransformMatrix instead of the rect modelMatrix. This has the drawback that any "background" (overscrolls, zoom < 1, ...) will draw the CLAMP_TO_BORDER texture mess and there's no way around that.
The current version acts on textureRect.modelMatrix instead. In both cases there are some issues here.
We passed the video size to the engine. So we must UNDO some default behavior of SurfaceView. This is done and documented in onContentOrContainerSizeChanged.
OpenGL will apply translation first then scale, which is typically not what we want.
OpenGL will scale with respect to some fixed point, which is typically not the pan origin. (if we work on modelMatrix, this point is the translated viewport center)
OpenGL Y coordinates are reversed.
-
-
-
-