ADD week 5

This commit is contained in:
2025-03-31 16:33:42 +02:00
parent 86f265f22d
commit bf645048e6
4927 changed files with 544053 additions and 0 deletions

View File

@ -0,0 +1,40 @@
package com.google.android.material.resources;
import android.graphics.Typeface;
/* loaded from: classes.dex */
public final class CancelableFontCallback extends TextAppearanceFontCallback {
private final ApplyFont applyFont;
private boolean cancelled;
private final Typeface fallbackFont;
public interface ApplyFont {
void apply(Typeface typeface);
}
public void cancel() {
this.cancelled = true;
}
public CancelableFontCallback(ApplyFont applyFont, Typeface typeface) {
this.fallbackFont = typeface;
this.applyFont = applyFont;
}
@Override // com.google.android.material.resources.TextAppearanceFontCallback
public void onFontRetrieved(Typeface typeface, boolean z) {
updateIfNotCancelled(typeface);
}
@Override // com.google.android.material.resources.TextAppearanceFontCallback
public void onFontRetrievalFailed(int i) {
updateIfNotCancelled(this.fallbackFont);
}
private void updateIfNotCancelled(Typeface typeface) {
if (this.cancelled) {
return;
}
this.applyFont.apply(typeface);
}
}

View File

@ -0,0 +1,66 @@
package com.google.android.material.resources;
import android.content.Context;
import android.util.TypedValue;
import android.view.View;
import com.google.android.material.R;
/* loaded from: classes.dex */
public class MaterialAttributes {
public static TypedValue resolve(Context context, int i) {
TypedValue typedValue = new TypedValue();
if (context.getTheme().resolveAttribute(i, typedValue, true)) {
return typedValue;
}
return null;
}
public static TypedValue resolveTypedValueOrThrow(View view, int i) {
return resolveTypedValueOrThrow(view.getContext(), i, view.getClass().getCanonicalName());
}
public static TypedValue resolveTypedValueOrThrow(Context context, int i, String str) {
TypedValue resolve = resolve(context, i);
if (resolve != null) {
return resolve;
}
throw new IllegalArgumentException(String.format("%1$s requires a value for the %2$s attribute to be set in your app theme. You can either set the attribute in your theme or update your theme to inherit from Theme.MaterialComponents (or a descendant).", str, context.getResources().getResourceName(i)));
}
public static int resolveOrThrow(Context context, int i, String str) {
return resolveTypedValueOrThrow(context, i, str).data;
}
public static int resolveOrThrow(View view, int i) {
return resolveTypedValueOrThrow(view, i).data;
}
public static boolean resolveBooleanOrThrow(Context context, int i, String str) {
return resolveOrThrow(context, i, str) != 0;
}
public static boolean resolveBoolean(Context context, int i, boolean z) {
TypedValue resolve = resolve(context, i);
return (resolve == null || resolve.type != 18) ? z : resolve.data != 0;
}
public static int resolveInteger(Context context, int i, int i2) {
TypedValue resolve = resolve(context, i);
return (resolve == null || resolve.type != 16) ? i2 : resolve.data;
}
public static int resolveMinimumAccessibleTouchTarget(Context context) {
return resolveDimension(context, R.attr.minTouchTargetSize, R.dimen.mtrl_min_touch_target_size);
}
public static int resolveDimension(Context context, int i, int i2) {
float dimension;
TypedValue resolve = resolve(context, i);
if (resolve == null || resolve.type != 5) {
dimension = context.getResources().getDimension(i2);
} else {
dimension = resolve.getDimension(context.getResources().getDisplayMetrics());
}
return (int) dimension;
}
}

View File

