package com.davemorrissey.labs.subscaleview; import android.content.Context; import android.content.res.TypedArray; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Point; import android.graphics.PointF; import android.graphics.Rect; import android.graphics.RectF; import android.net.Uri; import android.os.AsyncTask; import android.os.Handler; import android.os.Message; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; import android.view.ViewParent; import androidx.core.internal.view.SupportMenu; import androidx.exifinterface.media.ExifInterface; import com.davemorrissey.labs.subscaleview.decoder.CompatDecoderFactory; import com.davemorrissey.labs.subscaleview.decoder.DecoderFactory; import com.davemorrissey.labs.subscaleview.decoder.ImageDecoder; import com.davemorrissey.labs.subscaleview.decoder.ImageRegionDecoder; import com.davemorrissey.labs.subscaleview.decoder.SkiaImageDecoder; import com.davemorrissey.labs.subscaleview.decoder.SkiaImageRegionDecoder; import io.sentry.HttpStatusCodeRange; import io.sentry.protocol.Device; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.concurrent.Executor; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; /* loaded from: classes2.dex */ public class SubsamplingScaleImageView extends View { public static final int EASE_IN_OUT_QUAD = 2; public static final int EASE_OUT_QUAD = 1; private static final int MESSAGE_LONG_CLICK = 1; public static final int ORIENTATION_0 = 0; public static final int ORIENTATION_90 = 90; public static final int ORIENTATION_USE_EXIF = -1; public static final int ORIGIN_ANIM = 1; public static final int ORIGIN_DOUBLE_TAP_ZOOM = 4; public static final int ORIGIN_FLING = 3; public static final int ORIGIN_TOUCH = 2; public static final int PAN_LIMIT_CENTER = 3; public static final int PAN_LIMIT_INSIDE = 1; public static final int PAN_LIMIT_OUTSIDE = 2; public static final int SCALE_TYPE_CENTER_CROP = 2; public static final int SCALE_TYPE_CENTER_INSIDE = 1; public static final int SCALE_TYPE_CUSTOM = 3; public static final int SCALE_TYPE_START = 4; private static final String TAG = "SubsamplingScaleImageView"; public static final int TILE_SIZE_AUTO = Integer.MAX_VALUE; public static final int ZOOM_FOCUS_CENTER = 2; public static final int ZOOM_FOCUS_CENTER_IMMEDIATE = 3; public static final int ZOOM_FOCUS_FIXED = 1; private static Bitmap.Config preferredBitmapConfig; private Anim anim; private Bitmap bitmap; private DecoderFactory bitmapDecoderFactory; private boolean bitmapIsCached; private boolean bitmapIsPreview; private Paint bitmapPaint; private boolean debug; private Paint debugLinePaint; private Paint debugTextPaint; private ImageRegionDecoder decoder; private final ReadWriteLock decoderLock; private final float density; private GestureDetector detector; private int doubleTapZoomDuration; private float doubleTapZoomScale; private int doubleTapZoomStyle; private final float[] dstArray; private boolean eagerLoadingEnabled; private Executor executor; private int fullImageSampleSize; private final Handler handler; private boolean imageLoadedSent; private boolean isPanning; private boolean isQuickScaling; private boolean isZooming; private Matrix matrix; private float maxScale; private int maxTileHeight; private int maxTileWidth; private int maxTouchCount; private float minScale; private int minimumScaleType; private int minimumTileDpi; private OnImageEventListener onImageEventListener; private View.OnLongClickListener onLongClickListener; private OnStateChangedListener onStateChangedListener; private int orientation; private Rect pRegion; private boolean panEnabled; private int panLimit; private Float pendingScale; private boolean quickScaleEnabled; private float quickScaleLastDistance; private boolean quickScaleMoved; private PointF quickScaleSCenter; private final float quickScaleThreshold; private PointF quickScaleVLastPoint; private PointF quickScaleVStart; private boolean readySent; private DecoderFactory regionDecoderFactory; private int sHeight; private int sOrientation; private PointF sPendingCenter; private RectF sRect; private Rect sRegion; private PointF sRequestedCenter; private int sWidth; private ScaleAndTranslate satTemp; private float scale; private float scaleStart; private GestureDetector singleDetector; private final float[] srcArray; private Paint tileBgPaint; private Map> tileMap; private Uri uri; private PointF vCenterStart; private float vDistStart; private PointF vTranslate; private PointF vTranslateBefore; private PointF vTranslateStart; private boolean zoomEnabled; public static final int ORIENTATION_180 = 180; public static final int ORIENTATION_270 = 270; private static final List VALID_ORIENTATIONS = Arrays.asList(0, 90, Integer.valueOf(ORIENTATION_180), Integer.valueOf(ORIENTATION_270), -1); private static final List VALID_ZOOM_STYLES = Arrays.asList(1, 2, 3); private static final List VALID_EASING_STYLES = Arrays.asList(2, 1); private static final List VALID_PAN_LIMITS = Arrays.asList(1, 2, 3); private static final List VALID_SCALE_TYPES = Arrays.asList(2, 1, 3, 4); /* loaded from: classes2.dex */ public static class DefaultOnAnimationEventListener implements OnAnimationEventListener { @Override // com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.OnAnimationEventListener public void onComplete() { } @Override // com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.OnAnimationEventListener public void onInterruptedByNewAnim() { } @Override // com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.OnAnimationEventListener public void onInterruptedByUser() { } } /* loaded from: classes2.dex */ public static class DefaultOnImageEventListener implements OnImageEventListener { @Override // com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.OnImageEventListener public void onImageLoadError(Exception exc) { } @Override // com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.OnImageEventListener public void onImageLoaded() { } @Override // com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.OnImageEventListener public void onPreviewLoadError(Exception exc) { } @Override // com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.OnImageEventListener public void onPreviewReleased() { } @Override // com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.OnImageEventListener public void onReady() { } @Override // com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.OnImageEventListener public void onTileLoadError(Exception exc) { } } /* loaded from: classes2.dex */ public static class DefaultOnStateChangedListener implements OnStateChangedListener { @Override // com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.OnStateChangedListener public void onCenterChanged(PointF pointF, int i) { } @Override // com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.OnStateChangedListener public void onScaleChanged(float f, int i) { } } /* loaded from: classes2.dex */ public interface OnAnimationEventListener { void onComplete(); void onInterruptedByNewAnim(); void onInterruptedByUser(); } /* loaded from: classes2.dex */ public interface OnImageEventListener { void onImageLoadError(Exception exc); void onImageLoaded(); void onPreviewLoadError(Exception exc); void onPreviewReleased(); void onReady(); void onTileLoadError(Exception exc); } /* loaded from: classes2.dex */ public interface OnStateChangedListener { void onCenterChanged(PointF pointF, int i); void onScaleChanged(float f, int i); } private float easeInOutQuad(long j, float f, float f2, long j2) { float f3; float f4 = ((float) j) / (((float) j2) / 2.0f); if (f4 < 1.0f) { f3 = (f2 / 2.0f) * f4; } else { float f5 = f4 - 1.0f; f3 = (-f2) / 2.0f; f4 = (f5 * (f5 - 2.0f)) - 1.0f; } return (f3 * f4) + f; } private float easeOutQuad(long j, float f, float f2, long j2) { float f3 = ((float) j) / ((float) j2); return ((-f2) * f3 * (f3 - 2.0f)) + f; } public static Bitmap.Config getPreferredBitmapConfig() { return preferredBitmapConfig; } private int getRequiredRotation() { int i = this.orientation; return i == -1 ? this.sOrientation : i; } private int px(int i) { return (int) (this.density * i); } public static void setPreferredBitmapConfig(Bitmap.Config config) { preferredBitmapConfig = config; } public float getMaxScale() { return this.maxScale; } public final int getOrientation() { return this.orientation; } public final int getSHeight() { return this.sHeight; } public final int getSWidth() { return this.sWidth; } public final float getScale() { return this.scale; } public boolean hasImage() { return (this.uri == null && this.bitmap == null) ? false : true; } public final boolean isImageLoaded() { return this.imageLoadedSent; } public final boolean isPanEnabled() { return this.panEnabled; } public final boolean isQuickScaleEnabled() { return this.quickScaleEnabled; } public final boolean isReady() { return this.readySent; } public final boolean isZoomEnabled() { return this.zoomEnabled; } protected void onImageLoaded() { } protected void onReady() { } public final void setDebug(boolean z) { this.debug = z; } public final void setDoubleTapZoomScale(float f) { this.doubleTapZoomScale = f; } public void setEagerLoadingEnabled(boolean z) { this.eagerLoadingEnabled = z; } public final void setMaxScale(float f) { this.maxScale = f; } public void setMaxTileSize(int i) { this.maxTileWidth = i; this.maxTileHeight = i; } public void setMaxTileSize(int i, int i2) { this.maxTileWidth = i; this.maxTileHeight = i2; } public final void setMinScale(float f) { this.minScale = f; } public void setOnImageEventListener(OnImageEventListener onImageEventListener) { this.onImageEventListener = onImageEventListener; } @Override // android.view.View public void setOnLongClickListener(View.OnLongClickListener onLongClickListener) { this.onLongClickListener = onLongClickListener; } public void setOnStateChangedListener(OnStateChangedListener onStateChangedListener) { this.onStateChangedListener = onStateChangedListener; } public final void setQuickScaleEnabled(boolean z) { this.quickScaleEnabled = z; } public final void setZoomEnabled(boolean z) { this.zoomEnabled = z; } public SubsamplingScaleImageView(Context context, AttributeSet attributeSet) { super(context, attributeSet); int resourceId; String string; this.orientation = 0; this.maxScale = 2.0f; this.minScale = minScale(); this.minimumTileDpi = -1; this.panLimit = 1; this.minimumScaleType = 1; this.maxTileWidth = Integer.MAX_VALUE; this.maxTileHeight = Integer.MAX_VALUE; this.executor = AsyncTask.THREAD_POOL_EXECUTOR; this.eagerLoadingEnabled = true; this.panEnabled = true; this.zoomEnabled = true; this.quickScaleEnabled = true; this.doubleTapZoomScale = 1.0f; this.doubleTapZoomStyle = 1; this.doubleTapZoomDuration = HttpStatusCodeRange.DEFAULT_MIN; this.decoderLock = new ReentrantReadWriteLock(true); this.bitmapDecoderFactory = new CompatDecoderFactory(SkiaImageDecoder.class); this.regionDecoderFactory = new CompatDecoderFactory(SkiaImageRegionDecoder.class); this.srcArray = new float[8]; this.dstArray = new float[8]; this.density = getResources().getDisplayMetrics().density; setMinimumDpi(160); setDoubleTapZoomDpi(160); setMinimumTileDpi(320); setGestureDetector(context); this.handler = new Handler(new Handler.Callback() { // from class: com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.1 @Override // android.os.Handler.Callback public boolean handleMessage(Message message) { if (message.what == 1 && SubsamplingScaleImageView.this.onLongClickListener != null) { SubsamplingScaleImageView.this.maxTouchCount = 0; SubsamplingScaleImageView subsamplingScaleImageView = SubsamplingScaleImageView.this; SubsamplingScaleImageView.super.setOnLongClickListener(subsamplingScaleImageView.onLongClickListener); SubsamplingScaleImageView.this.performLongClick(); SubsamplingScaleImageView.super.setOnLongClickListener(null); } return true; } }); if (attributeSet != null) { TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, R.styleable.SubsamplingScaleImageView); if (obtainStyledAttributes.hasValue(R.styleable.SubsamplingScaleImageView_assetName) && (string = obtainStyledAttributes.getString(R.styleable.SubsamplingScaleImageView_assetName)) != null && string.length() > 0) { setImage(ImageSource.asset(string).tilingEnabled()); } if (obtainStyledAttributes.hasValue(R.styleable.SubsamplingScaleImageView_src) && (resourceId = obtainStyledAttributes.getResourceId(R.styleable.SubsamplingScaleImageView_src, 0)) > 0) { setImage(ImageSource.resource(resourceId).tilingEnabled()); } if (obtainStyledAttributes.hasValue(R.styleable.SubsamplingScaleImageView_panEnabled)) { setPanEnabled(obtainStyledAttributes.getBoolean(R.styleable.SubsamplingScaleImageView_panEnabled, true)); } if (obtainStyledAttributes.hasValue(R.styleable.SubsamplingScaleImageView_zoomEnabled)) { setZoomEnabled(obtainStyledAttributes.getBoolean(R.styleable.SubsamplingScaleImageView_zoomEnabled, true)); } if (obtainStyledAttributes.hasValue(R.styleable.SubsamplingScaleImageView_quickScaleEnabled)) { setQuickScaleEnabled(obtainStyledAttributes.getBoolean(R.styleable.SubsamplingScaleImageView_quickScaleEnabled, true)); } if (obtainStyledAttributes.hasValue(R.styleable.SubsamplingScaleImageView_tileBackgroundColor)) { setTileBackgroundColor(obtainStyledAttributes.getColor(R.styleable.SubsamplingScaleImageView_tileBackgroundColor, Color.argb(0, 0, 0, 0))); } obtainStyledAttributes.recycle(); } this.quickScaleThreshold = TypedValue.applyDimension(1, 20.0f, context.getResources().getDisplayMetrics()); } public SubsamplingScaleImageView(Context context) { this(context, null); } public final void setOrientation(int i) { if (!VALID_ORIENTATIONS.contains(Integer.valueOf(i))) { throw new IllegalArgumentException("Invalid orientation: " + i); } this.orientation = i; reset(false); invalidate(); requestLayout(); } public final void setImage(ImageSource imageSource) { setImage(imageSource, null, null); } public final void setImage(ImageSource imageSource, ImageViewState imageViewState) { setImage(imageSource, null, imageViewState); } public final void setImage(ImageSource imageSource, ImageSource imageSource2) { setImage(imageSource, imageSource2, null); } public final void setImage(ImageSource imageSource, ImageSource imageSource2, ImageViewState imageViewState) { if (imageSource == null) { throw new NullPointerException("imageSource must not be null"); } reset(true); if (imageViewState != null) { restoreState(imageViewState); } if (imageSource2 != null) { if (imageSource.getBitmap() != null) { throw new IllegalArgumentException("Preview image cannot be used when a bitmap is provided for the main image"); } if (imageSource.getSWidth() <= 0 || imageSource.getSHeight() <= 0) { throw new IllegalArgumentException("Preview image cannot be used unless dimensions are provided for the main image"); } this.sWidth = imageSource.getSWidth(); this.sHeight = imageSource.getSHeight(); this.pRegion = imageSource2.getSRegion(); if (imageSource2.getBitmap() != null) { this.bitmapIsCached = imageSource2.isCached(); onPreviewLoaded(imageSource2.getBitmap()); } else { Uri uri = imageSource2.getUri(); if (uri == null && imageSource2.getResource() != null) { uri = Uri.parse("android.resource://" + getContext().getPackageName() + "/" + imageSource2.getResource()); } execute(new BitmapLoadTask(this, getContext(), this.bitmapDecoderFactory, uri, true)); } } if (imageSource.getBitmap() != null && imageSource.getSRegion() != null) { onImageLoaded(Bitmap.createBitmap(imageSource.getBitmap(), imageSource.getSRegion().left, imageSource.getSRegion().top, imageSource.getSRegion().width(), imageSource.getSRegion().height()), 0, false); return; } if (imageSource.getBitmap() != null) { onImageLoaded(imageSource.getBitmap(), 0, imageSource.isCached()); return; } this.sRegion = imageSource.getSRegion(); Uri uri2 = imageSource.getUri(); this.uri = uri2; if (uri2 == null && imageSource.getResource() != null) { this.uri = Uri.parse("android.resource://" + getContext().getPackageName() + "/" + imageSource.getResource()); } if (imageSource.getTile() || this.sRegion != null) { execute(new TilesInitTask(this, getContext(), this.regionDecoderFactory, this.uri)); } else { execute(new BitmapLoadTask(this, getContext(), this.bitmapDecoderFactory, this.uri, false)); } } private void reset(boolean z) { OnImageEventListener onImageEventListener; debug("reset newImage=" + z, new Object[0]); this.scale = 0.0f; this.scaleStart = 0.0f; this.vTranslate = null; this.vTranslateStart = null; this.vTranslateBefore = null; this.pendingScale = Float.valueOf(0.0f); this.sPendingCenter = null; this.sRequestedCenter = null; this.isZooming = false; this.isPanning = false; this.isQuickScaling = false; this.maxTouchCount = 0; this.fullImageSampleSize = 0; this.vCenterStart = null; this.vDistStart = 0.0f; this.quickScaleLastDistance = 0.0f; this.quickScaleMoved = false; this.quickScaleSCenter = null; this.quickScaleVLastPoint = null; this.quickScaleVStart = null; this.anim = null; this.satTemp = null; this.matrix = null; this.sRect = null; if (z) { this.uri = null; this.decoderLock.writeLock().lock(); try { ImageRegionDecoder imageRegionDecoder = this.decoder; if (imageRegionDecoder != null) { imageRegionDecoder.recycle(); this.decoder = null; } this.decoderLock.writeLock().unlock(); Bitmap bitmap = this.bitmap; if (bitmap != null && !this.bitmapIsCached) { bitmap.recycle(); } if (this.bitmap != null && this.bitmapIsCached && (onImageEventListener = this.onImageEventListener) != null) { onImageEventListener.onPreviewReleased(); } this.sWidth = 0; this.sHeight = 0; this.sOrientation = 0; this.sRegion = null; this.pRegion = null; this.readySent = false; this.imageLoadedSent = false; this.bitmap = null; this.bitmapIsPreview = false; this.bitmapIsCached = false; } catch (Throwable th) { this.decoderLock.writeLock().unlock(); throw th; } } Map> map = this.tileMap; if (map != null) { Iterator>> it = map.entrySet().iterator(); while (it.hasNext()) { for (Tile tile : it.next().getValue()) { tile.visible = false; if (tile.bitmap != null) { tile.bitmap.recycle(); tile.bitmap = null; } } } this.tileMap = null; } setGestureDetector(getContext()); } /* JADX INFO: Access modifiers changed from: private */ public void setGestureDetector(final Context context) { this.detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { // from class: com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.2 @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnGestureListener public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f2) { if (SubsamplingScaleImageView.this.panEnabled && SubsamplingScaleImageView.this.readySent && SubsamplingScaleImageView.this.vTranslate != null && motionEvent != null && motionEvent2 != null && ((Math.abs(motionEvent.getX() - motionEvent2.getX()) > 50.0f || Math.abs(motionEvent.getY() - motionEvent2.getY()) > 50.0f) && ((Math.abs(f) > 500.0f || Math.abs(f2) > 500.0f) && !SubsamplingScaleImageView.this.isZooming))) { PointF pointF = new PointF(SubsamplingScaleImageView.this.vTranslate.x + (f * 0.25f), SubsamplingScaleImageView.this.vTranslate.y + (f2 * 0.25f)); new AnimationBuilder(new PointF(((SubsamplingScaleImageView.this.getWidth() / 2) - pointF.x) / SubsamplingScaleImageView.this.scale, ((SubsamplingScaleImageView.this.getHeight() / 2) - pointF.y) / SubsamplingScaleImageView.this.scale)).withEasing(1).withPanLimited(false).withOrigin(3).start(); return true; } return super.onFling(motionEvent, motionEvent2, f, f2); } @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnDoubleTapListener public boolean onSingleTapConfirmed(MotionEvent motionEvent) { SubsamplingScaleImageView.this.performClick(); return true; } @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnDoubleTapListener public boolean onDoubleTap(MotionEvent motionEvent) { if (SubsamplingScaleImageView.this.zoomEnabled && SubsamplingScaleImageView.this.readySent && SubsamplingScaleImageView.this.vTranslate != null) { SubsamplingScaleImageView.this.setGestureDetector(context); if (SubsamplingScaleImageView.this.quickScaleEnabled) { SubsamplingScaleImageView.this.vCenterStart = new PointF(motionEvent.getX(), motionEvent.getY()); SubsamplingScaleImageView.this.vTranslateStart = new PointF(SubsamplingScaleImageView.this.vTranslate.x, SubsamplingScaleImageView.this.vTranslate.y); SubsamplingScaleImageView subsamplingScaleImageView = SubsamplingScaleImageView.this; subsamplingScaleImageView.scaleStart = subsamplingScaleImageView.scale; SubsamplingScaleImageView.this.isQuickScaling = true; SubsamplingScaleImageView.this.isZooming = true; SubsamplingScaleImageView.this.quickScaleLastDistance = -1.0f; SubsamplingScaleImageView subsamplingScaleImageView2 = SubsamplingScaleImageView.this; subsamplingScaleImageView2.quickScaleSCenter = subsamplingScaleImageView2.viewToSourceCoord(subsamplingScaleImageView2.vCenterStart); SubsamplingScaleImageView.this.quickScaleVStart = new PointF(motionEvent.getX(), motionEvent.getY()); SubsamplingScaleImageView.this.quickScaleVLastPoint = new PointF(SubsamplingScaleImageView.this.quickScaleSCenter.x, SubsamplingScaleImageView.this.quickScaleSCenter.y); SubsamplingScaleImageView.this.quickScaleMoved = false; return false; } SubsamplingScaleImageView subsamplingScaleImageView3 = SubsamplingScaleImageView.this; subsamplingScaleImageView3.doubleTapZoom(subsamplingScaleImageView3.viewToSourceCoord(new PointF(motionEvent.getX(), motionEvent.getY())), new PointF(motionEvent.getX(), motionEvent.getY())); return true; } return super.onDoubleTapEvent(motionEvent); } }); this.singleDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { // from class: com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.3 @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnDoubleTapListener public boolean onSingleTapConfirmed(MotionEvent motionEvent) { SubsamplingScaleImageView.this.performClick(); return true; } }); } @Override // android.view.View protected void onSizeChanged(int i, int i2, int i3, int i4) { debug("onSizeChanged %dx%d -> %dx%d", Integer.valueOf(i3), Integer.valueOf(i4), Integer.valueOf(i), Integer.valueOf(i2)); PointF center = getCenter(); if (!this.readySent || center == null) { return; } this.anim = null; this.pendingScale = Float.valueOf(this.scale); this.sPendingCenter = center; } @Override // android.view.View protected void onMeasure(int i, int i2) { int mode = View.MeasureSpec.getMode(i); int mode2 = View.MeasureSpec.getMode(i2); int size = View.MeasureSpec.getSize(i); int size2 = View.MeasureSpec.getSize(i2); boolean z = mode != 1073741824; boolean z2 = mode2 != 1073741824; if (this.sWidth > 0 && this.sHeight > 0) { if (z && z2) { size = sWidth(); size2 = sHeight(); } else if (z2) { size2 = (int) ((sHeight() / sWidth()) * size); } else if (z) { size = (int) ((sWidth() / sHeight()) * size2); } } setMeasuredDimension(Math.max(size, getSuggestedMinimumWidth()), Math.max(size2, getSuggestedMinimumHeight())); } @Override // android.view.View public boolean onTouchEvent(MotionEvent motionEvent) { GestureDetector gestureDetector; Anim anim = this.anim; if (anim != null && !anim.interruptible) { requestDisallowInterceptTouchEvent(true); return true; } Anim anim2 = this.anim; if (anim2 != null && anim2.listener != null) { try { this.anim.listener.onInterruptedByUser(); } catch (Exception e) { Log.w(TAG, "Error thrown by animation listener", e); } } this.anim = null; if (this.vTranslate == null) { GestureDetector gestureDetector2 = this.singleDetector; if (gestureDetector2 != null) { gestureDetector2.onTouchEvent(motionEvent); } return true; } if (!this.isQuickScaling && ((gestureDetector = this.detector) == null || gestureDetector.onTouchEvent(motionEvent))) { this.isZooming = false; this.isPanning = false; this.maxTouchCount = 0; return true; } if (this.vTranslateStart == null) { this.vTranslateStart = new PointF(0.0f, 0.0f); } if (this.vTranslateBefore == null) { this.vTranslateBefore = new PointF(0.0f, 0.0f); } if (this.vCenterStart == null) { this.vCenterStart = new PointF(0.0f, 0.0f); } float f = this.scale; this.vTranslateBefore.set(this.vTranslate); boolean onTouchEventInternal = onTouchEventInternal(motionEvent); sendStateChanged(f, this.vTranslateBefore, 2); return onTouchEventInternal || super.onTouchEvent(motionEvent); } /* JADX WARN: Code restructure failed: missing block: B:12:0x001f, code lost: if (r1 != 262) goto L133; */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ private boolean onTouchEventInternal(android.view.MotionEvent r11) { /* Method dump skipped, instructions count: 1210 To view this dump add '--comments-level debug' option */ throw new UnsupportedOperationException("Method not decompiled: com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView.onTouchEventInternal(android.view.MotionEvent):boolean"); } private void requestDisallowInterceptTouchEvent(boolean z) { ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(z); } } /* JADX INFO: Access modifiers changed from: private */ public void doubleTapZoom(PointF pointF, PointF pointF2) { if (!this.panEnabled) { PointF pointF3 = this.sRequestedCenter; if (pointF3 != null) { pointF.x = pointF3.x; pointF.y = this.sRequestedCenter.y; } else { pointF.x = sWidth() / 2; pointF.y = sHeight() / 2; } } float min = Math.min(this.maxScale, this.doubleTapZoomScale); float f = this.scale; boolean z = ((double) f) <= ((double) min) * 0.9d || f == this.minScale; if (!z) { min = minScale(); } float f2 = min; int i = this.doubleTapZoomStyle; if (i == 3) { setScaleAndCenter(f2, pointF); } else if (i == 2 || !z || !this.panEnabled) { new AnimationBuilder(f2, pointF).withInterruptible(false).withDuration(this.doubleTapZoomDuration).withOrigin(4).start(); } else if (i == 1) { new AnimationBuilder(f2, pointF, pointF2).withInterruptible(false).withDuration(this.doubleTapZoomDuration).withOrigin(4).start(); } invalidate(); } @Override // android.view.View protected void onDraw(Canvas canvas) { int i; float f; int i2; boolean z; int i3; super.onDraw(canvas); createPaints(); if (this.sWidth == 0 || this.sHeight == 0 || getWidth() == 0 || getHeight() == 0) { return; } if (this.tileMap == null && this.decoder != null) { initialiseBaseLayer(getMaxBitmapDimensions(canvas)); } if (checkReady()) { preDraw(); Anim anim = this.anim; if (anim != null && anim.vFocusStart != null) { float f2 = this.scale; if (this.vTranslateBefore == null) { this.vTranslateBefore = new PointF(0.0f, 0.0f); } this.vTranslateBefore.set(this.vTranslate); long currentTimeMillis = System.currentTimeMillis() - this.anim.time; boolean z2 = currentTimeMillis > this.anim.duration; long min = Math.min(currentTimeMillis, this.anim.duration); this.scale = ease(this.anim.easing, min, this.anim.scaleStart, this.anim.scaleEnd - this.anim.scaleStart, this.anim.duration); float ease = ease(this.anim.easing, min, this.anim.vFocusStart.x, this.anim.vFocusEnd.x - this.anim.vFocusStart.x, this.anim.duration); float ease2 = ease(this.anim.easing, min, this.anim.vFocusStart.y, this.anim.vFocusEnd.y - this.anim.vFocusStart.y, this.anim.duration); this.vTranslate.x -= sourceToViewX(this.anim.sCenterEnd.x) - ease; this.vTranslate.y -= sourceToViewY(this.anim.sCenterEnd.y) - ease2; fitToBounds(z2 || this.anim.scaleStart == this.anim.scaleEnd); sendStateChanged(f2, this.vTranslateBefore, this.anim.origin); refreshRequiredTiles(z2); if (z2) { if (this.anim.listener != null) { try { this.anim.listener.onComplete(); } catch (Exception e) { Log.w(TAG, "Error thrown by animation listener", e); } } this.anim = null; } invalidate(); } Map> map = this.tileMap; int i4 = 90; int i5 = ORIENTATION_180; if (map == null || !isBaseLayerReady()) { i = 15; if (this.bitmap != null) { float f3 = this.scale; if (this.bitmapIsPreview) { f3 *= this.sWidth / r0.getWidth(); f = this.scale * (this.sHeight / this.bitmap.getHeight()); } else { f = f3; } if (this.matrix == null) { this.matrix = new Matrix(); } this.matrix.reset(); this.matrix.postScale(f3, f); this.matrix.postRotate(getRequiredRotation()); this.matrix.postTranslate(this.vTranslate.x, this.vTranslate.y); if (getRequiredRotation() == 180) { Matrix matrix = this.matrix; float f4 = this.scale; matrix.postTranslate(this.sWidth * f4, f4 * this.sHeight); } else if (getRequiredRotation() == 90) { this.matrix.postTranslate(this.scale * this.sHeight, 0.0f); } else if (getRequiredRotation() == 270) { this.matrix.postTranslate(0.0f, this.scale * this.sWidth); } if (this.tileBgPaint != null) { if (this.sRect == null) { this.sRect = new RectF(); } this.sRect.set(0.0f, 0.0f, this.bitmapIsPreview ? this.bitmap.getWidth() : this.sWidth, this.bitmapIsPreview ? this.bitmap.getHeight() : this.sHeight); this.matrix.mapRect(this.sRect); canvas.drawRect(this.sRect, this.tileBgPaint); } canvas.drawBitmap(this.bitmap, this.matrix, this.bitmapPaint); } } else { int min2 = Math.min(this.fullImageSampleSize, calculateInSampleSize(this.scale)); boolean z3 = false; for (Map.Entry> entry : this.tileMap.entrySet()) { if (entry.getKey().intValue() == min2) { for (Tile tile : entry.getValue()) { if (tile.visible && (tile.loading || tile.bitmap == null)) { z3 = true; } } } } for (Map.Entry> entry2 : this.tileMap.entrySet()) { if (entry2.getKey().intValue() == min2 || z3) { for (Tile tile2 : entry2.getValue()) { sourceToViewRect(tile2.sRect, tile2.vRect); if (!tile2.loading && tile2.bitmap != null) { if (this.tileBgPaint != null) { canvas.drawRect(tile2.vRect, this.tileBgPaint); } if (this.matrix == null) { this.matrix = new Matrix(); } this.matrix.reset(); z = z3; i2 = i4; i3 = i5; setMatrixArray(this.srcArray, 0.0f, 0.0f, tile2.bitmap.getWidth(), 0.0f, tile2.bitmap.getWidth(), tile2.bitmap.getHeight(), 0.0f, tile2.bitmap.getHeight()); if (getRequiredRotation() != 0) { if (getRequiredRotation() != i2) { if (getRequiredRotation() != i3) { if (getRequiredRotation() == 270) { setMatrixArray(this.dstArray, tile2.vRect.left, tile2.vRect.bottom, tile2.vRect.left, tile2.vRect.top, tile2.vRect.right, tile2.vRect.top, tile2.vRect.right, tile2.vRect.bottom); } } else { setMatrixArray(this.dstArray, tile2.vRect.right, tile2.vRect.bottom, tile2.vRect.left, tile2.vRect.bottom, tile2.vRect.left, tile2.vRect.top, tile2.vRect.right, tile2.vRect.top); } } else { setMatrixArray(this.dstArray, tile2.vRect.right, tile2.vRect.top, tile2.vRect.right, tile2.vRect.bottom, tile2.vRect.left, tile2.vRect.bottom, tile2.vRect.left, tile2.vRect.top); } } else { setMatrixArray(this.dstArray, tile2.vRect.left, tile2.vRect.top, tile2.vRect.right, tile2.vRect.top, tile2.vRect.right, tile2.vRect.bottom, tile2.vRect.left, tile2.vRect.bottom); } this.matrix.setPolyToPoly(this.srcArray, 0, this.dstArray, 0, 4); canvas.drawBitmap(tile2.bitmap, this.matrix, this.bitmapPaint); if (this.debug) { canvas.drawRect(tile2.vRect, this.debugLinePaint); } } else { i2 = i4; z = z3; i3 = i5; if (tile2.loading && this.debug) { canvas.drawText("LOADING", tile2.vRect.left + px(5), tile2.vRect.top + px(35), this.debugTextPaint); } } if (tile2.visible && this.debug) { canvas.drawText("ISS " + tile2.sampleSize + " RECT " + tile2.sRect.top + "," + tile2.sRect.left + "," + tile2.sRect.bottom + "," + tile2.sRect.right, tile2.vRect.left + px(5), tile2.vRect.top + px(15), this.debugTextPaint); } i5 = i3; i4 = i2; z3 = z; } } i5 = i5; i4 = i4; z3 = z3; } i = 15; } if (this.debug) { canvas.drawText("Scale: " + String.format(Locale.ENGLISH, "%.2f", Float.valueOf(this.scale)) + " (" + String.format(Locale.ENGLISH, "%.2f", Float.valueOf(minScale())) + " - " + String.format(Locale.ENGLISH, "%.2f", Float.valueOf(this.maxScale)) + ")", px(5), px(i), this.debugTextPaint); canvas.drawText("Translate: " + String.format(Locale.ENGLISH, "%.2f", Float.valueOf(this.vTranslate.x)) + ":" + String.format(Locale.ENGLISH, "%.2f", Float.valueOf(this.vTranslate.y)), px(5), px(30), this.debugTextPaint); PointF center = getCenter(); canvas.drawText("Source center: " + String.format(Locale.ENGLISH, "%.2f", Float.valueOf(center.x)) + ":" + String.format(Locale.ENGLISH, "%.2f", Float.valueOf(center.y)), px(5), px(45), this.debugTextPaint); Anim anim2 = this.anim; if (anim2 != null) { PointF sourceToViewCoord = sourceToViewCoord(anim2.sCenterStart); PointF sourceToViewCoord2 = sourceToViewCoord(this.anim.sCenterEndRequested); PointF sourceToViewCoord3 = sourceToViewCoord(this.anim.sCenterEnd); canvas.drawCircle(sourceToViewCoord.x, sourceToViewCoord.y, px(10), this.debugLinePaint); this.debugLinePaint.setColor(SupportMenu.CATEGORY_MASK); canvas.drawCircle(sourceToViewCoord2.x, sourceToViewCoord2.y, px(20), this.debugLinePaint); this.debugLinePaint.setColor(-16776961); canvas.drawCircle(sourceToViewCoord3.x, sourceToViewCoord3.y, px(25), this.debugLinePaint); this.debugLinePaint.setColor(-16711681); canvas.drawCircle(getWidth() / 2, getHeight() / 2, px(30), this.debugLinePaint); } if (this.vCenterStart != null) { this.debugLinePaint.setColor(SupportMenu.CATEGORY_MASK); canvas.drawCircle(this.vCenterStart.x, this.vCenterStart.y, px(20), this.debugLinePaint); } if (this.quickScaleSCenter != null) { this.debugLinePaint.setColor(-16776961); canvas.drawCircle(sourceToViewX(this.quickScaleSCenter.x), sourceToViewY(this.quickScaleSCenter.y), px(35), this.debugLinePaint); } if (this.quickScaleVStart != null && this.isQuickScaling) { this.debugLinePaint.setColor(-16711681); canvas.drawCircle(this.quickScaleVStart.x, this.quickScaleVStart.y, px(30), this.debugLinePaint); } this.debugLinePaint.setColor(-65281); } } } private void setMatrixArray(float[] fArr, float f, float f2, float f3, float f4, float f5, float f6, float f7, float f8) { fArr[0] = f; fArr[1] = f2; fArr[2] = f3; fArr[3] = f4; fArr[4] = f5; fArr[5] = f6; fArr[6] = f7; fArr[7] = f8; } private boolean isBaseLayerReady() { boolean z = true; if (this.bitmap != null && !this.bitmapIsPreview) { return true; } Map> map = this.tileMap; if (map == null) { return false; } for (Map.Entry> entry : map.entrySet()) { if (entry.getKey().intValue() == this.fullImageSampleSize) { for (Tile tile : entry.getValue()) { if (tile.loading || tile.bitmap == null) { z = false; } } } } return z; } private boolean checkReady() { boolean z = getWidth() > 0 && getHeight() > 0 && this.sWidth > 0 && this.sHeight > 0 && (this.bitmap != null || isBaseLayerReady()); if (!this.readySent && z) { preDraw(); this.readySent = true; onReady(); OnImageEventListener onImageEventListener = this.onImageEventListener; if (onImageEventListener != null) { onImageEventListener.onReady(); } } return z; } private boolean checkImageLoaded() { boolean isBaseLayerReady = isBaseLayerReady(); if (!this.imageLoadedSent && isBaseLayerReady) { preDraw(); this.imageLoadedSent = true; onImageLoaded(); OnImageEventListener onImageEventListener = this.onImageEventListener; if (onImageEventListener != null) { onImageEventListener.onImageLoaded(); } } return isBaseLayerReady; } private void createPaints() { if (this.bitmapPaint == null) { Paint paint = new Paint(); this.bitmapPaint = paint; paint.setAntiAlias(true); this.bitmapPaint.setFilterBitmap(true); this.bitmapPaint.setDither(true); } if ((this.debugTextPaint == null || this.debugLinePaint == null) && this.debug) { Paint paint2 = new Paint(); this.debugTextPaint = paint2; paint2.setTextSize(px(12)); this.debugTextPaint.setColor(-65281); this.debugTextPaint.setStyle(Paint.Style.FILL); Paint paint3 = new Paint(); this.debugLinePaint = paint3; paint3.setColor(-65281); this.debugLinePaint.setStyle(Paint.Style.STROKE); this.debugLinePaint.setStrokeWidth(px(1)); } } private synchronized void initialiseBaseLayer(Point point) { debug("initialiseBaseLayer maxTileDimensions=%dx%d", Integer.valueOf(point.x), Integer.valueOf(point.y)); ScaleAndTranslate scaleAndTranslate = new ScaleAndTranslate(0.0f, new PointF(0.0f, 0.0f)); this.satTemp = scaleAndTranslate; fitToBounds(true, scaleAndTranslate); int calculateInSampleSize = calculateInSampleSize(this.satTemp.scale); this.fullImageSampleSize = calculateInSampleSize; if (calculateInSampleSize > 1) { this.fullImageSampleSize = calculateInSampleSize / 2; } if (this.fullImageSampleSize == 1 && this.sRegion == null && sWidth() < point.x && sHeight() < point.y) { this.decoder.recycle(); this.decoder = null; execute(new BitmapLoadTask(this, getContext(), this.bitmapDecoderFactory, this.uri, false)); } else { initialiseTileMap(point); Iterator it = this.tileMap.get(Integer.valueOf(this.fullImageSampleSize)).iterator(); while (it.hasNext()) { execute(new TileLoadTask(this, this.decoder, it.next())); } refreshRequiredTiles(true); } } private void refreshRequiredTiles(boolean z) { if (this.decoder == null || this.tileMap == null) { return; } int min = Math.min(this.fullImageSampleSize, calculateInSampleSize(this.scale)); Iterator>> it = this.tileMap.entrySet().iterator(); while (it.hasNext()) { for (Tile tile : it.next().getValue()) { if (tile.sampleSize < min || (tile.sampleSize > min && tile.sampleSize != this.fullImageSampleSize)) { tile.visible = false; if (tile.bitmap != null) { tile.bitmap.recycle(); tile.bitmap = null; } } if (tile.sampleSize == min) { if (tileVisible(tile)) { tile.visible = true; if (!tile.loading && tile.bitmap == null && z) { execute(new TileLoadTask(this, this.decoder, tile)); } } else if (tile.sampleSize != this.fullImageSampleSize) { tile.visible = false; if (tile.bitmap != null) { tile.bitmap.recycle(); tile.bitmap = null; } } } else if (tile.sampleSize == this.fullImageSampleSize) { tile.visible = true; } } } } private boolean tileVisible(Tile tile) { return viewToSourceX(0.0f) <= ((float) tile.sRect.right) && ((float) tile.sRect.left) <= viewToSourceX((float) getWidth()) && viewToSourceY(0.0f) <= ((float) tile.sRect.bottom) && ((float) tile.sRect.top) <= viewToSourceY((float) getHeight()); } private void preDraw() { Float f; if (getWidth() == 0 || getHeight() == 0 || this.sWidth <= 0 || this.sHeight <= 0) { return; } if (this.sPendingCenter != null && (f = this.pendingScale) != null) { this.scale = f.floatValue(); if (this.vTranslate == null) { this.vTranslate = new PointF(); } this.vTranslate.x = (getWidth() / 2) - (this.scale * this.sPendingCenter.x); this.vTranslate.y = (getHeight() / 2) - (this.scale * this.sPendingCenter.y); this.sPendingCenter = null; this.pendingScale = null; fitToBounds(true); refreshRequiredTiles(true); } fitToBounds(false); } private int calculateInSampleSize(float f) { int round; if (this.minimumTileDpi > 0) { DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); f *= this.minimumTileDpi / ((displayMetrics.xdpi + displayMetrics.ydpi) / 2.0f); } int sWidth = (int) (sWidth() * f); int sHeight = (int) (sHeight() * f); if (sWidth == 0 || sHeight == 0) { return 32; } int i = 1; if (sHeight() > sHeight || sWidth() > sWidth) { round = Math.round(sHeight() / sHeight); int round2 = Math.round(sWidth() / sWidth); if (round >= round2) { round = round2; } } else { round = 1; } while (true) { int i2 = i * 2; if (i2 >= round) { return i; } i = i2; } } /* JADX INFO: Access modifiers changed from: private */ public void fitToBounds(boolean z, ScaleAndTranslate scaleAndTranslate) { float max; int max2; float max3; if (this.panLimit == 2 && isReady()) { z = false; } PointF pointF = scaleAndTranslate.vTranslate; float limitedScale = limitedScale(scaleAndTranslate.scale); float sWidth = sWidth() * limitedScale; float sHeight = sHeight() * limitedScale; if (this.panLimit == 3 && isReady()) { pointF.x = Math.max(pointF.x, (getWidth() / 2) - sWidth); pointF.y = Math.max(pointF.y, (getHeight() / 2) - sHeight); } else if (z) { pointF.x = Math.max(pointF.x, getWidth() - sWidth); pointF.y = Math.max(pointF.y, getHeight() - sHeight); } else { pointF.x = Math.max(pointF.x, -sWidth); pointF.y = Math.max(pointF.y, -sHeight); } float paddingLeft = (getPaddingLeft() > 0 || getPaddingRight() > 0) ? getPaddingLeft() / (getPaddingLeft() + getPaddingRight()) : 0.5f; float paddingTop = (getPaddingTop() > 0 || getPaddingBottom() > 0) ? getPaddingTop() / (getPaddingTop() + getPaddingBottom()) : 0.5f; if (this.panLimit == 3 && isReady()) { max = Math.max(0, getWidth() / 2); max2 = Math.max(0, getHeight() / 2); } else { if (z) { max = Math.max(0.0f, (getWidth() - sWidth) * paddingLeft); max3 = Math.max(0.0f, (getHeight() - sHeight) * paddingTop); pointF.x = Math.min(pointF.x, max); pointF.y = Math.min(pointF.y, max3); scaleAndTranslate.scale = limitedScale; } max = Math.max(0, getWidth()); max2 = Math.max(0, getHeight()); } max3 = max2; pointF.x = Math.min(pointF.x, max); pointF.y = Math.min(pointF.y, max3); scaleAndTranslate.scale = limitedScale; } private void fitToBounds(boolean z) { boolean z2; float f = 0.0f; if (this.vTranslate == null) { this.vTranslate = new PointF(0.0f, 0.0f); z2 = true; } else { z2 = false; } if (this.satTemp == null) { this.satTemp = new ScaleAndTranslate(f, new PointF(0.0f, 0.0f)); } this.satTemp.scale = this.scale; this.satTemp.vTranslate.set(this.vTranslate); fitToBounds(z, this.satTemp); this.scale = this.satTemp.scale; this.vTranslate.set(this.satTemp.vTranslate); if (!z2 || this.minimumScaleType == 4) { return; } this.vTranslate.set(vTranslateForSCenter(sWidth() / 2, sHeight() / 2, this.scale)); } /* JADX WARN: Multi-variable type inference failed */ private void initialiseTileMap(Point point) { debug("initialiseTileMap maxTileDimensions=%dx%d", Integer.valueOf(point.x), Integer.valueOf(point.y)); this.tileMap = new LinkedHashMap(); int i = this.fullImageSampleSize; int i2 = 1; int i3 = 1; int i4 = 1; while (true) { int sWidth = sWidth() / i3; int sHeight = sHeight() / i4; int i5 = sWidth / i; int i6 = sHeight / i; while (true) { if (i5 + i3 + i2 > point.x || (i5 > getWidth() * 1.25d && i < this.fullImageSampleSize)) { i3++; sWidth = sWidth() / i3; i5 = sWidth / i; } } while (true) { if (i6 + i4 + i2 > point.y || (i6 > getHeight() * 1.25d && i < this.fullImageSampleSize)) { i4++; sHeight = sHeight() / i4; i6 = sHeight / i; } } ArrayList arrayList = new ArrayList(i3 * i4); int i7 = 0; while (i7 < i3) { int i8 = 0; while (i8 < i4) { Tile tile = new Tile(); tile.sampleSize = i; tile.visible = i == this.fullImageSampleSize ? i2 : 0; tile.sRect = new Rect(i7 * sWidth, i8 * sHeight, i7 == i3 + (-1) ? sWidth() : (i7 + 1) * sWidth, i8 == i4 + (-1) ? sHeight() : (i8 + 1) * sHeight); tile.vRect = new Rect(0, 0, 0, 0); tile.fileSRect = new Rect(tile.sRect); arrayList.add(tile); i8++; i2 = 1; } i7++; i2 = 1; } this.tileMap.put(Integer.valueOf(i), arrayList); i2 = 1; if (i == 1) { return; } else { i /= 2; } } } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes2.dex */ public static class TilesInitTask extends AsyncTask { private final WeakReference contextRef; private ImageRegionDecoder decoder; private final WeakReference> decoderFactoryRef; private Exception exception; private final Uri source; private final WeakReference viewRef; TilesInitTask(SubsamplingScaleImageView subsamplingScaleImageView, Context context, DecoderFactory decoderFactory, Uri uri) { this.viewRef = new WeakReference<>(subsamplingScaleImageView); this.contextRef = new WeakReference<>(context); this.decoderFactoryRef = new WeakReference<>(decoderFactory); this.source = uri; } /* JADX INFO: Access modifiers changed from: protected */ @Override // android.os.AsyncTask public int[] doInBackground(Void... voidArr) { try { String uri = this.source.toString(); Context context = this.contextRef.get(); DecoderFactory decoderFactory = this.decoderFactoryRef.get(); SubsamplingScaleImageView subsamplingScaleImageView = this.viewRef.get(); if (context == null || decoderFactory == null || subsamplingScaleImageView == null) { return null; } subsamplingScaleImageView.debug("TilesInitTask.doInBackground", new Object[0]); ImageRegionDecoder make = decoderFactory.make(); this.decoder = make; Point init = make.init(context, this.source); int i = init.x; int i2 = init.y; int exifOrientation = subsamplingScaleImageView.getExifOrientation(context, uri); if (subsamplingScaleImageView.sRegion != null) { subsamplingScaleImageView.sRegion.left = Math.max(0, subsamplingScaleImageView.sRegion.left); subsamplingScaleImageView.sRegion.top = Math.max(0, subsamplingScaleImageView.sRegion.top); subsamplingScaleImageView.sRegion.right = Math.min(i, subsamplingScaleImageView.sRegion.right); subsamplingScaleImageView.sRegion.bottom = Math.min(i2, subsamplingScaleImageView.sRegion.bottom); i = subsamplingScaleImageView.sRegion.width(); i2 = subsamplingScaleImageView.sRegion.height(); } return new int[]{i, i2, exifOrientation}; } catch (Exception e) { Log.e(SubsamplingScaleImageView.TAG, "Failed to initialise bitmap decoder", e); this.exception = e; return null; } } /* JADX INFO: Access modifiers changed from: protected */ @Override // android.os.AsyncTask public void onPostExecute(int[] iArr) { SubsamplingScaleImageView subsamplingScaleImageView = this.viewRef.get(); if (subsamplingScaleImageView != null) { ImageRegionDecoder imageRegionDecoder = this.decoder; if (imageRegionDecoder == null || iArr == null || iArr.length != 3) { if (this.exception == null || subsamplingScaleImageView.onImageEventListener == null) { return; } subsamplingScaleImageView.onImageEventListener.onImageLoadError(this.exception); return; } subsamplingScaleImageView.onTilesInited(imageRegionDecoder, iArr[0], iArr[1], iArr[2]); } } } /* JADX INFO: Access modifiers changed from: private */ public synchronized void onTilesInited(ImageRegionDecoder imageRegionDecoder, int i, int i2, int i3) { int i4; int i5; int i6; debug("onTilesInited sWidth=%d, sHeight=%d, sOrientation=%d", Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(this.orientation)); int i7 = this.sWidth; if (i7 > 0 && (i6 = this.sHeight) > 0 && (i7 != i || i6 != i2)) { reset(false); Bitmap bitmap = this.bitmap; if (bitmap != null) { if (!this.bitmapIsCached) { bitmap.recycle(); } this.bitmap = null; OnImageEventListener onImageEventListener = this.onImageEventListener; if (onImageEventListener != null && this.bitmapIsCached) { onImageEventListener.onPreviewReleased(); } this.bitmapIsPreview = false; this.bitmapIsCached = false; } } this.decoder = imageRegionDecoder; this.sWidth = i; this.sHeight = i2; this.sOrientation = i3; checkReady(); if (!checkImageLoaded() && (i4 = this.maxTileWidth) > 0 && i4 != Integer.MAX_VALUE && (i5 = this.maxTileHeight) > 0 && i5 != Integer.MAX_VALUE && getWidth() > 0 && getHeight() > 0) { initialiseBaseLayer(new Point(this.maxTileWidth, this.maxTileHeight)); } invalidate(); requestLayout(); } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes2.dex */ public static class TileLoadTask extends AsyncTask { private final WeakReference decoderRef; private Exception exception; private final WeakReference tileRef; private final WeakReference viewRef; TileLoadTask(SubsamplingScaleImageView subsamplingScaleImageView, ImageRegionDecoder imageRegionDecoder, Tile tile) { this.viewRef = new WeakReference<>(subsamplingScaleImageView); this.decoderRef = new WeakReference<>(imageRegionDecoder); this.tileRef = new WeakReference<>(tile); tile.loading = true; } /* JADX INFO: Access modifiers changed from: protected */ @Override // android.os.AsyncTask public Bitmap doInBackground(Void... voidArr) { try { SubsamplingScaleImageView subsamplingScaleImageView = this.viewRef.get(); ImageRegionDecoder imageRegionDecoder = this.decoderRef.get(); Tile tile = this.tileRef.get(); if (imageRegionDecoder == null || tile == null || subsamplingScaleImageView == null || !imageRegionDecoder.isReady() || !tile.visible) { if (tile == null) { return null; } tile.loading = false; return null; } subsamplingScaleImageView.debug("TileLoadTask.doInBackground, tile.sRect=%s, tile.sampleSize=%d", tile.sRect, Integer.valueOf(tile.sampleSize)); subsamplingScaleImageView.decoderLock.readLock().lock(); try { if (imageRegionDecoder.isReady()) { subsamplingScaleImageView.fileSRect(tile.sRect, tile.fileSRect); if (subsamplingScaleImageView.sRegion != null) { tile.fileSRect.offset(subsamplingScaleImageView.sRegion.left, subsamplingScaleImageView.sRegion.top); } return imageRegionDecoder.decodeRegion(tile.fileSRect, tile.sampleSize); } tile.loading = false; subsamplingScaleImageView.decoderLock.readLock().unlock(); return null; } finally { subsamplingScaleImageView.decoderLock.readLock().unlock(); } } catch (Exception e) { Log.e(SubsamplingScaleImageView.TAG, "Failed to decode tile", e); this.exception = e; return null; } catch (OutOfMemoryError e2) { Log.e(SubsamplingScaleImageView.TAG, "Failed to decode tile - OutOfMemoryError", e2); this.exception = new RuntimeException(e2); return null; } } /* JADX INFO: Access modifiers changed from: protected */ @Override // android.os.AsyncTask public void onPostExecute(Bitmap bitmap) { SubsamplingScaleImageView subsamplingScaleImageView = this.viewRef.get(); Tile tile = this.tileRef.get(); if (subsamplingScaleImageView == null || tile == null) { return; } if (bitmap == null) { if (this.exception == null || subsamplingScaleImageView.onImageEventListener == null) { return; } subsamplingScaleImageView.onImageEventListener.onTileLoadError(this.exception); return; } tile.bitmap = bitmap; tile.loading = false; subsamplingScaleImageView.onTileLoaded(); } } /* JADX INFO: Access modifiers changed from: private */ public synchronized void onTileLoaded() { Bitmap bitmap; debug("onTileLoaded", new Object[0]); checkReady(); checkImageLoaded(); if (isBaseLayerReady() && (bitmap = this.bitmap) != null) { if (!this.bitmapIsCached) { bitmap.recycle(); } this.bitmap = null; OnImageEventListener onImageEventListener = this.onImageEventListener; if (onImageEventListener != null && this.bitmapIsCached) { onImageEventListener.onPreviewReleased(); } this.bitmapIsPreview = false; this.bitmapIsCached = false; } invalidate(); } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes2.dex */ public static class BitmapLoadTask extends AsyncTask { private Bitmap bitmap; private final WeakReference contextRef; private final WeakReference> decoderFactoryRef; private Exception exception; private final boolean preview; private final Uri source; private final WeakReference viewRef; BitmapLoadTask(SubsamplingScaleImageView subsamplingScaleImageView, Context context, DecoderFactory decoderFactory, Uri uri, boolean z) { this.viewRef = new WeakReference<>(subsamplingScaleImageView); this.contextRef = new WeakReference<>(context); this.decoderFactoryRef = new WeakReference<>(decoderFactory); this.source = uri; this.preview = z; } /* JADX INFO: Access modifiers changed from: protected */ @Override // android.os.AsyncTask public Integer doInBackground(Void... voidArr) { try { String uri = this.source.toString(); Context context = this.contextRef.get(); DecoderFactory decoderFactory = this.decoderFactoryRef.get(); SubsamplingScaleImageView subsamplingScaleImageView = this.viewRef.get(); if (context == null || decoderFactory == null || subsamplingScaleImageView == null) { return null; } subsamplingScaleImageView.debug("BitmapLoadTask.doInBackground", new Object[0]); this.bitmap = decoderFactory.make().decode(context, this.source); return Integer.valueOf(subsamplingScaleImageView.getExifOrientation(context, uri)); } catch (Exception e) { Log.e(SubsamplingScaleImageView.TAG, "Failed to load bitmap", e); this.exception = e; return null; } catch (OutOfMemoryError e2) { Log.e(SubsamplingScaleImageView.TAG, "Failed to load bitmap - OutOfMemoryError", e2); this.exception = new RuntimeException(e2); return null; } } /* JADX INFO: Access modifiers changed from: protected */ @Override // android.os.AsyncTask public void onPostExecute(Integer num) { SubsamplingScaleImageView subsamplingScaleImageView = this.viewRef.get(); if (subsamplingScaleImageView != null) { Bitmap bitmap = this.bitmap; if (bitmap != null && num != null) { if (this.preview) { subsamplingScaleImageView.onPreviewLoaded(bitmap); return; } else { subsamplingScaleImageView.onImageLoaded(bitmap, num.intValue(), false); return; } } if (this.exception == null || subsamplingScaleImageView.onImageEventListener == null) { return; } if (this.preview) { subsamplingScaleImageView.onImageEventListener.onPreviewLoadError(this.exception); } else { subsamplingScaleImageView.onImageEventListener.onImageLoadError(this.exception); } } } } /* JADX INFO: Access modifiers changed from: private */ public synchronized void onPreviewLoaded(Bitmap bitmap) { debug("onPreviewLoaded", new Object[0]); if (this.bitmap == null && !this.imageLoadedSent) { Rect rect = this.pRegion; if (rect != null) { this.bitmap = Bitmap.createBitmap(bitmap, rect.left, this.pRegion.top, this.pRegion.width(), this.pRegion.height()); } else { this.bitmap = bitmap; } this.bitmapIsPreview = true; if (checkReady()) { invalidate(); requestLayout(); } return; } bitmap.recycle(); } /* JADX INFO: Access modifiers changed from: private */ public synchronized void onImageLoaded(Bitmap bitmap, int i, boolean z) { OnImageEventListener onImageEventListener; debug("onImageLoaded", new Object[0]); int i2 = this.sWidth; if (i2 > 0 && this.sHeight > 0 && (i2 != bitmap.getWidth() || this.sHeight != bitmap.getHeight())) { reset(false); } Bitmap bitmap2 = this.bitmap; if (bitmap2 != null && !this.bitmapIsCached) { bitmap2.recycle(); } if (this.bitmap != null && this.bitmapIsCached && (onImageEventListener = this.onImageEventListener) != null) { onImageEventListener.onPreviewReleased(); } this.bitmapIsPreview = false; this.bitmapIsCached = z; this.bitmap = bitmap; this.sWidth = bitmap.getWidth(); this.sHeight = bitmap.getHeight(); this.sOrientation = i; boolean checkReady = checkReady(); boolean checkImageLoaded = checkImageLoaded(); if (checkReady || checkImageLoaded) { invalidate(); requestLayout(); } } /* JADX INFO: Access modifiers changed from: private */ public int getExifOrientation(Context context, String str) { int i; int i2 = 0; if (str.startsWith("content")) { Cursor cursor = null; try { try { cursor = context.getContentResolver().query(Uri.parse(str), new String[]{Device.JsonKeys.ORIENTATION}, null, null, null); if (cursor != null && cursor.moveToFirst()) { int i3 = cursor.getInt(0); if (!VALID_ORIENTATIONS.contains(Integer.valueOf(i3)) || i3 == -1) { Log.w(TAG, "Unsupported orientation: " + i3); } else { i2 = i3; } } if (cursor == null) { return i2; } } catch (Exception unused) { Log.w(TAG, "Could not get orientation of image from media store"); if (cursor == null) { return 0; } } cursor.close(); return i2; } catch (Throwable th) { if (cursor != null) { cursor.close(); } throw th; } } if (!str.startsWith("file:///") || str.startsWith("file:///android_asset/")) { return 0; } try { int attributeInt = new ExifInterface(str.substring(7)).getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); if (attributeInt != 1 && attributeInt != 0) { if (attributeInt == 6) { i = 90; } else if (attributeInt == 3) { i = ORIENTATION_180; } else { if (attributeInt != 8) { Log.w(TAG, "Unsupported EXIF orientation: " + attributeInt); return 0; } i = ORIENTATION_270; } return i; } return 0; } catch (Exception unused2) { Log.w(TAG, "Could not get EXIF orientation of image"); return 0; } } private void execute(AsyncTask asyncTask) { asyncTask.executeOnExecutor(this.executor, new Void[0]); } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes2.dex */ public static class Tile { private Bitmap bitmap; private Rect fileSRect; private boolean loading; private Rect sRect; private int sampleSize; private Rect vRect; private boolean visible; private Tile() { } } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes2.dex */ public static class Anim { private long duration; private int easing; private boolean interruptible; private OnAnimationEventListener listener; private int origin; private PointF sCenterEnd; private PointF sCenterEndRequested; private PointF sCenterStart; private float scaleEnd; private float scaleStart; private long time; private PointF vFocusEnd; private PointF vFocusStart; private Anim() { this.duration = 500L; this.interruptible = true; this.easing = 2; this.origin = 1; this.time = System.currentTimeMillis(); } } /* JADX INFO: Access modifiers changed from: private */ /* loaded from: classes2.dex */ public static class ScaleAndTranslate { private float scale; private final PointF vTranslate; private ScaleAndTranslate(float f, PointF pointF) { this.scale = f; this.vTranslate = pointF; } } private void restoreState(ImageViewState imageViewState) { if (imageViewState == null || !VALID_ORIENTATIONS.contains(Integer.valueOf(imageViewState.getOrientation()))) { return; } this.orientation = imageViewState.getOrientation(); this.pendingScale = Float.valueOf(imageViewState.getScale()); this.sPendingCenter = imageViewState.getCenter(); invalidate(); } private Point getMaxBitmapDimensions(Canvas canvas) { return new Point(Math.min(canvas.getMaximumBitmapWidth(), this.maxTileWidth), Math.min(canvas.getMaximumBitmapHeight(), this.maxTileHeight)); } private int sWidth() { int requiredRotation = getRequiredRotation(); return (requiredRotation == 90 || requiredRotation == 270) ? this.sHeight : this.sWidth; } private int sHeight() { int requiredRotation = getRequiredRotation(); return (requiredRotation == 90 || requiredRotation == 270) ? this.sWidth : this.sHeight; } /* JADX INFO: Access modifiers changed from: private */ public void fileSRect(Rect rect, Rect rect2) { if (getRequiredRotation() == 0) { rect2.set(rect); return; } if (getRequiredRotation() == 90) { rect2.set(rect.top, this.sHeight - rect.right, rect.bottom, this.sHeight - rect.left); } else if (getRequiredRotation() == 180) { rect2.set(this.sWidth - rect.right, this.sHeight - rect.bottom, this.sWidth - rect.left, this.sHeight - rect.top); } else { rect2.set(this.sWidth - rect.bottom, rect.left, this.sWidth - rect.top, rect.right); } } private float distance(float f, float f2, float f3, float f4) { float f5 = f - f2; float f6 = f3 - f4; return (float) Math.sqrt((f5 * f5) + (f6 * f6)); } public void recycle() { reset(true); this.bitmapPaint = null; this.debugTextPaint = null; this.debugLinePaint = null; this.tileBgPaint = null; } private float viewToSourceX(float f) { PointF pointF = this.vTranslate; if (pointF == null) { return Float.NaN; } return (f - pointF.x) / this.scale; } private float viewToSourceY(float f) { PointF pointF = this.vTranslate; if (pointF == null) { return Float.NaN; } return (f - pointF.y) / this.scale; } public void viewToFileRect(Rect rect, Rect rect2) { if (this.vTranslate == null || !this.readySent) { return; } rect2.set((int) viewToSourceX(rect.left), (int) viewToSourceY(rect.top), (int) viewToSourceX(rect.right), (int) viewToSourceY(rect.bottom)); fileSRect(rect2, rect2); rect2.set(Math.max(0, rect2.left), Math.max(0, rect2.top), Math.min(this.sWidth, rect2.right), Math.min(this.sHeight, rect2.bottom)); Rect rect3 = this.sRegion; if (rect3 != null) { rect2.offset(rect3.left, this.sRegion.top); } } public void visibleFileRect(Rect rect) { if (this.vTranslate == null || !this.readySent) { return; } rect.set(0, 0, getWidth(), getHeight()); viewToFileRect(rect, rect); } public final PointF viewToSourceCoord(PointF pointF) { return viewToSourceCoord(pointF.x, pointF.y, new PointF()); } public final PointF viewToSourceCoord(float f, float f2) { return viewToSourceCoord(f, f2, new PointF()); } public final PointF viewToSourceCoord(PointF pointF, PointF pointF2) { return viewToSourceCoord(pointF.x, pointF.y, pointF2); } public final PointF viewToSourceCoord(float f, float f2, PointF pointF) { if (this.vTranslate == null) { return null; } pointF.set(viewToSourceX(f), viewToSourceY(f2)); return pointF; } private float sourceToViewX(float f) { PointF pointF = this.vTranslate; if (pointF == null) { return Float.NaN; } return (f * this.scale) + pointF.x; } private float sourceToViewY(float f) { PointF pointF = this.vTranslate; if (pointF == null) { return Float.NaN; } return (f * this.scale) + pointF.y; } public final PointF sourceToViewCoord(PointF pointF) { return sourceToViewCoord(pointF.x, pointF.y, new PointF()); } public final PointF sourceToViewCoord(float f, float f2) { return sourceToViewCoord(f, f2, new PointF()); } public final PointF sourceToViewCoord(PointF pointF, PointF pointF2) { return sourceToViewCoord(pointF.x, pointF.y, pointF2); } public final PointF sourceToViewCoord(float f, float f2, PointF pointF) { if (this.vTranslate == null) { return null; } pointF.set(sourceToViewX(f), sourceToViewY(f2)); return pointF; } private void sourceToViewRect(Rect rect, Rect rect2) { rect2.set((int) sourceToViewX(rect.left), (int) sourceToViewY(rect.top), (int) sourceToViewX(rect.right), (int) sourceToViewY(rect.bottom)); } private PointF vTranslateForSCenter(float f, float f2, float f3) { int paddingLeft = getPaddingLeft() + (((getWidth() - getPaddingRight()) - getPaddingLeft()) / 2); int paddingTop = getPaddingTop() + (((getHeight() - getPaddingBottom()) - getPaddingTop()) / 2); if (this.satTemp == null) { this.satTemp = new ScaleAndTranslate(0.0f, new PointF(0.0f, 0.0f)); } this.satTemp.scale = f3; this.satTemp.vTranslate.set(paddingLeft - (f * f3), paddingTop - (f2 * f3)); fitToBounds(true, this.satTemp); return this.satTemp.vTranslate; } /* JADX INFO: Access modifiers changed from: private */ public PointF limitedSCenter(float f, float f2, float f3, PointF pointF) { PointF vTranslateForSCenter = vTranslateForSCenter(f, f2, f3); pointF.set(((getPaddingLeft() + (((getWidth() - getPaddingRight()) - getPaddingLeft()) / 2)) - vTranslateForSCenter.x) / f3, ((getPaddingTop() + (((getHeight() - getPaddingBottom()) - getPaddingTop()) / 2)) - vTranslateForSCenter.y) / f3); return pointF; } private float minScale() { int paddingBottom = getPaddingBottom() + getPaddingTop(); int paddingLeft = getPaddingLeft() + getPaddingRight(); int i = this.minimumScaleType; if (i == 2 || i == 4) { return Math.max((getWidth() - paddingLeft) / sWidth(), (getHeight() - paddingBottom) / sHeight()); } if (i == 3) { float f = this.minScale; if (f > 0.0f) { return f; } } return Math.min((getWidth() - paddingLeft) / sWidth(), (getHeight() - paddingBottom) / sHeight()); } /* JADX INFO: Access modifiers changed from: private */ public float limitedScale(float f) { return Math.min(this.maxScale, Math.max(minScale(), f)); } private float ease(int i, long j, float f, float f2, long j2) { if (i == 1) { return easeOutQuad(j, f, f2, j2); } if (i == 2) { return easeInOutQuad(j, f, f2, j2); } throw new IllegalStateException("Unexpected easing type: " + i); } /* JADX INFO: Access modifiers changed from: private */ public void debug(String str, Object... objArr) { if (this.debug) { Log.d(TAG, String.format(str, objArr)); } } public final void setRegionDecoderClass(Class cls) { if (cls == null) { throw new IllegalArgumentException("Decoder class cannot be set to null"); } this.regionDecoderFactory = new CompatDecoderFactory(cls); } public final void setRegionDecoderFactory(DecoderFactory decoderFactory) { if (decoderFactory == null) { throw new IllegalArgumentException("Decoder factory cannot be set to null"); } this.regionDecoderFactory = decoderFactory; } public final void setBitmapDecoderClass(Class cls) { if (cls == null) { throw new IllegalArgumentException("Decoder class cannot be set to null"); } this.bitmapDecoderFactory = new CompatDecoderFactory(cls); } public final void setBitmapDecoderFactory(DecoderFactory decoderFactory) { if (decoderFactory == null) { throw new IllegalArgumentException("Decoder factory cannot be set to null"); } this.bitmapDecoderFactory = decoderFactory; } public final void getPanRemaining(RectF rectF) { if (isReady()) { float sWidth = this.scale * sWidth(); float sHeight = this.scale * sHeight(); int i = this.panLimit; if (i == 3) { rectF.top = Math.max(0.0f, -(this.vTranslate.y - (getHeight() / 2))); rectF.left = Math.max(0.0f, -(this.vTranslate.x - (getWidth() / 2))); rectF.bottom = Math.max(0.0f, this.vTranslate.y - ((getHeight() / 2) - sHeight)); rectF.right = Math.max(0.0f, this.vTranslate.x - ((getWidth() / 2) - sWidth)); return; } if (i == 2) { rectF.top = Math.max(0.0f, -(this.vTranslate.y - getHeight())); rectF.left = Math.max(0.0f, -(this.vTranslate.x - getWidth())); rectF.bottom = Math.max(0.0f, this.vTranslate.y + sHeight); rectF.right = Math.max(0.0f, this.vTranslate.x + sWidth); return; } rectF.top = Math.max(0.0f, -this.vTranslate.y); rectF.left = Math.max(0.0f, -this.vTranslate.x); rectF.bottom = Math.max(0.0f, (sHeight + this.vTranslate.y) - getHeight()); rectF.right = Math.max(0.0f, (sWidth + this.vTranslate.x) - getWidth()); } } public final void setPanLimit(int i) { if (!VALID_PAN_LIMITS.contains(Integer.valueOf(i))) { throw new IllegalArgumentException("Invalid pan limit: " + i); } this.panLimit = i; if (isReady()) { fitToBounds(true); invalidate(); } } public final void setMinimumScaleType(int i) { if (!VALID_SCALE_TYPES.contains(Integer.valueOf(i))) { throw new IllegalArgumentException("Invalid scale type: " + i); } this.minimumScaleType = i; if (isReady()) { fitToBounds(true); invalidate(); } } public final void setMinimumDpi(int i) { DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); setMaxScale(((displayMetrics.xdpi + displayMetrics.ydpi) / 2.0f) / i); } public final void setMaximumDpi(int i) { DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); setMinScale(((displayMetrics.xdpi + displayMetrics.ydpi) / 2.0f) / i); } public final float getMinScale() { return minScale(); } public void setMinimumTileDpi(int i) { DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); this.minimumTileDpi = (int) Math.min((displayMetrics.xdpi + displayMetrics.ydpi) / 2.0f, i); if (isReady()) { reset(false); invalidate(); } } public final PointF getCenter() { return viewToSourceCoord(getWidth() / 2, getHeight() / 2); } public final void setScaleAndCenter(float f, PointF pointF) { this.anim = null; this.pendingScale = Float.valueOf(f); this.sPendingCenter = pointF; this.sRequestedCenter = pointF; invalidate(); } public final void resetScaleAndCenter() { this.anim = null; this.pendingScale = Float.valueOf(limitedScale(0.0f)); if (isReady()) { this.sPendingCenter = new PointF(sWidth() / 2, sHeight() / 2); } else { this.sPendingCenter = new PointF(0.0f, 0.0f); } invalidate(); } public final int getAppliedOrientation() { return getRequiredRotation(); } public final ImageViewState getState() { if (this.vTranslate == null || this.sWidth <= 0 || this.sHeight <= 0) { return null; } return new ImageViewState(getScale(), getCenter(), getOrientation()); } public final void setPanEnabled(boolean z) { PointF pointF; this.panEnabled = z; if (z || (pointF = this.vTranslate) == null) { return; } pointF.x = (getWidth() / 2) - (this.scale * (sWidth() / 2)); this.vTranslate.y = (getHeight() / 2) - (this.scale * (sHeight() / 2)); if (isReady()) { refreshRequiredTiles(true); invalidate(); } } public final void setTileBackgroundColor(int i) { if (Color.alpha(i) == 0) { this.tileBgPaint = null; } else { Paint paint = new Paint(); this.tileBgPaint = paint; paint.setStyle(Paint.Style.FILL); this.tileBgPaint.setColor(i); } invalidate(); } public final void setDoubleTapZoomDpi(int i) { DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); setDoubleTapZoomScale(((displayMetrics.xdpi + displayMetrics.ydpi) / 2.0f) / i); } public final void setDoubleTapZoomStyle(int i) { if (!VALID_ZOOM_STYLES.contains(Integer.valueOf(i))) { throw new IllegalArgumentException("Invalid zoom style: " + i); } this.doubleTapZoomStyle = i; } public final void setDoubleTapZoomDuration(int i) { this.doubleTapZoomDuration = Math.max(0, i); } public void setExecutor(Executor executor) { if (executor == null) { throw new NullPointerException("Executor must not be null"); } this.executor = executor; } private void sendStateChanged(float f, PointF pointF, int i) { OnStateChangedListener onStateChangedListener = this.onStateChangedListener; if (onStateChangedListener != null) { float f2 = this.scale; if (f2 != f) { onStateChangedListener.onScaleChanged(f2, i); } } if (this.onStateChangedListener == null || this.vTranslate.equals(pointF)) { return; } this.onStateChangedListener.onCenterChanged(getCenter(), i); } public AnimationBuilder animateCenter(PointF pointF) { if (isReady()) { return new AnimationBuilder(pointF); } return null; } public AnimationBuilder animateScale(float f) { if (isReady()) { return new AnimationBuilder(f); } return null; } public AnimationBuilder animateScaleAndCenter(float f, PointF pointF) { if (isReady()) { return new AnimationBuilder(f, pointF); } return null; } /* loaded from: classes2.dex */ public final class AnimationBuilder { private long duration; private int easing; private boolean interruptible; private OnAnimationEventListener listener; private int origin; private boolean panLimited; private final PointF targetSCenter; private final float targetScale; private final PointF vFocus; /* JADX INFO: Access modifiers changed from: private */ public AnimationBuilder withOrigin(int i) { this.origin = i; return this; } /* JADX INFO: Access modifiers changed from: private */ public AnimationBuilder withPanLimited(boolean z) { this.panLimited = z; return this; } public AnimationBuilder withDuration(long j) { this.duration = j; return this; } public AnimationBuilder withInterruptible(boolean z) { this.interruptible = z; return this; } public AnimationBuilder withOnAnimationEventListener(OnAnimationEventListener onAnimationEventListener) { this.listener = onAnimationEventListener; return this; } private AnimationBuilder(PointF pointF) { this.duration = 500L; this.easing = 2; this.origin = 1; this.interruptible = true; this.panLimited = true; this.targetScale = SubsamplingScaleImageView.this.scale; this.targetSCenter = pointF; this.vFocus = null; } private AnimationBuilder(float f) { this.duration = 500L; this.easing = 2; this.origin = 1; this.interruptible = true; this.panLimited = true; this.targetScale = f; this.targetSCenter = SubsamplingScaleImageView.this.getCenter(); this.vFocus = null; } private AnimationBuilder(float f, PointF pointF) { this.duration = 500L; this.easing = 2; this.origin = 1; this.interruptible = true; this.panLimited = true; this.targetScale = f; this.targetSCenter = pointF; this.vFocus = null; } private AnimationBuilder(float f, PointF pointF, PointF pointF2) { this.duration = 500L; this.easing = 2; this.origin = 1; this.interruptible = true; this.panLimited = true; this.targetScale = f; this.targetSCenter = pointF; this.vFocus = pointF2; } public AnimationBuilder withEasing(int i) { if (!SubsamplingScaleImageView.VALID_EASING_STYLES.contains(Integer.valueOf(i))) { throw new IllegalArgumentException("Unknown easing type: " + i); } this.easing = i; return this; } public void start() { if (SubsamplingScaleImageView.this.anim != null && SubsamplingScaleImageView.this.anim.listener != null) { try { SubsamplingScaleImageView.this.anim.listener.onInterruptedByNewAnim(); } catch (Exception e) { Log.w(SubsamplingScaleImageView.TAG, "Error thrown by animation listener", e); } } int paddingLeft = SubsamplingScaleImageView.this.getPaddingLeft() + (((SubsamplingScaleImageView.this.getWidth() - SubsamplingScaleImageView.this.getPaddingRight()) - SubsamplingScaleImageView.this.getPaddingLeft()) / 2); int paddingTop = SubsamplingScaleImageView.this.getPaddingTop() + (((SubsamplingScaleImageView.this.getHeight() - SubsamplingScaleImageView.this.getPaddingBottom()) - SubsamplingScaleImageView.this.getPaddingTop()) / 2); float limitedScale = SubsamplingScaleImageView.this.limitedScale(this.targetScale); PointF limitedSCenter = this.panLimited ? SubsamplingScaleImageView.this.limitedSCenter(this.targetSCenter.x, this.targetSCenter.y, limitedScale, new PointF()) : this.targetSCenter; SubsamplingScaleImageView.this.anim = new Anim(); SubsamplingScaleImageView.this.anim.scaleStart = SubsamplingScaleImageView.this.scale; SubsamplingScaleImageView.this.anim.scaleEnd = limitedScale; SubsamplingScaleImageView.this.anim.time = System.currentTimeMillis(); SubsamplingScaleImageView.this.anim.sCenterEndRequested = limitedSCenter; SubsamplingScaleImageView.this.anim.sCenterStart = SubsamplingScaleImageView.this.getCenter(); SubsamplingScaleImageView.this.anim.sCenterEnd = limitedSCenter; SubsamplingScaleImageView.this.anim.vFocusStart = SubsamplingScaleImageView.this.sourceToViewCoord(limitedSCenter); SubsamplingScaleImageView.this.anim.vFocusEnd = new PointF(paddingLeft, paddingTop); SubsamplingScaleImageView.this.anim.duration = this.duration; SubsamplingScaleImageView.this.anim.interruptible = this.interruptible; SubsamplingScaleImageView.this.anim.easing = this.easing; SubsamplingScaleImageView.this.anim.origin = this.origin; SubsamplingScaleImageView.this.anim.time = System.currentTimeMillis(); SubsamplingScaleImageView.this.anim.listener = this.listener; PointF pointF = this.vFocus; if (pointF != null) { float f = pointF.x - (SubsamplingScaleImageView.this.anim.sCenterStart.x * limitedScale); float f2 = this.vFocus.y - (SubsamplingScaleImageView.this.anim.sCenterStart.y * limitedScale); ScaleAndTranslate scaleAndTranslate = new ScaleAndTranslate(limitedScale, new PointF(f, f2)); SubsamplingScaleImageView.this.fitToBounds(true, scaleAndTranslate); SubsamplingScaleImageView.this.anim.vFocusEnd = new PointF(this.vFocus.x + (scaleAndTranslate.vTranslate.x - f), this.vFocus.y + (scaleAndTranslate.vTranslate.y - f2)); } SubsamplingScaleImageView.this.invalidate(); } } }