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 com.amazon.a.a.o.b.f;
import com.bytedance.sdk.component.adexpress.dynamic.animation.view.IAnimation;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes2.dex */
public abstract class wN extends FrameLayout implements IAnimation, GS, Sco {
    private static final View.OnTouchListener Ne = new View.OnTouchListener() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.wN.1
        @Override // android.view.View.OnTouchListener
        public boolean onTouch(View view, MotionEvent motionEvent) {
            return true;
        }
    };
    private static final View.OnClickListener VOe = new View.OnClickListener() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.wN.2
        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
        }
    };
    protected float AlY;
    protected int DSW;
    protected View EH;
    protected com.bytedance.sdk.component.adexpress.dynamic.AlY.qsH GA;
    protected int NjR;
    private float Sg;
    com.bytedance.sdk.component.adexpress.dynamic.animation.view.tN Wwa;
    private float YFl;
    protected com.bytedance.sdk.component.adexpress.dynamic.AlY.DSW YoT;
    private float aIu;
    protected Context eT;
    protected com.bytedance.sdk.component.adexpress.dynamic.animation.YFl.Sg lG;
    protected int nc;
    protected DynamicRootView pDU;
    private float qO;
    protected int qsH;
    protected boolean rkt;
    protected float tN;
    protected float vc;
    protected float wN;
    private com.bytedance.sdk.component.utils.aIu wXo;

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

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

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

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

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

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

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

    public void setShouldInvisible(boolean z) {
        this.rkt = z;
    }

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

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

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

    @Override // com.bytedance.sdk.component.adexpress.dynamic.animation.view.IAnimation
    public void setStretchValue(float f) {
        this.aIu = f;
        this.Wwa.YFl(this, f);
    }

    public wN(Context context, DynamicRootView dynamicRootView, com.bytedance.sdk.component.adexpress.dynamic.AlY.qsH qsh) {
        super(context);
        this.eT = context;
        this.pDU = dynamicRootView;
        this.GA = qsh;
        this.tN = qsh.vc();
        this.AlY = qsh.DSW();
        this.wN = qsh.qsH();
        this.vc = qsh.NjR();
        this.NjR = (int) com.bytedance.sdk.component.adexpress.AlY.qsH.YFl(this.eT, this.tN);
        this.nc = (int) com.bytedance.sdk.component.adexpress.AlY.qsH.YFl(this.eT, this.AlY);
        this.DSW = (int) com.bytedance.sdk.component.adexpress.AlY.qsH.YFl(this.eT, this.wN);
        this.qsH = (int) com.bytedance.sdk.component.adexpress.AlY.qsH.YFl(this.eT, this.vc);
        com.bytedance.sdk.component.adexpress.dynamic.AlY.DSW dsw = new com.bytedance.sdk.component.adexpress.dynamic.AlY.DSW(qsh.nc());
        this.YoT = dsw;
        if (dsw.Wwa() > 0) {
            this.DSW += this.YoT.Wwa() * 2;
            this.qsH += this.YoT.Wwa() * 2;
            this.NjR -= this.YoT.Wwa();
            this.nc -= this.YoT.Wwa();
            List<com.bytedance.sdk.component.adexpress.dynamic.AlY.qsH> eT = qsh.eT();
            if (eT != null) {
                for (com.bytedance.sdk.component.adexpress.dynamic.AlY.qsH qsh2 : eT) {
                    qsh2.tN(qsh2.vc() + com.bytedance.sdk.component.adexpress.AlY.qsH.Sg(this.eT, this.YoT.Wwa()));
                    qsh2.AlY(qsh2.DSW() + com.bytedance.sdk.component.adexpress.AlY.qsH.Sg(this.eT, this.YoT.Wwa()));
                    qsh2.YFl(com.bytedance.sdk.component.adexpress.AlY.qsH.Sg(this.eT, this.YoT.Wwa()));
                    qsh2.Sg(com.bytedance.sdk.component.adexpress.AlY.qsH.Sg(this.eT, this.YoT.Wwa()));
                }
            }
        }
        this.rkt = this.YoT.pDU() > FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
        this.Wwa = new com.bytedance.sdk.component.adexpress.dynamic.animation.view.tN();
    }

    public boolean tN() {
        NjR();
        vc();
        AlY();
        return true;
    }

    public void YFl(int i) {
        com.bytedance.sdk.component.adexpress.dynamic.AlY.DSW dsw = this.YoT;
        if (dsw != null && dsw.YFl(i)) {
            NjR();
            int childCount = getChildCount();
            for (int i2 = 0; i2 < childCount; i2++) {
                View childAt = getChildAt(i2);
                if (childAt != null && (getChildAt(i2) instanceof wN)) {
                    ((wN) childAt).YFl(i);
                }
            }
        }
    }

    protected boolean AlY() {
        View.OnTouchListener onTouchListener;
        View.OnClickListener onClickListener;
        View view = this.EH;
        if (view == null) {
            view = this;
        }
        if (wN()) {
            onTouchListener = (View.OnTouchListener) getDynamicClickListener();
            onClickListener = (View.OnClickListener) getDynamicClickListener();
        } else {
            onTouchListener = Ne;
            onClickListener = VOe;
        }
        if (onTouchListener != null && onClickListener != null) {
            view.setOnTouchListener(onTouchListener);
            view.setOnClickListener(onClickListener);
            int YFl = com.bytedance.sdk.component.adexpress.dynamic.Sg.YFl.YFl(this.YoT);
            if (YFl == 2 || YFl == 3) {
                view.setOnClickListener(VOe);
            } else {
                view.setOnClickListener(onClickListener);
            }
        }
        YFl(view);
        Sg(view);
        return true;
    }

    protected void YFl(View view) {
        try {
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("width", this.GA.qsH());
            jSONObject.put("height", this.GA.NjR());
            if (com.bytedance.sdk.component.adexpress.AlY.Sg()) {
                view.setTag(com.bytedance.sdk.component.adexpress.dynamic.YFl.aIu, this.YoT.lu());
                view.setTag(com.bytedance.sdk.component.adexpress.dynamic.YFl.wXo, this.GA.nc().Sg());
                view.setTag(com.bytedance.sdk.component.adexpress.dynamic.YFl.Ne, this.GA.tN());
                view.setTag(com.bytedance.sdk.component.adexpress.dynamic.YFl.VOe, jSONObject.toString());
                return;
            }
            view.setTag(2097610717, this.YoT.lu());
            view.setTag(2097610715, this.GA.nc().Sg());
            view.setTag(2097610714, this.GA.tN());
            view.setTag(2097610713, jSONObject.toString());
            int YFl = com.bytedance.sdk.component.adexpress.dynamic.Sg.YFl.YFl(this.YoT);
            if (YFl == 1) {
                view.setTag(2097610707, new Pair(this.YoT.UZM(), Long.valueOf(this.YoT.YI())));
                view.setTag(2097610708, Integer.valueOf(YFl));
            }
        } catch (JSONException unused) {
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void Sg(View view) {
        com.bytedance.sdk.component.adexpress.dynamic.AlY.vc wN;
        com.bytedance.sdk.component.adexpress.dynamic.AlY.qsH qsh = this.GA;
        if (qsh == null || (wN = qsh.nc().wN()) == null) {
            return;
        }
        view.setTag(2097610716, Boolean.valueOf(wN.JT()));
    }

    public boolean wN() {
        com.bytedance.sdk.component.adexpress.dynamic.AlY.DSW dsw = this.YoT;
        return (dsw == null || dsw.Ga() == 0) ? false : true;
    }

    public void vc() {
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(this.DSW, this.qsH);
        layoutParams.topMargin = this.nc;
        layoutParams.leftMargin = this.NjR;
        layoutParams.setMarginStart(layoutParams.leftMargin);
        layoutParams.setMarginEnd(layoutParams.rightMargin);
        setLayoutParams(layoutParams);
    }

    public int getClickArea() {
        return this.YoT.Ga();
    }

    public String getImageObjectFit() {
        return this.YoT.VB();
    }

    public com.bytedance.sdk.component.adexpress.dynamic.vc.YFl getDynamicClickListener() {
        return this.pDU.getDynamicClickListener();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public Drawable getBackgroundDrawable() {
        return YFl(false, "");
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public Drawable YFl(boolean z, String str) {
        String[] split;
        int[] iArr;
        int dXO;
        if (!TextUtils.isEmpty(this.YoT.GS())) {
            try {
                String GS = this.YoT.GS();
                String substring = GS.substring(GS.indexOf("(") + 1, GS.length() - 1);
                if (substring.contains("rgba") && substring.contains("%")) {
                    split = new String[]{substring.substring(0, substring.indexOf(f.f114a)).trim(), substring.substring(substring.indexOf(f.f114a) + 1, substring.indexOf("%") + 1).trim(), substring.substring(substring.indexOf("%") + 2).trim()};
                    iArr = new int[]{com.bytedance.sdk.component.adexpress.dynamic.AlY.DSW.YFl(split[1]), com.bytedance.sdk.component.adexpress.dynamic.AlY.DSW.YFl(split[2])};
                } else {
                    split = substring.split(", ");
                    iArr = new int[]{com.bytedance.sdk.component.adexpress.dynamic.AlY.DSW.YFl(split[1].substring(0, 7)), com.bytedance.sdk.component.adexpress.dynamic.AlY.DSW.YFl(split[2].substring(0, 7))};
                }
                try {
                    double parseDouble = Double.parseDouble(substring.substring(substring.indexOf("linear-gradient(") + 1, substring.indexOf("deg")));
                    if (parseDouble > 225.0d && parseDouble < 315.0d) {
                        int i = iArr[1];
                        iArr[1] = iArr[0];
                        iArr[0] = i;
                    }
                } catch (Exception unused) {
                }
                GradientDrawable YFl = YFl(YFl(split[0]), iArr);
                YFl.setShape(0);
                YFl.setCornerRadius(com.bytedance.sdk.component.adexpress.AlY.qsH.YFl(this.eT, this.YoT.EH()));
                return YFl;
            } catch (Exception unused2) {
                Drawable mutilBackgroundDrawable = getMutilBackgroundDrawable();
                if (mutilBackgroundDrawable != null) {
                    return mutilBackgroundDrawable;
                }
            }
        }
        GradientDrawable drawable = getDrawable();
        drawable.setShape(0);
        float YFl2 = com.bytedance.sdk.component.adexpress.AlY.qsH.YFl(this.eT, this.YoT.EH());
        drawable.setCornerRadius(YFl2);
        if (YFl2 < 1.0f) {
            float YFl3 = com.bytedance.sdk.component.adexpress.AlY.qsH.YFl(this.eT, this.YoT.hQ());
            float YFl4 = com.bytedance.sdk.component.adexpress.AlY.qsH.YFl(this.eT, this.YoT.pq());
            float YFl5 = com.bytedance.sdk.component.adexpress.AlY.qsH.YFl(this.eT, this.YoT.mn());
            float YFl6 = com.bytedance.sdk.component.adexpress.AlY.qsH.YFl(this.eT, this.YoT.zB());
            float[] fArr = new float[8];
            if (YFl3 > 0.0f) {
                fArr[0] = YFl3;
                fArr[1] = YFl3;
            }
            if (YFl4 > 0.0f) {
                fArr[2] = YFl4;
                fArr[3] = YFl4;
            }
            if (YFl5 > 0.0f) {
                fArr[4] = YFl5;
                fArr[5] = YFl5;
            }
            if (YFl6 > 0.0f) {
                fArr[6] = YFl6;
                fArr[7] = YFl6;
            }
            drawable.setCornerRadii(fArr);
        }
        if (z) {
            dXO = Color.parseColor(str);
        } else {
            dXO = this.YoT.dXO();
        }
        drawable.setColor(dXO);
        if (this.YoT.lG() > 0.0f) {
            drawable.setStroke((int) com.bytedance.sdk.component.adexpress.AlY.qsH.YFl(this.eT, this.YoT.lG()), this.YoT.rkt());
            return drawable;
        } else if (this.YoT.Wwa() > 0) {
            drawable.setStroke(this.YoT.Wwa(), this.YoT.rkt());
            drawable.setAlpha(50);
            if (TextUtils.equals(this.GA.nc().Sg(), "video-vd")) {
                setLayerType(1, null);
                return new qO((int) YFl2, this.YoT.Wwa());
            }
            return drawable;
        } else {
            return drawable;
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public Sg YFl(Bitmap bitmap) {
        return new YFl(bitmap, null);
    }

    protected Drawable getMutilBackgroundDrawable() {
        try {
            return new LayerDrawable(YFl(Sg(this.YoT.GS().replaceAll("/\\*.*\\*/", ""))));
        } catch (Exception unused) {
            return null;
        }
    }

    private Drawable[] YFl(List<String> list) {
        Drawable[] drawableArr = new Drawable[list.size()];
        for (int i = 0; i < list.size(); i++) {
            String str = list.get(i);
            if (str.contains("linear-gradient")) {
                String[] split = str.substring(str.indexOf("(") + 1, str.length() - 1).split(", ");
                int length = split.length - 1;
                int[] iArr = new int[length];
                int i2 = 0;
                while (i2 < length) {
                    int i3 = i2 + 1;
                    iArr[i2] = com.bytedance.sdk.component.adexpress.dynamic.AlY.DSW.YFl(split[i3].substring(0, 7));
                    i2 = i3;
                }
                GradientDrawable YFl = YFl(YFl(split[0]), iArr);
                YFl.setShape(0);
                YFl.setCornerRadius(com.bytedance.sdk.component.adexpress.AlY.qsH.YFl(this.eT, this.YoT.EH()));
                drawableArr[(list.size() - 1) - i] = YFl;
            }
        }
        return drawableArr;
    }

    private List<String> Sg(String str) {
        ArrayList arrayList = new ArrayList();
        int i = 0;
        boolean z = false;
        int i2 = 0;
        for (int i3 = 0; i3 < str.length(); i3++) {
            if (str.charAt(i3) == '(') {
                i++;
                z = true;
            } else if (str.charAt(i3) == ')' && i - 1 == 0 && z) {
                int i4 = i3 + 1;
                arrayList.add(str.substring(i2, i4));
                i2 = i4;
                z = false;
            }
        }
        return arrayList;
    }

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

    /* JADX INFO: Access modifiers changed from: protected */
    public GradientDrawable YFl(GradientDrawable.Orientation orientation, int[] iArr) {
        if (iArr == null || iArr.length == 0) {
            return new GradientDrawable();
        }
        if (iArr.length == 1) {
            GradientDrawable gradientDrawable = new GradientDrawable();
            gradientDrawable.setColor(iArr[0]);
            return gradientDrawable;
        }
        return new GradientDrawable(orientation, iArr);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public GradientDrawable.Orientation YFl(String str) {
        try {
            int parseFloat = (int) Float.parseFloat(str.substring(0, str.length() - 3));
            if (parseFloat <= 90) {
                return GradientDrawable.Orientation.LEFT_RIGHT;
            }
            if (parseFloat <= 180) {
                return GradientDrawable.Orientation.TOP_BOTTOM;
            }
            if (parseFloat <= 270) {
                return GradientDrawable.Orientation.RIGHT_LEFT;
            }
            return GradientDrawable.Orientation.BOTTOM_TOP;
        } catch (Exception unused) {
            return GradientDrawable.Orientation.LEFT_RIGHT;
        }
    }

    @Override // android.view.View
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        this.Wwa.YFl(canvas, this, this);
    }

    @Override // android.view.View
    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        super.onSizeChanged(i, i2, i3, i4);
        com.bytedance.sdk.component.adexpress.dynamic.animation.view.tN tNVar = this.Wwa;
        View view = this.EH;
        if (view == null) {
            view = this;
        }
        tNVar.YFl(view, i, i2);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        DSW();
        YFl();
    }

    @Override // android.view.View
    public void onWindowFocusChanged(boolean z) {
        com.bytedance.sdk.component.utils.aIu aiu = this.wXo;
        if (aiu == null || !z) {
            return;
        }
        aiu.onResume();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        Sg();
        super.onDetachedFromWindow();
    }

    public void DSW() {
        if (qsH()) {
            return;
        }
        View view = this.EH;
        if (view == null) {
            view = this;
        }
        com.bytedance.sdk.component.adexpress.dynamic.animation.YFl.Sg sg = new com.bytedance.sdk.component.adexpress.dynamic.animation.YFl.Sg(view, this.GA.nc().wN().ZS());
        this.lG = sg;
        sg.YFl();
    }

    public void Sg() {
        com.bytedance.sdk.component.adexpress.dynamic.animation.YFl.Sg sg = this.lG;
        if (sg != null) {
            sg.Sg();
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public boolean qsH() {
        com.bytedance.sdk.component.adexpress.dynamic.AlY.qsH qsh = this.GA;
        return qsh == null || qsh.nc() == null || this.GA.nc().wN() == null || this.GA.nc().wN().ZS() == null;
    }

    public com.bytedance.sdk.component.adexpress.dynamic.AlY.vc getDynamicLayoutBrickValue() {
        com.bytedance.sdk.component.adexpress.dynamic.AlY.wN nc;
        com.bytedance.sdk.component.adexpress.dynamic.AlY.qsH qsh = this.GA;
        if (qsh == null || (nc = qsh.nc()) == null) {
            return null;
        }
        return nc.wN();
    }

    private void YFl() {
        if (isShown()) {
            int YFl = com.bytedance.sdk.component.adexpress.dynamic.Sg.YFl.YFl(this.YoT);
            if (YFl == 2) {
                if (this.wXo == null) {
                    this.wXo = new com.bytedance.sdk.component.utils.aIu(getContext().getApplicationContext(), 1);
                }
                new Object() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.wN.3
                };
                com.bytedance.sdk.component.adexpress.Sg.GA renderRequest = this.pDU.getRenderRequest();
                if (renderRequest != null) {
                    renderRequest.EH();
                    renderRequest.wXo();
                    renderRequest.qO();
                }
            } else if (YFl == 3) {
                if (this.wXo == null) {
                    this.wXo = new com.bytedance.sdk.component.utils.aIu(getContext().getApplicationContext(), 2);
                }
                new Object() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.wN.4
                };
                com.bytedance.sdk.component.adexpress.Sg.GA renderRequest2 = this.pDU.getRenderRequest();
                if (renderRequest2 != null) {
                    renderRequest2.lG();
                    renderRequest2.Ne();
                    renderRequest2.Wwa();
                    renderRequest2.aIu();
                }
            }
            com.bytedance.sdk.component.utils.aIu aiu = this.wXo;
            if (aiu != null) {
                aiu.onResume();
            }
        }
    }
}
