package com.bytedance.sdk.component.adexpress.dynamic.dynamicview;

import a3.r;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

/* JADX INFO: loaded from: classes.dex */
public class ajl extends jnr {
    private static String wey = "";
    private Runnable fm;
    protected com.bytedance.sdk.component.adexpress.dynamic.lb.ef gqi;
    private Runnable ro;
    private volatile boolean sds;

    public static class fm implements com.bytedance.sdk.component.jnr.irt {
        private final WeakReference<View> fm;

        /* JADX INFO: renamed from: lb, reason: collision with root package name */
        private final com.bytedance.sdk.component.adexpress.dynamic.yz.wu f6468lb;
        private final WeakReference<DynamicRootView> ro;

        public fm(View view, DynamicRootView dynamicRootView, com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar) {
            this.fm = new WeakReference<>(view);
            this.ro = new WeakReference<>(dynamicRootView);
            this.f6468lb = wuVar;
        }

        @Override // com.bytedance.sdk.component.jnr.irt
        public void fm(int i10, String str, @Nullable Throwable th) {
        }

        @Override // com.bytedance.sdk.component.jnr.irt
        public void fm(com.bytedance.sdk.component.jnr.ku kuVar) {
            Drawable bitmapDrawable;
            View view = this.fm.get();
            Object objRo = kuVar.ro();
            if (objRo instanceof Bitmap) {
                bitmapDrawable = new BitmapDrawable((Bitmap) objRo);
            } else if (objRo instanceof Drawable) {
                if (Build.VERSION.SDK_INT >= 28 && r.D(objRo)) {
                    a.h(objRo).start();
                }
                bitmapDrawable = (Drawable) objRo;
            } else {
                bitmapDrawable = null;
            }
            if (!com.bytedance.sdk.component.adexpress.yz.ro()) {
                DynamicRootView dynamicRootView = this.ro.get();
                if (dynamicRootView == null) {
                    return;
                }
                if ("open_ad".equals(dynamicRootView.getRenderRequest().yz()) || "splash_ad".equals(dynamicRootView.getRenderRequest().yz())) {
                    view.setBackground(bitmapDrawable);
                    return;
                } else {
                    view.setBackground(bitmapDrawable);
                    return;
                }
            }
            if (view == null) {
                return;
            }
            view.setBackground(bitmapDrawable);
            com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar = this.f6468lb;
            if (wuVar == null || wuVar.vt() == null || 6 != this.f6468lb.vt().fm() || view.getBackground() == null) {
                return;
            }
            view.getBackground().setAutoMirrored(true);
        }
    }

    public static class lb implements com.bytedance.sdk.component.jnr.wu {
        private final WeakReference<Context> fm;
        private final int ro;

        public lb(Context context, int i10) {
            this.fm = new WeakReference<>(context);
            this.ro = i10;
        }

        @Override // com.bytedance.sdk.component.jnr.wu
        public Bitmap fm(Bitmap bitmap) {
            Context context = this.fm.get();
            if (context != null) {
                return com.bytedance.sdk.component.adexpress.yz.fm.fm(context, bitmap, this.ro);
            }
            return null;
        }
    }

    public static class ro implements com.bytedance.sdk.component.jnr.irt {
        private final WeakReference<View> fm;
        private final WeakReference<jnr> ro;

        public ro(View view, jnr jnrVar) {
            this.fm = new WeakReference<>(view);
            this.ro = new WeakReference<>(jnrVar);
        }

        @Override // com.bytedance.sdk.component.jnr.irt
        public void fm(int i10, String str, @Nullable Throwable th) {
        }

        @Override // com.bytedance.sdk.component.jnr.irt
        public void fm(com.bytedance.sdk.component.jnr.ku kuVar) {
            Object objRo;
            jnr jnrVar;
            View view = this.fm.get();
            if (view == null || (objRo = kuVar.ro()) == null || kuVar.lb() == null || (jnrVar = this.ro.get()) == null || !(objRo instanceof Bitmap)) {
                return;
            }
            view.setBackground(jnrVar.fm((Bitmap) objRo));
        }
    }

