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,96 @@
package com.google.android.material.elevation;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import androidx.core.graphics.ColorUtils;
import com.google.android.material.R;
import com.google.android.material.color.MaterialColors;
import com.google.android.material.internal.ViewUtils;
import com.google.android.material.resources.MaterialAttributes;
/* loaded from: classes.dex */
public class ElevationOverlayProvider {
private static final float FORMULA_MULTIPLIER = 4.5f;
private static final float FORMULA_OFFSET = 2.0f;
private static final int OVERLAY_ACCENT_COLOR_ALPHA = (int) Math.round(5.1000000000000005d);
private final int colorSurface;
private final float displayDensity;
private final int elevationOverlayAccentColor;
private final int elevationOverlayColor;
private final boolean elevationOverlayEnabled;
public int getThemeElevationOverlayColor() {
return this.elevationOverlayColor;
}
public int getThemeSurfaceColor() {
return this.colorSurface;
}
public boolean isThemeElevationOverlayEnabled() {
return this.elevationOverlayEnabled;
}
public ElevationOverlayProvider(Context context) {
this(MaterialAttributes.resolveBoolean(context, R.attr.elevationOverlayEnabled, false), MaterialColors.getColor(context, R.attr.elevationOverlayColor, 0), MaterialColors.getColor(context, R.attr.elevationOverlayAccentColor, 0), MaterialColors.getColor(context, R.attr.colorSurface, 0), context.getResources().getDisplayMetrics().density);
}
public ElevationOverlayProvider(boolean z, int i, int i2, int i3, float f) {
this.elevationOverlayEnabled = z;
this.elevationOverlayColor = i;
this.elevationOverlayAccentColor = i2;
this.colorSurface = i3;
this.displayDensity = f;
}
public int compositeOverlayWithThemeSurfaceColorIfNeeded(float f, View view) {
return compositeOverlayWithThemeSurfaceColorIfNeeded(f + getParentAbsoluteElevation(view));
}
public int compositeOverlayWithThemeSurfaceColorIfNeeded(float f) {
return compositeOverlayIfNeeded(this.colorSurface, f);
}
public int compositeOverlayIfNeeded(int i, float f, View view) {
return compositeOverlayIfNeeded(i, f + getParentAbsoluteElevation(view));
}
public int compositeOverlayIfNeeded(int i, float f) {
return (this.elevationOverlayEnabled && isThemeSurfaceColor(i)) ? compositeOverlay(i, f) : i;
}
public int compositeOverlay(int i, float f, View view) {
return compositeOverlay(i, f + getParentAbsoluteElevation(view));
}
public int compositeOverlay(int i, float f) {
int i2;
float calculateOverlayAlphaFraction = calculateOverlayAlphaFraction(f);
int alpha = Color.alpha(i);
int layer = MaterialColors.layer(ColorUtils.setAlphaComponent(i, 255), this.elevationOverlayColor, calculateOverlayAlphaFraction);
if (calculateOverlayAlphaFraction > 0.0f && (i2 = this.elevationOverlayAccentColor) != 0) {
layer = MaterialColors.layer(layer, ColorUtils.setAlphaComponent(i2, OVERLAY_ACCENT_COLOR_ALPHA));
}
return ColorUtils.setAlphaComponent(layer, alpha);
}
public int calculateOverlayAlpha(float f) {
return Math.round(calculateOverlayAlphaFraction(f) * 255.0f);
}
public float calculateOverlayAlphaFraction(float f) {
if (this.displayDensity <= 0.0f || f <= 0.0f) {
return 0.0f;
}
return Math.min(((((float) Math.log1p(f / r0)) * FORMULA_MULTIPLIER) + FORMULA_OFFSET) / 100.0f, 1.0f);
}
public float getParentAbsoluteElevation(View view) {
return ViewUtils.getParentAbsoluteElevation(view);
}
private boolean isThemeSurfaceColor(int i) {
return ColorUtils.setAlphaComponent(i, 255) == this.colorSurface;
}
}

View File

@ -0,0 +1,29 @@
package com.google.android.material.elevation;
import android.content.Context;
import com.google.android.material.R;
import com.google.android.material.color.MaterialColors;
/* loaded from: classes.dex */
public enum SurfaceColors {
SURFACE_0(R.dimen.m3_sys_elevation_level0),
SURFACE_1(R.dimen.m3_sys_elevation_level1),
SURFACE_2(R.dimen.m3_sys_elevation_level2),
SURFACE_3(R.dimen.m3_sys_elevation_level3),
SURFACE_4(R.dimen.m3_sys_elevation_level4),
SURFACE_5(R.dimen.m3_sys_elevation_level5);
private final int elevationResId;
SurfaceColors(int i) {
this.elevationResId = i;
}
public int getColor(Context context) {
return getColorForElevation(context, context.getResources().getDimension(this.elevationResId));
}
public static int getColorForElevation(Context context, float f) {
return new ElevationOverlayProvider(context).compositeOverlay(MaterialColors.getColor(context, R.attr.colorSurface, 0), f);
}
}