package com.seewo.factoryaging.camera811;

import android.content.Context;
import android.graphics.SurfaceTexture;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraManager;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.cvte.vman.R;
import j.n;
import j.p0.d.r;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

/* JADX INFO: compiled from: CameraFragment.kt */
/* JADX INFO: loaded from: classes.dex */
@n
public final class CameraFragment extends com.seewo.factoryaging.s0.d<Object, d> implements Object, TextureView.SurfaceTextureListener {
    private TextureView b0;
    private TextView c0;
    private volatile boolean d0;
    private i.a.k.b e0;
    private SurfaceTexture f0;
    public Map<Integer, View> g0 = new LinkedHashMap();

    private final boolean K1() throws CameraAccessException {
        Context contextP = P();
        Object systemService = contextP != null ? contextP.getSystemService("camera") : null;
        if (systemService == null) {
            throw new NullPointerException("null cannot be cast to non-null type android.hardware.camera2.CameraManager");
        }
        Log.d("CameraFragment", "成功获取CameraManager");
        String[] cameraIdList = ((CameraManager) systemService).getCameraIdList();
        r.e(cameraIdList, "mCameraManager.cameraIdList");
        return !(cameraIdList.length == 0);
    }

    @Override // g.h.a.c
    public View B0(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        r.f(layoutInflater, "inflater");
        View viewInflate = layoutInflater.inflate(R.layout.fragment_camera_811, viewGroup);
        View viewFindViewById = viewInflate.findViewById(R.id.textureView);
        r.e(viewFindViewById, "inflate.findViewById(R.id.textureView)");
        this.b0 = (TextureView) viewFindViewById;
        View viewFindViewById2 = viewInflate.findViewById(R.id.camera_bg_view);
        r.e(viewFindViewById2, "inflate.findViewById(R.id.camera_bg_view)");
        this.c0 = (TextView) viewFindViewById2;
        TextureView textureView = this.b0;
        if (textureView == null) {
            r.t("mTextureView");
            throw null;
        }
        textureView.setSurfaceTextureListener(this);
        View viewFindViewById3 = viewInflate.findViewById(R.id.fl_camera_811);
        r.e(viewFindViewById3, "inflate.findViewById(R.id.fl_camera_811)");
        com.seewo.factoryaging.e1.d dVar = com.seewo.factoryaging.e1.d.a;
        TextView textView = this.c0;
        if (textView != null) {
            dVar.c(textView);
            return viewInflate;
        }
        r.t("mBgTextView");
        throw null;
    }

    @Override // g.h.a.c
    public void C0() {
        super.C0();
        i.a.k.b bVar = this.e0;
        if (bVar != null) {
            bVar.dispose();
        }
    }

    @Override // com.seewo.factoryaging.s0.d, g.h.a.c
    public /* synthetic */ void E0() {
        super.E0();
        G1();
    }

    @Override // com.seewo.factoryaging.s0.d
    public void G1() {
        this.g0.clear();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.seewo.factoryaging.s0.d
    /* JADX INFO: renamed from: L1, reason: merged with bridge method [inline-methods] */
    public d I1() {
        return new e();
    }

    @Override // com.seewo.factoryaging.s0.d, g.h.a.c
    public void V0(View view, Bundle bundle) {
        r.f(view, "view");
        super.V0(view, bundle);
        if (!K1()) {
            TextView textView = this.c0;
            if (textView != null) {
                textView.setVisibility(0);
                return;
            } else {
                r.t("mBgTextView");
                throw null;
            }
        }
        Log.d("CameraFragment", "摄像头存在，打开摄像头");
        if (this.d0) {
            return;
        }
        TextView textView2 = this.c0;
        if (textView2 == null) {
            r.t("mBgTextView");
            throw null;
        }
        textView2.setVisibility(8);
        d dVarH1 = H1();
        if (dVarH1 != null) {
            TextureView textureView = this.b0;
            if (textureView == null) {
                r.t("mTextureView");
                throw null;
            }
            dVarH1.m(textureView);
        }
        if (this.f0 != null) {
            this.d0 = true;
            d dVarH12 = H1();
            if (dVarH12 != null) {
                SurfaceTexture surfaceTexture = this.f0;
                r.c(surfaceTexture);
                dVarH12.n(surfaceTexture);
            }
        }
    }

    @Override // android.view.TextureView.SurfaceTextureListener
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i2, int i3) {
        r.f(surfaceTexture, "surfaceTexture");
        try {
            this.f0 = surfaceTexture;
            d dVarH1 = H1();
            if (dVarH1 != null) {
                dVarH1.n(surfaceTexture);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override // android.view.TextureView.SurfaceTextureListener
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
        r.f(surfaceTexture, "surfaceTexture");
        d dVarH1 = H1();
        r.c(dVarH1);
        dVarH1.l();
        return false;
    }

    @Override // android.view.TextureView.SurfaceTextureListener
    public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i2, int i3) {
        r.f(surfaceTexture, "surfaceTexture");
    }

    @Override // android.view.TextureView.SurfaceTextureListener
    public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
        r.f(surfaceTexture, "surfaceTexture");
    }
}
