]> git.ktnx.net Git - mobile-ledger.git/commitdiff
rework theme color spectrum to match the holy grail violet and get a darker yellow...
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Tue, 16 Apr 2019 17:36:54 +0000 (20:36 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Tue, 16 Apr 2019 17:36:54 +0000 (20:36 +0300)
also, automate theme XML update

app/src/main/java/net/ktnx/mobileledger/utils/Colors.java
app/src/main/res/values/styles.xml
tools/gen-styles

index acfea2f4519e1baf076a82e2c475a08bf554f0ed..8f59c1cf23ccf0c1247cfa0b597431a9f1e3293f 100644 (file)
@@ -33,6 +33,8 @@ import static java.lang.Math.abs;
 
 public class Colors {
     public static final int DEFAULT_HUE_DEG = 261;
+    private static final float blueLightness = 0.665f;
+    private static final float yellowLightness = 0.350f;
     public static @ColorInt
     int accent;
     @ColorInt
@@ -42,7 +44,6 @@ public class Colors {
     @ColorInt
     public static int primary, defaultTextColor;
     public static int profileThemeId = -1;
-
     public static ObservableValue<Integer> themeWatch = new ObservableValue<>(0);
     public static void refreshColors(Resources.Theme theme) {
         TypedValue tv = new TypedValue();
@@ -75,8 +76,8 @@ public class Colors {
         return 0xff000000 | hsvTriplet(hue, saturation, value);
     }
     public static @ColorInt
-    int hslColor(float hue, float saturation, float lightness) {
-        return 0xff000000 | hslTriplet(hue, saturation, lightness);
+    int hslColor(float hueRatio, float saturation, float lightness) {
+        return 0xff000000 | hslTriplet(hueRatio, saturation, lightness);
     }
     public static @ColorInt
     int hsvTriplet(float hue, float saturation, float value) {
@@ -115,9 +116,9 @@ public class Colors {
         }
     }
     public static @ColorInt
-    int hslTriplet(float hue, float saturation, float lightness) {
+    int hslTriplet(float hueRatio, float saturation, float lightness) {
         @ColorLong long result;
-        float h = hue * 6;
+        float h = hueRatio * 6;
         float c = (1 - abs(2f * lightness - 1)) * saturation;
         float h_mod_2 = h % 2;
         float x = c * (1 - Math.abs(h_mod_2 - 1));
@@ -133,7 +134,7 @@ public class Colors {
 
         throw new IllegalArgumentException(String.format(
                 "Unexpected value for h (%1.3f) while converting hsl(%1.3f, %1.3f, %1.3f) to rgb",
-                h, hue, saturation, lightness));
+                h, hueRatio, saturation, lightness));
     }
 
     public static @ColorInt
@@ -144,16 +145,14 @@ public class Colors {
         return (r_int << 16) | (g_int << 8) | b_int;
     }
     public static @ColorInt
-    int getPrimaryColorForHue(int degrees) {
-        // 0/360f becomes -0.000something for some reason
-        if (degrees == 0) return getPrimaryColorForHue(0f);
-        return getPrimaryColorForHue(degrees / 360f);
-    }
-    public static @ColorInt
-    int getPrimaryColorForHue(float hue) {
-//        int result = hsvColor(hue, 0.61f, 0.95f);
-        int result = hslColor(hue, 0.60f, 0.60f);
-        Log.d("colors", String.format("getPrimaryColorForHue(%1.2f) = %x", hue, result));
+    int getPrimaryColorForHue(int hueDegrees) {
+//        int result = hsvColor(hueDegrees, 0.61f, 0.95f);
+        float y = hueDegrees - 60;
+        if (y < 0) y += 360;
+        float l = yellowLightness + (blueLightness - yellowLightness) *
+                                    (float) Math.cos(Math.toRadians(Math.abs(180 - y) / 2f));
+        int result = hslColor(hueDegrees/360f, 0.845f, l);
+        Log.d("colors", String.format("getPrimaryColorForHue(%d) = %x", hueDegrees, result));
         return result;
     }
     public static void setupTheme(Activity activity) {
index 6c0e377f0a828087ee6df34eeaa49ef34adfd590..76dbd4db921d8f1b3b728516d9055882680dbb60 100644 (file)
     <style name="AppTheme.NoActionBar">
         <item name="windowActionBar">false</item>
         <item name="windowNoTitle">true</item>
-        <item name="textColor">#8a000000</item>
-        <item name="colorPrimary">#875cd6</item>
-        <item name="colorPrimaryTransparent">#00875cd6</item>
-        <item name="colorAccent">#6013ec</item>
+        <item name="textColor">#d0000000</item>
+        <item name="colorPrimary">#935ff2</item>
+        <item name="colorPrimaryTransparent">#00935ff2</item>
+        <item name="colorAccent">#5f14e8</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#efe7fd</item>
         <item name="table_row_light_bg">#f9f6fe</item>
     </style>
+
     <style name="AppTheme.NoActionBar.0" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#d65c5c</item>
-        <item name="colorPrimaryTransparent">#00d65c5c</item>
-        <item name="colorAccent">#ec1313</item>
+        <item name="colorPrimary">#ec1717</item>
+        <item name="colorPrimaryTransparent">#00ec1717</item>
+        <item name="colorAccent">#990d0d</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#fde7e7</item>
         <item name="table_row_light_bg">#fef6f6</item>
     </style>
+
     <style name="AppTheme.NoActionBar.15" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#d67a5c</item>
-        <item name="colorPrimaryTransparent">#00d67a5c</item>
-        <item name="colorAccent">#ec4913</item>
+        <item name="colorPrimary">#dd4513</item>
+        <item name="colorPrimaryTransparent">#00dd4513</item>
+        <item name="colorAccent">#862a0b</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#fdede7</item>
         <item name="table_row_light_bg">#fef8f6</item>
     </style>
+
     <style name="AppTheme.NoActionBar.30" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#d6995c</item>
-        <item name="colorPrimaryTransparent">#00d6995c</item>
-        <item name="colorAccent">#ec8013</item>
+        <item name="colorPrimary">#cb6e11</item>
+        <item name="colorPrimaryTransparent">#00cb6e11</item>
+        <item name="colorAccent">#713d0a</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#fdf2e7</item>
         <item name="table_row_light_bg">#fefaf6</item>
     </style>
+
     <style name="AppTheme.NoActionBar.45" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#d6b85c</item>
-        <item name="colorPrimaryTransparent">#00d6b85c</item>
-        <item name="colorAccent">#ecb613</item>
+        <item name="colorPrimary">#b88e0f</item>
+        <item name="colorPrimaryTransparent">#00b88e0f</item>
+        <item name="colorAccent">#5c4708</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#fdf8e7</item>
         <item name="table_row_light_bg">#fefcf6</item>
     </style>
+
     <style name="AppTheme.NoActionBar.60" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#d6d65c</item>
-        <item name="colorPrimaryTransparent">#00d6d65c</item>
-        <item name="colorAccent">#ecec13</item>
+        <item name="colorPrimary">#a5a50e</item>
+        <item name="colorPrimaryTransparent">#00a5a50e</item>
+        <item name="colorAccent">#474706</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#fdfde7</item>
         <item name="table_row_light_bg">#fefef6</item>
     </style>
+
     <style name="AppTheme.NoActionBar.75" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#b8d65c</item>
-        <item name="colorPrimaryTransparent">#00b8d65c</item>
-        <item name="colorAccent">#b6ec13</item>
+        <item name="colorPrimary">#8eb80f</item>
+        <item name="colorPrimaryTransparent">#008eb80f</item>
+        <item name="colorAccent">#475c08</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#f8fde7</item>
         <item name="table_row_light_bg">#fcfef6</item>
     </style>
+
     <style name="AppTheme.NoActionBar.90" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#99d65c</item>
-        <item name="colorPrimaryTransparent">#0099d65c</item>
-        <item name="colorAccent">#80ec13</item>
+        <item name="colorPrimary">#6ecb11</item>
+        <item name="colorPrimaryTransparent">#006ecb11</item>
+        <item name="colorAccent">#3d710a</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#f2fde7</item>
         <item name="table_row_light_bg">#fafef6</item>
     </style>
+
     <style name="AppTheme.NoActionBar.105" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#7ad65c</item>
-        <item name="colorPrimaryTransparent">#007ad65c</item>
-        <item name="colorAccent">#49ec13</item>
+        <item name="colorPrimary">#45dd13</item>
+        <item name="colorPrimaryTransparent">#0045dd13</item>
+        <item name="colorAccent">#2a860b</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#edfde7</item>
         <item name="table_row_light_bg">#f8fef6</item>
     </style>
+
     <style name="AppTheme.NoActionBar.120" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#5cd65c</item>
-        <item name="colorPrimaryTransparent">#005cd65c</item>
-        <item name="colorAccent">#13ec13</item>
+        <item name="colorPrimary">#17ec17</item>
+        <item name="colorPrimaryTransparent">#0017ec17</item>
+        <item name="colorAccent">#0d990d</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#e7fde7</item>
         <item name="table_row_light_bg">#f6fef6</item>
     </style>
+
     <style name="AppTheme.NoActionBar.135" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#5cd67a</item>
-        <item name="colorPrimaryTransparent">#005cd67a</item>
-        <item name="colorAccent">#13ec49</item>
+        <item name="colorPrimary">#27ed59</item>
+        <item name="colorPrimaryTransparent">#0027ed59</item>
+        <item name="colorAccent">#0eab35</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#e7fded</item>
         <item name="table_row_light_bg">#f6fef8</item>
     </style>
+
     <style name="AppTheme.NoActionBar.150" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#5cd699</item>
-        <item name="colorPrimaryTransparent">#005cd699</item>
-        <item name="colorAccent">#13ec80</item>
+        <item name="colorPrimary">#36ee92</item>
+        <item name="colorPrimaryTransparent">#0036ee92</item>
+        <item name="colorAccent">#10bb65</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#e7fdf2</item>
         <item name="table_row_light_bg">#f6fefa</item>
     </style>
+
     <style name="AppTheme.NoActionBar.165" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#5cd6b8</item>
-        <item name="colorPrimaryTransparent">#005cd6b8</item>
-        <item name="colorAccent">#13ecb6</item>
+        <item name="colorPrimary">#43efc4</item>
+        <item name="colorPrimaryTransparent">#0043efc4</item>
+        <item name="colorAccent">#11c99b</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#e7fdf8</item>
         <item name="table_row_light_bg">#f6fefc</item>
     </style>
+
     <style name="AppTheme.NoActionBar.180" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#5cd6d6</item>
-        <item name="colorPrimaryTransparent">#005cd6d6</item>
-        <item name="colorAccent">#13ecec</item>
+        <item name="colorPrimary">#4ef0f0</item>
+        <item name="colorPrimaryTransparent">#004ef0f0</item>
+        <item name="colorAccent">#12d5d5</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#e7fdfd</item>
         <item name="table_row_light_bg">#f6fefe</item>
     </style>
+
     <style name="AppTheme.NoActionBar.195" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#5cb8d6</item>
-        <item name="colorPrimaryTransparent">#005cb8d6</item>
-        <item name="colorAccent">#13b6ec</item>
+        <item name="colorPrimary">#56caf1</item>
+        <item name="colorPrimaryTransparent">#0056caf1</item>
+        <item name="colorAccent">#13acdf</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#e7f8fd</item>
         <item name="table_row_light_bg">#f6fcfe</item>
     </style>
+
     <style name="AppTheme.NoActionBar.210" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#5c99d6</item>
-        <item name="colorPrimaryTransparent">#005c99d6</item>
-        <item name="colorAccent">#1380ec</item>
+        <item name="colorPrimary">#5ca7f1</item>
+        <item name="colorPrimaryTransparent">#005ca7f1</item>
+        <item name="colorAccent">#137ce6</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#e7f2fd</item>
         <item name="table_row_light_bg">#f6fafe</item>
     </style>
+
     <style name="AppTheme.NoActionBar.225" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#5c7ad6</item>
-        <item name="colorPrimaryTransparent">#005c7ad6</item>
-        <item name="colorAccent">#1349ec</item>
+        <item name="colorPrimary">#6085f2</item>
+        <item name="colorPrimaryTransparent">#006085f2</item>
+        <item name="colorAccent">#1449ea</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#e7edfd</item>
         <item name="table_row_light_bg">#f6f8fe</item>
     </style>
+
     <style name="AppTheme.NoActionBar.240" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#5c5cd6</item>
-        <item name="colorPrimaryTransparent">#005c5cd6</item>
-        <item name="colorAccent">#1313ec</item>
+        <item name="colorPrimary">#6161f2</item>
+        <item name="colorPrimaryTransparent">#006161f2</item>
+        <item name="colorAccent">#1414eb</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#e7e7fd</item>
         <item name="table_row_light_bg">#f6f6fe</item>
     </style>
+
     <style name="AppTheme.NoActionBar.255" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#7a5cd6</item>
-        <item name="colorPrimaryTransparent">#007a5cd6</item>
-        <item name="colorAccent">#4913ec</item>
+        <item name="colorPrimary">#8560f2</item>
+        <item name="colorPrimaryTransparent">#008560f2</item>
+        <item name="colorAccent">#4914ea</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#ede7fd</item>
         <item name="table_row_light_bg">#f8f6fe</item>
     </style>
+
     <style name="AppTheme.NoActionBar.270" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#995cd6</item>
-        <item name="colorPrimaryTransparent">#00995cd6</item>
-        <item name="colorAccent">#8013ec</item>
+        <item name="colorPrimary">#a75cf1</item>
+        <item name="colorPrimaryTransparent">#00a75cf1</item>
+        <item name="colorAccent">#7c13e6</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#f2e7fd</item>
         <item name="table_row_light_bg">#faf6fe</item>
     </style>
+
     <style name="AppTheme.NoActionBar.285" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#b85cd6</item>
-        <item name="colorPrimaryTransparent">#00b85cd6</item>
-        <item name="colorAccent">#b613ec</item>
+        <item name="colorPrimary">#ca56f1</item>
+        <item name="colorPrimaryTransparent">#00ca56f1</item>
+        <item name="colorAccent">#ac13df</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#f8e7fd</item>
         <item name="table_row_light_bg">#fcf6fe</item>
     </style>
+
     <style name="AppTheme.NoActionBar.300" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#d65cd6</item>
-        <item name="colorPrimaryTransparent">#00d65cd6</item>
-        <item name="colorAccent">#ec13ec</item>
+        <item name="colorPrimary">#f04ef0</item>
+        <item name="colorPrimaryTransparent">#00f04ef0</item>
+        <item name="colorAccent">#d512d5</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#fde7fd</item>
         <item name="table_row_light_bg">#fef6fe</item>
     </style>
+
     <style name="AppTheme.NoActionBar.315" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#d65cb8</item>
-        <item name="colorPrimaryTransparent">#00d65cb8</item>
-        <item name="colorAccent">#ec13b6</item>
+        <item name="colorPrimary">#ef43c4</item>
+        <item name="colorPrimaryTransparent">#00ef43c4</item>
+        <item name="colorAccent">#c9119b</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#fde7f8</item>
         <item name="table_row_light_bg">#fef6fc</item>
     </style>
+
     <style name="AppTheme.NoActionBar.330" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#d65c99</item>
-        <item name="colorPrimaryTransparent">#00d65c99</item>
-        <item name="colorAccent">#ec1380</item>
+        <item name="colorPrimary">#ee3692</item>
+        <item name="colorPrimaryTransparent">#00ee3692</item>
+        <item name="colorAccent">#bb1065</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#fde7f2</item>
         <item name="table_row_light_bg">#fef6fa</item>
     </style>
+
     <style name="AppTheme.NoActionBar.345" parent="AppTheme.NoActionBar">
-        <item name="colorPrimary">#d65c7a</item>
-        <item name="colorPrimaryTransparent">#00d65c7a</item>
-        <item name="colorAccent">#ec1349</item>
+        <item name="colorPrimary">#ed2759</item>
+        <item name="colorPrimaryTransparent">#00ed2759</item>
+        <item name="colorAccent">#ab0e35</item>
         <item name="drawer_background">#ffffffff</item>
         <item name="table_row_dark_bg">#fde7ed</item>
         <item name="table_row_light_bg">#fef6f8</item>
index a86983b764729bf9791d0c63cd5e8e916640b29c..1c2c4c8524af8796d0c35ce33214857f70a3a069 100644 (file)
@@ -1,6 +1,10 @@
 #!/usr/bin/perl
 
 use strict; use warnings; use utf8;
+use autodie;
+use Math::Trig;
+use File::Basename qw(basename dirname);
+use File::Temp qw(tempfile);
 
 sub hexTuple {
        my ($r, $g, $b) = @_;
@@ -27,9 +31,10 @@ sub hsvHex {
 # https://en.wikipedia.org/wiki/HSL_and_HSV#From_HSL
 sub hslHex {
        my ($hue, $sat, $lig ) = @_;
-       my $h = ($hue * 6);
+       $hue = $hue / 360.0;
+       my $h = ($hue * 6.0);
        my $c = (1 - abs(2.0*$lig - 1)) * $sat;
-       my $h_mod_2 = $h - 2*int($h/2);
+       my $h_mod_2 = $h - 2.0*int($h/2);
        my $x = $c * (1 - abs($h_mod_2 - 1));
        my ($r, $g, $b);
        my $m = $lig - $c / 2.0;
@@ -65,14 +70,20 @@ sub max {
        return $max;
 }
 
+sub hexToRGB {
+       my $hexTriplet = shift;
+
+       my @d = $hexTriplet =~ /^#?(.)(.)(.)(.)(.)(.)/;
+
+       return (16 * $hexValue{$d[0]} + $hexValue{$d[1]},
+               16 * $hexValue{$d[2]} + $hexValue{$d[3]},
+               16 * $hexValue{$d[4]} + $hexValue{$d[5]});
+}
+
 sub hexToHSL {
        my $hexTriplet = shift;
-       my ( $r,$g,$b ) = $hexTriplet =~ /^#?(..)(..)(..)/;
-       for ($r,$g,$b) {
-               my @d = split(//);
-               $_ = 16 * $hexValue{$d[0]} + $hexValue{$d[1]};
-       }
 
+       my ($r,$g,$b) = hexToRGB($hexTriplet);
        warn "$hexTriplet -> $r:$g:$b";
 
        for ($r, $g, $b ) { $_ = $_ / 255.0 }
@@ -107,8 +118,25 @@ sub hexToHSL {
 
 my $baseColorHSV = [ hexToHSL('#935ff2') ];
 my $baseColorHue = $baseColorHSV->[0];
-warn sprintf( 'H:%1.4f S:%1.4f L:%1.4f', @$baseColorHSV );
+warn sprintf( 'H:%1.4f S:%1.4f V:%1.4f', @$baseColorHSV );
 warn sprintf( 'H:%1.4f S:%1.4f L:%1.4f', hexToHSL('#3e148c') );
+my @target = hexToRGB('#935ff2');
+my ($best, $min_dist);
+for (my $s = 0.50; $s < 0.90; $s += 0.001) {
+       for ( my $l = 0.50; $l <= 0.80; $l += 0.001 ) {
+               my $hexColor = hslHex($baseColorHue, $s, $l);
+               my ($r,$g,$b) = hexToRGB( $hexColor );
+               my $dist = abs($r-$target[0])
+                        + abs($g-$target[1])
+                        + abs($b-$target[2]);
+               if (not defined($best) or $dist < $min_dist) {
+                       $best = [ $s, $l, $hexColor ];
+                       $min_dist = $dist;
+               }
+       }
+}
+warn sprintf( 's%1.3f, l%1.3f -> %s',
+       @$best );
 
 my $baseTheme = "AppTheme.NoActionBar";
 
@@ -133,36 +161,93 @@ my $baseTheme = "AppTheme.NoActionBar";
 # }
 
 # HSL
-hslStyleForHue($baseColorHue);
-for( my $hue = 0; $hue < 360; $hue += 15 ) {
-       hslStyleForHue($hue, $baseTheme);
+sub outputThemes {
+       my $out = shift;
+       $out->print(hslStyleForHue($baseColorHue));
+       for( my $hue = 0; $hue < 360; $hue += 15 ) {
+               $out->print(hslStyleForHue($hue, $baseTheme));
+       }
 }
 
 sub hslStyleForHue {
        my $hue = shift;
        my $base = shift;
 
+       my $blueL = 0.665;
+       my $yellowL = 0.350;
+
+       my $y = $hue - 60;
+       $y += 360 if $y < 0;
+       my $q = cos(deg2rad(abs($y-180)/2.0));
+       my $l1 = $yellowL + ($blueL - $yellowL) * $q;
+       my $l2 = 0.150 + 0.350 * $q;
+       my $l3 = 0.950;
+       my $l4 = 0.980;
+
+       my $result = "";
+
        if ($base) {
-               printf "<style name=\"%s.%d\" parent=\"%s\">\n",
-                       $baseTheme, $hue, $baseTheme;
-       }
-       else {
-               printf "<style name=\"%s\">\n",
-                       $baseTheme;
-               printf "  <item name=\"windowActionBar\">false</item>\n";
-               printf "  <item name=\"windowNoTitle\">true</item>\n";
-               printf "  <item name=\"textColor\">#d0000000</item>\n";
+               $result .= sprintf "<style name=\"%s.%d\" parent=\"%s\">\n",
+                        $baseTheme, $hue, $baseTheme;
+        }
+        else {
+                $result .= sprintf "<style name=\"%s\">\n",
+                        $baseTheme;
+                $result .= "  <item name=\"windowActionBar\">false</item>\n";
+                $result .= "  <item name=\"windowNoTitle\">true</item>\n";
+                $result .= "  <item name=\"textColor\">#d0000000</item>\n";
+        }
+        my $S = 0.845;
+        $result .= sprintf "  <item name=\"colorPrimary\">#%s</item>\n",
+                hslHex($hue, $S, $l1);
+        $result .= sprintf "  <item name=\"colorPrimaryTransparent\">#00%s</item>\n",
+                hslHex($hue, $S, $l1);
+        $result .= sprintf "  <item name=\"colorAccent\">#%s</item>\n",
+                hslHex($hue, $S, $l2);
+        $result .= "  <item name=\"drawer_background\">#ffffffff</item>\n";
+        $result .= sprintf "  <item name=\"table_row_dark_bg\">#%s</item>\n",
+                hslHex($hue, $S, $l3);
+        $result .= sprintf "  <item name=\"table_row_light_bg\">#%s</item>\n",
+                hslHex($hue, $S, $l4);
+        $result .= "</style>\n";
+
+        return $result;
+}
+
+my $xml = shift;
+
+if ($xml) {
+       my $start_marker = '<!-- theme list start -->';
+       my $end_marker = '<!-- theme list end -->';
+       my ($fh, $filename) = tempfile(basename($0).'.XXXXXXXX', DIR => dirname($xml));
+       open(my $in, '<', $xml);
+       my $state = 'waiting-for-start-marker';
+       while (<$in>) {
+               if ( $state eq 'waiting-for-start-marker' ) {
+                       print $fh $_;
+                       $state = 'skipping-styles' if /^\s*\Q$start_marker\E/;
+                       next;
+               }
+               if ( $state eq 'skipping-styles' ) {
+                       next unless /^\s*\Q$end_marker\E/;
+                       outputThemes($fh);
+                       print $fh $_;
+                       $state = 'copying-the-rest';
+                       next;
+               }
+               if ( $state eq 'copying-the-rest') {
+                       print $fh $_;
+                       next;
+               }
+
+               die "Unexpected state '$state'";
        }
-       printf "  <item name=\"colorPrimary\">#%s</item>\n",
-                       hslHex($hue/360.0, 0.60, 0.60);
-       printf "  <item name=\"colorPrimaryTransparent\">#00%s</item>\n",
-                       hslHex($hue/360.0, 0.60, 0.60);
-       printf "  <item name=\"colorAccent\">#%s</item>\n",
-                       hslHex($hue/360.0, 0.85, 0.50);
-       printf "  <item name=\"drawer_background\">#ffffffff</item>\n";
-       printf "  <item name=\"table_row_dark_bg\">#%s</item>\n",
-                       hslHex($hue/360.0, 0.85, 0.95);
-       printf "  <item name=\"table_row_light_bg\">#%s</item>\n",
-                       hslHex($hue/360.0, 0.85, 0.98);
-       printf "</style>\n";
+
+       close($fh);
+       close($in);
+
+       rename($filename, $xml);
+}
+else {
+       outputThemes(\*STDOUT);
 }