mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-13 09:27:16 +01:00
107 lines
4.2 KiB
Java
107 lines
4.2 KiB
Java
package com.google.android.material.elevation;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Color;
|
|
import android.view.View;
|
|
import androidx.annotation.ColorInt;
|
|
import androidx.annotation.NonNull;
|
|
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;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes7.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 ElevationOverlayProvider(@NonNull 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);
|
|
}
|
|
|
|
private boolean isThemeSurfaceColor(@ColorInt int i) {
|
|
return ColorUtils.setAlphaComponent(i, 255) == this.colorSurface;
|
|
}
|
|
|
|
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 / r2)) * FORMULA_MULTIPLIER) + 2.0f) / 100.0f, 1.0f);
|
|
}
|
|
|
|
@ColorInt
|
|
public int compositeOverlay(@ColorInt 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);
|
|
}
|
|
|
|
@ColorInt
|
|
public int compositeOverlayIfNeeded(@ColorInt int i, float f) {
|
|
return (this.elevationOverlayEnabled && isThemeSurfaceColor(i)) ? compositeOverlay(i, f) : i;
|
|
}
|
|
|
|
@ColorInt
|
|
public int compositeOverlayWithThemeSurfaceColorIfNeeded(float f, @NonNull View view) {
|
|
return compositeOverlayWithThemeSurfaceColorIfNeeded(getParentAbsoluteElevation(view) + f);
|
|
}
|
|
|
|
public float getParentAbsoluteElevation(@NonNull View view) {
|
|
return ViewUtils.getParentAbsoluteElevation(view);
|
|
}
|
|
|
|
@ColorInt
|
|
public int getThemeElevationOverlayColor() {
|
|
return this.elevationOverlayColor;
|
|
}
|
|
|
|
@ColorInt
|
|
public int getThemeSurfaceColor() {
|
|
return this.colorSurface;
|
|
}
|
|
|
|
public boolean isThemeElevationOverlayEnabled() {
|
|
return this.elevationOverlayEnabled;
|
|
}
|
|
|
|
@ColorInt
|
|
public int compositeOverlayWithThemeSurfaceColorIfNeeded(float f) {
|
|
return compositeOverlayIfNeeded(this.colorSurface, f);
|
|
}
|
|
|
|
@ColorInt
|
|
public int compositeOverlayIfNeeded(@ColorInt int i, float f, @NonNull View view) {
|
|
return compositeOverlayIfNeeded(i, getParentAbsoluteElevation(view) + f);
|
|
}
|
|
|
|
public ElevationOverlayProvider(boolean z, @ColorInt int i, @ColorInt int i2, @ColorInt int i3, float f) {
|
|
this.elevationOverlayEnabled = z;
|
|
this.elevationOverlayColor = i;
|
|
this.elevationOverlayAccentColor = i2;
|
|
this.colorSurface = i3;
|
|
this.displayDensity = f;
|
|
}
|
|
|
|
@ColorInt
|
|
public int compositeOverlay(@ColorInt int i, float f, @NonNull View view) {
|
|
return compositeOverlay(i, getParentAbsoluteElevation(view) + f);
|
|
}
|
|
}
|