package com.bytedance.sdk.openadsdk.core.widget;

import android.R;
import android.app.Dialog;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.window.OnBackInvokedCallback;
import com.bytedance.sdk.component.utils.maa;
import com.bytedance.sdk.openadsdk.utils.hi;
import com.bytedance.sdk.openadsdk.utils.zan;
import java.lang.ref.WeakReference;
import tv.danmaku.ijk.media.player.IjkEventListener;

/* JADX INFO: loaded from: classes2.dex */
public class ro extends Dialog {
    private com.bytedance.sdk.openadsdk.core.ajl.fm ajl;
    private int dsz;
    private String duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private String f7350ef;
    private boolean fhx;
    public InterfaceC0087ro fm;
    private float gof;
    private int gqi;
    private boolean irt;
    private com.bytedance.sdk.openadsdk.core.ajl.fm jnr;
    private String ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private com.bytedance.sdk.openadsdk.core.ajl.wu f7351lb;
    private OnBackInvokedCallback onz;
    private int qhl;
    private com.bytedance.sdk.openadsdk.core.ajl.yz ro;
    private String vt;
    private View wsy;
    private final Context wu;
    private com.bytedance.sdk.openadsdk.core.ajl.wu yz;

    public static class fm implements OnBackInvokedCallback {
        private final WeakReference<ro> fm;

        public fm(ro roVar) {
            this.fm = new WeakReference<>(roVar);
        }

        public void onBackInvoked() {
            ro roVar = this.fm.get();
            if (roVar != null) {
                com.bytedance.sdk.component.utils.wey.fm("CustomCommonDialog", "onBackInvoked");
                roVar.onBackPressed();
            }
        }
    }

    /* JADX INFO: renamed from: com.bytedance.sdk.openadsdk.core.widget.ro$ro, reason: collision with other inner class name */
    public interface InterfaceC0087ro {
        void fm();

        void ro();
    }

    public ro(Context context) {
        super(context, maa.ajl(context, "tt_custom_dialog"));
        this.dsz = -1;
        this.fhx = false;
        this.irt = false;
        this.wu = context;
    }

    @Override // android.app.Dialog, android.content.DialogInterface
    public void dismiss() {
        super.dismiss();
        lb();
    }

    public ro fm(InterfaceC0087ro interfaceC0087ro) {
        this.fm = interfaceC0087ro;
        return this;
    }

    public ro lb(String str) {
        this.ku = str;
        return this;
    }

    @Override // android.app.Dialog
    public void onBackPressed() {
        com.bytedance.sdk.component.utils.wey.fm("CustomCommonDialog", "onBackPressed");
    }

