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

import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Iterator;
import javax.annotation.ParametersAreNonnullByDefault;

/* JADX INFO: loaded from: classes2.dex */
@ParametersAreNonnullByDefault
public final class zzbkb extends RelativeLayout {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final float[] f19569a = {5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f};

    @Nullable
    private AnimationDrawable zzb;

    public zzbkb(Context context, fq fqVar, RelativeLayout.LayoutParams layoutParams) {
        super(context);
        com.google.android.gms.common.internal.w.checkNotNull(fqVar);
        ShapeDrawable shapeDrawable = new ShapeDrawable(new RoundRectShape(f19569a, null, null));
        shapeDrawable.getPaint().setColor(fqVar.f11358d);
        setLayoutParams(layoutParams);
        setBackground(shapeDrawable);
        RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(-2, -2);
        String str = fqVar.f11355a;
        if (!TextUtils.isEmpty(str)) {
            RelativeLayout.LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(-2, -2);
            TextView textView = new TextView(context);
            textView.setLayoutParams(layoutParams3);
            textView.setId(1195835393);
            textView.setTypeface(Typeface.DEFAULT);
            textView.setText(str);
            textView.setTextColor(fqVar.f11359e);
            textView.setTextSize(fqVar.f11360f);
            q7.e eVar = n7.x.f31085g.f31086a;
            textView.setPadding(q7.e.g(context.getResources().getDisplayMetrics(), 4), 0, q7.e.g(context.getResources().getDisplayMetrics(), 4), 0);
            addView(textView);
            layoutParams2.addRule(1, textView.getId());
        }
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(layoutParams2);
        imageView.setId(1195835394);
        ArrayList arrayList = fqVar.f11356b;
        if (arrayList != null && arrayList.size() > 1) {
            this.zzb = new AnimationDrawable();
            Iterator it = arrayList.iterator();
            while (it.hasNext()) {
                try {
                    this.zzb.addFrame((Drawable) k8.b.O(((hq) it.next()).zzb()), fqVar.f11361g);
                } catch (Exception unused) {
                }
            }
            imageView.setBackground(this.zzb);
        } else if (arrayList.size() == 1) {
            try {
                imageView.setImageDrawable((Drawable) k8.b.O(((hq) arrayList.get(0)).zzb()));
            } catch (Exception unused2) {
            }
        }
        addView(imageView);
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onAttachedToWindow() {
        AnimationDrawable animationDrawable = this.zzb;
        if (animationDrawable != null) {
            animationDrawable.start();
        }
        super.onAttachedToWindow();
    }
}
