/** * Restricts state's translation and zoom bounds. * * @param state State to be restricted * @param prevState Previous state to calculate overscroll and overzoom (optional) * @param pivotX Pivot's X coordinate * @param pivotY Pivot's Y coordinate * @param allowOverscroll Whether overscroll is allowed * @param allowOverzoom Whether overzoom is allowed * @param restrictRotation Whether rotation should be restricted to a nearest N*90 angle * @return End state to animate changes or null if no changes are required. */ @SuppressWarnings("SameParameterValue") // Using same method params as in restrictStateBounds @Nullable State restrictStateBoundsCopy(State state, State prevState, float pivotX, float pivotY, boolean allowOverscroll, boolean allowOverzoom, boolean restrictRotation) { tmpState.set(state); boolean changed = restrictStateBounds(tmpState, prevState, pivotX, pivotY, allowOverscroll, allowOverzoom, restrictRotation); return changed ? tmpState.copy() : null; }
isStateChangedDuringTouch = false; stateController.restrictStateBounds( state, prevState, pivotX, pivotY, true, true, false);
/** * Updates state (or resets state if reset was scheduled, see {@link #resetState(State)}). * * @param state State to be updated * @return {@code true} if state was reset to initial state or {@code false} if state was * updated. */ boolean updateState(State state) { if (isResetRequired) { // Applying initial state state.set(0f, 0f, zoomBounds.set(state).getFitZoom(), 0f); GravityUtils.getImagePosition(state, settings, tmpRect); state.translateTo(tmpRect.left, tmpRect.top); // We can correctly reset state only when we have both image size and viewport size // but there can be a delay before we have all values properly set // (waiting for layout or waiting for image to be loaded) isResetRequired = !settings.hasImageSize() || !settings.hasViewportSize(); return !isResetRequired; } else { // Restricts state's translation and zoom bounds, disallowing overscroll / overzoom. restrictStateBounds(state, state, Float.NaN, Float.NaN, false, false, true); return false; } }