package com.google.android.gms.ads;

import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.gms.common.internal.w;
import com.google.android.gms.internal.ads.ao;
import com.google.android.gms.internal.ads.mp;
import g7.f;
import g7.g;
import g7.n;
import g7.u;
import h7.d;
import l.l;
import n7.a;
import n7.e4;
import n7.v2;
import n7.w2;
import n7.x;
import n7.y;
import q7.b;
import q7.e;

/* JADX INFO: loaded from: classes2.dex */
public abstract class BaseAdView extends ViewGroup {

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

    public BaseAdView(Context context) {
        super(context);
        this.f7866a = new w2(this, null, false, e4.f30941a, null, 0);
    }

    public final void a(f fVar) {
        w.d("#008 Must be called on the main UI thread.");
        ao.a(getContext());
        if (((Boolean) mp.f14330f.j()).booleanValue()) {
            if (((Boolean) y.f31093e.f31096c.b(ao.f9089tc)).booleanValue()) {
                b.f32218b.execute(new l(this, fVar, 24, 0));
                return;
            }
        }
        this.f7866a.e(fVar.f26279a);
    }

    @NonNull
    public g7.b getAdListener() {
        return this.f7866a.f31077e;
    }

    @Nullable
    public g getAdSize() {
        return this.f7866a.zzc();
    }

    @NonNull
    public String getAdUnitId() {
        return this.f7866a.d();
    }

    @Nullable
    public n getOnPaidEventListener() {
        this.f7866a.zzx();
        return null;
    }

    public long getPlacementId() {
        return this.f7866a.j();
    }

    @Nullable
    public u getResponseInfo() {
        return this.f7866a.zzt();
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        View childAt = getChildAt(0);
        if (childAt == null || childAt.getVisibility() == 8) {
            return;
        }
        int measuredWidth = childAt.getMeasuredWidth();
        int measuredHeight = childAt.getMeasuredHeight();
        int i14 = ((i12 - i10) - measuredWidth) / 2;
        int i15 = ((i13 - i11) - measuredHeight) / 2;
        childAt.layout(i14, i15, measuredWidth + i14, measuredHeight + i15);
    }

    @Override // android.view.View
    public final void onMeasure(int i10, int i11) {
        g adSize;
        int measuredHeight;
        int iG;
        int iG2;
        int measuredWidth = 0;
        View childAt = getChildAt(0);
        if (childAt == null || childAt.getVisibility() == 8) {
            try {
                adSize = getAdSize();
            } catch (NullPointerException unused) {
                adSize = null;
            }
            if (adSize != null) {
                Context context = getContext();
                int i12 = adSize.f26290a;
                if (i12 == -3) {
                    iG = -1;
                } else if (i12 != -1) {
                    e eVar = x.f31085g.f31086a;
                    iG = e.g(context.getResources().getDisplayMetrics(), i12);
                } else {
                    iG = context.getResources().getDisplayMetrics().widthPixels;
                }
                int i13 = adSize.f26291b;
                if (i13 == -4 || i13 == -3) {
                    iG2 = -1;
                } else if (i13 != -2) {
                    e eVar2 = x.f31085g.f31086a;
                    iG2 = e.g(context.getResources().getDisplayMetrics(), i13);
                } else {
                    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
                    float f10 = displayMetrics.heightPixels;
                    float f11 = displayMetrics.density;
                    int i14 = (int) (f10 / f11);
                    iG2 = (int) ((i14 <= 400 ? 32 : i14 <= 720 ? 50 : 90) * f11);
                }
                measuredHeight = iG2;
                measuredWidth = iG;
            } else {
                measuredHeight = 0;
            }
        } else {
            measureChild(childAt, i10, i11);
            measuredWidth = childAt.getMeasuredWidth();
            measuredHeight = childAt.getMeasuredHeight();
        }
        setMeasuredDimension(View.resolveSize(Math.max(measuredWidth, getSuggestedMinimumWidth()), i10), View.resolveSize(Math.max(measuredHeight, getSuggestedMinimumHeight()), i11));
    }

    /* JADX WARN: Multi-variable type inference failed */
    public void setAdListener(@NonNull g7.b bVar) {
        w2 w2Var = this.f7866a;
        w2Var.f31077e = bVar;
        v2 v2Var = w2Var.f31076d;
        synchronized (v2Var.f31068b) {
            v2Var.f31069c = bVar;
        }
        if (bVar == 0) {
            w2Var.zzl(null);
            return;
        }
        if (bVar instanceof a) {
            w2Var.zzl((a) bVar);
        }
        if (bVar instanceof d) {
            w2Var.zzp((d) bVar);
        }
    }

    public void setAdSize(@NonNull g gVar) {
        g[] gVarArr = {gVar};
        w2 w2Var = this.f7866a;
        if (w2Var.f31078f != null) {
            throw new IllegalStateException("The ad size can only be set once on AdView.");
        }
        w2Var.h(gVarArr);
    }

    public void setAdUnitId(@NonNull String str) {
        w2 w2Var = this.f7866a;
        if (w2Var.f31080h != null) {
            throw new IllegalStateException("The ad unit ID can only be set once on AdView.");
        }
        w2Var.f31080h = str;
    }

    public void setOnPaidEventListener(@Nullable n nVar) {
        this.f7866a.zzu(nVar);
    }

    public void setPlacementId(long j10) {
        this.f7866a.k(j10);
    }

    public BaseAdView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f7866a = new w2(this, attributeSet, false);
    }

    public BaseAdView(Context context, AttributeSet attributeSet, int i10, int i11) {
        super(context, attributeSet, i10);
        this.f7866a = new w2(this, attributeSet, false);
    }

    public BaseAdView(Context context, AttributeSet attributeSet, int i10, Object obj) {
        super(context, attributeSet, i10);
        this.f7866a = new w2(this, attributeSet, true);
    }

    public BaseAdView(Context context, AttributeSet attributeSet, int i10) {
        super(context, attributeSet);
        this.f7866a = new w2(this, attributeSet, true, e4.f30941a, null, 0);
    }
}
