Skip to content

Commit

Permalink
crash in ImageViewFragment on pan/zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Mar 9, 2020
1 parent da128cf commit 617bd0b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/co/tinode/tindroid/ImageViewFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public class ImageViewFragment extends Fragment {
private static final String TAG = "ImageViewFragment";

// The matrix actually used for scaling.
private Matrix mMatrix;
private Matrix mMatrix = null;
// Working matrix for pre-testing image bounds.
private Matrix mWorkingMatrix;
private Matrix mWorkingMatrix = null;
// Initial image bounds before any zooming and scaling.
private RectF mInitialRect;
// Screen bounds
Expand All @@ -74,6 +74,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
GestureDetector.OnGestureListener listener = new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float dX, float dY) {

mWorkingMatrix.postTranslate(-dX, -dY);
// Ignore pan if the image is too small. It should be pinned to the center of the screen.
// If it's large, make sure it covers the entire screen.
Expand Down Expand Up @@ -125,6 +126,11 @@ public boolean onScale(ScaleGestureDetector scaleDetector) {

view.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (mWorkingMatrix == null) {
// The image is invalid. Disable scrolling/panning.
return false;
}

mGestureDetector.onTouchEvent(event);
mScaleGestureDetector.onTouchEvent(event);
return true;
Expand Down

0 comments on commit 617bd0b

Please sign in to comment.