public void moveTo ( float offsetX , float offsetY ) { if ( swipeVertical ) { // Check X offset if ( toCurrentScale ( optimalPageWidth ) < getWidth ( ) ) { offsetX = getWidth ( ) / 2 - toCurrentScale ( optimalPageWidth ) / 2 ; } else { if ( offsetX > 0 ) { offsetX = 0 ; } else if ( offsetX + toCurrentScale ( optimalPageWidth ) < getWidth ( ) ) { offsetX = getWidth ( ) - toCurrentScale ( optimalPageWidth ) ; } } // Check Y offset if ( isZooming ( ) ) { if ( toCurrentScale ( optimalPageHeight ) < getHeight ( ) ) { miniMapRequired = false ; offsetY = getHeight ( ) / 2 - toCurrentScale ( ( currentFilteredPage + 0.5f ) * optimalPageHeight ) ; } else { miniMapRequired = true ; if ( offsetY + toCurrentScale ( currentFilteredPage * optimalPageHeight ) > 0 ) { offsetY = - toCurrentScale ( currentFilteredPage * optimalPageHeight ) ; } else if ( offsetY + toCurrentScale ( ( currentFilteredPage + 1 ) * optimalPageHeight ) < getHeight ( ) ) { offsetY = getHeight ( ) - toCurrentScale ( ( currentFilteredPage + 1 ) * optimalPageHeight ) ; } } } else { float maxY = calculateCenterOffsetForPage ( currentFilteredPage + 1 ) ; float minY = calculateCenterOffsetForPage ( currentFilteredPage - 1 ) ; if ( offsetY < maxY ) { offsetY = maxY ; } else if ( offsetY > minY ) { offsetY = minY ; } } } else { // Check Y offset if ( toCurrentScale ( optimalPageHeight ) < getHeight ( ) ) { offsetY = getHeight ( ) / 2 - toCurrentScale ( optimalPageHeight ) / 2 ; } else { if ( offsetY > 0 ) { offsetY = 0 ; } else if ( offsetY + toCurrentScale ( optimalPageHeight ) < getHeight ( ) ) { offsetY = getHeight ( ) - toCurrentScale ( optimalPageHeight ) ; } } // Check X offset if ( isZooming ( ) ) { if ( toCurrentScale ( optimalPageWidth ) < getWidth ( ) ) { miniMapRequired = false ; offsetX = getWidth ( ) / 2 - toCurrentScale ( ( currentFilteredPage + 0.5f ) * optimalPageWidth ) ; } else { miniMapRequired = true ; if ( offsetX + toCurrentScale ( currentFilteredPage * optimalPageWidth ) > 0 ) { offsetX = - toCurrentScale ( currentFilteredPage * optimalPageWidth ) ; } else if ( offsetX + toCurrentScale ( ( currentFilteredPage + 1 ) * optimalPageWidth ) < getWidth ( ) ) { offsetX = getWidth ( ) - toCurrentScale ( ( currentFilteredPage + 1 ) * optimalPageWidth ) ; } } } else { float maxX = calculateCenterOffsetForPage ( currentFilteredPage + 1 ) ; float minX = calculateCenterOffsetForPage ( currentFilteredPage - 1 ) ; if ( offsetX < maxX ) { offsetX = maxX ; } else if ( offsetX > minX ) { offsetX = minX ; } } } currentXOffset = offsetX ; currentYOffset = offsetY ; calculateMinimapAreaBounds ( ) ; invalidate ( ) ; }
Move to the given X and Y offsets but check them ahead of time to be sure not to go outside the the big strip .