package com.google.android.gms.internal.ads;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.media3.exoplayer.rtsp.SessionDescription;
import java.util.HashMap;
import javax.annotation.ParametersAreNonnullByDefault;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

/* JADX INFO: loaded from: classes2.dex */
@ParametersAreNonnullByDefault
public final class zzcfs extends FrameLayout implements q30 {
    public String[] Q;
    public Bitmap R;
    public final ImageView S;
    public boolean T;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final FrameLayout f19587b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final View f19588c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final mo f19589d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final s30 f19590e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final long f19591f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public boolean f19592g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public boolean f19593h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public boolean f19594i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public boolean f19595j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public long f19596k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public long f19597l;

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

    @Nullable
    private final zzcfk zzg;

    public zzcfs(Context context, c40 c40Var, int i10, boolean z10, mo moVar, b40 b40Var, @Nullable cr0 cr0Var) {
        super(context);
        this.f19586a = c40Var;
        this.f19589d = moVar;
        FrameLayout frameLayout = new FrameLayout(context);
        this.f19587b = frameLayout;
        addView(frameLayout, new FrameLayout.LayoutParams(-1, -1));
        com.google.android.gms.common.internal.w.checkNotNull(c40Var.zzk());
        g30 g30Var = c40Var.zzk().f30421a;
        d40 d40Var = new d40(context, c40Var.zzs(), c40Var.zzm(), moVar, c40Var.zzi());
        zzcfk zzcjaVar = i10 == 3 ? new zzcja(context, d40Var) : i10 == 2 ? new zzcgw(context, d40Var, c40Var, z10, c40Var.zzN().b(), b40Var, cr0Var) : new zzcfi(context, c40Var, z10, c40Var.zzN().b(), b40Var, new d40(context, c40Var.zzs(), c40Var.zzm(), moVar, c40Var.zzi()), cr0Var);
        this.zzg = zzcjaVar;
        View view = new View(context);
        this.f19588c = view;
        view.setBackgroundColor(0);
        frameLayout.addView(zzcjaVar, new FrameLayout.LayoutParams(-1, -1, 17));
        tn tnVar = ao.f8863g0;
        n7.y yVar = n7.y.f31093e;
        if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
            frameLayout.addView(view, new FrameLayout.LayoutParams(-1, -1));
            frameLayout.bringChildToFront(view);
        }
        if (((Boolean) yVar.f31096c.b(ao.f8812d0)).booleanValue()) {
            d();
        }
        this.S = new ImageView(context);
        this.f19591f = ((Long) yVar.f31096c.b(ao.f8895i0)).longValue();
        boolean zBooleanValue = ((Boolean) yVar.f31096c.b(ao.f8846f0)).booleanValue();
        this.f19595j = zBooleanValue;
        if (moVar != null) {
            moVar.c("spinner_used", true != zBooleanValue ? SessionDescription.SUPPORTED_SDP_VERSION : "1");
        }
        this.f19590e = new s30(this);
        zzcjaVar.j(this);
    }

    public final void A(int i10) {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        zzcfkVar.z(i10);
    }

    public final void B(int i10) {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        zzcfkVar.a(i10);
    }

    public final void a(int i10) {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        zzcfkVar.b(i10);
    }

    public final void b(int i10) {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        zzcfkVar.g(i10);
    }

    public final void c(MotionEvent motionEvent) {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        zzcfkVar.dispatchTouchEvent(motionEvent);
    }

    public final void d() {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        TextView textView = new TextView(zzcfkVar.getContext());
        Resources resourcesZzf = m7.n.C.f30469h.zzf();
        textView.setText(String.valueOf(resourcesZzf == null ? "AdMob - " : resourcesZzf.getString(k7.d.watermark_label_prefix)).concat(zzcfkVar.i()));
        textView.setTextColor(-65536);
        textView.setBackgroundColor(-256);
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-2, -2, 17);
        FrameLayout frameLayout = this.f19587b;
        frameLayout.addView(textView, layoutParams);
        frameLayout.bringChildToFront(textView);
    }

    public final void e() {
        this.f19590e.a();
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar != null) {
            zzcfkVar.k();
        }
        h();
    }

    public final void f() {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        long jO = zzcfkVar.o();
        if (this.f19596k == jO || jO <= 0) {
            return;
        }
        float f10 = jO / 1000.0f;
        if (((Boolean) n7.y.f31093e.f31096c.b(ao.f8979n2)).booleanValue()) {
            String strValueOf = String.valueOf(f10);
            String strValueOf2 = String.valueOf(zzcfkVar.w());
            String strValueOf3 = String.valueOf(zzcfkVar.u());
            String strValueOf4 = String.valueOf(zzcfkVar.t());
            String strValueOf5 = String.valueOf(zzcfkVar.x());
            m7.n.C.f30472k.getClass();
            g("timeupdate", "time", strValueOf, "totalBytes", strValueOf2, "qoeCachedBytes", strValueOf3, "qoeLoadedBytes", strValueOf4, "droppedFrames", strValueOf5, "reportTime", String.valueOf(System.currentTimeMillis()));
        } else {
            g("timeupdate", "time", String.valueOf(f10));
        }
        this.f19596k = jO;
    }

    public final void finalize() throws Throwable {
        try {
            this.f19590e.a();
            zzcfk zzcfkVar = this.zzg;
            if (zzcfkVar != null) {
                b30.f9364f.execute(new mv1(zzcfkVar, 20));
            }
        } finally {
            super.finalize();
        }
    }

    public final void g(String str, String... strArr) {
        HashMap map = new HashMap();
        Integer numZzl = zzl();
        if (numZzl != null) {
            map.put("playerId", numZzl.toString());
        }
        map.put("event", str);
        String str2 = null;
        for (String str3 : strArr) {
            if (str2 == null) {
                str2 = str3;
            } else {
                map.put(str2, str3);
                str2 = null;
            }
        }
        this.f19586a.d("onVideoEvent", map);
    }

    public final void h() {
        c40 c40Var = this.f19586a;
        if (c40Var.zzj() == null || !this.f19593h || this.f19594i) {
            return;
        }
        c40Var.zzj().getWindow().clearFlags(128);
        this.f19593h = false;
    }

    public final void i() {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar != null && this.f19597l == 0) {
            g("canplaythrough", "duration", String.valueOf(zzcfkVar.n() / 1000.0f), "videoWidth", String.valueOf(zzcfkVar.r()), "videoHeight", String.valueOf(zzcfkVar.s()));
        }
    }

    public final void j() {
        if (((Boolean) n7.y.f31093e.f31096c.b(ao.f9013p2)).booleanValue()) {
            s30 s30Var = this.f19590e;
            s30Var.f16285c = false;
            p7.m0 m0Var = p7.r0.f31763l;
            m0Var.removeCallbacks(s30Var);
            m0Var.postDelayed(s30Var, 250L);
        }
        c40 c40Var = this.f19586a;
        if (c40Var.zzj() != null && !this.f19593h) {
            boolean z10 = (c40Var.zzj().getWindow().getAttributes().flags & 128) != 0;
            this.f19594i = z10;
            if (!z10) {
                c40Var.zzj().getWindow().addFlags(128);
                this.f19593h = true;
            }
        }
        this.f19592g = true;
    }

    public final void k() {
        g("pause", new String[0]);
        h();
        this.f19592g = false;
    }

    public final void l() {
        if (((Boolean) n7.y.f31093e.f31096c.b(ao.f9013p2)).booleanValue()) {
            this.f19590e.a();
        }
        g("ended", new String[0]);
        h();
    }

    public final void m() {
        if (this.T && this.R != null) {
            ImageView imageView = this.S;
            if (imageView.getParent() == null) {
                imageView.setImageBitmap(this.R);
                imageView.invalidate();
                FrameLayout frameLayout = this.f19587b;
                frameLayout.addView(imageView, new FrameLayout.LayoutParams(-1, -1));
                frameLayout.bringChildToFront(imageView);
            }
        }
        this.f19590e.a();
        this.f19597l = this.f19596k;
        p7.r0.f31763l.post(new r30(this, 1));
    }

    public final void n() {
        if (this.f19592g) {
            ImageView imageView = this.S;
            if (imageView.getParent() != null) {
                this.f19587b.removeView(imageView);
            }
        }
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null || this.R == null) {
            return;
        }
        m7.n nVar = m7.n.C;
        nVar.f30472k.getClass();
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        if (zzcfkVar.getBitmap(this.R) != null) {
            this.T = true;
        }
        nVar.f30472k.getClass();
        long jElapsedRealtime2 = SystemClock.elapsedRealtime() - jElapsedRealtime;
        if (p7.l0.h()) {
            StringBuilder sb = new StringBuilder(String.valueOf(jElapsedRealtime2).length() + 26);
            sb.append("Spinner frame grab took ");
            sb.append(jElapsedRealtime2);
            sb.append("ms");
            p7.l0.g(sb.toString());
        }
        if (jElapsedRealtime2 > this.f19591f) {
            q7.j.d("Spinner frame grab crossed jank threshold! Suspending spinner.");
            this.f19595j = false;
            this.R = null;
            mo moVar = this.f19589d;
            if (moVar != null) {
                moVar.c("spinner_jank", Long.toString(jElapsedRealtime2));
            }
        }
    }

    public final void o(int i10, int i11) {
        if (this.f19595j) {
            tn tnVar = ao.f8879h0;
            n7.y yVar = n7.y.f31093e;
            int iMax = Math.max(i10 / ((Integer) yVar.f31096c.b(tnVar)).intValue(), 1);
            int iMax2 = Math.max(i11 / ((Integer) yVar.f31096c.b(tnVar)).intValue(), 1);
            Bitmap bitmap = this.R;
            if (bitmap != null && bitmap.getWidth() == iMax && this.R.getHeight() == iMax2) {
                return;
            }
            this.R = Bitmap.createBitmap(iMax, iMax2, Bitmap.Config.ARGB_8888);
            this.T = false;
        }
    }

    @Override // android.view.View
    public final void onWindowFocusChanged(boolean z10) {
        super.onWindowFocusChanged(z10);
        s30 s30Var = this.f19590e;
        if (z10) {
            s30Var.f16285c = false;
            p7.m0 m0Var = p7.r0.f31763l;
            m0Var.removeCallbacks(s30Var);
            m0Var.postDelayed(s30Var, 250L);
        } else {
            s30Var.a();
            this.f19597l = this.f19596k;
        }
        p7.r0.f31763l.post(new s30(this, z10, 1));
    }

    @Override // android.view.View, com.google.android.gms.internal.ads.q30
    public final void onWindowVisibilityChanged(int i10) {
        boolean z10;
        super.onWindowVisibilityChanged(i10);
        s30 s30Var = this.f19590e;
        if (i10 == 0) {
            s30Var.f16285c = false;
            p7.m0 m0Var = p7.r0.f31763l;
            m0Var.removeCallbacks(s30Var);
            m0Var.postDelayed(s30Var, 250L);
            z10 = true;
        } else {
            s30Var.a();
            this.f19597l = this.f19596k;
            z10 = false;
        }
        p7.r0.f31763l.post(new s30(this, z10, 0));
    }

    public final void p() {
        this.f19588c.setVisibility(4);
        p7.r0.f31763l.post(new r30(this, 2));
    }

    public final void q(int i10, int i11, int i12, int i13) {
        if (p7.l0.h()) {
            int length = String.valueOf(i10).length();
            StringBuilder sb = new StringBuilder(length + 25 + String.valueOf(i11).length() + 3 + String.valueOf(i12).length() + 3 + String.valueOf(i13).length());
            com.google.android.gms.measurement.internal.u1.y(sb, "Set video bounds to x:", i10, ";y:", i11);
            sb.append(";w:");
            sb.append(i12);
            sb.append(";h:");
            sb.append(i13);
            p7.l0.g(sb.toString());
        }
        if (i12 == 0 || i13 == 0) {
            return;
        }
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(i12, i13);
        layoutParams.setMargins(i10, i11, 0, 0);
        this.f19587b.setLayoutParams(layoutParams);
        requestLayout();
    }

    public final void r(float f10, float f11) {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar != null) {
            zzcfkVar.q(f10, f11);
        }
    }

    public final void s(Integer num) {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        if (TextUtils.isEmpty(this.f19598m)) {
            g("no_src", new String[0]);
        } else {
            zzcfkVar.zzx(this.f19598m, this.Q, num);
        }
    }

    public final void t() {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        zzcfkVar.m();
    }

    public final void u() {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        zzcfkVar.l();
    }

    public final void v(int i10) {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        zzcfkVar.p(i10);
    }

    public final void w() {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        f40 f40Var = zzcfkVar.f19585b;
        f40Var.f11017e = true;
        f40Var.a();
        zzcfkVar.zzq();
    }

    public final void x() {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        f40 f40Var = zzcfkVar.f19585b;
        f40Var.f11017e = false;
        f40Var.a();
        zzcfkVar.zzq();
    }

    public final void y(float f10) {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        f40 f40Var = zzcfkVar.f19585b;
        f40Var.f11018f = f10;
        f40Var.a();
        zzcfkVar.zzq();
    }

    public final void z(int i10) {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar == null) {
            return;
        }
        zzcfkVar.y(i10);
    }

    @Override // com.google.android.gms.internal.ads.q30
    public final void zzf(String str, @Nullable String str2) {
        g(IjkMediaPlayer.OnNativeInvokeListener.ARG_ERROR, "what", str, "extra", str2);
    }

    @Override // com.google.android.gms.internal.ads.q30
    public final void zzg(String str, @Nullable String str2) {
        g("exception", "what", "ExoPlayerAdapter exception", "extra", str2);
    }

    @Nullable
    public final Integer zzl() {
        zzcfk zzcfkVar = this.zzg;
        if (zzcfkVar != null) {
            return zzcfkVar.zzw();
        }
        return null;
    }
}
