Skip to content

Commit

Permalink
feat: Use lStared colors for default colors
Browse files Browse the repository at this point in the history
Used reflection API to access private method
  • Loading branch information
aikrq committed Dec 1, 2024
1 parent 947d069 commit 792f6c8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions app/src/main/java/mod/hey/studios/util/ProjectFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import android.graphics.Color;
import android.os.Build;

import androidx.core.content.res.ColorStateListInflaterCompat;

import pro.sketchware.SketchApplication;

import a.a.a.lC;
import a.a.a.yB;

import java.lang.reflect.Method;

public class ProjectFile {
public static final String COLOR_ACCENT = "color_accent";
public static final String COLOR_PRIMARY = "color_primary";
Expand Down Expand Up @@ -51,15 +55,10 @@ public static int getDefaultColor(String color) {
final Context ctx = SketchApplication.getContext();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// final int defaultColor = modulateColorWithLStar(
// ctx.getColor(android.R.color.system_accentl1_600), 90.0f);
// final int colorBackground = modulateColorWithLStar(
// ctx.getColor(android.R.color.system_neutral2_600), 98.0f);

return switch (color) {
case COLOR_CONTROL_HIGHLIGHT -> ctx.getColor(android.R.color.system_accent1_100);
case COLOR_BACKGROUND -> ctx.getColor(android.R.color.system_neutral1_0);
default -> ctx.getColor(android.R.color.system_accent1_600);
case COLOR_BACKGROUND -> getLStaredColor(ctx, android.R.color.system_neutral2_600, 98.0f);
default -> getLStaredColor(ctx, android.R.color.system_accentl1_600, 90.0f);
};
} else {
return switch (color) {
Expand All @@ -69,4 +68,10 @@ public static int getDefaultColor(String color) {
};
}
}

private static int getLStaredColor(Context ctx, int colorId, float lStar) {
Method method = ColorStateListInflaterCompat.class.getDeclaredMethod("modulateColorAlpha", int.class, float.class, float.class);
method.setAccessible(true);
return (int) method.invoke(ColorStateListInflaterCompat.class, ctx.getColor(colorId), 1.0f, lStar);
}
}

0 comments on commit 792f6c8

Please sign in to comment.