@ -0,0 +1,99 @@
package com.google.android.material.resources;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.TypedValue;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.TintTypedArray;
import com.google.android.material.R;
/* loaded from: classes.dex */
public class MaterialResources {
private static final float FONT_SCALE_1_3 = 1.3f;
private static final float FONT_SCALE_2_0 = 2.0f;
private MaterialResources() {
}
public static ColorStateList getColorStateList(Context context, TypedArray typedArray, int i) {
int resourceId;
ColorStateList colorStateList;
return (!typedArray.hasValue(i) || (resourceId = typedArray.getResourceId(i, 0)) == 0 || (colorStateList = AppCompatResources.getColorStateList(context, resourceId)) == null) ? typedArray.getColorStateList(i) : colorStateList;
}
public static ColorStateList getColorStateList(Context context, TintTypedArray tintTypedArray, int i) {
int resourceId;
ColorStateList colorStateList;
return (!tintTypedArray.hasValue(i) || (resourceId = tintTypedArray.getResourceId(i, 0)) == 0 || (colorStateList = AppCompatResources.getColorStateList(context, resourceId)) == null) ? tintTypedArray.getColorStateList(i) : colorStateList;
}
public static Drawable getDrawable(Context context, TypedArray typedArray, int i) {
int resourceId;
Drawable drawable;
return (!typedArray.hasValue(i) || (resourceId = typedArray.getResourceId(i, 0)) == 0 || (drawable = AppCompatResources.getDrawable(context, resourceId)) == null) ? typedArray.getDrawable(i) : drawable;
}
public static TextAppearance getTextAppearance(Context context, TypedArray typedArray, int i) {
int resourceId;
if (!typedArray.hasValue(i) || (resourceId = typedArray.getResourceId(i, 0)) == 0) {
return null;
}
return new TextAppearance(context, resourceId);
}
public static int getDimensionPixelSize(Context context, TypedArray typedArray, int i, int i2) {
TypedValue typedValue = new TypedValue();
if (!typedArray.getValue(i, typedValue) || typedValue.type != 2) {
return typedArray.getDimensionPixelSize(i, i2);
}
TypedArray obtainStyledAttributes = context.getTheme().obtainStyledAttributes(new int[]{typedValue.data});
int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(0, i2);
obtainStyledAttributes.recycle();
return dimensionPixelSize;
}
public static boolean isFontScaleAtLeast1_3(Context context) {
return context.getResources().getConfiguration().fontScale >= FONT_SCALE_1_3;
}
public static boolean isFontScaleAtLeast2_0(Context context) {
return context.getResources().getConfiguration().fontScale >= FONT_SCALE_2_0;
}
public static float getFontScale(Context context) {
return context.getResources().getConfiguration().fontScale;
}
public static int getUnscaledTextSize(Context context, int i, int i2) {
if (i == 0) {
return i2;
}
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(i, R.styleable.TextAppearance);
TypedValue typedValue = new TypedValue();
boolean value = obtainStyledAttributes.getValue(R.styleable.TextAppearance_android_textSize, typedValue);
obtainStyledAttributes.recycle();
if (!value) {
return i2;
}
if (getComplexUnit(typedValue) == 2) {
return Math.round(TypedValue.complexToFloat(typedValue.data) * context.getResources().getDisplayMetrics().density);
}
return TypedValue.complexToDimensionPixelSize(typedValue.data, context.getResources().getDisplayMetrics());
}
private static int getComplexUnit(TypedValue typedValue) {
int complexUnit;
if (Build.VERSION.SDK_INT >= 22) {
complexUnit = typedValue.getComplexUnit();
return complexUnit;
}
return typedValue.data & 15;
}
static int getIndexWithValue(TypedArray typedArray, int i, int i2) {
return typedArray.hasValue(i) ? i : i2;
}
}

View File

