private boolean canScroll(float dy) { if (!controller.getSettings().isRestrictBounds()) { return true; } final State state = controller.getState(); controller.getStateController().getMovementArea(state, tmpArea); return (dy > 0f && State.compare(state.getY(), tmpArea.bottom) < 0f) || (dy < 0f && State.compare(state.getY(), tmpArea.top) > 0f); }
private boolean isZoomedOut() { final State state = controller.getState(); final float minZoom = controller.getStateController().getMinZoom(state); return State.compare(state.getZoom(), minZoom) <= 0; }
private void startDetection() { controller.getSettings().disableBounds(); if (controller instanceof GestureControllerForPager) { ((GestureControllerForPager) controller).disableViewPager(true); } }
public void setValuesFrom(Settings settings) { isPanEnabled = settings.isPanEnabled(); isZoomEnabled = settings.isZoomEnabled(); isRotationEnabled = settings.isRotationEnabled(); isRestrictRotation = settings.isRestrictRotation(); isFillViewport = settings.isFillViewport(); fitMethod = settings.getFitMethod(); boundsType = settings.getBoundsType(); gravity = settings.getGravity(); }
public void applyZoomPatch(State state) { if (zoomPatch > 0f) { state.set(state.getX(), state.getY(), state.getZoom() * zoomPatch, state.getRotation()); } }
@Override protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) { super.onSizeChanged(width, height, oldWidth, oldHeight); controller.getSettings().setViewport(width, height).setImage(width, height); controller.updateState(); }
private boolean canDetectScroll() { ExitType exitType = controller.getSettings().getExitType(); return (exitType == ExitType.ALL || exitType == ExitType.SCROLL) && !isZoomInAction && !isRotationInAction && isZoomedOut(); }
@Override public void onStateChanged(State state) { // Applying zoom patch (needed in case if image size is changed) toController.getStateController().applyZoomPatch(fromState); toController.getStateController().applyZoomPatch(toState); }
@SuppressWarnings("WeakerAccess") // Public API (can be overridden) protected void notifyStateUpdated() { prevState.set(state); for (OnStateChangeListener listener : stateListeners) { listener.onStateChanged(state); } }
private void notifyStateSourceChanged() { StateSource type = StateSource.NONE; if (isAnimating()) { type = StateSource.ANIMATION; } else if (isScrollDetected || isScaleDetected || isRotationDetected) { type = StateSource.USER; } if (stateSource != type) { stateSource = type; if (sourceListener != null) { sourceListener.onStateSourceChanged(type); } } }
/** * Animates to correct position withing the bounds. * * @return {@code true} if animation started, {@code false} otherwise. Animation may * not be started if image already withing the bounds. */ @SuppressWarnings("WeakerAccess") // Public API public boolean animateKeepInBounds() { return animateStateTo(state, true); }
@SuppressWarnings("WeakerAccess") // Public API (can be overridden) protected void onFlingAnimationFinished(boolean forced) { if (!forced) { animateKeepInBounds(); } notifyStateSourceChanged(); }
@Override protected boolean onFling(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float vx, float vy) { return !hasViewPagerX() && super.onFling(e1, e2, vx, vy); }
@SuppressWarnings("WeakerAccess") // Public API (can be overridden) protected boolean onSingleTapConfirmed(MotionEvent event) { // If double tap is enabled we should propagate click only if we aren't in a double tap now if (settings.isDoubleTapEnabled()) { targetView.performClick(); } return gestureListener != null && gestureListener.onSingleTapConfirmed(event); }
private void ensureControllerCreated() { if (controller == null) { controller = new GestureControllerForPager(this); } }
@SuppressWarnings({ "UnusedParameters", "WeakerAccess" }) // Public API (can be overridden) protected void onStateAnimationFinished(boolean forced) { isAnimatingInBounds = false; pivotX = Float.NaN; pivotY = Float.NaN; notifyStateSourceChanged(); }
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { // Passing original event to controller return controller.onInterceptTouch(this, currentMotionEvent); }
/** * Resets to initial state (min zoom, position according to gravity). Reset will only occur * when image and viewport sizes are known, otherwise reset will occur sometime in the future * when {@link #updateState(State)} method will be called. * * @param state State to be reset * @return {@code true} if reset was completed or {@code false} if reset is scheduled for future */ boolean resetState(State state) { isResetRequired = true; return updateState(state); }
public void applyZoomPatch() { // Applying zoom patch (needed in case if image size is changed) initialZoom = controller.getStateController().applyZoomPatch(initialZoom); }