App 2.27.1: accent colour only for styles drawn in it

Settings → Display now has the Overview style first with the accent
colour beside it; for styles with their own palette the accent field is
greyed out with a note. Styles are an enum, OverviewStyle, with
usesAccent (unit-tested). Emulator only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
This commit is contained in:
2026-10-24 21:28:39 +02:00
co-authored by Claude Opus 5.5
parent 4ef386a8d9
commit ef2ba89fba
10 changed files with 163 additions and 42 deletions
@@ -68,7 +68,7 @@ public class MainActivity extends AppCompatActivity {
private OctagonView octagonView;
/** The styles built on {@link ClusterCanvasView}, fed together. */
private final java.util.List<ClusterCanvasView> canvasStyles = new java.util.ArrayList<>();
/** The pane of each Overview style, by its index in {@link #OVERVIEW_STYLES}. */
/** The pane of each Overview style, by its {@link OverviewStyle} ordinal. */
private View[] stylePanes;
private View consumptionPane;
private View chargingPane;
@@ -1226,6 +1226,7 @@ public class MainActivity extends AppCompatActivity {
prefs.edit().putString(AccentColor.PREF_KEY, colors[position].name()).apply();
recreate();
});
applyAccentAvailability();
}
/** Tyre pressure unit: display only, read on every refresh of the Overview. */
@@ -1479,35 +1480,45 @@ public class MainActivity extends AppCompatActivity {
// ---------- Gauges (Overview style) ----------
static final String PREF_OVERVIEW_STYLE = "overview_style";
static final String PREF_OVERVIEW_STYLE = OverviewStyle.PREF_KEY;
private GaugeView dashPower, dashSpeed, dashBattery;
private BatteryBarView dashBatteryBar;
private TextView dashGear, dashClimate, dashUsage, dashBatteryText;
/** Kilometres since start, from the range estimator; null until it has a distance. */
private Double dashTripKm;
/** The stored values of the Overview styles, in the order of the drop-down. */
private static final String[] OVERVIEW_STYLES = { "TILES", "GAUGES", "COCKPIT", "RETRO", "RETRO_ACCENT", "FUTURISTIC",
"SCIFI", "CARTOON", "BLUEPRINT", "MG", "MINIMAL", "TERMINAL", "AVIATION", "NIXIE", "CHRONOGRAPH" };
/** The chosen style's index in {@link #OVERVIEW_STYLES}; anything unknown is Tiles. */
private int overviewStyle() {
String style = prefs.getString(PREF_OVERVIEW_STYLE, "TILES");
if ("DASHBOARD".equals(style)) style = "GAUGES"; // its name before 2.22.3
for (int i = 0; i < OVERVIEW_STYLES.length; i++) if (OVERVIEW_STYLES[i].equals(style)) return i;
return 0;
private OverviewStyle overviewStyle() {
return OverviewStyle.fromPref(prefs.getString(PREF_OVERVIEW_STYLE, null));
}
private void applyOverviewStyle() {
int style = overviewStyle();
for (View pane : stylePanes) pane.setVisibility(pane == stylePanes[style] ? View.VISIBLE : View.GONE);
OverviewStyle style = overviewStyle();
for (View pane : stylePanes) pane.setVisibility(pane == stylePanes[style.ordinal()] ? View.VISIBLE : View.GONE);
// Retro in either palette: one pane, the view told which.
retroView.setAccentPalette("RETRO_ACCENT".equals(OVERVIEW_STYLES[style]));
retroView.setAccentPalette(style == OverviewStyle.RETRO_ACCENT);
applyAccentAvailability();
}
/** The style drop-down; every style is fed on every reading, only the chosen one is shown. */
private void bindOverviewStyle() {
String[] labels = { getString(R.string.overview_style_tiles), getString(R.string.overview_style_gauges),
/**
* The accent colour can only be picked for a style drawn in it; for the others the drop-down
* is greyed out (keeping the colour chosen before) and a line says why.
*/
private void applyAccentAvailability() {
if (settingsPane == null) return;
OverviewStyle style = overviewStyle();
View field = settingsPane.findViewById(R.id.accent_field);
if (field == null) return;
field.setEnabled(style.usesAccent);
settingsPane.findViewById(R.id.accent_choices).setEnabled(style.usesAccent);
field.setAlpha(style.usesAccent ? 1f : 0.45f);
TextView note = settingsPane.findViewById(R.id.accent_note);
note.setVisibility(style.usesAccent ? View.GONE : View.VISIBLE);
note.setText(getString(R.string.accent_not_used, styleLabels()[style.ordinal()]));
}
/** The drop-down's labels, by {@link OverviewStyle} ordinal. */
private String[] styleLabels() {
return new String[] { getString(R.string.overview_style_tiles), getString(R.string.overview_style_gauges),
getString(R.string.overview_style_cockpit), getString(R.string.overview_style_retro),
getString(R.string.overview_style_retro_accent), getString(R.string.overview_style_futuristic),
getString(R.string.overview_style_scifi), getString(R.string.overview_style_cartoon),
@@ -1515,9 +1526,18 @@ public class MainActivity extends AppCompatActivity {
getString(R.string.overview_style_minimal), getString(R.string.overview_style_terminal),
getString(R.string.overview_style_aviation), getString(R.string.overview_style_nixie),
getString(R.string.overview_style_chronograph) };
bindChoices(settingsPane.findViewById(R.id.overview_style_choices), labels, overviewStyle(),
}
/** The style drop-down; every style is fed on every reading, only the chosen one is shown. */
private void bindOverviewStyle() {
OverviewStyle[] styles = OverviewStyle.values();
com.google.android.material.textfield.MaterialAutoCompleteTextView field =
settingsPane.findViewById(R.id.overview_style_choices);
// Wider than its field, which shares a row with the accent colour: "Retro (accent colour)".
field.setDropDownWidth(Math.round(360 * getResources().getDisplayMetrics().density));
bindChoices(field, styleLabels(), overviewStyle().ordinal(),
position -> {
prefs.edit().putString(PREF_OVERVIEW_STYLE, OVERVIEW_STYLES[position]).apply();
prefs.edit().putString(PREF_OVERVIEW_STYLE, styles[position].name()).apply();
applyOverviewStyle();
});
}