@ -0,0 +1,222 @@
package com.google.android.material.resources;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.util.Log;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.view.ViewCompat;
import com.google.android.material.R;
/* loaded from: classes.dex */
public class TextAppearance {
private static final String TAG = "TextAppearance";
private static final int TYPEFACE_MONOSPACE = 3;
private static final int TYPEFACE_SANS = 1;
private static final int TYPEFACE_SERIF = 2;
private Typeface font;
public final String fontFamily;
private final int fontFamilyResourceId;
private boolean fontResolved = false;
public final boolean hasLetterSpacing;
public final float letterSpacing;
public final ColorStateList shadowColor;
public final float shadowDx;
public final float shadowDy;
public final float shadowRadius;
public final boolean textAllCaps;
private ColorStateList textColor;
public final ColorStateList textColorHint;
public final ColorStateList textColorLink;
private float textSize;
public final int textStyle;
public final int typeface;
public ColorStateList getTextColor() {
return this.textColor;
}
public float getTextSize() {
return this.textSize;
}
public void setTextColor(ColorStateList colorStateList) {
this.textColor = colorStateList;
}
public void setTextSize(float f) {
this.textSize = f;
}
public TextAppearance(Context context, int i) {
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(i, R.styleable.TextAppearance);
setTextSize(obtainStyledAttributes.getDimension(R.styleable.TextAppearance_android_textSize, 0.0f));
setTextColor(MaterialResources.getColorStateList(context, obtainStyledAttributes, R.styleable.TextAppearance_android_textColor));
this.textColorHint = MaterialResources.getColorStateList(context, obtainStyledAttributes, R.styleable.TextAppearance_android_textColorHint);
this.textColorLink = MaterialResources.getColorStateList(context, obtainStyledAttributes, R.styleable.TextAppearance_android_textColorLink);
this.textStyle = obtainStyledAttributes.getInt(R.styleable.TextAppearance_android_textStyle, 0);
this.typeface = obtainStyledAttributes.getInt(R.styleable.TextAppearance_android_typeface, 1);
int indexWithValue = MaterialResources.getIndexWithValue(obtainStyledAttributes, R.styleable.TextAppearance_fontFamily, R.styleable.TextAppearance_android_fontFamily);
this.fontFamilyResourceId = obtainStyledAttributes.getResourceId(indexWithValue, 0);
this.fontFamily = obtainStyledAttributes.getString(indexWithValue);
this.textAllCaps = obtainStyledAttributes.getBoolean(R.styleable.TextAppearance_textAllCaps, false);
this.shadowColor = MaterialResources.getColorStateList(context, obtainStyledAttributes, R.styleable.TextAppearance_android_shadowColor);
this.shadowDx = obtainStyledAttributes.getFloat(R.styleable.TextAppearance_android_shadowDx, 0.0f);
this.shadowDy = obtainStyledAttributes.getFloat(R.styleable.TextAppearance_android_shadowDy, 0.0f);
this.shadowRadius = obtainStyledAttributes.getFloat(R.styleable.TextAppearance_android_shadowRadius, 0.0f);
obtainStyledAttributes.recycle();
TypedArray obtainStyledAttributes2 = context.obtainStyledAttributes(i, R.styleable.MaterialTextAppearance);
this.hasLetterSpacing = obtainStyledAttributes2.hasValue(R.styleable.MaterialTextAppearance_android_letterSpacing);
this.letterSpacing = obtainStyledAttributes2.getFloat(R.styleable.MaterialTextAppearance_android_letterSpacing, 0.0f);
obtainStyledAttributes2.recycle();
}
public Typeface getFont(Context context) {
if (this.fontResolved) {
return this.font;
}
if (!context.isRestricted()) {
try {
Typeface font = ResourcesCompat.getFont(context, this.fontFamilyResourceId);
this.font = font;
if (font != null) {
this.font = Typeface.create(font, this.textStyle);
}
} catch (Resources.NotFoundException | UnsupportedOperationException unused) {
} catch (Exception e) {
Log.d(TAG, "Error loading font " + this.fontFamily, e);
}
}
createFallbackFont();
this.fontResolved = true;
return this.font;
}
public void getFontAsync(Context context, final TextAppearanceFontCallback textAppearanceFontCallback) {
if (shouldLoadFontSynchronously(context)) {
getFont(context);
} else {
createFallbackFont();
}
int i = this.fontFamilyResourceId;
if (i == 0) {
this.fontResolved = true;
}
if (this.fontResolved) {
textAppearanceFontCallback.onFontRetrieved(this.font, true);
return;
}
try {
ResourcesCompat.getFont(context, i, new ResourcesCompat.FontCallback() { // from class: com.google.android.material.resources.TextAppearance.1
@Override // androidx.core.content.res.ResourcesCompat.FontCallback
/* renamed from: onFontRetrieved */
public void m81x46c88379(Typeface typeface) {
TextAppearance textAppearance = TextAppearance.this;
textAppearance.font = Typeface.create(typeface, textAppearance.textStyle);
TextAppearance.this.fontResolved = true;
textAppearanceFontCallback.onFontRetrieved(TextAppearance.this.font, false);
}
@Override // androidx.core.content.res.ResourcesCompat.FontCallback
/* renamed from: onFontRetrievalFailed */
public void m80xb24343b7(int i2) {
TextAppearance.this.fontResolved = true;
textAppearanceFontCallback.onFontRetrievalFailed(i2);
}
}, null);
} catch (Resources.NotFoundException unused) {
this.fontResolved = true;
textAppearanceFontCallback.onFontRetrievalFailed(1);
} catch (Exception e) {
Log.d(TAG, "Error loading font " + this.fontFamily, e);
this.fontResolved = true;
textAppearanceFontCallback.onFontRetrievalFailed(-3);
}
}
public void getFontAsync(final Context context, final TextPaint textPaint, final TextAppearanceFontCallback textAppearanceFontCallback) {
updateTextPaintMeasureState(context, textPaint, getFallbackFont());
getFontAsync(context, new TextAppearanceFontCallback() { // from class: com.google.android.material.resources.TextAppearance.2
@Override // com.google.android.material.resources.TextAppearanceFontCallback
public void onFontRetrieved(Typeface typeface, boolean z) {
TextAppearance.this.updateTextPaintMeasureState(context, textPaint, typeface);
textAppearanceFontCallback.onFontRetrieved(typeface, z);
}
@Override // com.google.android.material.resources.TextAppearanceFontCallback
public void onFontRetrievalFailed(int i) {
textAppearanceFontCallback.onFontRetrievalFailed(i);
}
});
}
public Typeface getFallbackFont() {
createFallbackFont();
return this.font;
}
private void createFallbackFont() {
String str;
if (this.font == null && (str = this.fontFamily) != null) {
this.font = Typeface.create(str, this.textStyle);
}
if (this.font == null) {
int i = this.typeface;
if (i == 1) {
this.font = Typeface.SANS_SERIF;
} else if (i == 2) {
this.font = Typeface.SERIF;
} else if (i == 3) {
this.font = Typeface.MONOSPACE;
} else {
this.font = Typeface.DEFAULT;
}
this.font = Typeface.create(this.font, this.textStyle);
}
}
public void updateDrawState(Context context, TextPaint textPaint, TextAppearanceFontCallback textAppearanceFontCallback) {
updateMeasureState(context, textPaint, textAppearanceFontCallback);
ColorStateList colorStateList = this.textColor;
textPaint.setColor(colorStateList != null ? colorStateList.getColorForState(textPaint.drawableState, this.textColor.getDefaultColor()) : ViewCompat.MEASURED_STATE_MASK);
float f = this.shadowRadius;
float f2 = this.shadowDx;
float f3 = this.shadowDy;
ColorStateList colorStateList2 = this.shadowColor;
textPaint.setShadowLayer(f, f2, f3, colorStateList2 != null ? colorStateList2.getColorForState(textPaint.drawableState, this.shadowColor.getDefaultColor()) : 0);
}
public void updateMeasureState(Context context, TextPaint textPaint, TextAppearanceFontCallback textAppearanceFontCallback) {
if (shouldLoadFontSynchronously(context)) {
updateTextPaintMeasureState(context, textPaint, getFont(context));
} else {
getFontAsync(context, textPaint, textAppearanceFontCallback);
}
}
public void updateTextPaintMeasureState(Context context, TextPaint textPaint, Typeface typeface) {
Typeface maybeCopyWithFontWeightAdjustment = TypefaceUtils.maybeCopyWithFontWeightAdjustment(context, typeface);
if (maybeCopyWithFontWeightAdjustment != null) {
typeface = maybeCopyWithFontWeightAdjustment;
}
textPaint.setTypeface(typeface);
int i = this.textStyle & (~typeface.getStyle());
textPaint.setFakeBoldText((i & 1) != 0);
textPaint.setTextSkewX((i & 2) != 0 ? -0.25f : 0.0f);
textPaint.setTextSize(this.textSize);
if (this.hasLetterSpacing) {
textPaint.setLetterSpacing(this.letterSpacing);
}
}
private boolean shouldLoadFontSynchronously(Context context) {
if (TextAppearanceConfig.shouldLoadFontSynchronously()) {
return true;
}
int i = this.fontFamilyResourceId;
return (i != 0 ? ResourcesCompat.getCachedFont(context, i) : null) != null;
}
}

