mirror of
https://github.com/Dark98/SliceBeam.git
synced 2026-07-04 16:49:03 +00:00
Public source code release
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
package ru.ytkab0bp.slicebeam.theme;
|
||||
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import ru.ytkab0bp.slicebeam.R;
|
||||
import ru.ytkab0bp.slicebeam.utils.Prefs;
|
||||
|
||||
public class BeamTheme {
|
||||
public final static BeamTheme LIGHT = new BeamTheme() {{
|
||||
nameRes = R.string.SettingsInterfaceThemeLight;
|
||||
colors.put(R.attr.textColorOnAccent, 0xffffffff);
|
||||
colors.put(R.attr.defaultBedColor, 0xff404040);
|
||||
colors.put(R.attr.bedGridlinesColor, 0x99e5e5e5);
|
||||
colors.put(R.attr.bedContourlinesColor, 0x80ffffff);
|
||||
colors.put(R.attr.backgroundColorTop, 0xffc0c0c0);
|
||||
colors.put(R.attr.backgroundColorBottom, 0xff7a7a7a);
|
||||
colors.put(R.attr.dividerColor, 0xffeeeeee);
|
||||
colors.put(R.attr.dividerContrastColor, 0xffcccccc);
|
||||
colors.put(R.attr.dialogBackground, 0xffffffff);
|
||||
colors.put(R.attr.switchThumbUncheckedColor, 0xffeef2f3);
|
||||
colors.put(R.attr.boostyColorTop, 0xfff06e2a);
|
||||
colors.put(R.attr.boostyColorBottom, 0xfffce2d4);
|
||||
colors.put(R.attr.telegramColor, 0xff27a7e7);
|
||||
colors.put(R.attr.k3dColor, 0xff039045);
|
||||
colors.put(R.attr.modelHoverColor, 0xffffffff);
|
||||
colors.put(R.attr.textColorNegative, 0xffff464a);
|
||||
|
||||
colors.put(R.attr.gcodeViewerSkirt, 0x7FFF7F);
|
||||
colors.put(R.attr.gcodeViewerExternalPerimeter, 0xFFFF00);
|
||||
colors.put(R.attr.gcodeViewerSupportMaterial, 0x7FFF7F);
|
||||
colors.put(R.attr.gcodeViewerSupportMaterialInterface, 0x7FFF7F);
|
||||
colors.put(R.attr.gcodeViewerInternalInfill, 0xFF7F7F);
|
||||
colors.put(R.attr.gcodeViewerSolidInfill, 0xFF7F7F);
|
||||
colors.put(R.attr.gcodeViewerWipeTower, 0xF7FF7F);
|
||||
|
||||
colors.put(R.attr.xTrackColor, 0xffbf0000);
|
||||
colors.put(R.attr.yTrackColor, 0xff00bf00);
|
||||
colors.put(R.attr.zTrackColor, 0xff0000bf);
|
||||
|
||||
colors.put(android.R.attr.textColorPrimary, 0xff000000);
|
||||
colors.put(android.R.attr.textColorSecondary, 0x99000000);
|
||||
colors.put(android.R.attr.windowBackground, 0xffffffff);
|
||||
colors.put(android.R.attr.colorAccent, Prefs.getAccentColor());
|
||||
colors.put(android.R.attr.colorControlHighlight, 0x21000000);
|
||||
}};
|
||||
public final static BeamTheme DARK = new BeamTheme() {{
|
||||
nameRes = R.string.SettingsInterfaceThemeDark;
|
||||
colors = LIGHT.colors.clone();
|
||||
|
||||
colors.put(R.attr.dividerColor, 0xff333333);
|
||||
colors.put(R.attr.dividerContrastColor, 0xff444444);
|
||||
colors.put(R.attr.dialogBackground, 0xff212121);
|
||||
colors.put(R.attr.switchThumbUncheckedColor, 0xff212121);
|
||||
|
||||
colors.put(R.attr.defaultBedColor, 0xff333333);
|
||||
colors.put(R.attr.bedGridlinesColor, 0x99e5e5e5);
|
||||
colors.put(R.attr.bedContourlinesColor, 0x40ffffff);
|
||||
colors.put(R.attr.backgroundColorTop, 0xff292929);
|
||||
colors.put(R.attr.backgroundColorBottom, 0xff181818);
|
||||
colors.put(R.attr.boostyColorBottom, 0xff884725);
|
||||
|
||||
colors.put(R.attr.xTrackColor, 0xffee0000);
|
||||
colors.put(R.attr.yTrackColor, 0xff00ee00);
|
||||
colors.put(R.attr.zTrackColor, 0xff0000ee);
|
||||
|
||||
colors.put(android.R.attr.textColorPrimary, 0xffffffff);
|
||||
colors.put(android.R.attr.textColorSecondary, 0x99ffffff);
|
||||
colors.put(android.R.attr.windowBackground, 0xff121212);
|
||||
colors.put(android.R.attr.colorControlHighlight, 0x21ffffff);
|
||||
}};
|
||||
|
||||
String name;
|
||||
@StringRes
|
||||
int nameRes;
|
||||
|
||||
public SparseIntArray colors = new SparseIntArray();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package ru.ytkab0bp.slicebeam.theme;
|
||||
|
||||
public interface IThemeView {
|
||||
void onApplyTheme();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package ru.ytkab0bp.slicebeam.theme;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import ru.ytkab0bp.slicebeam.MainActivity;
|
||||
import ru.ytkab0bp.slicebeam.SliceBeam;
|
||||
import ru.ytkab0bp.slicebeam.utils.Prefs;
|
||||
|
||||
public class ThemesRepo {
|
||||
private static Boolean resolvedSystemMode;
|
||||
|
||||
public static BeamTheme getCurrent() {
|
||||
if (Prefs.getThemeMode() == Prefs.ThemeMode.SYSTEM) {
|
||||
if (resolvedSystemMode == null) {
|
||||
resolvedSystemMode = (SliceBeam.INSTANCE.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
|
||||
}
|
||||
return resolvedSystemMode ? BeamTheme.DARK : BeamTheme.LIGHT;
|
||||
}
|
||||
return Prefs.getThemeMode() == Prefs.ThemeMode.LIGHT ? BeamTheme.LIGHT : BeamTheme.DARK;
|
||||
}
|
||||
|
||||
public static void resetSystemResolvedTheme() {
|
||||
resolvedSystemMode = null;
|
||||
}
|
||||
|
||||
public static int getColor(int res) {
|
||||
return getCurrent().colors.get(res);
|
||||
}
|
||||
|
||||
public static void invalidate(Activity act) {
|
||||
if (act instanceof MainActivity) {
|
||||
((MainActivity) act).onApplyTheme();
|
||||
} else {
|
||||
invalidateView(act.getWindow().getDecorView());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
public static void invalidateView(View v) {
|
||||
if (v instanceof IThemeView) {
|
||||
((IThemeView) v).onApplyTheme();
|
||||
}
|
||||
if (v instanceof ViewGroup) {
|
||||
ViewGroup vg = (ViewGroup) v;
|
||||
for (int i = 0; i < vg.getChildCount(); i++) {
|
||||
invalidateView(vg.getChildAt(i));
|
||||
}
|
||||
}
|
||||
if (v instanceof RecyclerView) {
|
||||
((RecyclerView) v).getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user