-
Notifications
You must be signed in to change notification settings - Fork 297
/
generate-themes.pl
executable file
·205 lines (168 loc) · 9.86 KB
/
generate-themes.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/perl
use strict;
use constant THEMES_OUTDIR => './app/src/main/res/values-v21/';
use constant THEMES_LIST => './app/src/main/res/values-v21/themes-list.xml';
my $THEMES = [
{ name=>"standard_light", id=>0, dark=>0, colorAccent => '#ff3e677a', colorPrimary => '#ff37474f', colorPrimaryDark => '#ff263238', controlsNormal=>'@color/material_grey_900', floatColor=>'@color/material_grey_400', _bg => '#fff0f0f0' },
{ name=>"standard_dark", id=>1, dark=>1, colorAccent => '#ff3e677a', colorPrimary => '#ff37474f', colorPrimaryDark => '#ff263238', controlsNormal=>'@color/material_grey_300', floatColor=>'@color/material_grey_900', _bg => '#ff2a2a2a' },
{ name=>"grey_light", id=>2, dark=>0, colorAccent => '#ff000000', colorPrimary => '#ff212121', colorPrimaryDark => '#ff090909', controlsNormal=>'@color/material_grey_600', floatColor=>'@color/material_grey_400', _bg => '#fff0f0f0' },
{ name=>"grey_dark", id=>3, dark=>1, colorAccent => '#ffd8d8d8', colorPrimary => '#ff212121', colorPrimaryDark => '#ff090909', controlsNormal=>'@color/material_grey_600', floatColor=>'@color/material_grey_900',_bg => '#ff2a2a2a' },
{ name=>"orange_light", id=>4, dark=>0, colorAccent => '#FFF57F17', colorPrimary => '#FFE65100', colorPrimaryDark => '#FFBF360C', controlsNormal=>'@color/material_grey_900', floatColor=>'@color/material_grey_400', _bg => '#fff0f0f0' },
{ name=>"orange_dark", id=>5, dark=>1, colorAccent => '#FFF57F17', colorPrimary => '#FFE65100', colorPrimaryDark => '#FFBF360C', controlsNormal=>'@color/material_grey_300', floatColor=>'@color/material_grey_900',_bg => '#ff2a2a2a' },
{ name=>"blue_light", id=>6, dark=>0, colorAccent => '#FF03A9F4', colorPrimary => '#FF0277BD', colorPrimaryDark => '#FF01579B', controlsNormal=>'@color/material_grey_900', floatColor=>'@color/material_grey_400', _bg => '#fff0f0f0' },
{ name=>"blue_dark", id=>7, dark=>1, colorAccent => '#FF03A9F4', colorPrimary => '#FF0277BD', colorPrimaryDark => '#FF01579B', controlsNormal=>'@color/material_grey_300', floatColor=>'@color/material_grey_900',_bg => '#ff2a2a2a' },
{ name=>"red_light", id=>8, dark=>0, colorAccent => '#ffd50000', colorPrimary => '#ffc62828', colorPrimaryDark => '#ffb71c1c', controlsNormal=>'@color/material_grey_900', floatColor=>'@color/material_grey_400', _bg => '#fff0f0f0' },
{ name=>"red_dark", id=>9, dark=>1, colorAccent => '#ffd50000', colorPrimary => '#ffc62828', colorPrimaryDark => '#ffb71c1c', controlsNormal=>'@color/material_grey_300', floatColor=>'@color/material_grey_900',_bg => '#ff2a2a2a' },
{ name=>"amoled_dark", id=>10, dark=>1, colorAccent => '#ffd8d8d8', colorPrimary => '#ff000000', colorPrimaryDark => '#ff000000', controlsNormal=>'@color/material_grey_600', colorBackground=>'@android:color/black', floatColor=>'@color/material_grey_900', _bg => '#ff000000' },
{ name=>"start_wearing_purple", id=>11, dark=>1,
colorAccent => '#FF896FBC', colorPrimary=> '#FF5C038C', colorPrimaryDark => '#FF420264', controlsNormal=>'@color/material_grey_600',
colorBackground => '@color/start_wearing_purple_background', controlsActive=> '#FF5C038C', floatColor => '#FF420264',
_bg => '#ff1B1734' },
];
my $XML_ARRAYS = {};
foreach my $theme_ref (@$THEMES) {
my $theme_name = $theme_ref->{name};
my $theme_id = $theme_ref->{id} == 0 ? '' : ucfirst($theme_name)."."; # standard_light has no prefix
my $outfile = THEMES_OUTDIR."/theme-$theme_name.xml";
my $outbuff = get_theme_xml($theme_ref, $theme_id);
open(OUT, ">", $outfile) or die "Can not write to $outfile: $!\n";
print OUT $outbuff;
close(OUT);
# Get all styles found in get_theme_xml output.
foreach my $line (split(/\n/, $outbuff)) {
if (my ($style) = $line =~ /style name=\"([^"]+)\"/) {
my $category = "theme_category_".lc((split(/\./, $style))[-1]);
push(@{$XML_ARRAYS->{'integer-array'}->{$category}}, '@style/'.$style);
}
}
my $tvarr = join(",", map { $theme_ref->{$_} } qw(colorPrimaryDark _bg colorPrimary));
# csv list of theme info, such as its id and the primary colors to show in preview
push(@{$XML_ARRAYS->{'string-array'}->{theme_values}}, $tvarr);
# user visible names of themes
push(@{$XML_ARRAYS->{'string-array'}->{theme_entries}}, '@string/theme_name_'.$theme_ref->{name});
# id <-> sort mapping
push(@{$XML_ARRAYS->{'string-array'}->{theme_ids}}, $theme_ref->{id});
# set flag whether theme is dark or not
push(@{$XML_ARRAYS->{'string-array'}->{theme_variant}}, $theme_ref->{dark} ? 'dark' : 'light');
}
open(OUT, ">", THEMES_LIST) or die "Cannot write theme list: $!\n";
print OUT << "EOLIST";
<?xml version="1.0" encoding="utf-8"?>
<!-- THIS FILE IS AUTOGENERATED BY generate-themes.pl - DO NOT TOUCH! -->
<resources>
EOLIST
foreach my $array_type (sort(keys(%$XML_ARRAYS))) {
my $lists = $XML_ARRAYS->{$array_type};
foreach my $name (sort(keys(%$lists))) {
my $items = $lists->{$name};
print OUT "\t<$array_type name=\"$name\">\n";
foreach my $item (@$items) {
print OUT "\t\t<item>$item</item>\n";
}
print OUT "\t</$array_type>\n\n";
}
}
print OUT "</resources>\n";
close(OUT);
sub get_theme_xml {
my($this, $tid) = @_;
my $DATA = << "EOF";
<?xml version="1.0" encoding="utf-8"?>
<!--
*** THIS FILE WAS GENERATED BY 'generate-themes.pl' - DO NOT TOUCH ***
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<resources>
EOF
my $controlsActive = $this->{controlsActive} || $this->{colorAccent};
if($this->{dark} == 0) {
$DATA .= << "EOF"
<style name="${tid}VanillaBase" parent="android:Theme.Material.Light.DarkActionBar">
<item name="overlay_background_color">\@color/overlay_background_light</item>
<item name="overlay_foreground_color">\@color/overlay_foreground_light</item>
<item name="float_color">$this->{floatColor}</item>
<item name="tabs_background">$this->{colorPrimary}</item>
<item name="now_playing_marker">$this->{colorAccent}</item>
<item name="controls_normal">$this->{controlsNormal}</item>
<item name="controls_active">$controlsActive</item>
<item name="android:colorAccent">$this->{colorAccent}</item>
<item name="android:colorPrimary">$this->{colorPrimary}</item>
<item name="android:colorPrimaryDark">$this->{colorPrimaryDark}</item>
<item name="themed_letter_tile_colors">\@array/letter_tile_colors_light</item>
</style>
<style name="${tid}Playback" parent="${tid}VanillaBase">
<item name="android:actionBarStyle">\@style/Universal.PlaybackActionBar</item>
</style>
<style name="${tid}BackActionBar" parent="${tid}VanillaBase">
<item name="android:actionBarStyle">\@style/Universal.PlaybackActionBar</item>
</style>
<style name="${tid}Library" parent="${tid}VanillaBase">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="${tid}PopupDialog" parent="android:Theme.Material.Light.Dialog.MinWidth">
<item name="overlay_background_color">\@color/overlay_background_light</item>
<item name="controls_normal">$this->{controlsNormal}</item>
<item name="controls_active">$controlsActive</item>
</style>
<style name="${tid}BottomSheetDialog" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:colorBackground">\@color/overlay_background_light</item>
</style>
EOF
} else {
$DATA .= << "EOF"
<!-- dark theme -->
<style name="${tid}VanillaBase" parent="android:Theme.Material">
<item name="overlay_background_color">\@color/overlay_background_dark</item>
<item name="overlay_foreground_color">\@color/overlay_foreground_dark</item>
<item name="float_color">$this->{floatColor}</item>
<item name="tabs_background">$this->{colorPrimary}</item>
<item name="now_playing_marker">$this->{colorAccent}</item>
<item name="controls_normal">$this->{controlsNormal}</item>
<item name="controls_active">$this->{colorAccent}</item>
<item name="android:colorAccent">$this->{colorAccent}</item>
<item name="android:colorPrimary">$this->{colorPrimary}</item>
<item name="android:colorPrimaryDark">$this->{colorPrimaryDark}</item>
<item name="themed_letter_tile_colors">\@array/letter_tile_colors_dark</item>
</style>
<style name="${tid}Playback" parent="${tid}VanillaBase">
<item name="android:actionBarStyle">\@style/Universal.PlaybackActionBar</item>
</style>
<style name="${tid}BackActionBar" parent="${tid}VanillaBase">
<item name="android:actionBarStyle">\@style/Universal.PlaybackActionBar</item>
</style>
<style name="${tid}Library" parent="${tid}VanillaBase">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="${tid}PopupDialog" parent="android:Theme.Material.Dialog.MinWidth">
<item name="overlay_background_color">\@color/overlay_background_dark</item>
<item name="controls_normal">$this->{controlsNormal}</item>
<item name="controls_active">$controlsActive</item>
</style>
<style name="${tid}BottomSheetDialog" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:colorBackground">\@color/overlay_background_dark</item>
</style>
EOF
}
$DATA .= "\n</resources>\n";
# Add custom colorBackground if set, inherit from theme otherwise.
# If we force this, we also set overlay_background_color to the same value
# as it is expected to match the background.
if (defined($this->{colorBackground})) {
$DATA =~ s/<item name="(overlay_background_color)">.+<\/item>/
<item name="android:colorBackground">$this->{colorBackground}<\/item>
<item name="\1">$this->{colorBackground}<\/item>
/;
}
return $DATA
}