package com.bytedance.sdk.openadsdk.common;

import android.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.GradientDrawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.bytedance.sdk.openadsdk.utils.zan;

/* JADX INFO: loaded from: classes2.dex */
public class sds extends com.bytedance.sdk.openadsdk.core.ajl.lb {
    private Context fm;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private fm f6861lb;
    private LinearLayout ro;
    private boolean yz;

    public interface fm {
        void ajl();

        void fm();

        void jnr();

        void lb();

        void ro();

        void yz();
    }

    public sds(Context context, boolean z10) {
        super(context);
        this.fm = context;
        this.yz = z10;
        ro();
    }

    public void setOnMenuItemClickListener(fm fmVar) {
        this.f6861lb = fmVar;
    }

    private void fm(com.bytedance.sdk.openadsdk.core.ajl.jnr jnrVar, String str, String str2, View.OnClickListener onClickListener) {
        com.bytedance.sdk.openadsdk.core.ajl.jnr jnrVar2 = new com.bytedance.sdk.openadsdk.core.ajl.jnr(this.fm);
        jnrVar2.setOrientation(0);
        jnrVar2.setGravity(16);
        jnrVar2.setOnClickListener(onClickListener);
        ImageView imageView = new ImageView(this.fm);
        imageView.setImageResource(com.bytedance.sdk.component.utils.maa.yz(this.fm, str2));
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(fm(20.0f), fm(20.0f));
        layoutParams.setMargins(fm(16.0f), fm(0.0f), fm(16.0f), fm(0.0f));
        jnrVar2.addView(imageView, layoutParams);
        com.bytedance.sdk.openadsdk.core.ajl.wu wuVar = new com.bytedance.sdk.openadsdk.core.ajl.wu(this.fm);
        wuVar.setText(str);
        wuVar.setTextColor(Color.parseColor("#000000"));
        wuVar.setTextSize(2, 16.0f);
        wuVar.setGravity(8388627);
        wuVar.setTypeface(Typeface.defaultFromStyle(0));
        jnrVar2.addView(wuVar, new LinearLayout.LayoutParams(-2, -2));
        ViewGroup.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(-1, fm(52.0f));
        if (jnrVar.getChildCount() > 0) {
            View view = new View(this.fm);
            view.setBackgroundColor(Color.parseColor("#1F000000"));
            jnrVar.addView(view, new LinearLayout.LayoutParams(-1, fm(1.0f)));
        }
        jnrVar.addView(jnrVar2, layoutParams2);
    }

