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

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.mq;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class fm extends TextSwitcher implements ViewSwitcher.ViewFactory, mq.fm {
    private TextView ajl;
    private int dsz;
    private int duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private float f6436ef;
    Animation.AnimationListener fm;
    private Context jnr;
    private int ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private int f6437lb;
    private Handler onz;
    private List<String> ro;
    private int vt;
    private int wsy;
    private int wu;
    private final int yz;

    public fm(Context context, int i10, float f10, int i11, int i12) {
        super(context);
        this.ro = new ArrayList();
        this.f6437lb = 0;
        this.yz = 1;
        this.onz = new mq(Looper.getMainLooper(), this);
        this.fm = new Animation.AnimationListener() { // from class: com.bytedance.sdk.component.adexpress.ajl.fm.1
            @Override // android.view.animation.Animation.AnimationListener
            public void onAnimationEnd(Animation animation) {
                if (fm.this.ajl != null) {
                    fm.this.ajl.setText("");
                }
            }

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

            @Override // android.view.animation.Animation.AnimationListener
            public void onAnimationStart(Animation animation) {
            }
        };
        this.jnr = context;
        this.wu = i10;
        this.f6436ef = f10;
        this.vt = i11;
        this.dsz = i12;
        lb();
    }

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

    @Override // android.widget.ViewSwitcher.ViewFactory
    public View makeView() {
        TextView textView = new TextView(getContext());
        this.ajl = textView;
        textView.setTextColor(this.wu);
        this.ajl.setTextSize(this.f6436ef);
        this.ajl.setMaxLines(this.vt);
        this.ajl.setTextAlignment(this.dsz);
        return this.ajl;
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        this.onz.sendEmptyMessageDelayed(1, this.wsy);
    }

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

    @Override // android.widget.FrameLayout, android.view.View
    public void onMeasure(int i10, int i11) {
        try {
            super.onMeasure(View.MeasureSpec.makeMeasureSpec(com.bytedance.sdk.component.adexpress.dynamic.jnr.ku.ro(this.ro.get(this.ku), this.f6436ef, false)[0], 1073741824), i10);
        } catch (Exception unused) {
            super.onMeasure(i10, i11);
        }
    }

    public void ro() {
        List<String> list = this.ro;
        if (list == null || list.size() <= 0) {
            return;
        }
        int i10 = this.f6437lb;
        this.f6437lb = i10 + 1;
        this.ku = i10;
        setText(this.ro.get(i10));
        if (this.f6437lb > this.ro.size() - 1) {
            this.f6437lb = 0;
        }
    }

    public void setAnimationDuration(int i10) {
        this.wsy = i10;
    }

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

    public void setAnimationType(int i10) {
        this.duv = i10;
    }

    public void setMaxLines(int i10) {
        this.vt = i10;
    }

    public void setTextColor(int i10) {
        this.wu = i10;
    }

    public void setTextSize(float f10) {
        this.f6436ef = f10;
    }

    public void fm() {
        int i10 = this.duv;
        if (i10 == 1) {
            setInAnimation(getContext(), com.bytedance.sdk.component.utils.maa.ef(this.jnr, "tt_text_animation_y_in"));
            setOutAnimation(getContext(), com.bytedance.sdk.component.utils.maa.ef(this.jnr, "tt_text_animation_y_out"));
        } else if (i10 == 0) {
            setInAnimation(getContext(), com.bytedance.sdk.component.utils.maa.ef(this.jnr, "tt_text_animation_x_in"));
            setOutAnimation(getContext(), com.bytedance.sdk.component.utils.maa.ef(this.jnr, "tt_text_animation_x_in"));
            getInAnimation().setInterpolator(new LinearInterpolator());
            getOutAnimation().setInterpolator(new LinearInterpolator());
            getInAnimation().setAnimationListener(this.fm);
            getOutAnimation().setAnimationListener(this.fm);
        }
        this.onz.sendEmptyMessage(1);
    }

    @Override // com.bytedance.sdk.component.utils.mq.fm
    public void fm(Message message) {
        if (message.what != 1) {
            return;
        }
        ro();
        this.onz.sendEmptyMessageDelayed(1, this.wsy);
    }
}
