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

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.text.TextUtils;
import android.util.Pair;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import com.bytedance.sdk.component.adexpress.dynamic.animation.view.IAnimation;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes.dex */
public abstract class jnr extends FrameLayout implements IAnimation, hxv, pkk {
    protected float ajl;
    protected com.bytedance.sdk.component.adexpress.dynamic.yz.wu dsz;
    protected com.bytedance.sdk.component.adexpress.dynamic.yz.wsy duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    protected int f6471ef;
    protected View fhx;
    private float fm;
    com.bytedance.sdk.component.adexpress.dynamic.animation.view.lb gof;
    private float gqi;
    protected boolean irt;
    protected float jnr;
    protected Context ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    protected float f6472lb;
    protected DynamicRootView onz;
    protected com.bytedance.sdk.component.adexpress.dynamic.animation.fm.ro qhl;
    private float ro;
    private com.bytedance.sdk.component.utils.hlt sds;
    protected int vt;
    private float wey;
    protected int wsy;
    protected int wu;
    protected float yz;
    private static final View.OnTouchListener maa = new View.OnTouchListener() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.jnr.2
        @Override // android.view.View.OnTouchListener
        public boolean onTouch(View view, MotionEvent motionEvent) {
            return true;
        }
    };
    private static final View.OnClickListener lse = new View.OnClickListener() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.jnr.3
        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
        }
    };

    public jnr(Context context, DynamicRootView dynamicRootView, com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar) {
        super(context);
        this.ku = context;
        this.onz = dynamicRootView;
        this.dsz = wuVar;
        this.f6472lb = wuVar.ajl();
        this.yz = wuVar.wsy();
        this.jnr = wuVar.wu();
        this.ajl = wuVar.ef();
        this.f6471ef = (int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.f6472lb);
        this.vt = (int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.yz);
        this.wsy = (int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.jnr);
        this.wu = (int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.ajl);
        com.bytedance.sdk.component.adexpress.dynamic.yz.wsy wsyVar = new com.bytedance.sdk.component.adexpress.dynamic.yz.wsy(wuVar.vt());
        this.duv = wsyVar;
        if (wsyVar.gof() > 0) {
            this.wsy = (this.duv.gof() * 2) + this.wsy;
            this.wu = (this.duv.gof() * 2) + this.wu;
            this.f6471ef -= this.duv.gof();
            this.vt -= this.duv.gof();
            List<com.bytedance.sdk.component.adexpress.dynamic.yz.wu> listKu = wuVar.ku();
            if (listKu != null) {
                for (com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar2 : listKu) {
                    wuVar2.lb(wuVar2.ajl() + com.bytedance.sdk.component.adexpress.yz.wsy.ro(this.ku, this.duv.gof()));
                    wuVar2.yz(wuVar2.wsy() + com.bytedance.sdk.component.adexpress.yz.wsy.ro(this.ku, this.duv.gof()));
                    wuVar2.fm(com.bytedance.sdk.component.adexpress.yz.wsy.ro(this.ku, this.duv.gof()));
                    wuVar2.ro(com.bytedance.sdk.component.adexpress.yz.wsy.ro(this.ku, this.duv.gof()));
                }
            }
        }
        this.irt = this.duv.onz() > 0.0d;
        this.gof = new com.bytedance.sdk.component.adexpress.dynamic.animation.view.lb();
    }

    public void ajl() {
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(this.wsy, this.wu);
        layoutParams.topMargin = this.vt;
        int i10 = this.f6471ef;
        layoutParams.leftMargin = i10;
        layoutParams.setMarginStart(i10);
        layoutParams.setMarginEnd(layoutParams.rightMargin);
        setLayoutParams(layoutParams);
    }

    public void fm(View view) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("width", this.dsz.wu());
            jSONObject.put("height", this.dsz.ef());
            if (com.bytedance.sdk.component.adexpress.yz.ro()) {
                view.setTag(com.bytedance.sdk.component.adexpress.dynamic.fm.wey, this.duv.xgn());
                view.setTag(com.bytedance.sdk.component.adexpress.dynamic.fm.sds, this.dsz.vt().ro());
                view.setTag(com.bytedance.sdk.component.adexpress.dynamic.fm.maa, this.dsz.lb());
                view.setTag(com.bytedance.sdk.component.adexpress.dynamic.fm.lse, jSONObject.toString());
                return;
            }
            view.setTag(2097610717, this.duv.xgn());
            view.setTag(2097610715, this.dsz.vt().ro());
            view.setTag(2097610714, this.dsz.lb());
            view.setTag(2097610713, jSONObject.toString());
            int iFm = com.bytedance.sdk.component.adexpress.dynamic.ro.fm.fm(this.duv);
            if (iFm == 1) {
                view.setTag(2097610707, new Pair(this.duv.hi(), Long.valueOf(this.duv.nt())));
                view.setTag(2097610708, Integer.valueOf(iFm));
            }
        } catch (JSONException unused) {
        }
    }

    public Drawable getBackgroundDrawable() {
        return fm(false, "");
    }

    public boolean getBeginInvisibleAndShow() {
        return this.irt;
    }

    public int getClickArea() {
        return this.duv.mq();
    }

    public GradientDrawable getDrawable() {
        return new GradientDrawable();
    }

    public com.bytedance.sdk.component.adexpress.dynamic.ajl.fm getDynamicClickListener() {
        return this.onz.getDynamicClickListener();
    }

    public int getDynamicHeight() {
        return this.wu;
    }

    public com.bytedance.sdk.component.adexpress.dynamic.yz.ajl getDynamicLayoutBrickValue() {
        com.bytedance.sdk.component.adexpress.dynamic.yz.jnr jnrVarVt;
        com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar = this.dsz;
        if (wuVar == null || (jnrVarVt = wuVar.vt()) == null) {
            return null;
        }
        return jnrVarVt.jnr();
    }

    public int getDynamicWidth() {
        return this.wsy;
    }

    public String getImageObjectFit() {
        return this.duv.mpp();
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.animation.view.IAnimation
    public float getMarqueeValue() {
        return this.gqi;
    }

    public Drawable getMutilBackgroundDrawable() {
        try {
            return new LayerDrawable(fm(ro(this.duv.gc().replaceAll("/\\*.*\\*/", ""))));
        } catch (Exception unused) {
            return null;
        }
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.animation.view.IAnimation
    public float getRippleValue() {
        return this.fm;
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.animation.view.IAnimation
    public float getShineValue() {
        return this.ro;
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.animation.view.IAnimation
    public float getStretchValue() {
        return this.wey;
    }

    public boolean jnr() {
        com.bytedance.sdk.component.adexpress.dynamic.yz.wsy wsyVar = this.duv;
        return (wsyVar == null || wsyVar.mq() == 0) ? false : true;
    }

    public boolean lb() {
        ef();
        ajl();
        yz();
        return true;
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        wsy();
        fm();
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        ro();
        super.onDetachedFromWindow();
    }

    @Override // android.view.View
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        this.gof.fm(canvas, this, this);
    }

    @Override // android.view.View
    public void onSizeChanged(int i10, int i11, int i12, int i13) {
        super.onSizeChanged(i10, i11, i12, i13);
        com.bytedance.sdk.component.adexpress.dynamic.animation.view.lb lbVar = this.gof;
        View view = this.fhx;
        if (view == null) {
            view = this;
        }
        lbVar.fm(view, i10, i11);
    }

    @Override // android.view.View
    public void onWindowFocusChanged(boolean z10) {
    }

    public void ro(@NonNull View view) {
        com.bytedance.sdk.component.adexpress.dynamic.yz.ajl ajlVarJnr;
        com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar = this.dsz;
        if (wuVar == null || (ajlVarJnr = wuVar.vt().jnr()) == null) {
            return;
        }
        view.setTag(2097610716, Boolean.valueOf(ajlVarJnr.rbn()));
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.animation.view.IAnimation
    public void setMarqueeValue(float f10) {
        this.gqi = f10;
        postInvalidate();
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.animation.view.IAnimation
    public void setRippleValue(float f10) {
        this.fm = f10;
        postInvalidate();
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.animation.view.IAnimation
    public void setShineValue(float f10) {
        this.ro = f10;
        postInvalidate();
    }

    public void setShouldInvisible(boolean z10) {
        this.irt = z10;
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.animation.view.IAnimation
    public void setStretchValue(float f10) {
        this.wey = f10;
        this.gof.fm(this, f10);
    }

    public void wsy() {
        if (wu()) {
            return;
        }
        View view = this.fhx;
        if (view == null) {
            view = this;
        }
        this.qhl = new com.bytedance.sdk.component.adexpress.dynamic.animation.fm.ro(view, this.dsz.vt().jnr().vod());
        post(new Runnable() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.jnr.1
            @Override // java.lang.Runnable
            public void run() {
                com.bytedance.sdk.component.adexpress.dynamic.animation.fm.ro roVar = jnr.this.qhl;
                if (roVar != null) {
                    roVar.fm();
                }
            }
        });
    }

    public boolean wu() {
        com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar = this.dsz;
        return wuVar == null || wuVar.vt() == null || this.dsz.vt().jnr() == null || this.dsz.vt().jnr().vod() == null;
    }

    public boolean yz() {
        View.OnTouchListener onTouchListener;
        View.OnClickListener onClickListener;
        View view = this.fhx;
        View view2 = view;
        if (view == null) {
            view2 = this;
        }
        if (jnr()) {
            onTouchListener = (View.OnTouchListener) getDynamicClickListener();
            onClickListener = (View.OnClickListener) getDynamicClickListener();
        } else {
            onTouchListener = maa;
            onClickListener = lse;
        }
        if (onTouchListener != null && onClickListener != null) {
            view2.setOnTouchListener(onTouchListener);
            view2.setOnClickListener(onClickListener);
            int iFm = com.bytedance.sdk.component.adexpress.dynamic.ro.fm.fm(this.duv);
            if (iFm == 2 || iFm == 3) {
                view2.setOnClickListener(lse);
            } else {
                view2.setOnClickListener(onClickListener);
            }
        }
        fm(view2);
        ro(view2);
        return true;
    }

    private List<String> ro(String str) {
        ArrayList arrayList = new ArrayList();
        int i10 = 0;
        boolean z10 = false;
        int i11 = 0;
        for (int i12 = 0; i12 < str.length(); i12++) {
            if (str.charAt(i12) == '(') {
                i10++;
                z10 = true;
            } else if (str.charAt(i12) == ')' && i10 - 1 == 0 && z10) {
                int i13 = i12 + 1;
                arrayList.add(str.substring(i11, i13));
                i11 = i13;
                z10 = false;
            }
        }
        return arrayList;
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.dynamicview.hxv
    public void ro() {
        com.bytedance.sdk.component.adexpress.dynamic.animation.fm.ro roVar = this.qhl;
        if (roVar != null) {
            roVar.ro();
        }
    }

    public Drawable fm(boolean z10, String str) {
        String[] strArrSplit;
        int[] iArr;
        int iGzf;
        if (!TextUtils.isEmpty(this.duv.gc())) {
            try {
                String strGc = this.duv.gc();
                String strSubstring = strGc.substring(strGc.indexOf("(") + 1, strGc.length() - 1);
                if (strSubstring.contains("rgba") && strSubstring.contains("%")) {
                    strArrSplit = new String[]{strSubstring.substring(0, strSubstring.indexOf(",")).trim(), strSubstring.substring(strSubstring.indexOf(",") + 1, strSubstring.indexOf("%") + 1).trim(), strSubstring.substring(strSubstring.indexOf("%") + 2).trim()};
                    iArr = new int[]{com.bytedance.sdk.component.adexpress.dynamic.yz.wsy.fm(strArrSplit[1]), com.bytedance.sdk.component.adexpress.dynamic.yz.wsy.fm(strArrSplit[2])};
                } else {
                    strArrSplit = strSubstring.split(", ");
                    iArr = new int[]{com.bytedance.sdk.component.adexpress.dynamic.yz.wsy.fm(strArrSplit[1].substring(0, 7)), com.bytedance.sdk.component.adexpress.dynamic.yz.wsy.fm(strArrSplit[2].substring(0, 7))};
                }
                try {
                    double d10 = Double.parseDouble(strSubstring.substring(strSubstring.indexOf("linear-gradient(") + 1, strSubstring.indexOf("deg")));
                    if (d10 > 225.0d && d10 < 315.0d) {
                        int i10 = iArr[1];
                        iArr[1] = iArr[0];
                        iArr[0] = i10;
                    }
                } catch (Exception unused) {
                }
                GradientDrawable gradientDrawableFm = fm(fm(strArrSplit[0]), iArr);
                gradientDrawableFm.setShape(0);
                gradientDrawableFm.setCornerRadius(com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.duv.fhx()));
                return gradientDrawableFm;
            } catch (Exception unused2) {
                Drawable mutilBackgroundDrawable = getMutilBackgroundDrawable();
                if (mutilBackgroundDrawable != null) {
                    return mutilBackgroundDrawable;
                }
            }
        }
        GradientDrawable drawable = getDrawable();
        drawable.setShape(0);
        float fFm = com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.duv.fhx());
        drawable.setCornerRadius(fFm);
        if (fFm < 1.0f) {
            float fFm2 = com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.duv.ol());
            float fFm3 = com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.duv.wbw());
            float fFm4 = com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.duv.ha());
            float fFm5 = com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.duv.pkk());
            float[] fArr = new float[8];
            if (fFm2 > 0.0f) {
                fArr[0] = fFm2;
                fArr[1] = fFm2;
            }
            if (fFm3 > 0.0f) {
                fArr[2] = fFm3;
                fArr[3] = fFm3;
            }
            if (fFm4 > 0.0f) {
                fArr[4] = fFm4;
                fArr[5] = fFm4;
            }
            if (fFm5 > 0.0f) {
                fArr[6] = fFm5;
                fArr[7] = fFm5;
            }
            drawable.setCornerRadii(fArr);
        }
        if (z10) {
            iGzf = Color.parseColor(str);
        } else {
            iGzf = this.duv.gzf();
        }
        drawable.setColor(iGzf);
        if (this.duv.qhl() > 0.0f) {
            drawable.setStroke((int) com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.duv.qhl()), this.duv.irt());
            return drawable;
        }
        if (this.duv.gof() <= 0) {
            return drawable;
        }
        drawable.setStroke(this.duv.gof(), this.duv.irt());
        drawable.setAlpha(50);
        if (!b.r(this.dsz, "video-vd")) {
            return drawable;
        }
        setLayerType(1, null);
        return new gqi((int) fFm, this.duv.gof());
    }

    public ro fm(Bitmap bitmap) {
        return new fm(bitmap, null);
    }

    private Drawable[] fm(List<String> list) {
        Drawable[] drawableArr = new Drawable[list.size()];
        for (int i10 = 0; i10 < list.size(); i10++) {
            String str = list.get(i10);
            if (str.contains("linear-gradient")) {
                String[] strArrSplit = str.substring(str.indexOf("(") + 1, str.length() - 1).split(", ");
                int length = strArrSplit.length - 1;
                int[] iArr = new int[length];
                int i11 = 0;
                while (i11 < length) {
                    int i12 = i11 + 1;
                    iArr[i11] = com.bytedance.sdk.component.adexpress.dynamic.yz.wsy.fm(strArrSplit[i12].substring(0, 7));
                    i11 = i12;
                }
                GradientDrawable gradientDrawableFm = fm(fm(strArrSplit[0]), iArr);
                gradientDrawableFm.setShape(0);
                gradientDrawableFm.setCornerRadius(com.bytedance.sdk.component.adexpress.yz.wsy.fm(this.ku, this.duv.fhx()));
                drawableArr[(list.size() - 1) - i10] = gradientDrawableFm;
            }
        }
        return drawableArr;
    }

    public GradientDrawable fm(GradientDrawable.Orientation orientation, @ColorInt int[] iArr) {
        if (iArr != null && iArr.length != 0) {
            if (iArr.length == 1) {
                GradientDrawable gradientDrawable = new GradientDrawable();
                gradientDrawable.setColor(iArr[0]);
                return gradientDrawable;
            }
            return new GradientDrawable(orientation, iArr);
        }
        return new GradientDrawable();
    }

    public GradientDrawable.Orientation fm(String str) {
        try {
            int i10 = (int) Float.parseFloat(str.substring(0, str.length() - 3));
            if (i10 <= 90) {
                return GradientDrawable.Orientation.LEFT_RIGHT;
            }
            if (i10 <= 180) {
                return GradientDrawable.Orientation.TOP_BOTTOM;
            }
            if (i10 <= 270) {
                return GradientDrawable.Orientation.RIGHT_LEFT;
            }
            return GradientDrawable.Orientation.BOTTOM_TOP;
        } catch (Exception unused) {
            return GradientDrawable.Orientation.LEFT_RIGHT;
        }
    }

    private void fm() {
        if (isShown()) {
            int iFm = com.bytedance.sdk.component.adexpress.dynamic.ro.fm.fm(this.duv);
            if (iFm == 2) {
                if (this.sds == null) {
                    this.sds = new com.bytedance.sdk.component.utils.hlt(getContext().getApplicationContext(), 1);
                }
                new Object() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.jnr.4
                };
                com.bytedance.sdk.component.adexpress.ro.dsz renderRequest = this.onz.getRenderRequest();
                if (renderRequest != null) {
                    renderRequest.fhx();
                    renderRequest.sds();
                    renderRequest.gqi();
                    return;
                }
                return;
            }
            if (iFm == 3) {
                if (this.sds == null) {
                    this.sds = new com.bytedance.sdk.component.utils.hlt(getContext().getApplicationContext(), 2);
                }
                new Object() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.jnr.5
                };
                com.bytedance.sdk.component.adexpress.ro.dsz renderRequest2 = this.onz.getRenderRequest();
                if (renderRequest2 != null) {
                    renderRequest2.qhl();
                    renderRequest2.maa();
                    renderRequest2.gof();
                    renderRequest2.wey();
                }
            }
        }
    }
}
