package com.github.chrisbanes.photoview; import android.content.Context; import android.graphics.Matrix; import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; import android.view.ViewParent; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ImageView; import android.widget.OverScroller; import androidx.core.view.MotionEventCompat; /* loaded from: classes.dex */ public class PhotoViewAttacher implements View.OnTouchListener, View.OnLayoutChangeListener, View.OnGenericMotionListener { private static float H = 3.0f; private static float I = 1.75f; private static float J = 1.0f; private static int K = 200; private static int L = 1; private FlingRunnable A; private float C; private ImageView h; private GestureDetector i; private CustomGestureDetector j; private OnMatrixChangedListener p; private OnPhotoTapListener q; private OnOutsidePhotoTapListener r; private OnViewTapListener s; private View.OnClickListener t; private View.OnLongClickListener u; private OnScaleChangedListener v; private OnSingleFlingListener x; private OnViewDragListener y; private OnViewTouchListener z; private Interpolator a = new AccelerateDecelerateInterpolator(); private int b = K; private float c = J; private float d = I; private float e = H; private boolean f = true; private boolean g = false; private final Matrix k = new Matrix(); private final Matrix l = new Matrix(); private final Matrix m = new Matrix(); private final RectF n = new RectF(); private final float[] o = new float[9]; private int B = 2; private boolean D = true; private ImageView.ScaleType E = ImageView.ScaleType.FIT_CENTER; private float F = 0.75f; private OnGestureListener G = new OnGestureListener() { // from class: com.github.chrisbanes.photoview.PhotoViewAttacher.1 @Override // com.github.chrisbanes.photoview.OnGestureListener public void a(float f, float f2) { if (PhotoViewAttacher.this.j.b()) { return; } if (PhotoViewAttacher.this.y != null) { PhotoViewAttacher.this.y.a(f, f2); } PhotoViewAttacher.this.m.postTranslate(f, f2); PhotoViewAttacher.this.l(); ViewParent parent = PhotoViewAttacher.this.h.getParent(); if (!PhotoViewAttacher.this.f || PhotoViewAttacher.this.j.b() || PhotoViewAttacher.this.g) { if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } } else if ((PhotoViewAttacher.this.B == 2 || ((PhotoViewAttacher.this.B == 0 && f >= 1.0f) || (PhotoViewAttacher.this.B == 1 && f <= -1.0f))) && parent != null) { parent.requestDisallowInterceptTouchEvent(false); } } @Override // com.github.chrisbanes.photoview.OnGestureListener public void a(float f, float f2, float f3, float f4) { PhotoViewAttacher photoViewAttacher = PhotoViewAttacher.this; photoViewAttacher.A = photoViewAttacher.new FlingRunnable(photoViewAttacher.h.getContext()); FlingRunnable flingRunnable = PhotoViewAttacher.this.A; PhotoViewAttacher photoViewAttacher2 = PhotoViewAttacher.this; int b = photoViewAttacher2.b(photoViewAttacher2.h); PhotoViewAttacher photoViewAttacher3 = PhotoViewAttacher.this; flingRunnable.a(b, photoViewAttacher3.a(photoViewAttacher3.h), (int) f3, (int) f4); PhotoViewAttacher.this.h.post(PhotoViewAttacher.this.A); } @Override // com.github.chrisbanes.photoview.OnGestureListener public void a(float f, float f2, float f3) { if (PhotoViewAttacher.this.f() < PhotoViewAttacher.this.e || f < 1.0f) { if (PhotoViewAttacher.this.f() > PhotoViewAttacher.this.c || f > 1.0f) { if (PhotoViewAttacher.this.v != null) { PhotoViewAttacher.this.v.a(f, f2, f3); } PhotoViewAttacher.this.m.postScale(f, f, f2, f3); PhotoViewAttacher.this.l(); } } } }; /* renamed from: com.github.chrisbanes.photoview.PhotoViewAttacher$4, reason: invalid class name */ static /* synthetic */ class AnonymousClass4 { static final /* synthetic */ int[] a = new int[ImageView.ScaleType.values().length]; static { try { a[ImageView.ScaleType.FIT_CENTER.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { a[ImageView.ScaleType.FIT_START.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } try { a[ImageView.ScaleType.FIT_END.ordinal()] = 3; } catch (NoSuchFieldError unused3) { } try { a[ImageView.ScaleType.FIT_XY.ordinal()] = 4; } catch (NoSuchFieldError unused4) { } } } private class AnimatedZoomRunnable implements Runnable { private final float a; private final float b; private final long c = System.currentTimeMillis(); private final float d; private final float e; public AnimatedZoomRunnable(float f, float f2, float f3, float f4) { this.a = f3; this.b = f4; this.d = f; this.e = f2; } private float a() { return PhotoViewAttacher.this.a.getInterpolation(Math.min(1.0f, ((System.currentTimeMillis() - this.c) * 1.0f) / PhotoViewAttacher.this.b)); } @Override // java.lang.Runnable public void run() { float a = a(); float f = this.d; PhotoViewAttacher.this.G.a((f + ((this.e - f) * a)) / PhotoViewAttacher.this.f(), this.a, this.b); if (a < 1.0f) { Compat.a(PhotoViewAttacher.this.h, this); } } } private class FlingRunnable implements Runnable { private final OverScroller a; private int b; private int c; public FlingRunnable(Context context) { this.a = new OverScroller(context); } public void a() { this.a.forceFinished(true); } @Override // java.lang.Runnable public void run() { if (!this.a.isFinished() && this.a.computeScrollOffset()) { int currX = this.a.getCurrX(); int currY = this.a.getCurrY(); PhotoViewAttacher.this.m.postTranslate(this.b - currX, this.c - currY); PhotoViewAttacher.this.l(); this.b = currX; this.c = currY; Compat.a(PhotoViewAttacher.this.h, this); } } public void a(int i, int i2, int i3, int i4) { int i5; int i6; int i7; int i8; RectF a = PhotoViewAttacher.this.a(); if (a == null) { return; } int round = Math.round(-a.left); float f = i; if (f < a.width()) { i6 = Math.round(a.width() - f); i5 = 0; } else { i5 = round; i6 = i5; } int round2 = Math.round(-a.top); float f2 = i2; if (f2 < a.height()) { i8 = Math.round(a.height() - f2); i7 = 0; } else { i7 = round2; i8 = i7; } this.b = round; this.c = round2; if (round == i6 && round2 == i8) { return; } this.a.fling(round, round2, i3, i4, i5, i6, i7, i8, 0, 0); } } public PhotoViewAttacher(ImageView imageView) { this.h = imageView; imageView.setOnTouchListener(this); imageView.addOnLayoutChangeListener(this); imageView.setOnGenericMotionListener(this); if (imageView.isInEditMode()) { return; } this.C = 0.0f; this.j = new CustomGestureDetector(imageView.getContext(), this.G); this.i = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() { // from class: com.github.chrisbanes.photoview.PhotoViewAttacher.2 @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f2) { if (PhotoViewAttacher.this.x == null || PhotoViewAttacher.this.f() > PhotoViewAttacher.J || MotionEventCompat.b(motionEvent) > PhotoViewAttacher.L || MotionEventCompat.b(motionEvent2) > PhotoViewAttacher.L) { return false; } return PhotoViewAttacher.this.x.onFling(motionEvent, motionEvent2, f, f2); } @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener public void onLongPress(MotionEvent motionEvent) { if (PhotoViewAttacher.this.u != null) { PhotoViewAttacher.this.u.onLongClick(PhotoViewAttacher.this.h); } } }); this.i.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() { // from class: com.github.chrisbanes.photoview.PhotoViewAttacher.3 @Override // android.view.GestureDetector.OnDoubleTapListener public boolean onDoubleTap(MotionEvent motionEvent) { try { float f = PhotoViewAttacher.this.f(); float x = motionEvent.getX(); float y = motionEvent.getY(); if (f < PhotoViewAttacher.this.d()) { PhotoViewAttacher.this.a(PhotoViewAttacher.this.d(), x, y, true); } else if (f < PhotoViewAttacher.this.d() || f >= PhotoViewAttacher.this.c()) { PhotoViewAttacher.this.a(PhotoViewAttacher.this.e(), x, y, true); } else { PhotoViewAttacher.this.a(PhotoViewAttacher.this.c(), x, y, true); } } catch (ArrayIndexOutOfBoundsException unused) { } return true; } @Override // android.view.GestureDetector.OnDoubleTapListener public boolean onDoubleTapEvent(MotionEvent motionEvent) { return false; } @Override // android.view.GestureDetector.OnDoubleTapListener public boolean onSingleTapConfirmed(MotionEvent motionEvent) { if (PhotoViewAttacher.this.t != null) { PhotoViewAttacher.this.t.onClick(PhotoViewAttacher.this.h); } RectF a = PhotoViewAttacher.this.a(); float x = motionEvent.getX(); float y = motionEvent.getY(); if (PhotoViewAttacher.this.s != null) { PhotoViewAttacher.this.s.a(PhotoViewAttacher.this.h, x, y); } if (a == null) { return false; } if (!a.contains(x, y)) { if (PhotoViewAttacher.this.r == null) { return false; } PhotoViewAttacher.this.r.a(PhotoViewAttacher.this.h); return false; } float width = (x - a.left) / a.width(); float height = (y - a.top) / a.height(); if (PhotoViewAttacher.this.q == null) { return true; } PhotoViewAttacher.this.q.a(PhotoViewAttacher.this.h, width, height); return true; } }); } @Override // android.view.View.OnGenericMotionListener public boolean onGenericMotion(View view, MotionEvent motionEvent) { if ((motionEvent.getSource() & 2) == 0) { return false; } try { if (motionEvent.getAction() == 8) { float f = f(); float x = motionEvent.getX(); float y = motionEvent.getY(); if (motionEvent.getAxisValue(9) < 0.0f) { if (f != e()) { if (f - this.F <= e()) { a(e(), x, y, true); } else { a(f - this.F, x, y, true); } } } else if (f != c()) { if (this.F + f >= c()) { a(c(), x, y, true); } else { a(f + this.F, x, y, true); } } } return false; } catch (ArrayIndexOutOfBoundsException unused) { return false; } } @Override // android.view.View.OnLayoutChangeListener public void onLayoutChange(View view, int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8) { if (i == i5 && i2 == i6 && i3 == i7 && i4 == i8) { return; } a(this.h.getDrawable()); } /* JADX WARN: Removed duplicated region for block: B:16:0x0086 */ /* JADX WARN: Removed duplicated region for block: B:39:0x00b9 */ @Override // android.view.View.OnTouchListener /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public boolean onTouch(android.view.View r11, android.view.MotionEvent r12) { /* r10 = this; com.github.chrisbanes.photoview.OnViewTouchListener r0 = r10.z if (r0 == 0) goto L7 r0.a(r12) L7: boolean r0 = r10.D r1 = 0 r2 = 1 if (r0 == 0) goto Lc5 r0 = r11 android.widget.ImageView r0 = (android.widget.ImageView) r0 boolean r0 = com.github.chrisbanes.photoview.Util.a(r0) if (r0 == 0) goto Lc5 int r0 = r12.getAction() if (r0 == 0) goto L75 if (r0 == r2) goto L22 r3 = 3 if (r0 == r3) goto L22 goto L81 L22: float r0 = r10.f() float r3 = r10.c int r0 = (r0 > r3 ? 1 : (r0 == r3 ? 0 : -1)) if (r0 >= 0) goto L4b android.graphics.RectF r0 = r10.a() if (r0 == 0) goto L81 com.github.chrisbanes.photoview.PhotoViewAttacher$AnimatedZoomRunnable r9 = new com.github.chrisbanes.photoview.PhotoViewAttacher$AnimatedZoomRunnable float r5 = r10.f() float r6 = r10.c float r7 = r0.centerX() float r8 = r0.centerY() r3 = r9 r4 = r10 r3.(r5, r6, r7, r8) r11.post(r9) goto L73 L4b: float r0 = r10.f() float r3 = r10.e int r0 = (r0 > r3 ? 1 : (r0 == r3 ? 0 : -1)) if (r0 <= 0) goto L81 android.graphics.RectF r0 = r10.a() if (r0 == 0) goto L81 com.github.chrisbanes.photoview.PhotoViewAttacher$AnimatedZoomRunnable r9 = new com.github.chrisbanes.photoview.PhotoViewAttacher$AnimatedZoomRunnable float r5 = r10.f() float r6 = r10.e float r7 = r0.centerX() float r8 = r0.centerY() r3 = r9 r4 = r10 r3.(r5, r6, r7, r8) r11.post(r9) L73: r11 = 1 goto L82 L75: android.view.ViewParent r11 = r11.getParent() if (r11 == 0) goto L7e r11.requestDisallowInterceptTouchEvent(r2) L7e: r10.k() L81: r11 = 0 L82: com.github.chrisbanes.photoview.CustomGestureDetector r0 = r10.j if (r0 == 0) goto Lb9 boolean r11 = r0.b() com.github.chrisbanes.photoview.CustomGestureDetector r0 = r10.j boolean r0 = r0.a() com.github.chrisbanes.photoview.CustomGestureDetector r3 = r10.j boolean r3 = r3.a(r12) if (r11 != 0) goto La2 com.github.chrisbanes.photoview.CustomGestureDetector r11 = r10.j boolean r11 = r11.b() if (r11 != 0) goto La2 r11 = 1 goto La3 La2: r11 = 0 La3: if (r0 != 0) goto Laf com.github.chrisbanes.photoview.CustomGestureDetector r0 = r10.j boolean r0 = r0.a() if (r0 != 0) goto Laf r0 = 1 goto Lb0 Laf: r0 = 0 Lb0: if (r11 == 0) goto Lb5 if (r0 == 0) goto Lb5 r1 = 1 Lb5: r10.g = r1 r1 = r3 goto Lba Lb9: r1 = r11 Lba: android.view.GestureDetector r11 = r10.i if (r11 == 0) goto Lc5 boolean r11 = r11.onTouchEvent(r12) if (r11 == 0) goto Lc5 r1 = 1 Lc5: return r1 */ throw new UnsupportedOperationException("Method not decompiled: com.github.chrisbanes.photoview.PhotoViewAttacher.onTouch(android.view.View, android.view.MotionEvent):boolean"); } private void k() { FlingRunnable flingRunnable = this.A; if (flingRunnable != null) { flingRunnable.a(); this.A = null; } } /* JADX INFO: Access modifiers changed from: private */ public void l() { if (m()) { b(n()); } } private boolean m() { float f; float f2; float f3; float f4; float f5; RectF a = a(n()); if (a == null) { return false; } float height = a.height(); float width = a.width(); float a2 = a(this.h); float f6 = 0.0f; if (height <= a2) { int i = AnonymousClass4.a[this.E.ordinal()]; if (i != 2) { if (i != 3) { a2 = (a2 - height) / 2.0f; f2 = a.top; } else { a2 -= height; f2 = a.top; } f3 = a2 - f2; } else { f = a.top; f3 = -f; } } else { f = a.top; if (f <= 0.0f) { f2 = a.bottom; if (f2 >= a2) { f3 = 0.0f; } f3 = a2 - f2; } f3 = -f; } float b = b(this.h); if (width <= b) { int i2 = AnonymousClass4.a[this.E.ordinal()]; if (i2 != 2) { if (i2 != 3) { f4 = (b - width) / 2.0f; f5 = a.left; } else { f4 = b - width; f5 = a.left; } f6 = f4 - f5; } else { f6 = -a.left; } this.B = 2; } else { float f7 = a.left; if (f7 > 0.0f) { this.B = 0; f6 = -f7; } else { float f8 = a.right; if (f8 < b) { f6 = b - f8; this.B = 1; } else { this.B = -1; } } } this.m.postTranslate(f6, f3); return true; } private Matrix n() { this.l.set(this.k); this.l.postConcat(this.m); return this.l; } private void o() { this.m.reset(); d(this.C); b(n()); m(); } public float c() { return this.e; } public void d(float f) { this.m.postRotate(f % 360.0f); l(); } public void e(float f) { this.m.setRotate(f % 360.0f); l(); } public float f() { return (float) Math.sqrt(((float) Math.pow(a(this.m, 0), 2.0d)) + ((float) Math.pow(a(this.m, 3), 2.0d))); } public ImageView.ScaleType g() { return this.E; } public void h() { if (this.D) { a(this.h.getDrawable()); } else { o(); } } public void b(float f) { Util.a(this.c, f, this.e); this.d = f; } public void c(float f) { Util.a(f, this.d, this.e); this.c = f; } public void f(float f) { a(f, false); } public void a(GestureDetector.OnDoubleTapListener onDoubleTapListener) { this.i.setOnDoubleTapListener(onDoubleTapListener); } public float d() { return this.d; } public float e() { return this.c; } public void a(OnScaleChangedListener onScaleChangedListener) { this.v = onScaleChangedListener; } public void b(boolean z) { this.D = z; h(); } public void a(OnSingleFlingListener onSingleFlingListener) { this.x = onSingleFlingListener; } public RectF a() { m(); return a(n()); } public Matrix b() { return this.l; } private void b(Matrix matrix) { RectF a; this.h.setImageMatrix(matrix); if (this.p == null || (a = a(matrix)) == null) { return; } this.p.a(a); } public void a(boolean z) { this.f = z; } public void a(float f) { Util.a(this.c, this.d, f); this.e = f; } /* JADX INFO: Access modifiers changed from: private */ public int b(ImageView imageView) { return (imageView.getWidth() - imageView.getPaddingLeft()) - imageView.getPaddingRight(); } public void a(View.OnLongClickListener onLongClickListener) { this.u = onLongClickListener; } public void a(View.OnClickListener onClickListener) { this.t = onClickListener; } public void a(OnMatrixChangedListener onMatrixChangedListener) { this.p = onMatrixChangedListener; } public void a(OnPhotoTapListener onPhotoTapListener) { this.q = onPhotoTapListener; } public void a(OnOutsidePhotoTapListener onOutsidePhotoTapListener) { this.r = onOutsidePhotoTapListener; } public void a(OnViewTapListener onViewTapListener) { this.s = onViewTapListener; } public void a(OnViewDragListener onViewDragListener) { this.y = onViewDragListener; } public void a(OnViewTouchListener onViewTouchListener) { this.z = onViewTouchListener; } public void a(float f, boolean z) { a(f, this.h.getRight() / 2, this.h.getBottom() / 2, z); } public void a(float f, float f2, float f3, boolean z) { if (f < this.c || f > this.e) { throw new IllegalArgumentException("Scale must be within the range of minScale and maxScale"); } if (z) { this.h.post(new AnimatedZoomRunnable(f(), f, f2, f3)); } else { this.m.setScale(f, f, f2, f3); l(); } } public void a(ImageView.ScaleType scaleType) { if (!Util.a(scaleType) || scaleType == this.E) { return; } this.E = scaleType; h(); } public void a(int i) { this.b = i; } private float a(Matrix matrix, int i) { matrix.getValues(this.o); return this.o[i]; } private RectF a(Matrix matrix) { if (this.h.getDrawable() == null) { return null; } this.n.set(0.0f, 0.0f, r0.getIntrinsicWidth(), r0.getIntrinsicHeight()); matrix.mapRect(this.n); return this.n; } private void a(Drawable drawable) { if (drawable == null) { return; } float b = b(this.h); float a = a(this.h); int intrinsicWidth = drawable.getIntrinsicWidth(); int intrinsicHeight = drawable.getIntrinsicHeight(); this.k.reset(); float f = intrinsicWidth; float f2 = b / f; float f3 = intrinsicHeight; float f4 = a / f3; ImageView.ScaleType scaleType = this.E; if (scaleType == ImageView.ScaleType.CENTER) { this.k.postTranslate((b - f) / 2.0f, (a - f3) / 2.0f); } else if (scaleType == ImageView.ScaleType.CENTER_CROP) { float max = Math.max(f2, f4); this.k.postScale(max, max); this.k.postTranslate((b - (f * max)) / 2.0f, (a - (f3 * max)) / 2.0f); } else if (scaleType == ImageView.ScaleType.CENTER_INSIDE) { float min = Math.min(1.0f, Math.min(f2, f4)); this.k.postScale(min, min); this.k.postTranslate((b - (f * min)) / 2.0f, (a - (f3 * min)) / 2.0f); } else { RectF rectF = new RectF(0.0f, 0.0f, f, f3); RectF rectF2 = new RectF(0.0f, 0.0f, b, a); if (((int) this.C) % 180 != 0) { rectF = new RectF(0.0f, 0.0f, f3, f); } int i = AnonymousClass4.a[this.E.ordinal()]; if (i == 1) { this.k.setRectToRect(rectF, rectF2, Matrix.ScaleToFit.CENTER); } else if (i == 2) { this.k.setRectToRect(rectF, rectF2, Matrix.ScaleToFit.START); } else if (i == 3) { this.k.setRectToRect(rectF, rectF2, Matrix.ScaleToFit.END); } else if (i == 4) { this.k.setRectToRect(rectF, rectF2, Matrix.ScaleToFit.FILL); } } o(); } /* JADX INFO: Access modifiers changed from: private */ public int a(ImageView imageView) { return (imageView.getHeight() - imageView.getPaddingTop()) - imageView.getPaddingBottom(); } }