package com.bytedance.sdk.component.adexpress.vc;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;
import com.bytedance.sdk.component.utils.bZ;
import java.util.ArrayList;
import java.util.List;
/* loaded from: classes2.dex */
public class YFl extends TextSwitcher implements ViewSwitcher.ViewFactory, bZ.YFl {
    private final int AlY;
    private int DSW;
    private int GA;
    private float NjR;
    private List<String> Sg;
    Animation.AnimationListener YFl;
    private int YoT;
    private int eT;
    private int nc;
    private Handler pDU;
    private int qsH;
    private int tN;
    private TextView vc;
    private Context wN;

    public void setAnimationDuration(int i) {
        this.DSW = i;
    }

    public void setAnimationText(List<String> list) {
        this.Sg = list;
    }

    public void setAnimationType(int i) {
        this.YoT = i;
    }

    public void setMaxLines(int i) {
        this.nc = i;
    }

    public void setTextColor(int i) {
        this.qsH = i;
    }

    public void setTextSize(float f) {
        this.NjR = f;
    }

    public YFl(Context context, int i, float f, int i2, int i3) {
        super(context);
        this.Sg = new ArrayList();
        this.tN = 0;
        this.AlY = 1;
        this.pDU = new com.bytedance.sdk.component.utils.bZ(Looper.getMainLooper(), this);
        this.YFl = new Animation.AnimationListener() { // from class: com.bytedance.sdk.component.adexpress.vc.YFl.1
            @Override // android.view.animation.Animation.AnimationListener
            public void onAnimationRepeat(Animation animation) {
            }

            @Override // android.view.animation.Animation.AnimationListener
            public void onAnimationStart(Animation animation) {
            }

            @Override // android.view.animation.Animation.AnimationListener
            public void onAnimationEnd(Animation animation) {
                if (YFl.this.vc != null) {
                    YFl.this.vc.setText("");
                }
            }
        };
        this.wN = context;
        this.qsH = i;
        this.NjR = f;
        this.nc = i2;
        this.GA = i3;
        tN();
    }

    private void tN() {
        setFactory(this);
    }

    public void YFl() {
        int i = this.YoT;
        if (i == 1) {
            setInAnimation(getContext(), com.bytedance.sdk.component.utils.qO.NjR(this.wN, "tt_text_animation_y_in"));
            setOutAnimation(getContext(), com.bytedance.sdk.component.utils.qO.NjR(this.wN, "tt_text_animation_y_out"));
        } else if (i == 0) {
            setInAnimation(getContext(), com.bytedance.sdk.component.utils.qO.NjR(this.wN, "tt_text_animation_x_in"));
            setOutAnimation(getContext(), com.bytedance.sdk.component.utils.qO.NjR(this.wN, "tt_text_animation_x_in"));
            getInAnimation().setInterpolator(new LinearInterpolator());
            getOutAnimation().setInterpolator(new LinearInterpolator());
            getInAnimation().setAnimationListener(this.YFl);
            getOutAnimation().setAnimationListener(this.YFl);
        }
        this.pDU.sendEmptyMessage(1);
    }

    public void Sg() {
        List<String> list = this.Sg;
        if (list == null || list.size() <= 0) {
            return;
        }
        int i = this.tN;
        this.tN = i + 1;
        this.eT = i;
        setText(this.Sg.get(i));
        if (this.tN > this.Sg.size() - 1) {
            this.tN = 0;
        }
    }

    @Override // android.widget.ViewSwitcher.ViewFactory
    public View makeView() {
        TextView textView = new TextView(getContext());
        this.vc = textView;
        textView.setTextColor(this.qsH);
        this.vc.setTextSize(this.NjR);
        this.vc.setMaxLines(this.nc);
        this.vc.setTextAlignment(this.GA);
        return this.vc;
    }

    @Override // com.bytedance.sdk.component.utils.bZ.YFl
    public void YFl(Message message) {
        if (message.what != 1) {
            return;
        }
        Sg();
        this.pDU.sendEmptyMessageDelayed(1, this.DSW);
    }

    @Override // android.widget.FrameLayout, android.view.View
    protected void onMeasure(int i, int i2) {
        try {
            super.onMeasure(View.MeasureSpec.makeMeasureSpec(com.bytedance.sdk.component.adexpress.dynamic.wN.eT.Sg(this.Sg.get(this.eT), this.NjR, false)[0], 1073741824), i);
        } catch (Exception unused) {
            super.onMeasure(i, i2);
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.pDU.removeMessages(1);
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        this.pDU.sendEmptyMessageDelayed(1, this.DSW);
    }
}
