From ad1fbc5bd881b1576b0dab4432c3d30067e135d0 Mon Sep 17 00:00:00 2001 From: tom5079 Date: Thu, 1 Oct 2020 21:13:54 +0900 Subject: [PATCH] Better NPE handling --- .../labs/subscaleview/SubsamplingScaleImageView.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java b/library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java index 56a6b5ee..82b0885e 100755 --- a/library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java +++ b/library/src/main/java/com/davemorrissey/labs/subscaleview/SubsamplingScaleImageView.java @@ -685,12 +685,15 @@ public boolean onTouchEvent(@NonNull MotionEvent event) { } if (vTranslateStart == null) { vTranslateStart = new PointF(0, 0); } - if (vTranslateBefore == null) { vTranslateBefore = new PointF(0, 0); } + if (vTranslateBefore == null) { + vTranslateBefore = new PointF(vTranslate.x, vTranslate.y); + } else { + vTranslateBefore.set(vTranslate); + } if (vCenterStart == null) { vCenterStart = new PointF(0, 0); } // Store current values so we can send an event if they change float scaleBefore = scale; - vTranslateBefore.set(vTranslate); boolean handled = onTouchEventInternal(event); sendStateChanged(scaleBefore, vTranslateBefore, ORIGIN_TOUCH);