Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TIMOB-13494-make sure that image doesn't scroll beyond it boundaries #4361

Merged
merged 1 commit into from
Jun 7, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,19 @@ public boolean onDown(MotionEvent e)
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float dx, float dy)
{
if (zoomControls.getVisibility() == View.VISIBLE) {
changeMatrix.postTranslate(-dx, -dy);
imageView.setImageMatrix(getViewMatrix());
requestLayout();
scheduleControlTimeout();
return true;
} else {
return false;
boolean retValue = false;
// Allow scrolling only if the image is zoomed in
if (zoomControls.getVisibility() == View.VISIBLE && scaleFactor > 1) {
// check if image scroll beyond its borders
if (!checkImageScrollBeyondBorders(dx, dy)) {
changeMatrix.postTranslate(-dx, -dy);
imageView.setImageMatrix(getViewMatrix());
requestLayout();
scheduleControlTimeout();
retValue = true;
}
}
return retValue;
}

@Override
Expand Down Expand Up @@ -445,4 +449,22 @@ public void setOrientation(int orientation)
this.orientation = orientation;
updateScaleType();
}

private boolean checkImageScrollBeyondBorders(float dx, float dy)
{
float[] matrixValues = new float[9];
Matrix m = new Matrix(changeMatrix);
// Apply the translation
m.postTranslate(-dx, -dy);
m.getValues(matrixValues);
// Image can move only the extra width or height that is available
// after scaling from the original width or height
float scaledAdditionalHeight = imageView.getHeight() * (matrixValues[4] - 1);
float scaledAdditionalWidth = imageView.getWidth() * (matrixValues[0] - 1);
if (matrixValues[5] > -scaledAdditionalHeight && matrixValues[5] < 0 && matrixValues[2] > -scaledAdditionalWidth
&& matrixValues[2] < 0) {
return false;
}
return true;
}
}