package com.journeyapps.barcodescanner;

import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
import android.util.AttributeSet;
import com.google.zxing.DecodeHintType;
import java.util.Collection;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import mc.l;
import mc.m;
import mc.n;
import mc.o;
import mc.q;
import mc.r;
import mc.s;
import mc.t;
import nb.g;
import nc.d;
import nc.f;
import ob.c;

/* JADX INFO: loaded from: classes.dex */
public class BarcodeView extends CameraPreview {

    /* JADX INFO: renamed from: h0, reason: collision with root package name */
    public DecodeMode f24559h0;

    /* JADX INFO: renamed from: i0, reason: collision with root package name */
    public mc.a f24560i0;

    /* JADX INFO: renamed from: j0, reason: collision with root package name */
    public o f24561j0;

    /* JADX INFO: renamed from: k0, reason: collision with root package name */
    public m f24562k0;

    /* JADX INFO: renamed from: l0, reason: collision with root package name */
    public Handler f24563l0;

    /* JADX INFO: renamed from: m0, reason: collision with root package name */
    public final a f24564m0;

    /* JADX WARN: Failed to restore enum class, 'enum' modifier and super class removed */
    /* JADX WARN: Unknown enum class pattern. Please report as an issue! */
    public static final class DecodeMode {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public static final DecodeMode f24565a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public static final DecodeMode f24566b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public static final DecodeMode f24567c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public static final /* synthetic */ DecodeMode[] f24568d;

        static {
            DecodeMode decodeMode = new DecodeMode("NONE", 0);
            f24565a = decodeMode;
            DecodeMode decodeMode2 = new DecodeMode("SINGLE", 1);
            f24566b = decodeMode2;
            DecodeMode decodeMode3 = new DecodeMode("CONTINUOUS", 2);
            f24567c = decodeMode3;
            f24568d = new DecodeMode[]{decodeMode, decodeMode2, decodeMode3};
        }

        public static DecodeMode valueOf(String str) {
            return (DecodeMode) Enum.valueOf(DecodeMode.class, str);
        }

        public static DecodeMode[] values() {
            return (DecodeMode[]) f24568d.clone();
        }
    }

    public BarcodeView(Context context) {
        super(context);
        this.f24559h0 = DecodeMode.f24565a;
        this.f24560i0 = null;
        this.f24564m0 = new a(this);
        l();
    }

    @Override // com.journeyapps.barcodescanner.CameraPreview
    public final void e() {
        n();
        super.e();
    }

    @Override // com.journeyapps.barcodescanner.CameraPreview
    public final void f() {
        m();
    }

    public m getDecoderFactory() {
        return this.f24562k0;
    }

    public final l j() {
        l lVar;
        if (this.f24562k0 == null) {
            this.f24562k0 = new r();
        }
        n nVar = new n();
        HashMap map = new HashMap();
        map.put(DecodeHintType.f24324i, nVar);
        r rVar = (r) this.f24562k0;
        rVar.getClass();
        EnumMap enumMap = new EnumMap(DecodeHintType.class);
        enumMap.putAll(map);
        Map map2 = rVar.f30640b;
        if (map2 != null) {
            enumMap.putAll(map2);
        }
        Collection collection = rVar.f30639a;
        if (collection != null) {
            enumMap.put(DecodeHintType.f24317b, collection);
        }
        String str = rVar.f30641c;
        if (str != null) {
            enumMap.put(DecodeHintType.f24319d, str);
        }
        c cVar = new c();
        cVar.d(enumMap);
        int i10 = rVar.f30642d;
        if (i10 == 0) {
            lVar = new l(cVar);
        } else if (i10 == 1) {
            lVar = new s(cVar);
        } else if (i10 != 2) {
            lVar = new l(cVar);
        } else {
            t tVar = new t(cVar);
            tVar.f30643c = true;
            lVar = tVar;
        }
        nVar.f30624a = lVar;
        return lVar;
    }

    public final void k(q qVar) {
        this.f24559h0 = DecodeMode.f24567c;
        this.f24560i0 = qVar;
        m();
    }

    public final void l() {
        this.f24562k0 = new r();
        this.f24563l0 = new Handler(this.f24564m0);
    }

    public final void m() {
        n();
        if (this.f24559h0 == DecodeMode.f24565a || !this.f24582g) {
            return;
        }
        o oVar = new o(getCameraInstance(), j(), this.f24563l0);
        this.f24561j0 = oVar;
        oVar.f30631f = getPreviewFramingRect();
        o oVar2 = this.f24561j0;
        oVar2.getClass();
        g.V();
        HandlerThread handlerThread = new HandlerThread("o");
        oVar2.f30627b = handlerThread;
        handlerThread.start();
        oVar2.f30628c = new Handler(oVar2.f30627b.getLooper(), oVar2.f30634i);
        oVar2.f30632g = true;
        f fVar = oVar2.f30626a;
        fVar.f31210h.post(new d(fVar, oVar2.f30635j, 0));
    }

    public final void n() {
        o oVar = this.f24561j0;
        if (oVar != null) {
            oVar.getClass();
            g.V();
            synchronized (oVar.f30633h) {
                oVar.f30632g = false;
                oVar.f30628c.removeCallbacksAndMessages(null);
                oVar.f30627b.quit();
            }
            this.f24561j0 = null;
        }
    }

    public final void o() {
        this.f24559h0 = DecodeMode.f24565a;
        this.f24560i0 = null;
        n();
    }

    public void setDecoderFactory(m mVar) {
        g.V();
        this.f24562k0 = mVar;
        o oVar = this.f24561j0;
        if (oVar != null) {
            oVar.f30629d = j();
        }
    }

    public BarcodeView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f24559h0 = DecodeMode.f24565a;
        this.f24560i0 = null;
        this.f24564m0 = new a(this);
        l();
    }

    public BarcodeView(Context context, AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        this.f24559h0 = DecodeMode.f24565a;
        this.f24560i0 = null;
        this.f24564m0 = new a(this);
        l();
    }
}
