package com.journeyapps.barcodescanner;

import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import bm.h;
import cm.i;
import dl.f;
import dl.g;
import dl.k;
import dl.l;
import dl.o;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import yk.s;

/* loaded from: classes3.dex */
public class DecoratedBarcodeView extends FrameLayout {

    /* renamed from: p, reason: collision with root package name */
    private BarcodeView f15286p;

    /* renamed from: q, reason: collision with root package name */
    private ViewfinderView f15287q;

    /* renamed from: r, reason: collision with root package name */
    private TextView f15288r;

    /* loaded from: classes3.dex */
    public interface a {
    }

    /* loaded from: classes3.dex */
    private class b implements bm.a {

        /* renamed from: a, reason: collision with root package name */
        private bm.a f15289a;

        public b(bm.a aVar) {
            this.f15289a = aVar;
        }

        @Override // bm.a
        public void a(List list) {
            Iterator it = list.iterator();
            while (it.hasNext()) {
                DecoratedBarcodeView.this.f15287q.a((s) it.next());
            }
            this.f15289a.a(list);
        }

        @Override // bm.a
        public void b(bm.c cVar) {
            this.f15289a.b(cVar);
        }
    }

    public DecoratedBarcodeView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        c(attributeSet);
    }

    private void c(AttributeSet attributeSet) {
        TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, o.f16375t);
        int resourceId = obtainStyledAttributes.getResourceId(o.f16376u, l.f16350a);
        obtainStyledAttributes.recycle();
        View.inflate(getContext(), resourceId, this);
        BarcodeView barcodeView = (BarcodeView) findViewById(k.f16339b);
        this.f15286p = barcodeView;
        if (barcodeView == null) {
            throw new IllegalArgumentException("There is no a com.journeyapps.barcodescanner.BarcodeView on provided layout with the id \"zxing_barcode_surface\".");
        }
        barcodeView.q(attributeSet);
        ViewfinderView viewfinderView = (ViewfinderView) findViewById(k.f16349l);
        this.f15287q = viewfinderView;
        if (viewfinderView == null) {
            throw new IllegalArgumentException("There is no a com.journeyapps.barcodescanner.ViewfinderView on provided layout with the id \"zxing_viewfinder_view\".");
        }
        viewfinderView.setCameraPreview(this.f15286p);
        this.f15288r = (TextView) findViewById(k.f16348k);
    }

    public void b(bm.a aVar) {
        this.f15286p.I(new b(aVar));
    }

    public void d(Intent intent) {
        int intExtra;
        Set a10 = f.a(intent);
        Map a11 = g.a(intent);
        i iVar = new i();
        if (intent.hasExtra("SCAN_CAMERA_ID") && (intExtra = intent.getIntExtra("SCAN_CAMERA_ID", -1)) >= 0) {
            iVar.i(intExtra);
        }
        if (intent.hasExtra("TORCH_ENABLED") && intent.getBooleanExtra("TORCH_ENABLED", false)) {
            i();
        }
        String stringExtra = intent.getStringExtra("PROMPT_MESSAGE");
        if (stringExtra != null) {
            setStatusText(stringExtra);
        }
        int intExtra2 = intent.getIntExtra("SCAN_TYPE", 0);
        String stringExtra2 = intent.getStringExtra("CHARACTER_SET");
        new yk.k().e(a11);
        this.f15286p.setCameraSettings(iVar);
        this.f15286p.setDecoderFactory(new bm.k(a10, a11, stringExtra2, intExtra2));
    }

    public void e() {
        this.f15286p.u();
    }

    public void f() {
        this.f15286p.v();
    }

    public void g() {
        this.f15286p.y();
    }

    public BarcodeView getBarcodeView() {
        return (BarcodeView) findViewById(k.f16339b);
    }

    public i getCameraSettings() {
        return this.f15286p.getCameraSettings();
    }

    public h getDecoderFactory() {
        return this.f15286p.getDecoderFactory();
    }

    public TextView getStatusView() {
        return this.f15288r;
    }

    public ViewfinderView getViewFinder() {
        return this.f15287q;
    }

    public void h() {
        this.f15286p.setTorch(false);
    }

    public void i() {
        this.f15286p.setTorch(true);
    }

    @Override // android.view.View, android.view.KeyEvent.Callback
    public boolean onKeyDown(int i10, KeyEvent keyEvent) {
        if (i10 == 24) {
            i();
            return true;
        }
        if (i10 == 25) {
            h();
            return true;
        }
        if (i10 == 27 || i10 == 80) {
            return true;
        }
        return super.onKeyDown(i10, keyEvent);
    }

    public void setCameraSettings(i iVar) {
        this.f15286p.setCameraSettings(iVar);
    }

    public void setDecoderFactory(h hVar) {
        this.f15286p.setDecoderFactory(hVar);
    }

    public void setStatusText(String str) {
        TextView textView = this.f15288r;
        if (textView != null) {
            textView.setText(str);
        }
    }

    public void setTorchListener(a aVar) {
    }
}
