package com.google.android.material.internal; import android.R; import android.animation.TimeInterpolator; import android.content.res.ColorStateList; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Typeface; import android.os.Build; import android.text.TextPaint; import android.text.TextUtils; import android.view.View; import androidx.appcompat.R$styleable; import androidx.appcompat.widget.TintTypedArray; import androidx.core.math.MathUtils; import androidx.core.text.TextDirectionHeuristicsCompat; import androidx.core.view.GravityCompat; import androidx.core.view.ViewCompat; import com.google.android.material.animation.AnimationUtils; /* loaded from: classes.dex */ public final class CollapsingTextHelper { private static final boolean T; private static final Paint U; private Paint A; private float B; private float C; private float D; private float E; private int[] F; private boolean G; private TimeInterpolator J; private TimeInterpolator K; private float L; private float M; private float N; private int O; private float P; private float Q; private float R; private int S; private final View a; private boolean b; private float c; private ColorStateList k; private ColorStateList l; private float m; private float n; private float o; private float p; private float q; private float r; private Typeface s; private Typeface t; private Typeface u; private CharSequence v; private CharSequence w; private boolean x; private boolean y; private Bitmap z; private int g = 16; private int h = 16; private float i = 15.0f; private float j = 15.0f; private final TextPaint H = new TextPaint(129); private final TextPaint I = new TextPaint(this.H); private final Rect e = new Rect(); private final Rect d = new Rect(); private final RectF f = new RectF(); static { T = Build.VERSION.SDK_INT < 18; U = null; Paint paint = U; if (paint != null) { paint.setAntiAlias(true); U.setColor(-65281); } } public CollapsingTextHelper(View view) { this.a = view; } private Typeface e(int i) { TypedArray obtainStyledAttributes = this.a.getContext().obtainStyledAttributes(i, new int[]{R.attr.fontFamily}); try { String string = obtainStyledAttributes.getString(0); if (string != null) { return Typeface.create(string, 0); } obtainStyledAttributes.recycle(); return null; } finally { obtainStyledAttributes.recycle(); } } private void n() { float f = this.E; d(this.j); CharSequence charSequence = this.w; float measureText = charSequence != null ? this.H.measureText(charSequence, 0, charSequence.length()) : 0.0f; int a = GravityCompat.a(this.h, this.x ? 1 : 0); int i = a & 112; if (i == 48) { this.n = this.e.top - this.H.ascent(); } else if (i != 80) { this.n = this.e.centerY() + (((this.H.descent() - this.H.ascent()) / 2.0f) - this.H.descent()); } else { this.n = this.e.bottom; } int i2 = a & 8388615; if (i2 == 1) { this.p = this.e.centerX() - (measureText / 2.0f); } else if (i2 != 5) { this.p = this.e.left; } else { this.p = this.e.right - measureText; } d(this.i); CharSequence charSequence2 = this.w; float measureText2 = charSequence2 != null ? this.H.measureText(charSequence2, 0, charSequence2.length()) : 0.0f; int a2 = GravityCompat.a(this.g, this.x ? 1 : 0); int i3 = a2 & 112; if (i3 == 48) { this.m = this.d.top - this.H.ascent(); } else if (i3 != 80) { this.m = this.d.centerY() + (((this.H.descent() - this.H.ascent()) / 2.0f) - this.H.descent()); } else { this.m = this.d.bottom; } int i4 = a2 & 8388615; if (i4 == 1) { this.o = this.d.centerX() - (measureText2 / 2.0f); } else if (i4 != 5) { this.o = this.d.left; } else { this.o = this.d.right - measureText2; } p(); f(f); } private void o() { c(this.c); } private void p() { Bitmap bitmap = this.z; if (bitmap != null) { bitmap.recycle(); this.z = null; } } private void q() { if (this.z != null || this.d.isEmpty() || TextUtils.isEmpty(this.w)) { return; } c(0.0f); this.B = this.H.ascent(); this.C = this.H.descent(); TextPaint textPaint = this.H; CharSequence charSequence = this.w; int round = Math.round(textPaint.measureText(charSequence, 0, charSequence.length())); int round2 = Math.round(this.C - this.B); if (round <= 0 || round2 <= 0) { return; } this.z = Bitmap.createBitmap(round, round2, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(this.z); CharSequence charSequence2 = this.w; canvas.drawText(charSequence2, 0, charSequence2.length(), 0.0f, round2 - this.H.descent(), this.H); if (this.A == null) { this.A = new Paint(3); } } private int r() { int[] iArr = this.F; return iArr != null ? this.k.getColorForState(iArr, 0) : this.k.getDefaultColor(); } public void a(TimeInterpolator timeInterpolator) { this.J = timeInterpolator; m(); } public void b(TimeInterpolator timeInterpolator) { this.K = timeInterpolator; m(); } public int c() { return this.h; } public float d() { a(this.I); return -this.I.ascent(); } public int f() { int[] iArr = this.F; return iArr != null ? this.l.getColorForState(iArr, 0) : this.l.getDefaultColor(); } public int g() { return this.g; } public Typeface h() { Typeface typeface = this.t; return typeface != null ? typeface : Typeface.DEFAULT; } public float i() { return this.c; } public CharSequence j() { return this.v; } public final boolean k() { ColorStateList colorStateList; ColorStateList colorStateList2 = this.l; return (colorStateList2 != null && colorStateList2.isStateful()) || ((colorStateList = this.k) != null && colorStateList.isStateful()); } void l() { this.b = this.e.width() > 0 && this.e.height() > 0 && this.d.width() > 0 && this.d.height() > 0; } public void m() { if (this.a.getHeight() <= 0 || this.a.getWidth() <= 0) { return; } n(); o(); } public void c(int i) { TintTypedArray a = TintTypedArray.a(this.a.getContext(), i, R$styleable.TextAppearance); if (a.g(R$styleable.TextAppearance_android_textColor)) { this.k = a.a(R$styleable.TextAppearance_android_textColor); } if (a.g(R$styleable.TextAppearance_android_textSize)) { this.i = a.c(R$styleable.TextAppearance_android_textSize, (int) this.i); } this.S = a.d(R$styleable.TextAppearance_android_shadowColor, 0); this.Q = a.b(R$styleable.TextAppearance_android_shadowDx, 0.0f); this.R = a.b(R$styleable.TextAppearance_android_shadowDy, 0.0f); this.P = a.b(R$styleable.TextAppearance_android_shadowRadius, 0.0f); a.a(); if (Build.VERSION.SDK_INT >= 16) { this.t = e(i); } m(); } public void a(float f) { if (this.i != f) { this.i = f; m(); } } public void b(ColorStateList colorStateList) { if (this.k != colorStateList) { this.k = colorStateList; m(); } } public void d(int i) { if (this.g != i) { this.g = i; m(); } } private void f(float f) { d(f); this.y = T && this.D != 1.0f; if (this.y) { q(); } ViewCompat.A(this.a); } private void d(float f) { float f2; boolean z; boolean z2; if (this.v == null) { return; } float width = this.e.width(); float width2 = this.d.width(); if (a(f, this.j)) { float f3 = this.j; this.D = 1.0f; Typeface typeface = this.u; Typeface typeface2 = this.s; if (typeface != typeface2) { this.u = typeface2; z2 = true; } else { z2 = false; } f2 = f3; z = z2; } else { f2 = this.i; Typeface typeface3 = this.u; Typeface typeface4 = this.t; if (typeface3 != typeface4) { this.u = typeface4; z = true; } else { z = false; } if (a(f, this.i)) { this.D = 1.0f; } else { this.D = f / this.i; } float f4 = this.j / this.i; width = width2 * f4 > width ? Math.min(width / f4, width2) : width2; } if (width > 0.0f) { z = this.E != f2 || this.G || z; this.E = f2; this.G = false; } if (this.w == null || z) { this.H.setTextSize(this.E); this.H.setTypeface(this.u); this.H.setLinearText(this.D != 1.0f); CharSequence ellipsize = TextUtils.ellipsize(this.v, this.H, width, TextUtils.TruncateAt.END); if (TextUtils.equals(ellipsize, this.w)) { return; } this.w = ellipsize; this.x = b(this.w); } } public void a(ColorStateList colorStateList) { if (this.l != colorStateList) { this.l = colorStateList; m(); } } public void b(int i, int i2, int i3, int i4) { if (a(this.d, i, i2, i3, i4)) { return; } this.d.set(i, i2, i3, i4); this.G = true; l(); } public Typeface e() { Typeface typeface = this.s; return typeface != null ? typeface : Typeface.DEFAULT; } private void e(float f) { this.f.left = a(this.d.left, this.e.left, f, this.J); this.f.top = a(this.m, this.n, f, this.J); this.f.right = a(this.d.right, this.e.right, f, this.J); this.f.bottom = a(this.d.bottom, this.e.bottom, f, this.J); } public void a(int i, int i2, int i3, int i4) { if (a(this.e, i, i2, i3, i4)) { return; } this.e.set(i, i2, i3, i4); this.G = true; l(); } public void b(int i) { if (this.h != i) { this.h = i; m(); } } public float a() { if (this.v == null) { return 0.0f; } a(this.I); TextPaint textPaint = this.I; CharSequence charSequence = this.v; return textPaint.measureText(charSequence, 0, charSequence.length()); } public void b(Typeface typeface) { if (this.t != typeface) { this.t = typeface; m(); } } public void a(RectF rectF) { boolean b = b(this.v); Rect rect = this.e; rectF.left = !b ? rect.left : rect.right - a(); Rect rect2 = this.e; rectF.top = rect2.top; rectF.right = !b ? rectF.left + a() : rect2.right; rectF.bottom = this.e.top + d(); } public void b(float f) { float a = MathUtils.a(f, 0.0f, 1.0f); if (a != this.c) { this.c = a; o(); } } private boolean b(CharSequence charSequence) { return (ViewCompat.k(this.a) == 1 ? TextDirectionHeuristicsCompat.b : TextDirectionHeuristicsCompat.a).a(charSequence, 0, charSequence.length()); } private void a(TextPaint textPaint) { textPaint.setTextSize(this.j); textPaint.setTypeface(this.s); } public void c(Typeface typeface) { this.t = typeface; this.s = typeface; m(); } public void a(int i) { TintTypedArray a = TintTypedArray.a(this.a.getContext(), i, R$styleable.TextAppearance); if (a.g(R$styleable.TextAppearance_android_textColor)) { this.l = a.a(R$styleable.TextAppearance_android_textColor); } if (a.g(R$styleable.TextAppearance_android_textSize)) { this.j = a.c(R$styleable.TextAppearance_android_textSize, (int) this.j); } this.O = a.d(R$styleable.TextAppearance_android_shadowColor, 0); this.M = a.b(R$styleable.TextAppearance_android_shadowDx, 0.0f); this.N = a.b(R$styleable.TextAppearance_android_shadowDy, 0.0f); this.L = a.b(R$styleable.TextAppearance_android_shadowRadius, 0.0f); a.a(); if (Build.VERSION.SDK_INT >= 16) { this.s = e(i); } m(); } public ColorStateList b() { return this.l; } private void c(float f) { e(f); this.q = a(this.o, this.p, f, this.J); this.r = a(this.m, this.n, f, this.J); f(a(this.i, this.j, f, this.K)); if (this.l != this.k) { this.H.setColor(a(r(), f(), f)); } else { this.H.setColor(f()); } this.H.setShadowLayer(a(this.P, this.L, f, (TimeInterpolator) null), a(this.Q, this.M, f, (TimeInterpolator) null), a(this.R, this.N, f, (TimeInterpolator) null), a(this.S, this.O, f)); ViewCompat.A(this.a); } public void a(Typeface typeface) { if (this.s != typeface) { this.s = typeface; m(); } } public final boolean a(int[] iArr) { this.F = iArr; if (!k()) { return false; } m(); return true; } public void a(Canvas canvas) { float ascent; int save = canvas.save(); if (this.w != null && this.b) { float f = this.q; float f2 = this.r; boolean z = this.y && this.z != null; if (z) { ascent = this.B * this.D; } else { ascent = this.H.ascent() * this.D; this.H.descent(); } if (z) { f2 += ascent; } float f3 = f2; float f4 = this.D; if (f4 != 1.0f) { canvas.scale(f4, f4, f, f3); } if (z) { canvas.drawBitmap(this.z, f, f3, this.A); } else { CharSequence charSequence = this.w; canvas.drawText(charSequence, 0, charSequence.length(), f, f3, this.H); } } canvas.restoreToCount(save); } public void a(CharSequence charSequence) { if (charSequence == null || !charSequence.equals(this.v)) { this.v = charSequence; this.w = null; p(); m(); } } private static boolean a(float f, float f2) { return Math.abs(f - f2) < 0.001f; } private static int a(int i, int i2, float f) { float f2 = 1.0f - f; return Color.argb((int) ((Color.alpha(i) * f2) + (Color.alpha(i2) * f)), (int) ((Color.red(i) * f2) + (Color.red(i2) * f)), (int) ((Color.green(i) * f2) + (Color.green(i2) * f)), (int) ((Color.blue(i) * f2) + (Color.blue(i2) * f))); } private static float a(float f, float f2, float f3, TimeInterpolator timeInterpolator) { if (timeInterpolator != null) { f3 = timeInterpolator.getInterpolation(f3); } return AnimationUtils.a(f, f2, f3); } private static boolean a(Rect rect, int i, int i2, int i3, int i4) { return rect.left == i && rect.top == i2 && rect.right == i3 && rect.bottom == i4; } }