172 lines
6 KiB
Java
172 lines
6 KiB
Java
|
package com.discord.utilities.color;
|
||
|
|
||
|
import android.app.Activity;
|
||
|
import android.content.Context;
|
||
|
import android.content.res.ColorStateList;
|
||
|
import android.content.res.Resources;
|
||
|
import android.graphics.Color;
|
||
|
import android.os.Build;
|
||
|
import android.util.TypedValue;
|
||
|
import android.view.View;
|
||
|
import android.view.Window;
|
||
|
import androidx.annotation.AttrRes;
|
||
|
import androidx.annotation.ColorInt;
|
||
|
import androidx.annotation.ColorRes;
|
||
|
import androidx.core.content.ContextCompat;
|
||
|
import androidx.fragment.app.Fragment;
|
||
|
import d0.z.d.m;
|
||
|
/* compiled from: ColorCompat.kt */
|
||
|
public final class ColorCompat {
|
||
|
public static final ColorCompat INSTANCE = new ColorCompat();
|
||
|
|
||
|
private ColorCompat() {
|
||
|
}
|
||
|
|
||
|
@ColorInt
|
||
|
public static final int getColor(Context context, @ColorRes int i) {
|
||
|
if (context != null) {
|
||
|
return ContextCompat.getColor(context, i);
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
@ColorInt
|
||
|
public static final int getColor(View view, @ColorRes int i) {
|
||
|
m.checkNotNullParameter(view, "view");
|
||
|
return getColor(view.getContext(), i);
|
||
|
}
|
||
|
|
||
|
@ColorInt
|
||
|
public static final int getColor(Fragment fragment, @ColorRes int i) {
|
||
|
m.checkNotNullParameter(fragment, "fragment");
|
||
|
return getColor(fragment.getContext(), i);
|
||
|
}
|
||
|
|
||
|
@ColorInt
|
||
|
public static final int getThemedColor(Context context, @AttrRes int i) {
|
||
|
TypedValue typedValue = new TypedValue();
|
||
|
Resources.Theme theme = context != null ? context.getTheme() : null;
|
||
|
if (theme != null) {
|
||
|
theme.resolveAttribute(i, typedValue, true);
|
||
|
}
|
||
|
return typedValue.data;
|
||
|
}
|
||
|
|
||
|
@ColorInt
|
||
|
public static final int getThemedColor(View view, @AttrRes int i) {
|
||
|
m.checkNotNullParameter(view, "view");
|
||
|
return getThemedColor(view.getContext(), i);
|
||
|
}
|
||
|
|
||
|
@ColorInt
|
||
|
public static final int getThemedColor(Fragment fragment, @AttrRes int i) {
|
||
|
m.checkNotNullParameter(fragment, "fragment");
|
||
|
return getThemedColor(fragment.getContext(), i);
|
||
|
}
|
||
|
|
||
|
public static final boolean isColorDark(int i) {
|
||
|
return isColorDark$default(i, 0.0f, 2, null);
|
||
|
}
|
||
|
|
||
|
public static final boolean isColorDark(int i, float f) {
|
||
|
return ((double) 1) - (((((double) Color.blue(i)) * 0.114d) + ((((double) Color.green(i)) * 0.587d) + (((double) Color.red(i)) * 0.299d))) / ((double) 255)) >= ((double) f);
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ boolean isColorDark$default(int i, float f, int i2, Object obj) {
|
||
|
if ((i2 & 2) != 0) {
|
||
|
f = 0.4f;
|
||
|
}
|
||
|
return isColorDark(i, f);
|
||
|
}
|
||
|
|
||
|
public static final void setStatusBarColor(Activity activity, @ColorInt int i) {
|
||
|
setStatusBarColor$default(activity, i, false, 4, (Object) null);
|
||
|
}
|
||
|
|
||
|
public static final void setStatusBarColor(Activity activity, @ColorInt int i, boolean z2) {
|
||
|
setStatusBarColor(activity != null ? activity.getWindow() : null, i, z2);
|
||
|
}
|
||
|
|
||
|
public static final void setStatusBarColor(Window window, @ColorInt int i) {
|
||
|
setStatusBarColor$default(window, i, false, 4, (Object) null);
|
||
|
}
|
||
|
|
||
|
public static final void setStatusBarColor(Window window, @ColorInt int i, boolean z2) {
|
||
|
View decorView;
|
||
|
if (window != null) {
|
||
|
window.clearFlags(67108864);
|
||
|
}
|
||
|
if (window != null) {
|
||
|
window.addFlags(Integer.MIN_VALUE);
|
||
|
}
|
||
|
if (window != null) {
|
||
|
window.setStatusBarColor(i);
|
||
|
}
|
||
|
if (Build.VERSION.SDK_INT >= 23 && z2 && window != null && (decorView = window.getDecorView()) != null) {
|
||
|
decorView.setSystemUiVisibility(0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static final void setStatusBarColor(Fragment fragment, @ColorInt int i) {
|
||
|
setStatusBarColor$default(fragment, i, false, 4, (Object) null);
|
||
|
}
|
||
|
|
||
|
public static final void setStatusBarColor(Fragment fragment, @ColorInt int i, boolean z2) {
|
||
|
m.checkNotNullParameter(fragment, "fragment");
|
||
|
setStatusBarColor(fragment.getActivity(), i, z2);
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ void setStatusBarColor$default(Activity activity, int i, boolean z2, int i2, Object obj) {
|
||
|
if ((i2 & 4) != 0) {
|
||
|
z2 = false;
|
||
|
}
|
||
|
setStatusBarColor(activity, i, z2);
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ void setStatusBarColor$default(Window window, int i, boolean z2, int i2, Object obj) {
|
||
|
if ((i2 & 4) != 0) {
|
||
|
z2 = false;
|
||
|
}
|
||
|
setStatusBarColor(window, i, z2);
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ void setStatusBarColor$default(Fragment fragment, int i, boolean z2, int i2, Object obj) {
|
||
|
if ((i2 & 4) != 0) {
|
||
|
z2 = false;
|
||
|
}
|
||
|
setStatusBarColor(fragment, i, z2);
|
||
|
}
|
||
|
|
||
|
public static final void setStatusBarColorResourceId(Activity activity, @ColorRes int i) {
|
||
|
setStatusBarColorResourceId(activity != null ? activity.getWindow() : null, i);
|
||
|
}
|
||
|
|
||
|
public static final void setStatusBarColorResourceId(Window window, @ColorRes int i) {
|
||
|
setStatusBarColor$default(window, getColor(window != null ? window.getContext() : null, i), false, 4, (Object) null);
|
||
|
}
|
||
|
|
||
|
public static final void setStatusBarColorResourceId(Fragment fragment, @ColorRes int i) {
|
||
|
m.checkNotNullParameter(fragment, "fragment");
|
||
|
setStatusBarColorResourceId(fragment.getActivity(), i);
|
||
|
}
|
||
|
|
||
|
public static final void setStatusBarTranslucent(Activity activity) {
|
||
|
setStatusBarTranslucent(activity != null ? activity.getWindow() : null);
|
||
|
}
|
||
|
|
||
|
public static final void setStatusBarTranslucent(Window window) {
|
||
|
if (window != null) {
|
||
|
window.setFlags(67108864, 67108864);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static final void setStatusBarTranslucent(Fragment fragment) {
|
||
|
m.checkNotNullParameter(fragment, "fragment");
|
||
|
setStatusBarTranslucent(fragment.getActivity());
|
||
|
}
|
||
|
|
||
|
public final ColorStateList createDefaultColorStateList(@ColorInt int i) {
|
||
|
return new ColorStateList(new int[][]{new int[]{16842910}, new int[]{-16842910}, new int[]{-16842912}, new int[]{16842919}}, new int[]{i, i, i, i});
|
||
|
}
|
||
|
}
|