Skip to content

Commit

Permalink
feat: Add ability to customize colorBackground in built-in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
aikrq committed Nov 30, 2024
1 parent 862ea4c commit 79b4175
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 9 additions & 0 deletions app/src/main/java/a/a/a/yq.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public class yq {

public final int colorControlNormal;

public final int colorBackground;

public final String versionCode;

public final String versionName;
Expand Down Expand Up @@ -227,6 +229,7 @@ public yq(Context context, String myscFolderPath, HashMap<String, Object> 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);
Expand Down Expand Up @@ -837,11 +840,13 @@ public ArrayList<SrcCodeBean> 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");
Expand All @@ -857,18 +862,21 @@ public ArrayList<SrcCodeBean> 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");
Expand All @@ -880,6 +888,7 @@ public ArrayList<SrcCodeBean> 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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 79b4175

Please sign in to comment.