    public ajl(Context context, DynamicRootView dynamicRootView, com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar) {
        super(context, dynamicRootView, wuVar);
        this.sds = true;
        setTag(Integer.valueOf(getClickArea()));
        String strRo = wuVar.vt().ro();
        if ("logo-union".equals(strRo)) {
            dynamicRootView.setLogoUnionHeight(this.wu - ((int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(context, this.duv.fm() + this.duv.ro())));
        } else if ("scoreCountWithIcon".equals(strRo)) {
            dynamicRootView.setScoreCountWithIcon(this.wu - ((int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(context, this.duv.fm() + this.duv.ro())));
        }
    }

    private static String getBuildModel() {
        try {
            wey = com.bytedance.sdk.component.utils.hi.fm();
        } catch (Throwable unused) {
            wey = Build.MODEL;
        }
        if (TextUtils.isEmpty(wey)) {
            wey = Build.MODEL;
        }
        return wey;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public Drawable lb(String str) {
        try {
            JSONArray jSONArray = new JSONArray(str);
            ArrayList arrayList = new ArrayList();
            String string = "";
            for (int i10 = 0; i10 < jSONArray.length(); i10++) {
                if (jSONArray.getString(i10).startsWith("#")) {
                    arrayList.add(jSONArray.getString(i10));
                } else if (jSONArray.getString(i10).endsWith("deg")) {
                    string = jSONArray.getString(i10);
                }
            }
            if (arrayList.size() <= 0) {
                return null;
            }
            int[] iArr = new int[arrayList.size()];
            for (int i11 = 0; i11 < arrayList.size(); i11++) {
                iArr[i11] = com.bytedance.sdk.component.adexpress.dynamic.yz.wsy.fm(((String) arrayList.get(i11)).substring(0, 7));
            }
            GradientDrawable gradientDrawableFm = fm(fm(string), iArr);
            gradientDrawableFm.setShape(0);
            gradientDrawableFm.setCornerRadius(com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.duv.fhx()));
            return gradientDrawableFm;
        } catch (Throwable unused) {
            return null;
        }
    }

    private String ro(String str) {
        try {
            Map<String, String> mapKu = this.onz.getRenderRequest().ku();
            if (mapKu != null && mapKu.size() > 0) {
                return mapKu.get(str);
            }
        } catch (Throwable unused) {
        }
        return null;
    }

    public boolean ef() {
        int iIrt;
        int iQhl;
        Drawable backgroundDrawable;
        DynamicRootView dynamicRootView;
        JSONObject jSONObjectOptJSONObject;
        final View view = this.fhx;
        if (view == null) {
            view = this;
        }
        setContentDescription(this.dsz.fm(this.duv.mq()));
        String strCg = this.duv.cg();
        String strHlt = null;
        String strFm = (TextUtils.isEmpty(strCg) || (dynamicRootView = this.onz) == null || dynamicRootView.getRenderRequest() == null || this.onz.getRenderRequest().lb() == null || (jSONObjectOptJSONObject = this.onz.getRenderRequest().lb().optJSONObject("creative")) == null) ? null : fm(jSONObjectOptJSONObject.opt(strCg));
        if (TextUtils.isEmpty(strFm)) {
            strFm = this.duv.sds();
        }
        com.bytedance.sdk.component.adexpress.fm.fm.lb lbVarLb = com.bytedance.sdk.component.adexpress.fm.fm.fm.fm().lb();
        if (lbVarLb != null) {
            iIrt = lbVarLb.irt();
            iQhl = lbVarLb.qhl();
        } else {
            iIrt = 0;
            iQhl = 0;
        }
        if (this.duv.wey()) {
            int iGqi = this.duv.gqi();
            String str = this.duv.ro;
            com.bytedance.sdk.component.adexpress.fm.fm.fm.fm().jnr().fm(str).fm(this.wsy).ro(this.wu).yz(iIrt).jnr(iQhl).fm(ro(str)).lb(2).fm(new lb(this.ku, iGqi)).fm(new ro(view, this));
        } else if (!TextUtils.isEmpty(strFm)) {
            if (!strFm.startsWith("http:") && !strFm.startsWith("https:")) {
                DynamicRootView dynamicRootView2 = this.onz;
                if (dynamicRootView2 != null && dynamicRootView2.getRenderRequest() != null) {
                    strHlt = this.onz.getRenderRequest().hlt();
                }
                strFm = com.bytedance.sdk.component.adexpress.dynamic.jnr.ef.ro(strFm, strHlt);
            }
            com.bytedance.sdk.component.jnr.vt vtVarLb = com.bytedance.sdk.component.adexpress.fm.fm.fm.fm().jnr().fm(strFm).fm(this.wsy).ro(this.wu).yz(iIrt).jnr(iQhl).fm(ro(strFm)).lb(1);
            fm(vtVarLb);
            vtVarLb.fm(new fm(view, this.onz, this.dsz));
        }
        if (getBackground() == null && (backgroundDrawable = getBackgroundDrawable()) != null) {
            view.setBackground(backgroundDrawable);
        }
        if (this.duv.ai() > 0.0d) {
            postDelayed(new Runnable() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.ajl.1
                @Override // java.lang.Runnable
                public void run() {
                    try {
                        if (ajl.this.duv.hxv() > 0) {
                            ajl ajlVar = ajl.this;
                            Drawable drawableLb = ajlVar.lb(ajlVar.onz.getBgMaterialCenterCalcColor().get(Integer.valueOf(ajl.this.duv.hxv())));
                            if (drawableLb == null) {
                                ajl ajlVar2 = ajl.this;
                                drawableLb = ajlVar2.fm(true, ajlVar2.onz.getBgMaterialCenterCalcColor().get(Integer.valueOf(ajl.this.duv.hxv())));
                            }
                            if (drawableLb != null) {
                                view.setBackground(drawableLb);
                                return;
                            }
                            View view2 = view;
                            ajl ajlVar3 = ajl.this;
                            view2.setBackground(ajlVar3.fm(true, ajlVar3.onz.getBgColor()));
                        }
                    } catch (Exception unused) {
                    }
                }
            }, (long) (this.duv.ai() * 1000.0d));
        }
        View view2 = this.fhx;
        if (view2 != null) {
            view2.setPadding((int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.duv.lb()), (int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.duv.ro()), (int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.duv.yz()), (int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.duv.fm()));
        }
        if (this.irt || this.duv.onz() > 0.0d) {
            setShouldInvisible(true);
            view.setVisibility(4);
            setVisibility(4);
        }
        return true;
    }

    public FrameLayout.LayoutParams getWidgetLayoutParams() {
        return new FrameLayout.LayoutParams(this.wsy, this.wu);
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.dynamicview.jnr, android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        View view = this.fhx;
        View view2 = view;
        if (view == null) {
            view2 = this;
        }
        double dWey = this.dsz.vt().jnr().wey();
        if (dWey < 90.0d && dWey > 0.0d) {
            com.bytedance.sdk.component.utils.ef.ro().postDelayed(new Runnable() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.ajl.2
                @Override // java.lang.Runnable
                public void run() {
                    ajl.this.setVisibility(8);
                }
            }, (long) (dWey * 1000.0d));
        }
        fm(this.dsz.vt().jnr().gqi(), view2);
        if (!TextUtils.isEmpty(this.duv.tzk())) {
            fm();
        }
        super.onAttachedToWindow();
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.dynamicview.jnr, android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        try {
            removeCallbacks(this.fm);
            removeCallbacks(this.ro);
        } catch (Exception unused) {
        }
    }

