From 79b41751cc3f85f9512cfb0196ae28ec6b6afd10 Mon Sep 17 00:00:00 2001 From: aikrq <95296093+aikrq@users.noreply.github.com> Date: Sat, 30 Nov 2024 23:48:45 +0700 Subject: [PATCH] feat: Add ability to customize colorBackground in built-in UI --- app/src/main/java/a/a/a/yq.java | 9 +++++++++ .../sketch/projects/MyProjectSettingActivity.java | 11 +++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/a/a/a/yq.java b/app/src/main/java/a/a/a/yq.java index c487f7833a..75aea47cd7 100644 --- a/app/src/main/java/a/a/a/yq.java +++ b/app/src/main/java/a/a/a/yq.java @@ -110,6 +110,8 @@ public class yq { public final int colorControlNormal; + public final int colorBackground; + public final String versionCode; public final String versionName; @@ -227,6 +229,7 @@ public yq(Context context, String myscFolderPath, HashMap metada colorPrimaryDark = yB.a(metadata, ProjectFile.COLOR_PRIMARY_DARK, getDefaultColor(ProjectFile.COLOR_PRIMARY_DARK)); colorControlHighlight = yB.a(metadata, ProjectFile.COLOR_CONTROL_HIGHLIGHT, getDefaultColor(ProjectFile.COLOR_CONTROL_HIGHLIGHT)); colorControlNormal = yB.a(metadata, ProjectFile.COLOR_CONTROL_NORMAL, getDefaultColor(ProjectFile.COLOR_CONTROL_NORMAL)); + colorBackground = yB.a(metadata, ProjectFile.COLOR_BACKGROUND, getDefaultColor(ProjectFile.COLOR_BACKGROUND)); projectSettings = new ProjectSettings(sc_id); fileUtil = new oB(true); @@ -837,11 +840,13 @@ public ArrayList a(hC projectFileManager, eC projectDataManager, Bu colorsFileBuilder.addColor("colorAccent", String.format("#%06X", colorAccent & 0xffffff)); colorsFileBuilder.addColor("colorControlHighlight", String.format("#%06X", colorControlHighlight & 0xffffff)); colorsFileBuilder.addColor("colorControlNormal", String.format("#%06X", colorControlNormal & 0xffffff)); + colorsFileBuilder.addColor("colorBackground", String.format("#%06X", colorBackground & 0xffffff)); srcCodeBeans.add(new SrcCodeBean("colors.xml", CommandBlock.applyCommands("colors.xml", colorsFileBuilder.toCode()))); XmlBuilderHelper stylesFileBuilder = new XmlBuilderHelper(); stylesFileBuilder.addStyle("AppTheme", "Theme.MaterialComponents.Light.NoActionBar" + (useNewMaterialComponentsTheme ? "" : ".Bridge")); + stylesFileBuilder.addItemToStyle("AppTheme", "android:colorBackground", "@color/colorBackground"); stylesFileBuilder.addItemToStyle("AppTheme", "colorPrimary", "@color/colorPrimary"); stylesFileBuilder.addItemToStyle("AppTheme", "colorPrimaryDark", "@color/colorPrimaryDark"); stylesFileBuilder.addItemToStyle("AppTheme", "colorAccent", "@color/colorAccent"); @@ -857,18 +862,21 @@ public ArrayList a(hC projectFileManager, eC projectDataManager, Bu } else { XmlBuilderHelper stylesFileBuilder = new XmlBuilderHelper(); stylesFileBuilder.addStyle("AppTheme", "@android:style/Theme.Material.Light.DarkActionBar"); + stylesFileBuilder.addItemToStyle("AppTheme", "android:colorBackground", "@color/colorBackground"); stylesFileBuilder.addItemToStyle("AppTheme", "android:colorPrimary", "@color/colorPrimary"); stylesFileBuilder.addItemToStyle("AppTheme", "android:colorPrimaryDark", "@color/colorPrimaryDark"); stylesFileBuilder.addItemToStyle("AppTheme", "android:colorAccent", "@color/colorAccent"); stylesFileBuilder.addItemToStyle("AppTheme", "android:colorControlHighlight", "@color/colorControlHighlight"); stylesFileBuilder.addItemToStyle("AppTheme", "android:colorControlNormal", "@color/colorControlNormal"); stylesFileBuilder.addStyle("FullScreen", "@android:style/Theme.Material.Light.NoActionBar.Fullscreen"); + stylesFileBuilder.addItemToStyle("FullScreen", "android:colorBackground", "@color/colorBackground"); stylesFileBuilder.addItemToStyle("FullScreen", "android:colorPrimary", "@color/colorPrimary"); stylesFileBuilder.addItemToStyle("FullScreen", "android:colorPrimaryDark", "@color/colorPrimaryDark"); stylesFileBuilder.addItemToStyle("FullScreen", "android:colorAccent", "@color/colorAccent"); stylesFileBuilder.addItemToStyle("FullScreen", "android:colorControlHighlight", "@color/colorControlHighlight"); stylesFileBuilder.addItemToStyle("FullScreen", "android:colorControlNormal", "@color/colorControlNormal"); stylesFileBuilder.addStyle("NoActionBar", "@android:style/Theme.Material.Light.NoActionBar"); + stylesFileBuilder.addItemToStyle("NoActionBar", "android:colorBackground", "@color/colorBackground"); stylesFileBuilder.addItemToStyle("NoActionBar", "android:colorPrimary", "@color/colorPrimary"); stylesFileBuilder.addItemToStyle("NoActionBar", "android:colorPrimaryDark", "@color/colorPrimaryDark"); stylesFileBuilder.addItemToStyle("NoActionBar", "android:colorAccent", "@color/colorAccent"); @@ -880,6 +888,7 @@ public ArrayList a(hC projectFileManager, eC projectDataManager, Bu CommandBlock.applyCommands("styles.xml", stylesFileBuilder.toCode()))); XmlBuilderHelper colorsFileBuilder = new XmlBuilderHelper(); + colorsFileBuilder.addColor("colorBackground", String.format("#%06X", colorBackground & 0xffffff)); colorsFileBuilder.addColor("colorPrimary", String.format("#%06X", colorPrimary & 0xffffff)); colorsFileBuilder.addColor("colorPrimaryDark", String.format("#%06X", colorPrimaryDark & 0xffffff)); colorsFileBuilder.addColor("colorAccent", String.format("#%06X", colorAccent & 0xffffff)); diff --git a/app/src/main/java/com/besome/sketch/projects/MyProjectSettingActivity.java b/app/src/main/java/com/besome/sketch/projects/MyProjectSettingActivity.java index 3e3b0ddec3..7d9612176d 100644 --- a/app/src/main/java/com/besome/sketch/projects/MyProjectSettingActivity.java +++ b/app/src/main/java/com/besome/sketch/projects/MyProjectSettingActivity.java @@ -1,5 +1,11 @@ package com.besome.sketch.projects; +import static mod.hey.studios.util.ProjectFile.COLOR_ACCENT; +import static mod.hey.studios.util.ProjectFile.COLOR_BACKGROUND; +import static mod.hey.studios.util.ProjectFile.COLOR_CONTROL_HIGHLIGHT; +import static mod.hey.studios.util.ProjectFile.COLOR_CONTROL_NORMAL; +import static mod.hey.studios.util.ProjectFile.COLOR_PRIMARY; +import static mod.hey.studios.util.ProjectFile.COLOR_PRIMARY_DARK; import static mod.hey.studios.util.ProjectFile.getDefaultColor; import android.content.Context; @@ -57,8 +63,8 @@ public class MyProjectSettingActivity extends BaseAppCompatActivity implements V public MyprojectSettingBinding binding; private static final int REQUEST_CODE_CREATE_ICON = 200212; - private final String[] themeColorKeys = {"color_accent", "color_primary", "color_primary_dark", "color_control_highlight", "color_control_normal"}; - private final String[] themeColorLabels = {"colorAccent", "colorPrimary", "colorPrimaryDark", "colorControlHighlight", "colorControlNormal"}; + private final String[] themeColorKeys = {COLOR_ACCENT, COLOR_PRIMARY, COLOR_PRIMARY_DARK, COLOR_CONTROL_HIGHLIGHT, COLOR_CONTROL_NORMAL, COLOR_BACKGROUND}; + private final String[] themeColorLabels = {"colorAccent", "colorPrimary", "colorPrimaryDark", "colorControlHighlight", "colorControlNormal", "colorBackground"}; private final int[] projectThemeColors = new int[themeColorKeys.length]; private UB projectPackageNameValidator; private VB projectNameValidator; @@ -116,6 +122,7 @@ public void onCreate(Bundle savedInstanceState) { projectThemeColors[2] = getDefaultColor(ProjectFile.COLOR_PRIMARY_DARK); projectThemeColors[3] = getDefaultColor(ProjectFile.COLOR_CONTROL_HIGHLIGHT); projectThemeColors[4] = getDefaultColor(ProjectFile.COLOR_CONTROL_NORMAL); + projectThemeColors[5] = getDefaultColor(ProjectFile.COLOR_BACKGROUND); for (int i = 0; i < themeColorKeys.length; i++) { ThemeColorView colorView = new ThemeColorView(this, i);