package com.bytedance.adsdk.Sg;

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import com.amazon.a.a.o.b.f;
import com.bytedance.adsdk.Sg.DSW;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
/* loaded from: classes2.dex */
public class vc extends ImageView {
    private static final eT<Throwable> Sg = new eT<Throwable>() { // from class: com.bytedance.adsdk.Sg.vc.1
        @Override // com.bytedance.adsdk.Sg.eT
        public void YFl(Throwable th) {
            com.bytedance.adsdk.Sg.vc.vc.YFl(th);
        }
    };
    private static final String YFl = "vc";
    private final eT<Throwable> AlY;
    private YFl Cfr;
    private final NjR DSW;
    private final Set<Object> EH;
    private boolean GA;
    private final Runnable Ga;
    private int Ne;
    private int NjR;
    private int UZM;
    private int VOe;
    private final Handler Wwa;
    private String YI;
    private boolean YoT;
    private long aIu;
    private int bZ;
    private Sg dXO;
    private boolean eT;
    private DSW lG;
    private com.bytedance.adsdk.ugeno.tN nc;
    private final Set<AlY> pDU;
    private Handler qO;
    private String qsH;
    private GA<DSW> rkt;
    private final eT<DSW> tN;
    private int vc;
    private eT<Throwable> wN;
    private com.bytedance.adsdk.Sg.tN.tN.tN wXo;

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes2.dex */
    public enum AlY {
        SET_ANIMATION,
        SET_PROGRESS,
        SET_REPEAT_MODE,
        SET_REPEAT_COUNT,
        SET_IMAGE_ASSETS,
        PLAY_OPTION
    }

    /* loaded from: classes2.dex */
    public interface Sg {
    }

    /* loaded from: classes2.dex */
    public interface YFl {
    }

    public void YFl(com.bytedance.adsdk.ugeno.tN tNVar) {
        this.nc = tNVar;
    }

    public DSW getComposition() {
        return this.lG;
    }

    public void setCacheComposition(boolean z) {
        this.GA = z;
    }

    public void setFailureListener(eT<Throwable> eTVar) {
        this.wN = eTVar;
    }

    public void setFallbackResource(int i) {
        this.vc = i;
    }

    public void setLottieAnimListener(YFl yFl) {
        this.Cfr = yFl;
    }

    public void setLottieClicklistener(Sg sg) {
        this.dXO = sg;
    }

    static /* synthetic */ int EH(vc vcVar) {
        int i = vcVar.Ne;
        vcVar.Ne = i - 1;
        return i;
    }

