package com.google.android.material.internal;

import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextDirectionHeuristics;
import android.text.TextPaint;
import android.text.TextUtils;
import com.google.android.gms.common.api.Api;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;

/* loaded from: classes3.dex */
final class k {

    /* renamed from: n, reason: collision with root package name */
    static final int f13362n = 1;

    /* renamed from: a, reason: collision with root package name */
    private CharSequence f13363a;

    /* renamed from: b, reason: collision with root package name */
    private final TextPaint f13364b;

    /* renamed from: c, reason: collision with root package name */
    private final int f13365c;

    /* renamed from: e, reason: collision with root package name */
    private int f13367e;

    /* renamed from: l, reason: collision with root package name */
    private boolean f13374l;

    /* renamed from: d, reason: collision with root package name */
    private int f13366d = 0;

    /* renamed from: f, reason: collision with root package name */
    private Layout.Alignment f13368f = Layout.Alignment.ALIGN_NORMAL;

    /* renamed from: g, reason: collision with root package name */
    private int f13369g = Api.BaseClientBuilder.API_PRIORITY_OTHER;

    /* renamed from: h, reason: collision with root package name */
    private float f13370h = BitmapDescriptorFactory.HUE_RED;

    /* renamed from: i, reason: collision with root package name */
    private float f13371i = 1.0f;

    /* renamed from: j, reason: collision with root package name */
    private int f13372j = f13362n;

    /* renamed from: k, reason: collision with root package name */
    private boolean f13373k = true;

    /* renamed from: m, reason: collision with root package name */
    private TextUtils.TruncateAt f13375m = null;

    /* loaded from: classes3.dex */
    static class a extends Exception {
    }

    private k(CharSequence charSequence, TextPaint textPaint, int i10) {
        this.f13363a = charSequence;
        this.f13364b = textPaint;
        this.f13365c = i10;
        this.f13367e = charSequence.length();
    }

    public static k b(CharSequence charSequence, TextPaint textPaint, int i10) {
        return new k(charSequence, textPaint, i10);
    }

    public StaticLayout a() {
        if (this.f13363a == null) {
            this.f13363a = "";
        }
        int max = Math.max(0, this.f13365c);
        CharSequence charSequence = this.f13363a;
        if (this.f13369g == 1) {
            charSequence = TextUtils.ellipsize(charSequence, this.f13364b, max, this.f13375m);
        }
        int min = Math.min(charSequence.length(), this.f13367e);
        this.f13367e = min;
        if (this.f13374l && this.f13369g == 1) {
            this.f13368f = Layout.Alignment.ALIGN_OPPOSITE;
        }
        StaticLayout.Builder obtain = StaticLayout.Builder.obtain(charSequence, this.f13366d, min, this.f13364b, max);
        obtain.setAlignment(this.f13368f);
        obtain.setIncludePad(this.f13373k);
        obtain.setTextDirection(this.f13374l ? TextDirectionHeuristics.RTL : TextDirectionHeuristics.LTR);
        TextUtils.TruncateAt truncateAt = this.f13375m;
        if (truncateAt != null) {
            obtain.setEllipsize(truncateAt);
        }
        obtain.setMaxLines(this.f13369g);
        float f10 = this.f13370h;
        if (f10 != BitmapDescriptorFactory.HUE_RED || this.f13371i != 1.0f) {
            obtain.setLineSpacing(f10, this.f13371i);
        }
        if (this.f13369g > 1) {
            obtain.setHyphenationFrequency(this.f13372j);
        }
        return obtain.build();
    }

    public k c(Layout.Alignment alignment) {
        this.f13368f = alignment;
        return this;
    }

    public k d(TextUtils.TruncateAt truncateAt) {
        this.f13375m = truncateAt;
        return this;
    }

    public k e(int i10) {
        this.f13372j = i10;
        return this;
    }

    public k f(boolean z10) {
        this.f13373k = z10;
        return this;
    }

    public k g(boolean z10) {
        this.f13374l = z10;
        return this;
    }

    public k h(float f10, float f11) {
        this.f13370h = f10;
        this.f13371i = f11;
        return this;
    }

    public k i(int i10) {
        this.f13369g = i10;
        return this;
    }
}
