Skip to content

Commit

Permalink
feat: Use lStared project colors
Browse files Browse the repository at this point in the history
Customizable project color background
  • Loading branch information
aikrq committed Nov 30, 2024
1 parent 96a10c9 commit 862ea4c
Show file tree
Hide file tree
Showing 4 changed files with 567 additions and 373 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ private void setPreviewColors(String str) {
k.setBackgroundColor(ProjectFile.getColor(str, ProjectFile.COLOR_PRIMARY_DARK));
imgPhoneTopBg.setBackgroundColor(ProjectFile.getColor(str, ProjectFile.COLOR_PRIMARY_DARK));
toolbar.setBackgroundColor(ProjectFile.getColor(str, ProjectFile.COLOR_PRIMARY));
viewPane.setRootBackgroundColor(ProjectFile.getColor(str, ProjectFile.COLOR_BACKGROUND));
}

private void b(boolean z) {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/besome/sketch/editor/view/ViewPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import android.widget.SeekBar;
import android.widget.TextView;

import androidx.annotation.ColorInt;

import com.besome.sketch.beans.ImageBean;
import com.besome.sketch.beans.LayoutBean;
import com.besome.sketch.beans.ProjectResourceBean;
Expand Down Expand Up @@ -322,6 +324,10 @@ private void addRootLayout() {
addView(rootView);
}

public void setRootBackgroundColor(@ColorInt int backgroundColor) {
rootLayout.setBackgroundColor(backgroundColor);
}

private void updateItemView(View view, ViewBean viewBean) {
ImageBean imageBean;
String str;
Expand Down
24 changes: 17 additions & 7 deletions app/src/main/java/mod/hey/studios/util/ProjectFile.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package mod.hey.studios.util;

// import static mod.remaker.util.CamUtils.modulateColorWithLStar;

import android.content.Context;
import android.graphics.Color;
import android.os.Build;

Expand All @@ -15,6 +18,9 @@ public class ProjectFile {
public static final String COLOR_CONTROL_HIGHLIGHT = "color_control_highlight";
public static final String COLOR_CONTROL_NORMAL = "color_control_normal";

// Android Framework
public static final String COLOR_BACKGROUND = "color_background";

public static int getColor(String sc_id, String color) {
return yB.a(lC.b(sc_id), color, getDefaultColor(color));
/*
Expand Down Expand Up @@ -42,19 +48,23 @@ public static int a(Map<String, Object> paramMap, String paramString, int paramI
*/

public static int getDefaultColor(String color) {
// Check if the device is running Android 12 or above
final Context ctx = SketchApplication.getContext();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// Android 12+ (API level 31): Use Material 3 dynamic colors
// 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_PRIMARY_DARK -> SketchApplication.getContext().getColor(android.R.color.system_accent1_500);
case COLOR_CONTROL_HIGHLIGHT -> SketchApplication.getContext().getColor(android.R.color.system_accent1_100);
default -> SketchApplication.getContext().getColor(android.R.color.system_accent1_500);
case COLOR_CONTROL_HIGHLIGHT -> ctx.getColor(android.R.color.system_accent1_100);
case COLOR_BACKGROUND -> ctx.getColor(android.R.color.system_neutral2_600);
default -> ctx.getColor(android.R.color.system_accent1_600);
};
} else {
// For Android versions below 12: use static fallback colors
return switch (color) {
case COLOR_PRIMARY_DARK -> Color.parseColor("#ff1976d2");
case COLOR_CONTROL_HIGHLIGHT -> Color.parseColor("#202196f3");
case COLOR_BACKGROUND -> Color.parseColor("#fffafafa");
default -> Color.parseColor("#ff2196f3");
};
}
Expand Down
Loading

0 comments on commit 862ea4c

Please sign in to comment.