package androidx.leanback.widget;

import android.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.text.Layout;
import android.util.AttributeSet;
import android.view.ActionMode;
import android.widget.TextView;

/* JADX INFO: loaded from: classes.dex */
@SuppressLint({"AppCompatCustomView"})
class ResizingTextView extends TextView {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final int f8526q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final int f8527r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final boolean f8528s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final int f8529t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final int f8530u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public boolean f8531v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public int f8532w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public float f8533x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public int f8534y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public int f8535z;

    public ResizingTextView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet, R.attr.textViewStyle);
        this.f8531v = false;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, k0.a.f13745f, R.attr.textViewStyle, 0);
        try {
            this.f8526q = typedArrayObtainStyledAttributes.getInt(1, 1);
            this.f8527r = typedArrayObtainStyledAttributes.getDimensionPixelSize(4, -1);
            this.f8528s = typedArrayObtainStyledAttributes.getBoolean(0, false);
            this.f8529t = typedArrayObtainStyledAttributes.getDimensionPixelOffset(3, 0);
            this.f8530u = typedArrayObtainStyledAttributes.getDimensionPixelOffset(2, 0);
        } finally {
            typedArrayObtainStyledAttributes.recycle();
        }
    }

    public final void a(int i, int i5) {
        if (isPaddingRelative()) {
            setPaddingRelative(getPaddingStart(), i, getPaddingEnd(), i5);
        } else {
            setPadding(getPaddingLeft(), i, getPaddingRight(), i5);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0053  */
    /* JADX WARN: Removed duplicated region for block: B:42:0x00cd A[PHI: r2
      0x00cd: PHI (r2v6 boolean) = (r2v2 boolean), (r2v8 boolean) binds: [B:40:0x00ca, B:27:0x0097] A[DONT_GENERATE, DONT_INLINE]] */
    @Override // android.widget.TextView, android.view.View
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void onMeasure(int i, int i5) {
        boolean z8;
        int i8;
        boolean z9 = true;
        if (!this.f8531v) {
            this.f8532w = (int) getTextSize();
            this.f8533x = getLineSpacingExtra();
            this.f8534y = getPaddingTop();
            this.f8535z = getPaddingBottom();
            this.f8531v = true;
        }
        boolean z10 = false;
        setTextSize(0, this.f8532w);
        setLineSpacing(this.f8533x, getLineSpacingMultiplier());
        a(this.f8534y, this.f8535z);
        super.onMeasure(i, i5);
        Layout layout = getLayout();
        if (layout == null || (this.f8526q & 1) <= 0) {
            z8 = false;
        } else {
            int lineCount = layout.getLineCount();
            int maxLines = getMaxLines();
            if (maxLines > 1 && lineCount == maxLines) {
                z8 = true;
            }
        }
        int textSize = (int) getTextSize();
        boolean z11 = this.f8528s;
        int i9 = this.f8527r;
        if (z8) {
            if (i9 != -1 && textSize != i9) {
                setTextSize(0, i9);
                z10 = true;
            }
            float f3 = (this.f8533x + this.f8532w) - i9;
            if (z11 && getLineSpacingExtra() != f3) {
                setLineSpacing(f3, getLineSpacingMultiplier());
                z10 = true;
            }
            int i10 = this.f8534y + this.f8529t;
            int i11 = this.f8535z + this.f8530u;
            if (getPaddingTop() == i10 && getPaddingBottom() == i11) {
                z9 = z10;
            } else {
                a(i10, i11);
            }
        } else {
            if (i9 != -1 && textSize != (i8 = this.f8532w)) {
                setTextSize(0, i8);
                z10 = true;
            }
            if (z11) {
                float lineSpacingExtra = getLineSpacingExtra();
                float f7 = this.f8533x;
                if (lineSpacingExtra != f7) {
                    setLineSpacing(f7, getLineSpacingMultiplier());
                    z10 = true;
                }
            }
            if (getPaddingTop() != this.f8534y || getPaddingBottom() != this.f8535z) {
                a(this.f8534y, this.f8535z);
            }
        }
        if (z9) {
            super.onMeasure(i, i5);
        }
    }

    @Override // android.widget.TextView
    public final void setCustomSelectionActionModeCallback(ActionMode.Callback callback) {
        super.setCustomSelectionActionModeCallback(W3.b.A(callback, this));
    }
}