    public vc(Context context) {
        super(context);
        this.tN = new eT<DSW>() { // from class: com.bytedance.adsdk.Sg.vc.5
            @Override // com.bytedance.adsdk.Sg.eT
            public void YFl(DSW dsw) {
                vc.this.setComposition(dsw);
            }
        };
        this.AlY = new eT<Throwable>() { // from class: com.bytedance.adsdk.Sg.vc.6
            @Override // com.bytedance.adsdk.Sg.eT
            public void YFl(Throwable th) {
                if (vc.this.vc != 0) {
                    vc vcVar = vc.this;
                    vcVar.setImageResource(vcVar.vc);
                }
                (vc.this.wN == null ? vc.Sg : vc.this.wN).YFl(th);
            }
        };
        this.vc = 0;
        this.DSW = new NjR();
        this.eT = false;
        this.YoT = false;
        this.GA = true;
        this.pDU = new HashSet();
        this.EH = new HashSet();
        this.Wwa = new Handler(Looper.getMainLooper());
        this.aIu = 0L;
        this.Ga = new Runnable() { // from class: com.bytedance.adsdk.Sg.vc.3
            @Override // java.lang.Runnable
            public void run() {
                Log.i("TMe", "--==--- timer callback, timer: " + vc.this.Ne + ", " + vc.this.VOe);
                if (vc.this.Ne <= vc.this.VOe) {
                    if (vc.this.bZ >= 0 && vc.this.UZM >= 0) {
                        Log.i("TMe", "--==--- timer end, play anim, startframe: " + vc.this.bZ);
                        vc.this.YFl();
                        vc vcVar = vc.this;
                        vcVar.setFrame(vcVar.bZ);
                        vc.this.YFl(new ValueAnimator.AnimatorUpdateListener() { // from class: com.bytedance.adsdk.Sg.vc.3.1
                            @Override // android.animation.ValueAnimator.AnimatorUpdateListener
                            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                                if (vc.this.getFrame() < vc.this.UZM - 1 || vc.this.getFrame() >= vc.this.UZM + 2) {
                                    return;
                                }
                                Log.i("TMe", "--==--- timer end, play anim, endframe: " + vc.this.UZM);
                                vc.this.Sg(this);
                                vc.this.vc();
                            }
                        });
                    } else {
                        Log.i("TMe", "--==--- timer end, frame invalid: " + vc.this.bZ + f.f114a + vc.this.UZM);
                    }
                    if (TextUtils.isEmpty(vc.this.YI) || vc.this.dXO == null) {
                        return;
                    }
                    Sg unused = vc.this.dXO;
                    String unused2 = vc.this.YI;
                    return;
                }
                vc.EH(vc.this);
                vc.this.wXo.YFl(new StringBuilder().append(vc.this.Ne).toString());
                vc.this.invalidate();
                vc.this.EH();
            }
        };
        qsH();
    }

    private void qsH() {
        setSaveEnabled(false);
        this.GA = true;
        setFallbackResource(0);
        setImageAssetsFolder("");
        YFl(0.0f, false);
        YFl(false, getContext().getApplicationContext());
        setIgnoreDisabledSystemAnimations(false);
        this.DSW.YFl(Boolean.valueOf(com.bytedance.adsdk.Sg.vc.vc.YFl(getContext()) != 0.0f));
        NjR();
        nc();
        YoT();
    }

    private void NjR() {
        YFl(new Animator.AnimatorListener() { // from class: com.bytedance.adsdk.Sg.vc.7
            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationCancel(Animator animator) {
            }

            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationEnd(Animator animator) {
            }

            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationRepeat(Animator animator) {
            }

            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationStart(Animator animator) {
                vc.this.Sg(this);
                vc.this.pDU();
            }
        });
    }

    private void nc() {
        YFl(new ValueAnimator.AnimatorUpdateListener() { // from class: com.bytedance.adsdk.Sg.vc.8
            @Override // android.animation.ValueAnimator.AnimatorUpdateListener
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                Object animatedValue = valueAnimator.getAnimatedValue();
                if (!(animatedValue instanceof Float) || ((Float) animatedValue).floatValue() < 0.98f) {
                    return;
                }
                vc.this.Sg(this);
                DSW.YFl globalConfig = vc.this.getGlobalConfig();
                if (globalConfig == null || globalConfig.tN == null || globalConfig.tN.isEmpty() || vc.this.Cfr == null) {
                    return;
                }
                YFl unused = vc.this.Cfr;
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void eT() {
        DSW.YFl globalConfig = getGlobalConfig();
        if (globalConfig == null || globalConfig.Sg == null) {
            return;
        }
        globalConfig.Sg.isEmpty();
    }

    private void YoT() {
        YFl(new Animator.AnimatorListener() { // from class: com.bytedance.adsdk.Sg.vc.9
            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationCancel(Animator animator) {
            }

            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationEnd(Animator animator) {
            }

            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationRepeat(Animator animator) {
            }

            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationStart(Animator animator) {
                aIu Ne;
                vc.this.Sg(this);
                String playDelayedELExpressTimeS = vc.this.getPlayDelayedELExpressTimeS();
                if (!TextUtils.isEmpty(playDelayedELExpressTimeS) && (Ne = vc.this.DSW.Ne()) != null) {
                    try {
                        int parseInt = Integer.parseInt(Ne.YFl(playDelayedELExpressTimeS)) * 1000;
                        if (vc.this.aIu > 0) {
                            long elapsedRealtime = (vc.this.aIu + parseInt) - SystemClock.elapsedRealtime();
                            Log.i("TMe", "--==-- lottie delayed time: ".concat(String.valueOf(elapsedRealtime)));
                            if (elapsedRealtime > 0) {
                                vc.this.vc();
                                vc.this.setVisibility(8);
                                if (vc.this.qO == null) {
                                    vc.this.qO = new Handler(Looper.getMainLooper());
                                }
                                vc.this.qO.removeCallbacksAndMessages(null);
                                vc.this.qO.postDelayed(new Runnable() { // from class: com.bytedance.adsdk.Sg.vc.9.1
                                    @Override // java.lang.Runnable
                                    public void run() {
                                        Log.i("TMe", "--==-- lottie real start play");
                                        vc.this.setVisibility(0);
                                        vc.this.YFl();
                                        vc.this.eT();
                                    }
                                }, elapsedRealtime);
                                return;
                            }
                        }
                    } catch (NumberFormatException unused) {
                    }
                }
                vc.this.eT();
            }
        });
    }

    @Override // android.widget.ImageView
    public void setImageResource(int i) {
        GA();
        super.setImageResource(i);
    }

    @Override // android.widget.ImageView
    public void setImageDrawable(Drawable drawable) {
        GA();
        super.setImageDrawable(drawable);
    }

    @Override // android.widget.ImageView
    public void setImageBitmap(Bitmap bitmap) {
        GA();
        super.setImageBitmap(bitmap);
    }

    @Override // android.view.View
    public void unscheduleDrawable(Drawable drawable) {
        NjR njR;
        if (!this.eT && drawable == (njR = this.DSW) && njR.aIu()) {
            vc();
        } else if (!this.eT && (drawable instanceof NjR)) {
            NjR njR2 = (NjR) drawable;
            if (njR2.aIu()) {
                njR2.YI();
            }
        }
        super.unscheduleDrawable(drawable);
    }

    @Override // android.view.View
    public void invalidate() {
        super.invalidate();
        Drawable drawable = getDrawable();
        if ((drawable instanceof NjR) && ((NjR) drawable).wN() == qO.SOFTWARE) {
            this.DSW.invalidateSelf();
        }
    }

    @Override // android.widget.ImageView, android.view.View, android.graphics.drawable.Drawable.Callback
    public void invalidateDrawable(Drawable drawable) {
        Drawable drawable2 = getDrawable();
        NjR njR = this.DSW;
        if (drawable2 == njR) {
            super.invalidateDrawable(njR);
        } else {
            super.invalidateDrawable(drawable);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public String getPlayDelayedELExpressTimeS() {
        DSW bZ;
        NjR njR = this.DSW;
        if (njR == null || (bZ = njR.bZ()) == null) {
            return null;
        }
        return bZ.NjR();
    }

    private nc YFl(String str) {
        NjR njR;
        DSW bZ;
        Map<String, nc> rkt;
        if (TextUtils.isEmpty(str) || (njR = this.DSW) == null || (bZ = njR.bZ()) == null || (rkt = bZ.rkt()) == null) {
            return null;
        }
        return rkt.get(str);
    }

    private DSW.Sg getGlobalEvent() {
        DSW bZ;
        NjR njR = this.DSW;
        if (njR == null || (bZ = njR.bZ()) == null) {
            return null;
        }
        return bZ.nc();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public DSW.YFl getGlobalConfig() {
        DSW bZ;
        NjR njR = this.DSW;
        if (njR == null || (bZ = njR.bZ()) == null) {
            return null;
        }
        return bZ.eT();
    }

    private void YFl(int[][] iArr) {
        if (iArr == null || iArr.length == 0) {
            return;
        }
        try {
            int[] iArr2 = iArr[0];
            int i = iArr2[0];
            final int i2 = iArr2[1];
            if (i < 0 || i2 < 0) {
                return;
            }
            Log.i("TMe", "--==--- inel enter, play anim, startframe: ".concat(String.valueOf(i)));
            rkt();
            YFl();
            setFrame(i);
            YFl(new ValueAnimator.AnimatorUpdateListener() { // from class: com.bytedance.adsdk.Sg.vc.10
                @Override // android.animation.ValueAnimator.AnimatorUpdateListener
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    if (vc.this.getFrame() < i2 - 1 || vc.this.getFrame() >= i2 + 2) {
                        return;
                    }
                    Log.i("TMe", "--==--- inel enter, play anim end, endframe: " + i2 + ", realFrame: " + vc.this.getFrame());
                    vc.this.Sg(this);
                    vc.this.vc();
                }
            });
        } catch (Throwable unused) {
        }
    }

    private boolean YFl(MotionEvent motionEvent) {
        DSW.Sg globalEvent = getGlobalEvent();
        return (globalEvent == null || TextUtils.isEmpty(globalEvent.YFl)) ? false : true;
    }

    @Override // android.view.View
    public boolean onTouchEvent(MotionEvent motionEvent) {
        int[][] iArr;
        com.bytedance.adsdk.Sg.tN.tN.YFl Sg2 = Sg(motionEvent);
        if (Sg2 != null) {
            String NjR = Sg2.NjR();
            if (Sg2 instanceof com.bytedance.adsdk.Sg.tN.tN.Sg) {
                if (getGlobalConfig() == null || getGlobalConfig().YFl != 1) {
                    return super.onTouchEvent(motionEvent);
                }
                return false;
            }
            if (NjR != null && NjR.startsWith("CSJCLOSE")) {
                rkt();
            }
            nc YFl2 = YFl(Sg2.wN());
            if (YFl2 != null && motionEvent.getAction() == 1) {
                if (TextUtils.isEmpty(YFl2.wN()) && NjR != null && !NjR.endsWith("CSJNO")) {
                    YFl(motionEvent);
                }
                int[][] vc = YFl2.vc();
                if (vc != null) {
                    YFl(vc);
                } else if (getGlobalEvent() != null && (iArr = getGlobalEvent().Sg) != null) {
                    YFl(iArr);
                }
            }
            if (NjR == null || !NjR.startsWith("CSJNTP")) {
                return super.onTouchEvent(motionEvent);
            }
            return false;
        } else if (getGlobalConfig() == null || getGlobalConfig().YFl != 1) {
            return super.onTouchEvent(motionEvent);
        } else {
            return false;
        }
    }

    private com.bytedance.adsdk.Sg.tN.tN.YFl Sg(MotionEvent motionEvent) {
        com.bytedance.adsdk.Sg.tN.tN.Sg YFl2;
        NjR njR = this.DSW;
        if (njR == null || (YFl2 = njR.YFl()) == null) {
            return null;
        }
        return YFl(YFl2, motionEvent);
    }

    private com.bytedance.adsdk.Sg.tN.tN.YFl YFl(com.bytedance.adsdk.Sg.tN.tN.Sg sg, MotionEvent motionEvent) {
        com.bytedance.adsdk.Sg.tN.tN.YFl YFl2;
        for (com.bytedance.adsdk.Sg.tN.tN.YFl yFl : sg.YoT()) {
            if (yFl instanceof com.bytedance.adsdk.Sg.tN.tN.Sg) {
                if (yFl.qsH() && yFl.vc() > 0.0f) {
                    RectF rectF = new RectF();
                    yFl.YFl(rectF, yFl.AlY(), true);
                    if (rectF.width() >= 3.0f && rectF.height() >= 3.0f && (YFl2 = YFl((com.bytedance.adsdk.Sg.tN.tN.Sg) yFl, motionEvent)) != null) {
                        return YFl2;
                    }
                }
            } else if (yFl.qsH() && yFl.vc() > 0.0f) {
                RectF rectF2 = new RectF();
                yFl.YFl(rectF2, yFl.AlY(), true);
                RectF rectF3 = new RectF();
                YFl(rectF3, rectF2);
                if (YFl(motionEvent, rectF3)) {
                    return yFl;
                }
            }
        }
        return null;
    }

    private boolean YFl(MotionEvent motionEvent, RectF rectF) {
        if (motionEvent != null && rectF != null) {
            float x = motionEvent.getX();
            float y = motionEvent.getY();
            if (x >= rectF.left && x <= rectF.right && y >= rectF.top && y <= rectF.bottom) {
                return true;
            }
        }
        return false;
    }

    private void YFl(RectF rectF, RectF rectF2) {
        float width = getWidth();
        float height = getHeight();
        float width2 = this.DSW.getBounds().width();
        float height2 = this.DSW.getBounds().height();
        if (width == 0.0f || height == 0.0f || width2 == 0.0f || height2 == 0.0f) {
            return;
        }
        Matrix matrix = new Matrix();
        int i = AnonymousClass4.YFl[getScaleType().ordinal()];
        if (i == 1) {
            YFl(matrix, width, height, width2, height2);
        } else if (i == 2) {
            Sg(matrix, width, height, width2, height2);
        } else if (i == 3) {
            tN(matrix, width, height, width2, height2);
        } else if (i == 4) {
            AlY(matrix, width, height, width2, height2);
        }
        matrix.mapRect(rectF, rectF2);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: com.bytedance.adsdk.Sg.vc$4  reason: invalid class name */
    /* loaded from: classes2.dex */
    public static /* synthetic */ class AnonymousClass4 {
        static final /* synthetic */ int[] YFl;

        static {
            int[] iArr = new int[ImageView.ScaleType.values().length];
            YFl = iArr;
            try {
                iArr[ImageView.ScaleType.CENTER_CROP.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                YFl[ImageView.ScaleType.CENTER_INSIDE.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                YFl[ImageView.ScaleType.CENTER.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                YFl[ImageView.ScaleType.FIT_CENTER.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
        }
    }

    private void YFl(Matrix matrix, float f, float f2, float f3, float f4) {
        if (f3 / f4 >= f / f2) {
            float f5 = f2 / f4;
            matrix.preScale(f5, f5);
            matrix.postTranslate(-(((f3 * f5) - f) / 2.0f), 0.0f);
            return;
        }
        float f6 = f / f3;
        matrix.preScale(f6, f6);
        matrix.postTranslate(0.0f, -(((f4 * f6) - f2) / 2.0f));
    }

    private void Sg(Matrix matrix, float f, float f2, float f3, float f4) {
        if (f3 < f && f4 < f2) {
            matrix.postTranslate((f - f3) / 2.0f, (f2 - f4) / 2.0f);
        } else if (f3 / f4 >= f / f2) {
            float f5 = f / f3;
            matrix.preScale(f5, f5);
            matrix.postTranslate(0.0f, (f2 - (f4 * f5)) / 2.0f);
        } else {
            float f6 = f2 / f4;
            matrix.preScale(f6, f6);
            matrix.postTranslate((f - (f3 * f6)) / 2.0f, 0.0f);
        }
    }

    private void tN(Matrix matrix, float f, float f2, float f3, float f4) {
        matrix.postTranslate((f - f3) / 2.0f, (f2 - f4) / 2.0f);
    }

    private void AlY(Matrix matrix, float f, float f2, float f3, float f4) {
        if (f3 >= f || f4 >= f2) {
            if (f3 / f4 >= f / f2) {
                float f5 = f / f3;
                matrix.preScale(f5, f5);
                matrix.postTranslate(0.0f, (f2 - (f4 * f5)) / 2.0f);
                return;
            }
            float f6 = f2 / f4;
            matrix.preScale(f6, f6);
            matrix.postTranslate((f - (f3 * f6)) / 2.0f, 0.0f);
        } else if (f3 / f4 >= f / f2) {
            float f7 = f / f3;
            matrix.preScale(f7, f7);
            matrix.postTranslate(0.0f, (f2 - (f4 * f7)) / 2.0f);
        } else {
            float f8 = f2 / f4;
            matrix.preScale(f8, f8);
            matrix.postTranslate((f - (f3 * f8)) / 2.0f, 0.0f);
        }
    }

    @Override // android.view.View
    protected Parcelable onSaveInstanceState() {
        tN tNVar = new tN(super.onSaveInstanceState());
        tNVar.YFl = this.qsH;
        tNVar.Sg = this.NjR;
        tNVar.tN = this.DSW.Ga();
        tNVar.AlY = this.DSW.wXo();
        tNVar.wN = this.DSW.tN();
        tNVar.vc = this.DSW.Wwa();
        tNVar.DSW = this.DSW.qO();
        return tNVar;
    }

    @Override // android.view.View
    protected void onRestoreInstanceState(Parcelable parcelable) {
        int i;
        if (!(parcelable instanceof tN)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        tN tNVar = (tN) parcelable;
        super.onRestoreInstanceState(tNVar.getSuperState());
        this.qsH = tNVar.YFl;
        if (!this.pDU.contains(AlY.SET_ANIMATION) && !TextUtils.isEmpty(this.qsH)) {
            setAnimation(this.qsH);
        }
        this.NjR = tNVar.Sg;
        if (!this.pDU.contains(AlY.SET_ANIMATION) && (i = this.NjR) != 0) {
            setAnimation(i);
        }
        if (!this.pDU.contains(AlY.SET_PROGRESS)) {
            YFl(tNVar.tN, false);
        }
        if (!this.pDU.contains(AlY.PLAY_OPTION) && tNVar.AlY) {
            YFl();
        }
        if (!this.pDU.contains(AlY.SET_IMAGE_ASSETS)) {
            setImageAssetsFolder(tNVar.wN);
        }
        if (!this.pDU.contains(AlY.SET_REPEAT_MODE)) {
            setRepeatMode(tNVar.vc);
        }
        if (this.pDU.contains(AlY.SET_REPEAT_COUNT)) {
            return;
        }
        setRepeatCount(tNVar.DSW);
    }

    @Override // android.widget.ImageView, android.view.View
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (!isInEditMode() && this.YoT) {
            this.DSW.NjR();
        }
        com.bytedance.adsdk.ugeno.tN tNVar = this.nc;
        if (tNVar != null) {
            tNVar.DSW();
        }
    }

    @Override // android.widget.ImageView, android.view.View
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        rkt();
        Handler handler = this.qO;
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
        }
        tN();
        Sg();
        com.bytedance.adsdk.ugeno.tN tNVar = this.nc;
        if (tNVar != null) {
            tNVar.qsH();
        }
    }

    public void setIgnoreDisabledSystemAnimations(boolean z) {
        this.DSW.DSW(z);
    }

    public void setUseCompositionFrameRate(boolean z) {
        this.DSW.qsH(z);
    }

    public void YFl(boolean z, Context context) {
        this.DSW.YFl(z, context);
    }

    public void setClipToCompositionBounds(boolean z) {
        this.DSW.YFl(z);
    }

    public boolean getClipToCompositionBounds() {
        return this.DSW.Sg();
    }

    public void setOutlineMasksAndMattes(boolean z) {
        this.DSW.AlY(z);
    }

    public void setAnimation(int i) {
        this.NjR = i;
        this.qsH = null;
        setCompositionTask(YFl(i));
    }

    private GA<DSW> YFl(final int i) {
        if (isInEditMode()) {
            return new GA<>(new Callable<YoT<DSW>>() { // from class: com.bytedance.adsdk.Sg.vc.11
                @Override // java.util.concurrent.Callable
                /* renamed from: YFl */
                public YoT<DSW> call() throws Exception {
                    return vc.this.GA ? qsH.Sg(vc.this.getContext(), i) : qsH.Sg(vc.this.getContext(), i, (String) null);
                }
            }, true);
        }
        return this.GA ? qsH.YFl(getContext(), i) : qsH.YFl(getContext(), i, (String) null);
    }

    public void setAnimation(String str) {
        this.qsH = str;
        this.NjR = 0;
        setCompositionTask(Sg(str));
    }

    private GA<DSW> Sg(final String str) {
        if (isInEditMode()) {
            return new GA<>(new Callable<YoT<DSW>>() { // from class: com.bytedance.adsdk.Sg.vc.12
                @Override // java.util.concurrent.Callable
                /* renamed from: YFl */
                public YoT<DSW> call() throws Exception {
                    return vc.this.GA ? qsH.tN(vc.this.getContext(), str) : qsH.tN(vc.this.getContext(), str, null);
                }
            }, true);
        }
        return this.GA ? qsH.Sg(getContext(), str) : qsH.Sg(getContext(), str, (String) null);
    }

    @Deprecated
    public void setAnimationFromJson(String str) {
        YFl(str, (String) null);
    }

    public void YFl(String str, String str2) {
        YFl(new ByteArrayInputStream(str.getBytes()), str2);
    }

    public void YFl(InputStream inputStream, String str) {
        setCompositionTask(qsH.YFl(inputStream, str));
    }

    public void setAnimationFromUrl(String str) {
        setCompositionTask(this.GA ? qsH.YFl(getContext(), str) : qsH.YFl(getContext(), str, (String) null));
    }

    private void setCompositionTask(GA<DSW> ga) {
        this.pDU.add(AlY.SET_ANIMATION);
        lG();
        GA();
        this.rkt = ga.YFl(this.tN).tN(this.AlY);
    }

    private void GA() {
        GA<DSW> ga = this.rkt;
        if (ga != null) {
            ga.Sg(this.tN);
            this.rkt.AlY(this.AlY);
        }
    }

    private com.bytedance.adsdk.Sg.tN.tN.tN YFl(com.bytedance.adsdk.Sg.tN.tN.Sg sg, String str) {
        for (com.bytedance.adsdk.Sg.tN.tN.YFl yFl : sg.YoT()) {
            if (yFl instanceof com.bytedance.adsdk.Sg.tN.tN.Sg) {
                com.bytedance.adsdk.Sg.tN.tN.tN YFl2 = YFl((com.bytedance.adsdk.Sg.tN.tN.Sg) yFl, str);
                if (YFl2 != null) {
                    return YFl2;
                }
            } else if (TextUtils.equals(str, yFl.NjR()) && (yFl instanceof com.bytedance.adsdk.Sg.tN.tN.tN)) {
                return (com.bytedance.adsdk.Sg.tN.tN.tN) yFl;
            }
        }
        return null;
    }

    private com.bytedance.adsdk.Sg.tN.tN.tN tN(String str) {
        com.bytedance.adsdk.Sg.tN.tN.Sg YFl2;
        NjR njR = this.DSW;
        if (njR == null || (YFl2 = njR.YFl()) == null) {
            return null;
        }
        return YFl(YFl2, str);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void pDU() {
        NjR njR;
        int i;
        int i2;
        final int i3;
        if (this.lG == null || (njR = this.DSW) == null) {
            return;
        }
        aIu Ne = njR.Ne();
        DSW.tN qsH = this.lG.qsH();
        if (qsH == null || Ne == null) {
            return;
        }
        final int i4 = qsH.YFl;
        if (i4 < 0) {
            Log.i("TMe", "--==--- timer fail, ke is invalid: ".concat(String.valueOf(i4)));
            return;
        }
        final int i5 = -1;
        if (qsH.wN == null || qsH.wN.length < 2) {
            i = -1;
            i2 = -1;
        } else {
            i = qsH.wN[0];
            i2 = qsH.wN[1];
        }
        String YFl2 = Ne.YFl(qsH.tN);
        String YFl3 = Ne.YFl(qsH.AlY);
        try {
            i3 = Integer.parseInt(YFl2);
            try {
                i5 = Integer.parseInt(YFl3);
            } catch (NumberFormatException unused) {
            }
        } catch (NumberFormatException unused2) {
            i3 = -1;
        }
        Log.i("TMe", "--==--- prepare timer, startS: " + i3 + ", lenS: " + i5);
        if (!TextUtils.isEmpty(qsH.Sg)) {
            Log.i("TMe", "--==--- timer, id:" + qsH.Sg);
            com.bytedance.adsdk.Sg.tN.tN.tN tN2 = tN(qsH.Sg);
            if (tN2 != null) {
                Log.i("TMe", "--==--- timer success");
                this.YI = qsH.vc;
                this.wXo = tN2;
                this.Ne = i3;
                this.VOe = i3 - i5;
                this.bZ = i;
                this.UZM = i2;
                YFl(new ValueAnimator.AnimatorUpdateListener() { // from class: com.bytedance.adsdk.Sg.vc.2
                    @Override // android.animation.ValueAnimator.AnimatorUpdateListener
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        if (vc.this.getFrame() < i4 - 1 || vc.this.getFrame() >= i4 + 2) {
                            return;
                        }
                        Log.i("TMe", "--==--- enter timer point, frame: " + vc.this.getFrame());
                        vc.this.Sg(this);
                        if (i3 >= 0 && i5 >= 0) {
                            Log.i("TMe", "--==--- enter timer callback, start timer");
                            vc.this.EH();
                        } else {
                            Log.i("TMe", "--==--- enter timer callback, NOT start timer");
                        }
                        vc.this.vc();
                    }
                });
                return;
            }
            return;
        }
        Log.i("TMe", "--==--- timer fail, id is invalid: " + qsH.Sg);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void EH() {
        this.Wwa.postDelayed(this.Ga, 1000L);
    }

    private void rkt() {
        this.Wwa.removeCallbacksAndMessages(null);
    }

    public void setComposition(DSW dsw) {
        if (wN.YFl) {
            Log.v(YFl, "Set Composition \n".concat(String.valueOf(dsw)));
        }
        this.DSW.setCallback(this);
        this.lG = dsw;
        this.eT = true;
        boolean YFl2 = this.DSW.YFl(dsw, getContext().getApplicationContext());
        this.eT = false;
        if (getDrawable() != this.DSW || YFl2) {
            if (!YFl2) {
                Wwa();
            }
            onVisibilityChanged(this, getVisibility());
            requestLayout();
            Iterator<Object> it = this.EH.iterator();
            while (it.hasNext()) {
                it.next();
            }
        }
    }

    public void YFl() {
        this.pDU.add(AlY.PLAY_OPTION);
        this.DSW.NjR();
        if (this.aIu == 0) {
            this.aIu = SystemClock.elapsedRealtime();
        }
    }

    public void setMinFrame(int i) {
        this.DSW.YFl(i);
    }

    public float getMinFrame() {
        return this.DSW.YoT();
    }

    public void setMinProgress(float f) {
        this.DSW.YFl(f);
    }

    public void setMaxFrame(int i) {
        this.DSW.Sg(i);
    }

    public float getMaxFrame() {
        return this.DSW.GA();
    }

    public void setMaxProgress(float f) {
        this.DSW.Sg(f);
    }

    public void setMinFrame(String str) {
        this.DSW.Sg(str);
    }

    public void setMaxFrame(String str) {
        this.DSW.tN(str);
    }

    public void setMinAndMaxFrame(String str) {
        this.DSW.AlY(str);
    }

    public void setSpeed(float f) {
        this.DSW.tN(f);
    }

    public float getSpeed() {
        return this.DSW.pDU();
    }

    public void YFl(ValueAnimator.AnimatorUpdateListener animatorUpdateListener) {
        this.DSW.YFl(animatorUpdateListener);
    }

    public void Sg(ValueAnimator.AnimatorUpdateListener animatorUpdateListener) {
        this.DSW.Sg(animatorUpdateListener);
    }

    public void Sg() {
        this.DSW.EH();
    }

    public void YFl(Animator.AnimatorListener animatorListener) {
        this.DSW.YFl(animatorListener);
    }

    public void Sg(Animator.AnimatorListener animatorListener) {
        this.DSW.Sg(animatorListener);
    }

    public void tN() {
        this.DSW.rkt();
    }

    @Deprecated
    public void YFl(boolean z) {
        this.DSW.wN(z ? -1 : 0);
    }

    public void setRepeatMode(int i) {
        this.pDU.add(AlY.SET_REPEAT_MODE);
        this.DSW.AlY(i);
    }

    public int getRepeatMode() {
        return this.DSW.Wwa();
    }

    public void setRepeatCount(int i) {
        this.pDU.add(AlY.SET_REPEAT_COUNT);
        this.DSW.wN(i);
    }

    public int getRepeatCount() {
        return this.DSW.qO();
    }

    public boolean AlY() {
        return this.DSW.aIu();
    }

    public void setImageAssetsFolder(String str) {
        this.DSW.YFl(str);
    }

    public String getImageAssetsFolder() {
        return this.DSW.tN();
    }

    public void setMaintainOriginalImageBounds(boolean z) {
        this.DSW.Sg(z);
    }

    public boolean getMaintainOriginalImageBounds() {
        return this.DSW.AlY();
    }

    public Bitmap YFl(String str, Bitmap bitmap) {
        return this.DSW.YFl(str, bitmap);
    }

    public void setImageAssetDelegate(com.bytedance.adsdk.Sg.AlY alY) {
        this.DSW.YFl(alY);
    }

    public void setDefaultFontFileExtension(String str) {
        this.DSW.DSW(str);
    }

    public void setFontAssetDelegate(com.bytedance.adsdk.Sg.tN tNVar) {
        this.DSW.YFl(tNVar);
    }

    public void setFontMap(Map<String, Typeface> map) {
        this.DSW.YFl(map);
    }

    public void setTextDelegate(aIu aiu) {
        this.DSW.YFl(aiu);
    }

    public void wN() {
        this.pDU.add(AlY.PLAY_OPTION);
        this.DSW.UZM();
    }

    public void vc() {
        this.YoT = false;
        this.DSW.YI();
    }

    public void setFrame(int i) {
        this.DSW.tN(i);
    }

    public int getFrame() {
        return this.DSW.lG();
    }

    public void setProgress(float f) {
        YFl(f, true);
    }

    private void YFl(float f, boolean z) {
        if (z) {
            this.pDU.add(AlY.SET_PROGRESS);
        }
        this.DSW.AlY(f);
    }

    public float getProgress() {
        return this.DSW.Ga();
    }

    public long getDuration() {
        DSW dsw = this.lG;
        if (dsw != null) {
            return dsw.wN();
        }
        return 0L;
    }

    public void setPerformanceTrackingEnabled(boolean z) {
        this.DSW.tN(z);
    }

    public Wwa getPerformanceTracker() {
        return this.DSW.vc();
    }

    private void lG() {
        this.lG = null;
        this.DSW.qsH();
    }

    public void setSafeMode(boolean z) {
        this.DSW.vc(z);
    }

    public void setRenderMode(qO qOVar) {
        this.DSW.YFl(qOVar);
    }

    public qO getRenderMode() {
        return this.DSW.wN();
    }

    public void setApplyingOpacityToLayersEnabled(boolean z) {
        this.DSW.wN(z);
    }

    private void Wwa() {
        boolean AlY2 = AlY();
        setImageDrawable(null);
        setImageDrawable(this.DSW);
        if (AlY2) {
            this.DSW.eT();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes2.dex */
    public static class tN extends View.BaseSavedState {
        public static final Parcelable.Creator<tN> CREATOR = new Parcelable.Creator<tN>() { // from class: com.bytedance.adsdk.Sg.vc.tN.1
            @Override // android.os.Parcelable.Creator
            /* renamed from: YFl */
            public tN createFromParcel(Parcel parcel) {
                return new tN(parcel);
            }

            @Override // android.os.Parcelable.Creator
            /* renamed from: YFl */
            public tN[] newArray(int i) {
                return new tN[i];
            }
        };
        boolean AlY;
        int DSW;
        int Sg;
        String YFl;
        float tN;
        int vc;
        String wN;

        tN(Parcelable parcelable) {
            super(parcelable);
        }

        private tN(Parcel parcel) {
            super(parcel);
            this.YFl = parcel.readString();
            this.tN = parcel.readFloat();
            this.AlY = parcel.readInt() == 1;
            this.wN = parcel.readString();
            this.vc = parcel.readInt();
            this.DSW = parcel.readInt();
        }

        @Override // android.view.View.BaseSavedState, android.view.AbsSavedState, android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i) {
            super.writeToParcel(parcel, i);
            parcel.writeString(this.YFl);
            parcel.writeFloat(this.tN);
            parcel.writeInt(this.AlY ? 1 : 0);
            parcel.writeString(this.wN);
            parcel.writeInt(this.vc);
            parcel.writeInt(this.DSW);
        }
    }
}