    @Override // android.app.Dialog
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        boolean zAi = com.bytedance.sdk.openadsdk.core.gof.yz().ai();
        this.irt = zAi;
        if (zAi) {
            this.qhl = Color.argb(166, 0, 0, 0);
            this.gof = 16.0f;
            this.gqi = Color.parseColor("#000000");
            setContentView(ro(this.wu));
        } else {
            setContentView(fm(this.wu));
        }
        if (hi.fm()) {
            com.bytedance.sdk.component.utils.wey.fm("CustomCommonDialog", "isAtLeastT registerOnBackInvokedCallback");
            this.onz = new fm(this);
            getOnBackInvokedDispatcher().registerOnBackInvokedCallback(0, this.onz);
        }
        setCanceledOnTouchOutside(false);
        ro();
        fm();
    }

    public ro ro(String str) {
        this.vt = str;
        return this;
    }

    @Override // android.app.Dialog
    public void show() {
        super.show();
        ro();
    }

    public ro yz(String str) {
        this.duv = str;
        return this;
    }

    private void lb() {
        if (this.onz == null || !hi.fm()) {
            return;
        }
        com.bytedance.sdk.component.utils.wey.fm("CustomCommonDialog", "isAtLeastT unregisterOnBackInvokedCallback");
        getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(this.onz);
    }

    private void ro() {
        if (TextUtils.isEmpty(this.vt)) {
            this.f7351lb.setVisibility(8);
        } else {
            this.f7351lb.setText(this.vt);
            this.f7351lb.setVisibility(0);
        }
        if (!TextUtils.isEmpty(this.f7350ef)) {
            this.yz.setText(this.f7350ef);
        }
        if (TextUtils.isEmpty(this.ku)) {
            this.ajl.setText(maa.fm(com.bytedance.sdk.openadsdk.core.gof.fm(), "tt_postive_txt"));
        } else {
            this.ajl.setText(this.ku);
        }
        if (TextUtils.isEmpty(this.duv)) {
            this.jnr.setText(maa.fm(com.bytedance.sdk.openadsdk.core.gof.fm(), "tt_negtive_txt"));
        } else {
            this.jnr.setText(this.duv);
        }
        int i10 = this.dsz;
        if (i10 != -1) {
            this.ro.setImageResource(i10);
            this.ro.setVisibility(0);
        } else {
            this.ro.setVisibility(8);
        }
        if (this.fhx) {
            this.wsy.setVisibility(8);
            this.jnr.setVisibility(8);
        } else {
            this.jnr.setVisibility(0);
            this.wsy.setVisibility(0);
        }
    }

    public ro fm(String str) {
        this.f7350ef = str;
        return this;
    }

    private void fm() {
        this.ajl.setOnClickListener(new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.core.widget.ro.1
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                InterfaceC0087ro interfaceC0087ro = ro.this.fm;
                if (interfaceC0087ro != null) {
                    interfaceC0087ro.fm();
                }
            }
        });
        this.jnr.setOnClickListener(new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.core.widget.ro.2
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                InterfaceC0087ro interfaceC0087ro = ro.this.fm;
                if (interfaceC0087ro != null) {
                    interfaceC0087ro.ro();
                }
            }
        });
    }

    private View fm(Context context) {
        com.bytedance.sdk.openadsdk.core.ajl.wsy wsyVar = new com.bytedance.sdk.openadsdk.core.ajl.wsy(context);
        wsyVar.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
        com.bytedance.sdk.openadsdk.core.ajl.jnr jnrVar = new com.bytedance.sdk.openadsdk.core.ajl.jnr(context);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -2);
        layoutParams.addRule(13);
        jnrVar.setMinimumWidth(fm(260.0f));
        jnrVar.setPadding(0, fm(32.0f), 0, 0);
        jnrVar.setBackground(com.bytedance.sdk.openadsdk.utils.ku.fm(context, "tt_custom_dialog_bg"));
        jnrVar.setOrientation(1);
        jnrVar.setLayoutParams(layoutParams);
        this.f7351lb = new com.bytedance.sdk.openadsdk.core.ajl.wu(context);
        LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(-2, -2);
        layoutParams2.gravity = 17;
        layoutParams2.leftMargin = fm(16.0f);
        layoutParams2.rightMargin = fm(16.0f);
        layoutParams2.bottomMargin = fm(16.0f);
        this.f7351lb.setGravity(17);
        this.f7351lb.setVisibility(0);
        this.f7351lb.setTextColor(Color.parseColor("#333333"));
        this.f7351lb.setTextSize(18.0f);
        this.f7351lb.setLayoutParams(layoutParams2);
        this.ro = new com.bytedance.sdk.openadsdk.core.ajl.yz(context);
        LinearLayout.LayoutParams layoutParams3 = new LinearLayout.LayoutParams(-2, -2);
        layoutParams3.gravity = 17;
        layoutParams3.leftMargin = fm(16.0f);
        layoutParams3.rightMargin = fm(16.0f);
        layoutParams3.bottomMargin = fm(10.0f);
        this.ro.setMaxHeight(fm(150.0f));
        this.ro.setMaxWidth(fm(150.0f));
        this.ro.setVisibility(0);
        this.ro.setLayoutParams(layoutParams3);
        this.yz = new com.bytedance.sdk.openadsdk.core.ajl.wu(context);
        LinearLayout.LayoutParams layoutParams4 = new LinearLayout.LayoutParams(-1, -2);
        layoutParams4.leftMargin = fm(20.0f);
        layoutParams4.rightMargin = fm(20.0f);
        this.yz.setGravity(17);
        this.yz.setLineSpacing(fm(3.0f), 1.2f);
        this.yz.setTextSize(18.0f);
        this.yz.setTextColor(Color.parseColor("#000000"));
        this.yz.setLayoutParams(layoutParams4);
        View view = new View(context);
        LinearLayout.LayoutParams layoutParams5 = new LinearLayout.LayoutParams(-1, 1);
        layoutParams5.topMargin = fm(32.0f);
        view.setBackgroundColor(Color.parseColor("#E4E4E4"));
        view.setLayoutParams(layoutParams5);
        com.bytedance.sdk.openadsdk.core.ajl.jnr jnrVar2 = new com.bytedance.sdk.openadsdk.core.ajl.jnr(context);
        LinearLayout.LayoutParams layoutParams6 = new LinearLayout.LayoutParams(-1, -2);
        jnrVar2.setOrientation(0);
        jnrVar2.setLayoutParams(layoutParams6);
        com.bytedance.sdk.openadsdk.core.ajl.fm fmVar = new com.bytedance.sdk.openadsdk.core.ajl.fm(context);
        this.jnr = fmVar;
        fmVar.setId(520093718);
        LinearLayout.LayoutParams layoutParams7 = new LinearLayout.LayoutParams(0, -2);
        layoutParams7.leftMargin = fm(10.0f);
        layoutParams7.weight = 1.0f;
        this.jnr.setPadding(0, fm(16.0f), 0, fm(16.0f));
        this.jnr.setBackground(null);
        this.jnr.setGravity(17);
        this.jnr.setSingleLine(true);
        this.jnr.setTextColor(Color.parseColor("#999999"));
        this.jnr.setTextSize(16.0f);
        this.jnr.setLayoutParams(layoutParams7);
        this.wsy = new View(context);
        LinearLayout.LayoutParams layoutParams8 = new LinearLayout.LayoutParams(1, -1);
        this.wsy.setBackgroundColor(Color.parseColor("#E4E4E4"));
        this.wsy.setLayoutParams(layoutParams8);
        com.bytedance.sdk.openadsdk.core.ajl.fm fmVar2 = new com.bytedance.sdk.openadsdk.core.ajl.fm(context);
        this.ajl = fmVar2;
        fmVar2.setId(520093719);
        LinearLayout.LayoutParams layoutParams9 = new LinearLayout.LayoutParams(0, -2);
        layoutParams9.rightMargin = fm(10.0f);
        layoutParams9.weight = 1.0f;
        this.ajl.setPadding(0, fm(16.0f), 0, fm(16.0f));
        this.ajl.setBackground(null);
        this.ajl.setGravity(17);
        this.ajl.setSingleLine(true);
        this.ajl.setTextColor(Color.parseColor("#38ADFF"));
        this.ajl.setTextSize(16.0f);
        this.ajl.setLayoutParams(layoutParams9);
        wsyVar.addView(jnrVar);
        jnrVar.addView(this.f7351lb);
        jnrVar.addView(this.ro);
        jnrVar.addView(this.yz);
        jnrVar.addView(view);
        jnrVar.addView(jnrVar2);
        jnrVar2.addView(this.jnr);
        jnrVar2.addView(this.wsy);
        jnrVar2.addView(this.ajl);
        return wsyVar;
    }

    private View ro(Context context) {
        com.bytedance.sdk.openadsdk.core.ajl.wsy wsyVar = new com.bytedance.sdk.openadsdk.core.ajl.wsy(context);
        wsyVar.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
        com.bytedance.sdk.openadsdk.core.ajl.jnr jnrVar = new com.bytedance.sdk.openadsdk.core.ajl.jnr(context);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -2);
        layoutParams.addRule(13);
        jnrVar.setMinimumWidth(fm(280.0f));
        jnrVar.setPadding(0, fm(32.0f), 0, 0);
        jnrVar.setBackground(com.bytedance.sdk.openadsdk.utils.ku.fm(context, "tt_custom_dialog_bg_new"));
        jnrVar.setOrientation(1);
        jnrVar.setLayoutParams(layoutParams);
        this.f7351lb = new com.bytedance.sdk.openadsdk.core.ajl.wu(context);
        LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(-2, -2);
        layoutParams2.gravity = 17;
        layoutParams2.leftMargin = fm(16.0f);
        layoutParams2.rightMargin = fm(16.0f);
        layoutParams2.bottomMargin = fm(16.0f);
        this.f7351lb.setGravity(17);
        this.f7351lb.setVisibility(0);
        this.f7351lb.setTextColor(Color.parseColor("#333333"));
        this.f7351lb.setTextSize(20.0f);
        this.f7351lb.setTypeface(Typeface.defaultFromStyle(1));
        this.f7351lb.setLineSpacing(0.0f, 1.3f);
        this.f7351lb.setLetterSpacing(0.015f);
        this.f7351lb.setLayoutParams(layoutParams2);
        this.ro = new com.bytedance.sdk.openadsdk.core.ajl.yz(context);
        LinearLayout.LayoutParams layoutParams3 = new LinearLayout.LayoutParams(-2, -2);
        layoutParams3.gravity = 17;
        layoutParams3.leftMargin = fm(16.0f);
        layoutParams3.rightMargin = fm(16.0f);
        layoutParams3.bottomMargin = fm(10.0f);
        this.ro.setMaxHeight(fm(150.0f));
        this.ro.setMaxWidth(fm(150.0f));
        this.ro.setVisibility(0);
        this.ro.setLayoutParams(layoutParams3);
        this.yz = new com.bytedance.sdk.openadsdk.core.ajl.wu(context);
        LinearLayout.LayoutParams layoutParams4 = new LinearLayout.LayoutParams(-1, -2);
        layoutParams4.leftMargin = fm(20.0f);
        layoutParams4.rightMargin = fm(20.0f);
        this.yz.setGravity(17);
        this.yz.setLineSpacing(0.0f, 1.3f);
        this.yz.setLetterSpacing(0.004f);
        this.yz.setTextSize(15.0f);
        this.yz.setTextColor(this.qhl);
        this.yz.setLayoutParams(layoutParams4);
        View view = new View(context);
        LinearLayout.LayoutParams layoutParams5 = new LinearLayout.LayoutParams(-1, 1);
        layoutParams5.topMargin = fm(32.0f);
        view.setBackgroundColor(Color.parseColor("#E4E4E4"));
        view.setLayoutParams(layoutParams5);
        com.bytedance.sdk.openadsdk.core.ajl.jnr jnrVar2 = new com.bytedance.sdk.openadsdk.core.ajl.jnr(context);
        LinearLayout.LayoutParams layoutParams6 = new LinearLayout.LayoutParams(-1, -2);
        jnrVar2.setOrientation(0);
        jnrVar2.setLayoutParams(layoutParams6);
        com.bytedance.sdk.openadsdk.core.ajl.fm fmVar = new com.bytedance.sdk.openadsdk.core.ajl.fm(context);
        this.jnr = fmVar;
        fmVar.setId(520093718);
        LinearLayout.LayoutParams layoutParams7 = new LinearLayout.LayoutParams(0, -2);
        layoutParams7.leftMargin = fm(10.0f);
        layoutParams7.weight = 1.0f;
        this.jnr.setPadding(0, fm(16.0f), 0, fm(16.0f));
        this.jnr.setBackground(null);
        this.jnr.setGravity(17);
        this.jnr.setSingleLine(true);
        this.jnr.setTextSize(2, this.gof);
        this.jnr.setLineSpacing(0.0f, 1.3f);
        this.jnr.setLetterSpacing(0.0019f);
        this.jnr.setTypeface(Typeface.defaultFromStyle(0));
        this.jnr.setTextColor(ColorStateList.valueOf(this.qhl));
        this.jnr.setLayoutParams(layoutParams7);
        this.wsy = new View(context);
        LinearLayout.LayoutParams layoutParams8 = new LinearLayout.LayoutParams(1, -1);
        this.wsy.setBackgroundColor(Color.parseColor("#E4E4E4"));
        this.wsy.setLayoutParams(layoutParams8);
        com.bytedance.sdk.openadsdk.core.ajl.fm fmVar2 = new com.bytedance.sdk.openadsdk.core.ajl.fm(context);
        this.ajl = fmVar2;
        fmVar2.setId(520093719);
        LinearLayout.LayoutParams layoutParams9 = new LinearLayout.LayoutParams(0, -2);
        layoutParams9.rightMargin = fm(10.0f);
        layoutParams9.weight = 1.0f;
        this.ajl.setPadding(0, fm(16.0f), 0, fm(16.0f));
        this.ajl.setBackground(null);
        this.ajl.setGravity(17);
        this.ajl.setSingleLine(true);
        int i10 = Build.VERSION.SDK_INT;
        this.ajl.setTextAppearance(R.style.TextAppearance.Material.Medium);
        Typeface typefaceCreate = i10 >= 28 ? Typeface.create(this.ajl.getTypeface(), IjkEventListener.BUFFERING_START, false) : null;
        if (typefaceCreate != null) {
            this.ajl.setTypeface(typefaceCreate);
        }
        this.ajl.setLineSpacing(0.0f, 1.3f);
        this.ajl.setLetterSpacing(0.0019f);
        this.ajl.setTextColor(ColorStateList.valueOf(this.gqi));
        this.ajl.setTextSize(this.gof);
        this.ajl.setLayoutParams(layoutParams9);
        wsyVar.addView(jnrVar);
        jnrVar.addView(this.f7351lb);
        jnrVar.addView(this.ro);
        jnrVar.addView(this.yz);
        jnrVar.addView(view);
        jnrVar.addView(jnrVar2);
        jnrVar2.addView(this.jnr);
        jnrVar2.addView(this.wsy);
        jnrVar2.addView(this.ajl);
        return wsyVar;
    }

    private int fm(float f10) {
        return zan.ro(getContext(), f10);
    }
}
