jimu-decompiled/sources/androidx/appcompat/widget/AppCompatTextHelper.java
2025-05-13 19:24:51 +02:00

339 lines
12 KiB
Java

package androidx.appcompat.widget;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.method.PasswordTransformationMethod;
import android.util.AttributeSet;
import android.widget.TextView;
import androidx.appcompat.R$styleable;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.widget.AutoSizeableTextView;
import androidx.core.widget.TextViewCompat;
import java.lang.ref.WeakReference;
/* loaded from: classes.dex */
class AppCompatTextHelper {
private final TextView a;
private TintInfo b;
private TintInfo c;
private TintInfo d;
private TintInfo e;
private TintInfo f;
private TintInfo g;
private final AppCompatTextViewAutoSizeHelper h;
private int i = 0;
private Typeface j;
private boolean k;
AppCompatTextHelper(TextView textView) {
this.a = textView;
this.h = new AppCompatTextViewAutoSizeHelper(this.a);
}
@SuppressLint({"NewApi"})
void a(AttributeSet attributeSet, int i) {
ColorStateList colorStateList;
ColorStateList colorStateList2;
boolean z;
boolean z2;
Context context = this.a.getContext();
AppCompatDrawableManager a = AppCompatDrawableManager.a();
TintTypedArray a2 = TintTypedArray.a(context, attributeSet, R$styleable.AppCompatTextHelper, i, 0);
int g = a2.g(R$styleable.AppCompatTextHelper_android_textAppearance, -1);
if (a2.g(R$styleable.AppCompatTextHelper_android_drawableLeft)) {
this.b = a(context, a, a2.g(R$styleable.AppCompatTextHelper_android_drawableLeft, 0));
}
if (a2.g(R$styleable.AppCompatTextHelper_android_drawableTop)) {
this.c = a(context, a, a2.g(R$styleable.AppCompatTextHelper_android_drawableTop, 0));
}
if (a2.g(R$styleable.AppCompatTextHelper_android_drawableRight)) {
this.d = a(context, a, a2.g(R$styleable.AppCompatTextHelper_android_drawableRight, 0));
}
if (a2.g(R$styleable.AppCompatTextHelper_android_drawableBottom)) {
this.e = a(context, a, a2.g(R$styleable.AppCompatTextHelper_android_drawableBottom, 0));
}
if (Build.VERSION.SDK_INT >= 17) {
if (a2.g(R$styleable.AppCompatTextHelper_android_drawableStart)) {
this.f = a(context, a, a2.g(R$styleable.AppCompatTextHelper_android_drawableStart, 0));
}
if (a2.g(R$styleable.AppCompatTextHelper_android_drawableEnd)) {
this.g = a(context, a, a2.g(R$styleable.AppCompatTextHelper_android_drawableEnd, 0));
}
}
a2.a();
boolean z3 = this.a.getTransformationMethod() instanceof PasswordTransformationMethod;
boolean z4 = true;
if (g != -1) {
TintTypedArray a3 = TintTypedArray.a(context, g, R$styleable.TextAppearance);
if (z3 || !a3.g(R$styleable.TextAppearance_textAllCaps)) {
z = false;
z2 = false;
} else {
z2 = a3.a(R$styleable.TextAppearance_textAllCaps, false);
z = true;
}
a(context, a3);
if (Build.VERSION.SDK_INT < 23) {
ColorStateList a4 = a3.g(R$styleable.TextAppearance_android_textColor) ? a3.a(R$styleable.TextAppearance_android_textColor) : null;
colorStateList2 = a3.g(R$styleable.TextAppearance_android_textColorHint) ? a3.a(R$styleable.TextAppearance_android_textColorHint) : null;
ColorStateList colorStateList3 = a4;
colorStateList = a3.g(R$styleable.TextAppearance_android_textColorLink) ? a3.a(R$styleable.TextAppearance_android_textColorLink) : null;
r10 = colorStateList3;
} else {
colorStateList = null;
colorStateList2 = null;
}
a3.a();
} else {
colorStateList = null;
colorStateList2 = null;
z = false;
z2 = false;
}
TintTypedArray a5 = TintTypedArray.a(context, attributeSet, R$styleable.TextAppearance, i, 0);
if (z3 || !a5.g(R$styleable.TextAppearance_textAllCaps)) {
z4 = z;
} else {
z2 = a5.a(R$styleable.TextAppearance_textAllCaps, false);
}
if (Build.VERSION.SDK_INT < 23) {
if (a5.g(R$styleable.TextAppearance_android_textColor)) {
r10 = a5.a(R$styleable.TextAppearance_android_textColor);
}
if (a5.g(R$styleable.TextAppearance_android_textColorHint)) {
colorStateList2 = a5.a(R$styleable.TextAppearance_android_textColorHint);
}
if (a5.g(R$styleable.TextAppearance_android_textColorLink)) {
colorStateList = a5.a(R$styleable.TextAppearance_android_textColorLink);
}
}
if (Build.VERSION.SDK_INT >= 28 && a5.g(R$styleable.TextAppearance_android_textSize) && a5.c(R$styleable.TextAppearance_android_textSize, -1) == 0) {
this.a.setTextSize(0, 0.0f);
}
a(context, a5);
a5.a();
if (r10 != null) {
this.a.setTextColor(r10);
}
if (colorStateList2 != null) {
this.a.setHintTextColor(colorStateList2);
}
if (colorStateList != null) {
this.a.setLinkTextColor(colorStateList);
}
if (!z3 && z4) {
a(z2);
}
Typeface typeface = this.j;
if (typeface != null) {
this.a.setTypeface(typeface, this.i);
}
this.h.a(attributeSet, i);
if (AutoSizeableTextView.w && this.h.f() != 0) {
int[] e = this.h.e();
if (e.length > 0) {
if (this.a.getAutoSizeStepGranularity() != -1.0f) {
this.a.setAutoSizeTextTypeUniformWithConfiguration(this.h.c(), this.h.b(), this.h.d(), 0);
} else {
this.a.setAutoSizeTextTypeUniformWithPresetSizes(e, 0);
}
}
}
TintTypedArray a6 = TintTypedArray.a(context, attributeSet, R$styleable.AppCompatTextView);
int c = a6.c(R$styleable.AppCompatTextView_firstBaselineToTopHeight, -1);
int c2 = a6.c(R$styleable.AppCompatTextView_lastBaselineToBottomHeight, -1);
int c3 = a6.c(R$styleable.AppCompatTextView_lineHeight, -1);
a6.a();
if (c != -1) {
TextViewCompat.a(this.a, c);
}
if (c2 != -1) {
TextViewCompat.b(this.a, c2);
}
if (c3 != -1) {
TextViewCompat.c(this.a, c3);
}
}
void b() {
this.h.a();
}
int c() {
return this.h.b();
}
int d() {
return this.h.c();
}
int e() {
return this.h.d();
}
int[] f() {
return this.h.e();
}
int g() {
return this.h.f();
}
boolean h() {
return this.h.g();
}
private void b(int i, float f) {
this.h.a(i, f);
}
private void a(Context context, TintTypedArray tintTypedArray) {
String d;
this.i = tintTypedArray.d(R$styleable.TextAppearance_android_textStyle, this.i);
if (!tintTypedArray.g(R$styleable.TextAppearance_android_fontFamily) && !tintTypedArray.g(R$styleable.TextAppearance_fontFamily)) {
if (tintTypedArray.g(R$styleable.TextAppearance_android_typeface)) {
this.k = false;
int d2 = tintTypedArray.d(R$styleable.TextAppearance_android_typeface, 1);
if (d2 == 1) {
this.j = Typeface.SANS_SERIF;
return;
} else if (d2 == 2) {
this.j = Typeface.SERIF;
return;
} else {
if (d2 != 3) {
return;
}
this.j = Typeface.MONOSPACE;
return;
}
}
return;
}
this.j = null;
int i = tintTypedArray.g(R$styleable.TextAppearance_fontFamily) ? R$styleable.TextAppearance_fontFamily : R$styleable.TextAppearance_android_fontFamily;
if (!context.isRestricted()) {
final WeakReference weakReference = new WeakReference(this.a);
try {
this.j = tintTypedArray.a(i, this.i, new ResourcesCompat.FontCallback() { // from class: androidx.appcompat.widget.AppCompatTextHelper.1
@Override // androidx.core.content.res.ResourcesCompat.FontCallback
public void a(int i2) {
}
@Override // androidx.core.content.res.ResourcesCompat.FontCallback
public void a(Typeface typeface) {
AppCompatTextHelper.this.a(weakReference, typeface);
}
});
this.k = this.j == null;
} catch (Resources.NotFoundException | UnsupportedOperationException unused) {
}
}
if (this.j != null || (d = tintTypedArray.d(i)) == null) {
return;
}
this.j = Typeface.create(d, this.i);
}
void a(WeakReference<TextView> weakReference, Typeface typeface) {
if (this.k) {
this.j = typeface;
TextView textView = weakReference.get();
if (textView != null) {
textView.setTypeface(typeface, this.i);
}
}
}
void a(Context context, int i) {
ColorStateList a;
TintTypedArray a2 = TintTypedArray.a(context, i, R$styleable.TextAppearance);
if (a2.g(R$styleable.TextAppearance_textAllCaps)) {
a(a2.a(R$styleable.TextAppearance_textAllCaps, false));
}
if (Build.VERSION.SDK_INT < 23 && a2.g(R$styleable.TextAppearance_android_textColor) && (a = a2.a(R$styleable.TextAppearance_android_textColor)) != null) {
this.a.setTextColor(a);
}
if (a2.g(R$styleable.TextAppearance_android_textSize) && a2.c(R$styleable.TextAppearance_android_textSize, -1) == 0) {
this.a.setTextSize(0, 0.0f);
}
a(context, a2);
a2.a();
Typeface typeface = this.j;
if (typeface != null) {
this.a.setTypeface(typeface, this.i);
}
}
void a(boolean z) {
this.a.setAllCaps(z);
}
void a() {
if (this.b != null || this.c != null || this.d != null || this.e != null) {
Drawable[] compoundDrawables = this.a.getCompoundDrawables();
a(compoundDrawables[0], this.b);
a(compoundDrawables[1], this.c);
a(compoundDrawables[2], this.d);
a(compoundDrawables[3], this.e);
}
if (Build.VERSION.SDK_INT >= 17) {
if (this.f == null && this.g == null) {
return;
}
Drawable[] compoundDrawablesRelative = this.a.getCompoundDrawablesRelative();
a(compoundDrawablesRelative[0], this.f);
a(compoundDrawablesRelative[2], this.g);
}
}
private void a(Drawable drawable, TintInfo tintInfo) {
if (drawable == null || tintInfo == null) {
return;
}
AppCompatDrawableManager.a(drawable, tintInfo, this.a.getDrawableState());
}
private static TintInfo a(Context context, AppCompatDrawableManager appCompatDrawableManager, int i) {
ColorStateList b = appCompatDrawableManager.b(context, i);
if (b == null) {
return null;
}
TintInfo tintInfo = new TintInfo();
tintInfo.d = true;
tintInfo.a = b;
return tintInfo;
}
void a(boolean z, int i, int i2, int i3, int i4) {
if (AutoSizeableTextView.w) {
return;
}
b();
}
void a(int i, float f) {
if (AutoSizeableTextView.w || h()) {
return;
}
b(i, f);
}
void a(int i) {
this.h.a(i);
}
void a(int i, int i2, int i3, int i4) throws IllegalArgumentException {
this.h.a(i, i2, i3, i4);
}
void a(int[] iArr, int i) throws IllegalArgumentException {
this.h.a(iArr, i);
}
}