package nc;

import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.os.Handler;
import android.view.SurfaceHolder;
import mc.v;
import xyz.stream.utils.e0;

/* JADX INFO: loaded from: classes.dex */
public final class e implements Runnable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f31200a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ f f31201b;

    public /* synthetic */ e(f fVar, int i10) {
        this.f31200a = i10;
        this.f31201b = fVar;
    }

    @Override // java.lang.Runnable
    public final void run() {
        v vVar = null;
        switch (this.f31200a) {
            case 0:
                f fVar = this.f31201b;
                try {
                    fVar.f31205c.b();
                    return;
                } catch (Exception e10) {
                    Handler handler = fVar.f31206d;
                    if (handler != null) {
                        handler.obtainMessage(rb.i.zxing_camera_error, e10).sendToTarget();
                        return;
                    }
                    return;
                }
            case 1:
                f fVar2 = this.f31201b;
                try {
                    fVar2.f31205c.a();
                    Handler handler2 = fVar2.f31206d;
                    if (handler2 != null) {
                        int i10 = rb.i.zxing_prewiew_size_ready;
                        h hVar = fVar2.f31205c;
                        v vVar2 = hVar.f31228j;
                        if (vVar2 != null) {
                            int i11 = hVar.f31229k;
                            if (i11 == -1) {
                                throw new IllegalStateException("Rotation not calculated yet. Call configure() first.");
                            }
                            vVar = i11 % 180 != 0 ? new v(vVar2.f30646b, vVar2.f30645a) : vVar2;
                        }
                        handler2.obtainMessage(i10, vVar).sendToTarget();
                        return;
                    }
                    return;
                } catch (Exception e11) {
                    Handler handler3 = fVar2.f31206d;
                    if (handler3 != null) {
                        handler3.obtainMessage(rb.i.zxing_camera_error, e11).sendToTarget();
                        return;
                    }
                    return;
                }
            case 2:
                f fVar3 = this.f31201b;
                try {
                    h hVar2 = fVar3.f31205c;
                    e0 e0Var = fVar3.f31204b;
                    Camera camera = hVar2.f31219a;
                    SurfaceHolder surfaceHolder = (SurfaceHolder) e0Var.f36128b;
                    if (surfaceHolder != null) {
                        camera.setPreviewDisplay(surfaceHolder);
                    } else {
                        camera.setPreviewTexture((SurfaceTexture) e0Var.f36129c);
                    }
                    fVar3.f31205c.e();
                    return;
                } catch (Exception e12) {
                    Handler handler4 = fVar3.f31206d;
                    if (handler4 != null) {
                        handler4.obtainMessage(rb.i.zxing_camera_error, e12).sendToTarget();
                        return;
                    }
                    return;
                }
            default:
                try {
                    h hVar3 = this.f31201b.f31205c;
                    b bVar = hVar3.f31221c;
                    if (bVar != null) {
                        bVar.f31190a = true;
                        bVar.f31191b = false;
                        bVar.f31194e.removeMessages(1);
                        if (bVar.f31192c) {
                            try {
                                bVar.f31193d.cancelAutoFocus();
                                break;
                            } catch (RuntimeException unused) {
                            }
                        }
                        hVar3.f31221c = null;
                    }
                    if (hVar3.f31222d != null) {
                        hVar3.f31222d = null;
                    }
                    Camera camera2 = hVar3.f31219a;
                    if (camera2 != null && hVar3.f31223e) {
                        camera2.stopPreview();
                        hVar3.f31231m.f31215a = null;
                        hVar3.f31223e = false;
                    }
                    h hVar4 = this.f31201b.f31205c;
                    Camera camera3 = hVar4.f31219a;
                    if (camera3 != null) {
                        camera3.release();
                        hVar4.f31219a = null;
                    }
                    break;
                } catch (Exception unused2) {
                }
                f fVar4 = this.f31201b;
                fVar4.f31209g = true;
                fVar4.f31206d.sendEmptyMessage(rb.i.zxing_camera_closed);
                j jVar = this.f31201b.f31203a;
                synchronized (jVar.f31238d) {
                    int i12 = jVar.f31237c - 1;
                    jVar.f31237c = i12;
                    if (i12 == 0) {
                        synchronized (jVar.f31238d) {
                            jVar.f31236b.quit();
                            jVar.f31236b = null;
                            jVar.f31235a = null;
                        }
                    }
                    break;
                }
                return;
        }
    }
}
