package com.journeyapps.barcodescanner; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Matrix; import android.graphics.Rect; import android.graphics.SurfaceTexture; import android.os.Bundle; import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Parcelable; import android.util.AttributeSet; import android.view.OrientationEventListener; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.TextureView; import android.view.ViewGroup; import android.view.WindowManager; import com.journeyapps.barcodescanner.CameraPreview; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import o.C12047eqo; import o.C16524oza; import o.C17083tlK; import o.C17788zjJ; import o.IVU; import o.OTQ; import o.OtF; import o.RmV; import o.VDF; import o.VTt; import o.VZN; import o.Xad; import o.Yqe; /* loaded from: classes3.dex */ public class CameraPreview extends ViewGroup { private static final String d = "CameraPreview"; private boolean B; private WindowManager D; public C12047eqo a; private Xad b; Rect c; private VDF e; private final Sts f; private OTQ g; public List h; private VDF i; VDF j; private Rect k; private int l; private double m; private boolean n; /* renamed from: o, reason: collision with root package name */ private VDF f6500o; private VTt p; private final Handler.Callback q; private Handler r; private Yqe s; private OtF t; private Rect u; private TextureView v; private final SurfaceHolder.Callback w; private boolean x; private SurfaceView y; /* loaded from: classes3.dex */ public interface Sts { void b(); void c(); void d(); void d(Exception exc); void e(); } /* JADX INFO: Access modifiers changed from: protected */ public void c() { } static /* synthetic */ void d(CameraPreview cameraPreview, VDF vdf) { cameraPreview.j = vdf; VDF vdf2 = cameraPreview.e; if (vdf2 != null) { if (vdf2 != null && vdf != null && cameraPreview.g != null) { int i = vdf.c; int i2 = cameraPreview.j.b; int i3 = cameraPreview.e.c; int i4 = cameraPreview.e.b; OTQ otq = cameraPreview.g; Rect Oy_ = otq.b.Oy_(cameraPreview.j, otq.c); if (Oy_.width() > 0 && Oy_.height() > 0) { cameraPreview.u = Oy_; Rect rect = new Rect(0, 0, i3, i4); Rect rect2 = cameraPreview.u; Rect rect3 = new Rect(rect); rect3.intersect(rect2); if (cameraPreview.f6500o != null) { rect3.inset(Math.max(0, (rect3.width() - cameraPreview.f6500o.c) / 2), Math.max(0, (rect3.height() - cameraPreview.f6500o.b) / 2)); } else { int min = (int) Math.min(rect3.width() * cameraPreview.m, rect3.height() * cameraPreview.m); rect3.inset(min, min); if (rect3.height() > rect3.width()) { rect3.inset(0, (rect3.height() - rect3.width()) / 2); } } cameraPreview.c = rect3; Rect rect4 = new Rect(cameraPreview.c); rect4.offset(-cameraPreview.u.left, -cameraPreview.u.top); Rect rect5 = new Rect((rect4.left * i) / cameraPreview.u.width(), (rect4.top * i2) / cameraPreview.u.height(), (rect4.right * i) / cameraPreview.u.width(), (rect4.bottom * i2) / cameraPreview.u.height()); cameraPreview.k = rect5; if (rect5.width() <= 0 || cameraPreview.k.height() <= 0) { cameraPreview.k = null; cameraPreview.c = null; } else { cameraPreview.f.e(); } } cameraPreview.requestLayout(); cameraPreview.f(); return; } cameraPreview.k = null; cameraPreview.c = null; cameraPreview.u = null; throw new IllegalStateException("containerSize or previewSize is not set yet"); } } /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: com.journeyapps.barcodescanner.CameraPreview$5, reason: invalid class name */ /* loaded from: classes3.dex */ public final class AnonymousClass5 implements TextureView.SurfaceTextureListener { private CameraPreview b; @Override // android.view.TextureView.SurfaceTextureListener public final boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) { return false; } @Override // android.view.TextureView.SurfaceTextureListener public final void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) { } AnonymousClass5(CameraPreview cameraPreview) { this.b = cameraPreview; } @Override // android.view.TextureView.SurfaceTextureListener public final void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i2) { onSurfaceTextureSizeChanged(surfaceTexture, i, i2); } @Override // android.view.TextureView.SurfaceTextureListener public final void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i2) { this.b.i = new VDF(i, i2); this.b.f(); } } /* renamed from: com.journeyapps.barcodescanner.CameraPreview$4, reason: invalid class name */ /* loaded from: classes3.dex */ public class AnonymousClass4 implements Yqe { public final CameraPreview e; AnonymousClass4(CameraPreview cameraPreview) { this.e = cameraPreview; } @Override // o.Yqe public final void a() { this.e.r.postDelayed(new Runnable(this) { // from class: o.uxE private CameraPreview.AnonymousClass4 a; @Override // java.lang.Runnable public final void run() { CameraPreview.e(this.a.e); } { this.a = this; } }, 250L); } } public CameraPreview(Context context) { super(context); this.B = false; this.n = false; this.l = -1; this.h = new ArrayList(); this.b = new Xad(); this.c = null; this.k = null; this.f6500o = null; this.m = 0.1d; this.t = null; this.x = false; this.w = new SurfaceHolder.Callback(this) { // from class: com.journeyapps.barcodescanner.CameraPreview.2 private CameraPreview a; @Override // android.view.SurfaceHolder.Callback public final void surfaceCreated(SurfaceHolder surfaceHolder) { } { this.a = this; } @Override // android.view.SurfaceHolder.Callback public final void surfaceDestroyed(SurfaceHolder surfaceHolder) { this.a.i = null; } @Override // android.view.SurfaceHolder.Callback public final void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) { if (surfaceHolder != null) { this.a.i = new VDF(i2, i3); this.a.f(); return; } String unused = CameraPreview.d; } }; this.q = new Handler.Callback(this) { // from class: com.journeyapps.barcodescanner.CameraPreview.3 private CameraPreview b; { this.b = this; } @Override // android.os.Handler.Callback public final boolean handleMessage(Message message) { if (message.what == C17083tlK.LWm.zxing_prewiew_size_ready) { CameraPreview.d(this.b, (VDF) message.obj); return true; } if (message.what == C17083tlK.LWm.zxing_camera_error) { Exception exc = (Exception) message.obj; if (this.b.a == null) { return false; } this.b.e(); this.b.f.d(exc); return false; } if (message.what != C17083tlK.LWm.zxing_camera_closed) { return false; } this.b.f.b(); return false; } }; this.s = new AnonymousClass4(this); this.f = new Sts(this) { // from class: com.journeyapps.barcodescanner.CameraPreview.1 private CameraPreview a; { this.a = this; } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void e() { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).e(); } } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void c() { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).c(); } } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void d() { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).d(); } } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void d(Exception exc) { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).d(exc); } } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void b() { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).b(); } } }; Om_(context, null); } public CameraPreview(Context context, AttributeSet attributeSet) { super(context, attributeSet); this.B = false; this.n = false; this.l = -1; this.h = new ArrayList(); this.b = new Xad(); this.c = null; this.k = null; this.f6500o = null; this.m = 0.1d; this.t = null; this.x = false; this.w = new SurfaceHolder.Callback(this) { // from class: com.journeyapps.barcodescanner.CameraPreview.2 private CameraPreview a; @Override // android.view.SurfaceHolder.Callback public final void surfaceCreated(SurfaceHolder surfaceHolder) { } { this.a = this; } @Override // android.view.SurfaceHolder.Callback public final void surfaceDestroyed(SurfaceHolder surfaceHolder) { this.a.i = null; } @Override // android.view.SurfaceHolder.Callback public final void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) { if (surfaceHolder != null) { this.a.i = new VDF(i2, i3); this.a.f(); return; } String unused = CameraPreview.d; } }; this.q = new Handler.Callback(this) { // from class: com.journeyapps.barcodescanner.CameraPreview.3 private CameraPreview b; { this.b = this; } @Override // android.os.Handler.Callback public final boolean handleMessage(Message message) { if (message.what == C17083tlK.LWm.zxing_prewiew_size_ready) { CameraPreview.d(this.b, (VDF) message.obj); return true; } if (message.what == C17083tlK.LWm.zxing_camera_error) { Exception exc = (Exception) message.obj; if (this.b.a == null) { return false; } this.b.e(); this.b.f.d(exc); return false; } if (message.what != C17083tlK.LWm.zxing_camera_closed) { return false; } this.b.f.b(); return false; } }; this.s = new AnonymousClass4(this); this.f = new Sts(this) { // from class: com.journeyapps.barcodescanner.CameraPreview.1 private CameraPreview a; { this.a = this; } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void e() { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).e(); } } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void c() { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).c(); } } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void d() { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).d(); } } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void d(Exception exc) { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).d(exc); } } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void b() { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).b(); } } }; Om_(context, attributeSet); } public CameraPreview(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); this.B = false; this.n = false; this.l = -1; this.h = new ArrayList(); this.b = new Xad(); this.c = null; this.k = null; this.f6500o = null; this.m = 0.1d; this.t = null; this.x = false; this.w = new SurfaceHolder.Callback(this) { // from class: com.journeyapps.barcodescanner.CameraPreview.2 private CameraPreview a; @Override // android.view.SurfaceHolder.Callback public final void surfaceCreated(SurfaceHolder surfaceHolder) { } { this.a = this; } @Override // android.view.SurfaceHolder.Callback public final void surfaceDestroyed(SurfaceHolder surfaceHolder) { this.a.i = null; } @Override // android.view.SurfaceHolder.Callback public final void surfaceChanged(SurfaceHolder surfaceHolder, int i2, int i22, int i3) { if (surfaceHolder != null) { this.a.i = new VDF(i22, i3); this.a.f(); return; } String unused = CameraPreview.d; } }; this.q = new Handler.Callback(this) { // from class: com.journeyapps.barcodescanner.CameraPreview.3 private CameraPreview b; { this.b = this; } @Override // android.os.Handler.Callback public final boolean handleMessage(Message message) { if (message.what == C17083tlK.LWm.zxing_prewiew_size_ready) { CameraPreview.d(this.b, (VDF) message.obj); return true; } if (message.what == C17083tlK.LWm.zxing_camera_error) { Exception exc = (Exception) message.obj; if (this.b.a == null) { return false; } this.b.e(); this.b.f.d(exc); return false; } if (message.what != C17083tlK.LWm.zxing_camera_closed) { return false; } this.b.f.b(); return false; } }; this.s = new AnonymousClass4(this); this.f = new Sts(this) { // from class: com.journeyapps.barcodescanner.CameraPreview.1 private CameraPreview a; { this.a = this; } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void e() { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).e(); } } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void c() { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).c(); } } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void d() { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).d(); } } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void d(Exception exc) { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).d(exc); } } @Override // com.journeyapps.barcodescanner.CameraPreview.Sts public final void b() { Iterator it = this.a.h.iterator(); while (it.hasNext()) { ((Sts) it.next()).b(); } } }; Om_(context, attributeSet); } private void Om_(Context context, AttributeSet attributeSet) { if (getBackground() == null) { setBackgroundColor(-16777216); } Op_(attributeSet); this.D = (WindowManager) context.getSystemService("window"); this.r = new Handler(this.q); this.p = new VTt(); } @Override // android.view.ViewGroup, android.view.View protected void onAttachedToWindow() { super.onAttachedToWindow(); if (this.B) { TextureView textureView = new TextureView(getContext()); this.v = textureView; textureView.setSurfaceTextureListener(new AnonymousClass5(this)); addView(this.v); return; } SurfaceView surfaceView = new SurfaceView(getContext()); this.y = surfaceView; surfaceView.getHolder().addCallback(this.w); addView(this.y); } /* JADX INFO: Access modifiers changed from: protected */ public final void Op_(AttributeSet attributeSet) { TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, C17083tlK.ojQ.zxing_camera_preview); int dimension = (int) obtainStyledAttributes.getDimension(C17083tlK.ojQ.zxing_camera_preview_zxing_framing_rect_width, -1.0f); int dimension2 = (int) obtainStyledAttributes.getDimension(C17083tlK.ojQ.zxing_camera_preview_zxing_framing_rect_height, -1.0f); if (dimension > 0 && dimension2 > 0) { this.f6500o = new VDF(dimension, dimension2); } this.B = obtainStyledAttributes.getBoolean(C17083tlK.ojQ.zxing_camera_preview_zxing_use_texture_view, true); int integer = obtainStyledAttributes.getInteger(C17083tlK.ojQ.zxing_camera_preview_zxing_preview_scaling_strategy, -1); if (integer == 1) { this.t = new C17788zjJ(); } else if (integer == 2) { this.t = new IVU(); } else if (integer == 3) { this.t = new VZN(); } obtainStyledAttributes.recycle(); } public void setTorch(boolean z) { this.x = z; C12047eqo c12047eqo = this.a; if (c12047eqo != null) { c12047eqo.e(z); } } private static Matrix On_(VDF vdf, VDF vdf2) { float f; float f2 = vdf.c / vdf.b; float f3 = vdf2.c / vdf2.b; float f4 = 1.0f; if (f2 < f3) { float f5 = f3 / f2; f = 1.0f; f4 = f5; } else { f = f2 / f3; } Matrix matrix = new Matrix(); matrix.setScale(f4, f); matrix.postTranslate((vdf.c - (vdf.c * f4)) / 2.0f, (vdf.b - (vdf.b * f)) / 2.0f); return matrix; } /* JADX INFO: Access modifiers changed from: private */ public void f() { Rect rect; VDF vdf = this.i; if (vdf == null || this.j == null || (rect = this.u) == null) { return; } if (this.y != null && vdf.equals(new VDF(rect.width(), this.u.height()))) { d(new RmV(this.y.getHolder())); return; } TextureView textureView = this.v; if (textureView == null || textureView.getSurfaceTexture() == null) { return; } if (this.j != null) { this.v.setTransform(On_(new VDF(this.v.getWidth(), this.v.getHeight()), this.j)); } d(new RmV(this.v.getSurfaceTexture())); } @Override // android.view.ViewGroup, android.view.View protected void onLayout(boolean z, int i, int i2, int i3, int i4) { VDF vdf = new VDF(i3 - i, i4 - i2); this.e = vdf; C12047eqo c12047eqo = this.a; if (c12047eqo != null && c12047eqo.j == null) { OTQ otq = new OTQ(this.D.getDefaultDisplay().getRotation(), vdf); this.g = otq; OtF otF = this.t; if (otF == null) { if (this.v != null) { otF = new C17788zjJ(); } else { otF = new IVU(); } } otq.b = otF; C12047eqo c12047eqo2 = this.a; OTQ otq2 = this.g; c12047eqo2.j = otq2; c12047eqo2.a.j = otq2; C12047eqo c12047eqo3 = this.a; if (Looper.getMainLooper() == Looper.myLooper()) { if (c12047eqo3.g) { C16524oza c16524oza = c12047eqo3.c; Runnable runnable = c12047eqo3.h; synchronized (c16524oza.b) { c16524oza.b(); c16524oza.e.post(runnable); } boolean z2 = this.x; if (z2) { this.a.e(z2); } } else { throw new IllegalStateException("CameraInstance is not open"); } } else { throw new IllegalStateException("Must be called from the main thread."); } } SurfaceView surfaceView = this.y; if (surfaceView == null) { TextureView textureView = this.v; if (textureView != null) { textureView.layout(0, 0, getWidth(), getHeight()); return; } return; } Rect rect = this.u; if (rect == null) { surfaceView.layout(0, 0, getWidth(), getHeight()); } else { surfaceView.layout(rect.left, this.u.top, this.u.right, this.u.bottom); } } public void setMarginFraction(double d2) { if (d2 >= 0.5d) { throw new IllegalArgumentException("The margin fraction must be less than 0.5"); } this.m = d2; } @Override // android.view.View protected Parcelable onSaveInstanceState() { Parcelable onSaveInstanceState = super.onSaveInstanceState(); Bundle bundle = new Bundle(); bundle.putParcelable("super", onSaveInstanceState); bundle.putBoolean("torch", this.x); return bundle; } @Override // android.view.View protected void onRestoreInstanceState(Parcelable parcelable) { if (!(parcelable instanceof Bundle)) { super.onRestoreInstanceState(parcelable); return; } Bundle bundle = (Bundle) parcelable; super.onRestoreInstanceState(bundle.getParcelable("super")); setTorch(bundle.getBoolean("torch")); } public static /* synthetic */ void e(CameraPreview cameraPreview) { if (cameraPreview.a == null || cameraPreview.D.getDefaultDisplay().getRotation() == cameraPreview.l) { return; } cameraPreview.e(); cameraPreview.i(); } private void d() { if (this.a != null) { return; } C12047eqo c12047eqo = new C12047eqo(getContext()); Xad xad = this.b; if (!c12047eqo.g) { c12047eqo.e = xad; c12047eqo.a.l = xad; } this.a = c12047eqo; c12047eqo.k = this.r; C12047eqo c12047eqo2 = this.a; if (Looper.getMainLooper() == Looper.myLooper()) { c12047eqo2.g = true; c12047eqo2.d = false; C16524oza c16524oza = c12047eqo2.c; Runnable runnable = c12047eqo2.f; synchronized (c16524oza.b) { c16524oza.d++; synchronized (c16524oza.b) { c16524oza.b(); c16524oza.e.post(runnable); } } this.l = this.D.getDefaultDisplay().getRotation(); return; } throw new IllegalStateException("Must be called from the main thread."); } private void d(RmV rmV) { C12047eqo c12047eqo; if (this.n || (c12047eqo = this.a) == null) { return; } c12047eqo.n = rmV; C12047eqo c12047eqo2 = this.a; if (Looper.getMainLooper() == Looper.myLooper()) { if (!c12047eqo2.g) { throw new IllegalStateException("CameraInstance is not open"); } C16524oza c16524oza = c12047eqo2.c; Runnable runnable = c12047eqo2.l; synchronized (c16524oza.b) { c16524oza.b(); c16524oza.e.post(runnable); } this.n = true; c(); this.f.c(); return; } throw new IllegalStateException("Must be called from the main thread."); } public void e() { TextureView textureView; SurfaceView surfaceView; if (Looper.getMainLooper() == Looper.myLooper()) { this.l = -1; C12047eqo c12047eqo = this.a; if (c12047eqo == null) { this.r.sendEmptyMessage(C17083tlK.LWm.zxing_camera_closed); } else if (Looper.getMainLooper() == Looper.myLooper()) { if (!c12047eqo.g) { c12047eqo.d = true; } else { C16524oza c16524oza = c12047eqo.c; Runnable runnable = c12047eqo.b; synchronized (c16524oza.b) { c16524oza.b(); c16524oza.e.post(runnable); } } c12047eqo.g = false; this.a = null; this.n = false; } else { throw new IllegalStateException("Must be called from the main thread."); } if (this.i == null && (surfaceView = this.y) != null) { surfaceView.getHolder().removeCallback(this.w); } if (this.i == null && (textureView = this.v) != null) { textureView.setSurfaceTextureListener(null); } this.e = null; this.j = null; this.k = null; VTt vTt = this.p; OrientationEventListener orientationEventListener = vTt.e; if (orientationEventListener != null) { orientationEventListener.disable(); } vTt.e = null; vTt.a = null; vTt.c = null; this.f.d(); return; } throw new IllegalStateException("Must be called from the main thread."); } public final void i() { if (Looper.getMainLooper() == Looper.myLooper()) { d(); if (this.i != null) { f(); } else { SurfaceView surfaceView = this.y; if (surfaceView != null) { surfaceView.getHolder().addCallback(this.w); } else { TextureView textureView = this.v; if (textureView != null) { if (textureView.isAvailable()) { new AnonymousClass5(this).onSurfaceTextureAvailable(this.v.getSurfaceTexture(), this.v.getWidth(), this.v.getHeight()); } else { this.v.setSurfaceTextureListener(new AnonymousClass5(this)); } } } } requestLayout(); this.p.a(getContext(), this.s); return; } throw new IllegalStateException("Must be called from the main thread."); } public void setUseTextureView(boolean z) { this.B = z; } public void setPreviewScalingStrategy(OtF otF) { this.t = otF; } public void setFramingRectSize(VDF vdf) { this.f6500o = vdf; } public void setCameraSettings(Xad xad) { this.b = xad; } public final boolean g() { return this.n; } public final Rect Oo_() { return this.k; } }