View File

@ -0,0 +1,15 @@
package com.google.android.material.resources;
@Deprecated
/* loaded from: classes.dex */
public class TextAppearanceConfig {
private static boolean shouldLoadFontSynchronously;
public static void setShouldLoadFontSynchronously(boolean z) {
shouldLoadFontSynchronously = z;
}
public static boolean shouldLoadFontSynchronously() {
return shouldLoadFontSynchronously;
}
}

View File

@ -0,0 +1,10 @@
package com.google.android.material.resources;
import android.graphics.Typeface;
/* loaded from: classes.dex */
public abstract class TextAppearanceFontCallback {
public abstract void onFontRetrievalFailed(int i);
public abstract void onFontRetrieved(Typeface typeface, boolean z);
}

View File

@ -0,0 +1,40 @@
package com.google.android.material.resources;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.os.Build;
import androidx.core.math.MathUtils;
/* loaded from: classes.dex */
public class TypefaceUtils {
private TypefaceUtils() {
}
public static Typeface maybeCopyWithFontWeightAdjustment(Context context, Typeface typeface) {
return maybeCopyWithFontWeightAdjustment(context.getResources().getConfiguration(), typeface);
}
public static Typeface maybeCopyWithFontWeightAdjustment(Configuration configuration, Typeface typeface) {
int i;
int i2;
int weight;
int i3;
Typeface create;
if (Build.VERSION.SDK_INT < 31) {
return null;
}
i = configuration.fontWeightAdjustment;
if (i == Integer.MAX_VALUE) {
return null;
}
i2 = configuration.fontWeightAdjustment;
if (i2 == 0 || typeface == null) {
return null;
}
weight = typeface.getWeight();
i3 = configuration.fontWeightAdjustment;
create = Typeface.create(typeface, MathUtils.clamp(weight + i3, 1, 1000), typeface.isItalic());
return create;
}
}