package com.bytedance.adsdk.ugeno.ef.ajl;

import android.content.Context;
import android.graphics.Canvas;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.widget.TextView;
import com.bytedance.adsdk.ugeno.core.IAnimation;
import com.bytedance.adsdk.ugeno.fm.wsy;
import com.bytedance.adsdk.ugeno.fm.wu;
import com.bytedance.adsdk.ugeno.yz;

/* JADX INFO: loaded from: classes.dex */
public class fm extends TextView implements IAnimation, wsy {
    private float ajl;
    private yz fm;
    private float jnr;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private wu f6328lb;
    private float ro;
    private float wsy;
    private float yz;

    public fm(Context context) {
        super(context);
        this.yz = -1.0f;
        this.ajl = 1.0f;
        this.wsy = 0.0f;
        this.f6328lb = new wu(this);
    }

    @Override // android.view.View
    public void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        yz yzVar = this.fm;
        if (yzVar != null) {
            yzVar.ro(canvas);
        }
    }

    public void fm(yz yzVar) {
        this.fm = yzVar;
    }

    public float getBorderRadius() {
        return this.f6328lb.fm();
    }

    @Override // com.bytedance.adsdk.ugeno.core.IAnimation, com.bytedance.adsdk.ugeno.fm.wsy
    public float getRipple() {
        return this.ro;
    }

    @Override // com.bytedance.adsdk.ugeno.fm.wsy
    public float getRubIn() {
        return this.f6328lb.getRubIn();
    }

    @Override // com.bytedance.adsdk.ugeno.fm.wsy
    public float getShine() {
        return this.f6328lb.getShine();
    }

    @Override // com.bytedance.adsdk.ugeno.fm.wsy
    public float getStretch() {
        return this.f6328lb.getStretch();
    }

    @Override // android.widget.TextView, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        yz yzVar = this.fm;
        if (yzVar != null) {
            yzVar.wsy();
        }
    }

    @Override // android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        yz yzVar = this.fm;
        if (yzVar != null) {
            yzVar.wu();
        }
    }

    @Override // android.widget.TextView, android.view.View
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        yz yzVar = this.fm;
        if (yzVar != null) {
            yzVar.fm(canvas, this);
            this.fm.fm(canvas);
        }
    }

    @Override // android.widget.TextView, android.view.View
    public void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        yz yzVar = this.fm;
        if (yzVar != null) {
            yzVar.fm(i10, i11, i12, i13);
        }
        if (z10 && this.yz > 0.0f) {
            fm(((i12 - i10) - getCompoundPaddingLeft()) - getCompoundPaddingRight(), ((i13 - i11) - getCompoundPaddingBottom()) - getCompoundPaddingTop());
        }
        super.onLayout(z10, i10, i11, i12, i13);
    }

    @Override // android.widget.TextView, android.view.View
    public void onMeasure(int i10, int i11) {
        yz yzVar = this.fm;
        if (yzVar == null) {
            super.onMeasure(i10, i11);
        } else {
            int[] iArrFm = yzVar.fm(i10, i11);
            super.onMeasure(iArrFm[0], iArrFm[1]);
        }
    }

    @Override // android.view.View
    public void onSizeChanged(int i10, int i11, int i12, int i13) {
        super.onSizeChanged(i10, i11, i12, i13);
        yz yzVar = this.fm;
        if (yzVar != null) {
            yzVar.ro(i10, i11, i12, i12);
        }
    }

    @Override // android.widget.TextView, android.view.View
    public void onWindowFocusChanged(boolean z10) {
        super.onWindowFocusChanged(z10);
    }

    @Override // android.view.View
    public void setBackgroundColor(int i10) {
        this.f6328lb.fm(i10);
    }

    public void setBorderRadius(float f10) {
        wu wuVar = this.f6328lb;
        if (wuVar != null) {
            wuVar.fm(f10);
        }
    }

    @Override // android.widget.TextView
    public void setLineSpacing(float f10, float f11) {
        super.setLineSpacing(f10, f11);
        this.ajl = f11;
        this.wsy = f10;
    }

    public void setMinTextSize(float f10) {
        this.yz = f10;
    }

    @Override // com.bytedance.adsdk.ugeno.core.IAnimation
    public void setRipple(float f10) {
        this.ro = f10;
        wu wuVar = this.f6328lb;
        if (wuVar != null) {
            wuVar.ro(f10);
        }
        postInvalidate();
    }

    public void setRubIn(float f10) {
        wu wuVar = this.f6328lb;
        if (wuVar != null) {
            wuVar.jnr(f10);
        }
    }

    public void setShine(float f10) {
        wu wuVar = this.f6328lb;
        if (wuVar != null) {
            wuVar.lb(f10);
        }
    }

    public void setStretch(float f10) {
        wu wuVar = this.f6328lb;
        if (wuVar != null) {
            wuVar.yz(f10);
        }
    }

    @Override // android.widget.TextView
    public void setTextSize(float f10) {
        super.setTextSize(f10);
        this.jnr = getTextSize();
    }

    private void fm(int i10, int i11) {
        CharSequence text = getText();
        if (text == null || text.length() == 0 || i11 <= 0 || i10 <= 0 || this.jnr == 0.0f) {
            return;
        }
        TextPaint paint = getPaint();
        float fMax = this.jnr;
        int iFm = fm(text, paint, i10, fMax);
        while (iFm > i11) {
            float f10 = this.yz;
            if (fMax <= f10) {
                break;
            }
            fMax = Math.max(fMax - 1.0f, f10);
            iFm = fm(text, paint, i10, fMax);
        }
        "resizeText: targetSize: ".concat(String.valueOf(fMax));
        setTextSize(0, fMax);
        setLineSpacing(this.wsy, this.ajl);
    }

    @Override // android.widget.TextView
    public void setTextSize(int i10, float f10) {
        super.setTextSize(i10, f10);
        this.jnr = getTextSize();
    }

    private int fm(CharSequence charSequence, TextPaint textPaint, int i10, float f10) {
        TextPaint textPaint2 = new TextPaint(textPaint);
        textPaint2.setTextSize(f10);
        return new StaticLayout(charSequence, textPaint2, i10, Layout.Alignment.ALIGN_NORMAL, this.ajl, this.wsy, true).getHeight();
    }
}