    @SuppressLint({"ClickableViewAccessibility"})
    private void ro() {
        setLayoutParams(new ViewGroup.LayoutParams(-1, -2));
        setBackgroundColor(Color.parseColor("#80000000"));
        setOnTouchListener(new View.OnTouchListener() { // from class: com.bytedance.sdk.openadsdk.common.sds.1
            @Override // android.view.View.OnTouchListener
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (motionEvent.getAction() == 1) {
                    Rect rect = new Rect();
                    sds.this.ro.getGlobalVisibleRect(rect);
                    if (!rect.contains((int) motionEvent.getRawX(), (int) motionEvent.getRawY())) {
                        sds.this.fm();
                    }
                }
                return true;
            }
        });
        LinearLayout linearLayout = new LinearLayout(this.fm);
        this.ro = linearLayout;
        linearLayout.setOrientation(1);
        this.ro.setGravity(80);
        this.ro.setPadding(fm(16.0f), 0, fm(16.0f), fm(58.0f));
        GradientDrawable gradientDrawable = new GradientDrawable();
        gradientDrawable.setShape(0);
        gradientDrawable.setCornerRadius(fm(16.0f));
        gradientDrawable.setColor(Color.parseColor("#E1E1E1"));
        this.ro.setBackground(gradientDrawable);
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, -2);
        layoutParams.gravity = 81;
        layoutParams.bottomMargin = fm(16.0f);
        this.ro.setLayoutParams(layoutParams);
        com.bytedance.sdk.openadsdk.core.ajl.lb lbVar = new com.bytedance.sdk.openadsdk.core.ajl.lb(this.fm);
        lbVar.setPadding(fm(6.0f), 0, fm(6.0f), 0);
        lbVar.setLayoutParams(new LinearLayout.LayoutParams(-1, fm(44.0f)));
        com.bytedance.sdk.openadsdk.core.ajl.wu wuVar = new com.bytedance.sdk.openadsdk.core.ajl.wu(this.fm);
        Context context = this.fm;
        wuVar.setText(context.getString(com.bytedance.sdk.component.utils.maa.ro(context, "tt_more_title")));
        wuVar.setTextColor(Color.parseColor("#000000"));
        wuVar.setTextSize(2, 17.0f);
        wuVar.setGravity(17);
        wuVar.setTypeface(Typeface.defaultFromStyle(1));
        lbVar.addView(wuVar, new FrameLayout.LayoutParams(-1, -1));
        ImageView imageView = new ImageView(this.fm);
        imageView.setImageResource(com.bytedance.sdk.component.utils.maa.yz(this.fm, "tt_titlebar_close_drawable"));
        imageView.setPadding(fm(10.0f), fm(10.0f), fm(10.0f), fm(10.0f));
        imageView.setOnClickListener(new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.common.sds.2
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                sds.this.fm();
            }
        });
        FrameLayout.LayoutParams layoutParams2 = new FrameLayout.LayoutParams(fm(44.0f), fm(44.0f));
        layoutParams2.gravity = 8388629;
        lbVar.addView(imageView, layoutParams2);
        this.ro.addView(lbVar);
        boolean zFm = com.bytedance.sdk.openadsdk.hlt.jnr.fm("lp_iab_history", true);
        if (!this.yz && zFm) {
            com.bytedance.sdk.openadsdk.core.ajl.jnr jnrVarFm = fm(8);
            Context context2 = this.fm;
            fm(jnrVarFm, context2.getString(com.bytedance.sdk.component.utils.maa.ro(context2, "tt_more_history")), "tt_more_history_icon", new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.common.sds.3
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    if (sds.this.f6861lb != null) {
                        sds.this.f6861lb.fm();
                    }
                }
            });
            this.ro.addView(jnrVarFm);
        }
        com.bytedance.sdk.openadsdk.core.ajl.jnr jnrVarFm2 = fm(8);
        Context context3 = this.fm;
        fm(jnrVarFm2, context3.getString(com.bytedance.sdk.component.utils.maa.ro(context3, "tt_more_retry")), "tt_more_retry_icon", new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.common.sds.4
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                if (sds.this.f6861lb != null) {
                    sds.this.f6861lb.ro();
                }
            }
        });
        Context context4 = this.fm;
        fm(jnrVarFm2, context4.getString(com.bytedance.sdk.component.utils.maa.ro(context4, "tt_more_copy_link")), "tt_more_copy_icon", new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.common.sds.5
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                if (sds.this.f6861lb != null) {
                    sds.this.f6861lb.lb();
                }
            }
        });
        Context context5 = this.fm;
        fm(jnrVarFm2, context5.getString(com.bytedance.sdk.component.utils.maa.ro(context5, "tt_more_open_browser")), "tt_more_browser_icon", new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.common.sds.6
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                if (sds.this.f6861lb != null) {
                    sds.this.f6861lb.yz();
                }
            }
        });
        this.ro.addView(jnrVarFm2);
        com.bytedance.sdk.openadsdk.core.ajl.jnr jnrVarFm3 = fm(8);
        if (!this.yz) {
            Context context6 = this.fm;
            fm(jnrVarFm3, context6.getString(com.bytedance.sdk.component.utils.maa.ro(context6, "tt_privacy")), "tt_more_privacy_icon", new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.common.sds.7
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    if (sds.this.f6861lb != null) {
                        sds.this.f6861lb.ajl();
                    }
                }
            });
        }
        Context context7 = this.fm;
        fm(jnrVarFm3, context7.getString(com.bytedance.sdk.component.utils.maa.ro(context7, "tt_more_report")), "tt_more_report_icon", new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.common.sds.8
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                if (sds.this.f6861lb != null) {
                    sds.this.f6861lb.jnr();
                }
            }
        });
        this.ro.addView(jnrVarFm3);
        addView(this.ro);
    }

    private com.bytedance.sdk.openadsdk.core.ajl.jnr fm(int i10) {
        com.bytedance.sdk.openadsdk.core.ajl.jnr jnrVar = new com.bytedance.sdk.openadsdk.core.ajl.jnr(this.fm);
        jnrVar.setOrientation(1);
        GradientDrawable gradientDrawable = new GradientDrawable();
        gradientDrawable.setShape(0);
        gradientDrawable.setCornerRadius(fm(i10));
        gradientDrawable.setColor(-1);
        jnrVar.setBackgroundDrawable(gradientDrawable);
        jnrVar.setPadding(fm(8.0f), fm(8.0f), fm(8.0f), fm(8.0f));
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
        layoutParams.topMargin = fm(8.0f);
        jnrVar.setLayoutParams(layoutParams);
        return jnrVar;
    }

    public void fm(View view) {
        View viewFindViewById = view.getRootView().findViewById(R.id.content);
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(-1, -1);
        if (getParent() == null) {
            ((ViewGroup) viewFindViewById).addView(this, layoutParams);
        }
        setVisibility(0);
    }

    public void fm() {
        setVisibility(8);
        if (getParent() != null) {
            ((ViewGroup) getParent()).removeView(this);
        }
    }

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