    private String fm(Object obj) {
        if (obj instanceof String) {
            return (String) obj;
        }
        if (obj instanceof JSONArray) {
            return fm(((JSONArray) obj).opt(0));
        }
        if (obj instanceof JSONObject) {
            return fm((Object) ((JSONObject) obj).optString(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL));
        }
        return null;
    }

    private static void fm(com.bytedance.sdk.component.jnr.vt vtVar) {
        if ("SMARTISAN".equals(Build.BRAND) && "SM901".equals(getBuildModel())) {
            vtVar.fm(Bitmap.Config.ARGB_8888);
        }
    }

    private void fm(double d10, final View view) {
        if (d10 > 0.0d) {
            com.bytedance.sdk.component.utils.ef.ro().postDelayed(new Runnable() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.ajl.3
                @Override // java.lang.Runnable
                public void run() {
                    if (ajl.this.dsz.vt().jnr().vod() != null) {
                        return;
                    }
                    view.setVisibility(0);
                    ajl.this.setVisibility(0);
                }
            }, (long) (d10 * 1000.0d));
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void fm(ViewGroup viewGroup) {
        if (viewGroup == null || viewGroup.getChildCount() <= 0) {
            return;
        }
        for (int i10 = 0; i10 < viewGroup.getChildCount(); i10++) {
            if (viewGroup.getChildAt(i10) instanceof com.bytedance.sdk.component.adexpress.dynamic.lb.ef) {
                viewGroup.removeViewAt(i10);
            }
        }
    }

    private void fm() {
        if (this.sds) {
            int iNe = this.duv.ne();
            int iKwx = this.duv.kwx();
            Runnable runnable = new Runnable() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.ajl.4
                @Override // java.lang.Runnable
                public void run() {
                    DynamicRootView dynamicRootView = ajl.this.onz;
                    if (dynamicRootView == null || dynamicRootView.getRenderRequest() == null) {
                        ajl ajlVar = ajl.this;
                        ajl ajlVar2 = ajl.this;
                        ajlVar.gqi = new com.bytedance.sdk.component.adexpress.dynamic.lb.ef(ajlVar2.ku, ajlVar2, ajlVar2.duv);
                    } else {
                        com.bytedance.sdk.component.adexpress.ro.dsz renderRequest = ajl.this.onz.getRenderRequest();
                        com.bytedance.sdk.component.adexpress.dynamic.yz.vt vtVar = new com.bytedance.sdk.component.adexpress.dynamic.yz.vt();
                        vtVar.fm(renderRequest.fhx());
                        vtVar.ro(renderRequest.irt());
                        vtVar.lb(renderRequest.qhl());
                        vtVar.fm(renderRequest.gof());
                        vtVar.ro(renderRequest.gqi());
                        vtVar.lb(renderRequest.wey());
                        vtVar.yz(renderRequest.sds());
                        vtVar.jnr(renderRequest.maa());
                        ajl ajlVar3 = ajl.this;
                        ajl ajlVar4 = ajl.this;
                        ajlVar3.gqi = new com.bytedance.sdk.component.adexpress.dynamic.lb.ef(ajlVar4.ku, ajlVar4, ajlVar4.duv, vtVar, renderRequest);
                    }
                    ajl ajlVar5 = ajl.this;
                    ajlVar5.ro(ajlVar5.gqi);
                    if (ajl.this.getParent() instanceof ViewGroup) {
                        ((ViewGroup) ajl.this.getParent()).setClipChildren(false);
                    }
                    ajl.this.setClipChildren(false);
                    ajl.this.gqi.setTag(2);
                    ajl ajlVar6 = ajl.this;
                    ajlVar6.fm((ViewGroup) ajlVar6);
                    ajl ajlVar7 = ajl.this;
                    ajlVar7.addView(ajlVar7.gqi, new FrameLayout.LayoutParams(-1, -1));
                    ajl.this.gqi.lb();
                }
            };
            this.fm = runnable;
            postDelayed(runnable, ((long) iNe) * 1000);
            if (this.duv.bkb() || iKwx >= Integer.MAX_VALUE || iNe >= iKwx) {
                return;
            }
            Runnable runnable2 = new Runnable() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.ajl.5
                @Override // java.lang.Runnable
                public void run() {
                    ajl ajlVar = ajl.this;
                    if (ajlVar.gqi != null) {
                        ajlVar.sds = false;
                        ajl.this.gqi.yz();
                        ajl.this.gqi.setVisibility(4);
                        ajl ajlVar2 = ajl.this;
                        ajlVar2.removeView(ajlVar2.gqi);
                    }
                }
            };
            this.ro = runnable2;
            postDelayed(runnable2, ((long) iKwx) * 1000);
        }
    }
}
