Package 

Class ZoomEngine

  • All Implemented Interfaces:
    com.otaliastudios.zoom.ZoomApi

    
    public class ZoomEngine
     implements ZoomApi
                        

    A low level class that listens to touch events and posts zoom and pan updates. The most useful output is a Matrix that can be used to do pretty much everything, from canvas drawing to View hierarchies translations.

    Users are required to:

    • Constructor Detail

      • ZoomEngine

        ZoomEngine(Context context, View container)
        Constructs an helper instance.
        Parameters:
        context - a valid context
        container - the view hosting the zoomable content
      • ZoomEngine

        ZoomEngine(Context context, View container, ZoomEngine.Listener listener)
        Constructs an helper instance.
        Parameters:
        context - a valid context
        container - the view hosting the zoomable content
        listener - a listener for events
      • ZoomEngine

        ZoomEngine(Context context)
    • Method Detail

      • setOverScrollHorizontal

         Unit setOverScrollHorizontal(Boolean overScroll)

        Controls whether the content should be over-scrollable horizontally. If it is, drag and fling horizontal events can scroll the content outside the safe area, then return to safe values.

        Parameters:
        overScroll - whether to allow horizontal over scrolling
      • setOverScrollVertical

         Unit setOverScrollVertical(Boolean overScroll)

        Controls whether the content should be over-scrollable vertically. If it is, drag and fling vertical events can scroll the content outside the safe area, then return to safe values.

        Parameters:
        overScroll - whether to allow vertical over scrolling
      • setHorizontalPanEnabled

         Unit setHorizontalPanEnabled(Boolean enabled)

        Controls whether horizontal panning using gestures is enabled.

        Parameters:
        enabled - true enables horizontal panning, false disables it
      • setVerticalPanEnabled

         Unit setVerticalPanEnabled(Boolean enabled)

        Controls whether vertical panning using gestures is enabled.

        Parameters:
        enabled - true enables vertical panning, false disables it
      • setOverPinchable

         Unit setOverPinchable(Boolean overPinchable)

        Controls whether the content should be overPinchable. If it is, pinch events can change the zoom outside the safe bounds, than return to safe values.

        Parameters:
        overPinchable - whether to allow over pinching
      • setZoomEnabled

         Unit setZoomEnabled(Boolean enabled)

        Controls whether zoom using pinch gesture is enabled or not.

        Parameters:
        enabled - true enables zooming, false disables it
      • setFlingEnabled

         Unit setFlingEnabled(Boolean enabled)

        Controls whether fling gesture is enabled or not.

        Parameters:
        enabled - true enables fling gesture, false disables it
      • setScrollEnabled

         Unit setScrollEnabled(Boolean enabled)

        Controls whether scroll gesture is enabled or not.

        Parameters:
        enabled - true enables scroll gesture, false disables it
      • setOneFingerScrollEnabled

         Unit setOneFingerScrollEnabled(Boolean enabled)

        Controls whether one finger scroll gesture is enabled or not.

        Parameters:
        enabled - true enables one finger scroll gesture, false disables it
      • setTwoFingersScrollEnabled

         Unit setTwoFingersScrollEnabled(Boolean enabled)

        Controls whether two fingers scroll gesture is enabled or not.

        Parameters:
        enabled - true enables two fingers scroll gesture, false disables it
      • setThreeFingersScrollEnabled

         Unit setThreeFingersScrollEnabled(Boolean enabled)

        Controls whether three fingers scroll gesture is enabled or not.

        Parameters:
        enabled - true enables three fingers scroll gesture, false disables it
      • setAllowFlingInOverscroll

         Unit setAllowFlingInOverscroll(Boolean allow)

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

        Parameters:
        allow - true allows fling in overscroll, false disables it
      • setAlignment

         Unit setAlignment(Integer alignment)

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

        Keep in mind that this is disabled when the content is larger than the container, because a forced alignment in this case would result in part of the content being unreachable.

        Parameters:
        alignment - the new alignment
      • setContainer

         final Unit setContainer(View container)

        Set a container to perform transformations on. This method can only be called once at initialization time. It throws an exception if it is called twice.

        Parameters:
        container - view
      • setContentSize

        @Deprecated(message = Deprecated in favor of not using RectF class, replaceWith = @ReplaceWith(imports = {}, expression = setContentSize(width, height))) final Unit setContentSize(RectF rect)

        Notifies the helper of the content size (be it a child View, a Bitmap, or whatever else). This is needed for the helper to start working.

        Parameters:
        rect - the content rect
      • setContentSize

        @JvmOverloads() final Unit setContentSize(Float width, Float height, Boolean applyTransformation)

        Notifies the helper of the content size (be it a child View, a Bitmap, or whatever else). This is needed for the helper to start working.

        Parameters:
        width - the content width
        height - the content height
        applyTransformation - whether to apply the transformation defined by setTransformation
      • setContentSize

        @JvmOverloads() final Unit setContentSize(Float width, Float height)

        Notifies the helper of the content size (be it a child View, a Bitmap, or whatever else). This is needed for the helper to start working.

        Parameters:
        width - the content width
        height - the content height
      • setContainerSize

        @JvmOverloads() final Unit setContainerSize(Float width, Float height, Boolean applyTransformation)

        Sets the size of the container view. Normally you don't need to call this because the size is detected from the container passed to the constructor using a global layout listener.

        However, there are cases where you might want to update it, for example during View.onSizeChanged (called during shared element transitions).

        Parameters:
        width - the container width
        height - the container height
        applyTransformation - whether to apply the transformation defined by setTransformation
      • setContainerSize

        @JvmOverloads() final Unit setContainerSize(Float width, Float height)

        Sets the size of the container view. Normally you don't need to call this because the size is detected from the container passed to the constructor using a global layout listener.

        However, there are cases where you might want to update it, for example during View.onSizeChanged (called during shared element transitions).

        Parameters:
        width - the container width
        height - the container height
      • onInterceptTouchEvent

         final Boolean onInterceptTouchEvent(MotionEvent ev)

        This is required when the content is a View that has clickable hierarchies inside. If true is returned, implementors should not pass the call to super.

        Parameters:
        ev - the motion event
      • onTouchEvent

         final Boolean onTouchEvent(MotionEvent ev)

        Process the given touch event. If true is returned, implementors should not pass the call to super.

        Parameters:
        ev - the motion event
      • moveTo

         Unit moveTo(Float zoom, Float x, Float y, Boolean animate)

        A low level API that can animate both zoom and pan at the same time. Zoom might not be the actual matrix scale, see ZoomApi.zoom and ZoomApi.realZoom. The coordinates are referred to the content size passed in setContentSize so they do not depend on current zoom.

        Parameters:
        zoom - the desired zoom value
        x - the desired left coordinate
        y - the desired top coordinate
        animate - whether to animate the transition
      • moveToCenter

         Unit moveToCenter(Float zoom, Boolean animate)

        Moves to the center of the content.

        Parameters:
        zoom - the desired zoom value
        animate - whether to animate the transition
      • panTo

         Unit panTo(Float x, Float y, Boolean animate)

        Pans the content until the top-left coordinates match the given x-y values. These are referred to the content size passed in setContentSize, so they do not depend on current zoom.

        Parameters:
        x - the desired left coordinate
        y - the desired top coordinate
        animate - whether to animate the transition
      • panBy

         Unit panBy(Float dx, Float dy, Boolean animate)

        Pans the content by the given quantity in dx-dy values. These are referred to the content size passed in setContentSize, so they do not depend on current zoom.

        In other words, asking to pan by 1 pixel might result in a bigger pan, if the content was zoomed in.

        Parameters:
        dx - the desired delta x
        dy - the desired delta y
        animate - whether to animate the transition
      • zoomTo

         Unit zoomTo(Float zoom, Boolean animate)

        Zooms to the given scale. This might not be the actual matrix zoom, see ZoomApi.zoom and ZoomApi.realZoom.

        Parameters:
        zoom - the new scale value
        animate - whether to animate the transition
      • zoomBy

         Unit zoomBy(Float zoomFactor, Boolean animate)

        Applies the given factor to the current zoom.

        Parameters:
        zoomFactor - a multiplicative factor
        animate - whether to animate the transition
      • zoomIn

         Unit zoomIn()

        Applies a small, animated zoom-in. Shorthand for zoomBy with factor 1.3.

      • zoomOut

         Unit zoomOut()

        Applies a small, animated zoom-out. Shorthand for zoomBy with factor 0.7.

      • realZoomTo

         Unit realZoomTo(Float realZoom, Boolean animate)

        Animates the actual matrix zoom to the given value.

        Parameters:
        realZoom - the new real zoom value
        animate - whether to animate the transition
      • setMaxZoom

         Unit setMaxZoom(Float maxZoom, Integer type)

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

        Parameters:
        maxZoom - the max zoom
        type - the constraint mode
      • setMinZoom

         Unit setMinZoom(Float minZoom, Integer type)

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

        Parameters:
        minZoom - the min zoom
        type - the constraint mode
      • cancelAnimations

         Boolean cancelAnimations()

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