alexandroid/decompiled/jadx/sources/com/google/android/material/internal/TextDrawableHelper.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

149 lines
5.2 KiB
Java

package com.google.android.material.internal;
import android.content.Context;
import android.graphics.Typeface;
import android.text.TextPaint;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import com.google.android.material.resources.TextAppearance;
import com.google.android.material.resources.TextAppearanceFontCallback;
import java.lang.ref.WeakReference;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
/* loaded from: classes7.dex */
public class TextDrawableHelper {
@Nullable
private TextAppearance textAppearance;
private float textHeight;
private float textWidth;
private final TextPaint textPaint = new TextPaint(1);
private final TextAppearanceFontCallback fontCallback = new TextAppearanceFontCallback() { // from class: com.google.android.material.internal.TextDrawableHelper.1
@Override // com.google.android.material.resources.TextAppearanceFontCallback
public void onFontRetrievalFailed(int i) {
TextDrawableHelper.this.textSizeDirty = true;
TextDrawableDelegate textDrawableDelegate = (TextDrawableDelegate) TextDrawableHelper.this.delegate.get();
if (textDrawableDelegate != null) {
textDrawableDelegate.onTextSizeChange();
}
}
@Override // com.google.android.material.resources.TextAppearanceFontCallback
public void onFontRetrieved(@NonNull Typeface typeface, boolean z) {
if (z) {
return;
}
TextDrawableHelper.this.textSizeDirty = true;
TextDrawableDelegate textDrawableDelegate = (TextDrawableDelegate) TextDrawableHelper.this.delegate.get();
if (textDrawableDelegate != null) {
textDrawableDelegate.onTextSizeChange();
}
}
};
private boolean textSizeDirty = true;
@Nullable
private WeakReference<TextDrawableDelegate> delegate = new WeakReference<>(null);
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public interface TextDrawableDelegate {
@NonNull
int[] getState();
boolean onStateChange(int[] iArr);
void onTextSizeChange();
}
public TextDrawableHelper(@Nullable TextDrawableDelegate textDrawableDelegate) {
setDelegate(textDrawableDelegate);
}
private float calculateTextHeight(@Nullable String str) {
if (str == null) {
return 0.0f;
}
return Math.abs(this.textPaint.getFontMetrics().ascent);
}
private float calculateTextWidth(@Nullable CharSequence charSequence) {
if (charSequence == null) {
return 0.0f;
}
return this.textPaint.measureText(charSequence, 0, charSequence.length());
}
private void refreshTextDimens(String str) {
this.textWidth = calculateTextWidth(str);
this.textHeight = calculateTextHeight(str);
this.textSizeDirty = false;
}
@Nullable
public TextAppearance getTextAppearance() {
return this.textAppearance;
}
public float getTextHeight(@Nullable String str) {
if (!this.textSizeDirty) {
return this.textHeight;
}
refreshTextDimens(str);
return this.textHeight;
}
@NonNull
public TextPaint getTextPaint() {
return this.textPaint;
}
public float getTextWidth(String str) {
if (!this.textSizeDirty) {
return this.textWidth;
}
refreshTextDimens(str);
return this.textWidth;
}
public boolean isTextWidthDirty() {
return this.textSizeDirty;
}
public void setDelegate(@Nullable TextDrawableDelegate textDrawableDelegate) {
this.delegate = new WeakReference<>(textDrawableDelegate);
}
public void setTextAppearance(@Nullable TextAppearance textAppearance, Context context) {
if (this.textAppearance != textAppearance) {
this.textAppearance = textAppearance;
if (textAppearance != null) {
textAppearance.updateMeasureState(context, this.textPaint, this.fontCallback);
TextDrawableDelegate textDrawableDelegate = this.delegate.get();
if (textDrawableDelegate != null) {
this.textPaint.drawableState = textDrawableDelegate.getState();
}
textAppearance.updateDrawState(context, this.textPaint, this.fontCallback);
this.textSizeDirty = true;
}
TextDrawableDelegate textDrawableDelegate2 = this.delegate.get();
if (textDrawableDelegate2 != null) {
textDrawableDelegate2.onTextSizeChange();
textDrawableDelegate2.onStateChange(textDrawableDelegate2.getState());
}
}
}
public void setTextSizeDirty(boolean z) {
this.textSizeDirty = z;
}
public void setTextWidthDirty(boolean z) {
this.textSizeDirty = z;
}
public void updateTextPaintDrawState(Context context) {
this.textAppearance.updateDrawState(context, this.textPaint, this.fontCallback);
}
}