package com.bytedance.sdk.openadsdk.lb;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.ViewGroup;
import com.bytedance.sdk.openadsdk.utils.zan;

/* JADX INFO: loaded from: classes2.dex */
public class fm extends com.bytedance.sdk.openadsdk.core.ajl.wu {
    private Paint fm;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private boolean f7448lb;
    private float ro;
    private int yz;

    public fm(Context context) {
        super(context);
        fm();
    }

    private void fm() {
        this.ro = zan.fm(getContext(), 8.0f);
        this.fm = new Paint();
    }

    @Override // android.widget.TextView, android.view.View
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        fm(getText().toString(), getWidth());
    }

    @Override // com.bytedance.sdk.openadsdk.core.ajl.wu, android.widget.TextView, android.view.View
    public void onMeasure(int i10, int i11) {
        super.onMeasure(i10, i11);
        this.yz = getMeasuredHeight();
        ViewGroup.LayoutParams layoutParams = getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new ViewGroup.LayoutParams(-2, this.yz);
        } else {
            layoutParams.height = this.yz;
        }
        setLayoutParams(layoutParams);
    }

    @Override // com.bytedance.sdk.openadsdk.core.ajl.wu, android.view.View
    public void setLayoutParams(ViewGroup.LayoutParams layoutParams) {
        super.setLayoutParams(layoutParams);
        int i10 = this.yz;
        if (i10 == 0 || layoutParams == null) {
            return;
        }
        layoutParams.height = i10;
    }

    public void setMinTextSize(float f10) {
        if (f10 <= 0.0f) {
            return;
        }
        this.ro = f10;
    }

    private void fm(String str, int i10) {
        if (!this.f7448lb && i10 > 0) {
            float textSize = getTextSize();
            this.fm.set(getPaint());
            int paddingLeft = (i10 - getPaddingLeft()) - getPaddingRight();
            float fFm = fm(textSize, str);
            while (fFm > paddingLeft) {
                textSize -= 1.0f;
                this.fm.setTextSize(textSize);
                if (textSize <= this.ro) {
                    break;
                } else {
                    fFm = fm(textSize, str);
                }
            }
            setTextSize(0, textSize);
            this.f7448lb = true;
        }
    }

    private float fm(float f10, String str) {
        this.fm.setTextSize(f10);
        return this.fm.measureText(str);
    }
}
