#!/usr/bin/perl
use strict;
use constant THEMES_OUTDIR => './res/values-v21/';
use constant THEMES_LIST => './res/values-v21/themes-list.xml';
my $THEMES = [
{
_name => 'standard',
light => { colorAccent => '#ff3e677a', colorPrimary => '#ff37474f', colorPrimaryDark => '#ff263238', controlsNormal=>'@color/material_grey_900', _bg => '#fff0f0f0' },
dark => { colorAccent => '#ff3e677a', colorPrimary => '#ff37474f', colorPrimaryDark => '#ff263238', controlsNormal=>'@color/material_grey_300', _bg => '#ff2a2a2a' },
},
{
_name => 'greyish',
light => { colorAccent => '#ff000000', colorPrimary => '#ff212121', colorPrimaryDark => '#ff090909', controlsNormal=>'@color/material_grey_600', _bg => '#fff0f0f0' },
dark => { colorAccent => '#ffd8d8d8', colorPrimary => '#ff212121', colorPrimaryDark => '#ff090909', controlsNormal=>'@color/material_grey_600', _bg => '#ff2a2a2a' },
},
{
_name => 'orange',
light => { colorAccent => '#FFF57F17', colorPrimary => '#FFE65100', colorPrimaryDark => '#FFBF360C', controlsNormal=>'@color/material_grey_900', _bg => '#fff0f0f0' },
dark => { colorAccent => '#FFF57F17', colorPrimary => '#FFE65100', colorPrimaryDark => '#FFBF360C', controlsNormal=>'@color/material_grey_300', _bg => '#ff2a2a2a' },
},
{
_name => 'blue',
light => { colorAccent => '#FF03A9F4', colorPrimary => '#FF0277BD', colorPrimaryDark => '#FF01579B', controlsNormal=>'@color/material_grey_900', _bg => '#fff0f0f0' },
dark => { colorAccent => '#FF03A9F4', colorPrimary => '#FF0277BD', colorPrimaryDark => '#FF01579B', controlsNormal=>'@color/material_grey_300', _bg => '#ff2a2a2a' },
},
{
_name => 'red',
light => { colorAccent => '#ffd50000', colorPrimary => '#ffc62828', colorPrimaryDark => '#ffb71c1c', controlsNormal=>'@color/material_grey_900', _bg => '#fff0f0f0' },
dark => { colorAccent => '#ffd50000', colorPrimary => '#ffc62828', colorPrimaryDark => '#ffb71c1c', controlsNormal=>'@color/material_grey_300', _bg => '#ff2a2a2a' },
},
];
my $XML_ARRAYS = {};
my $THEME_ID = 0;
foreach my $theme_ref (@$THEMES) {
my $theme_name = $theme_ref->{_name};
my $theme_id = ($theme_name eq 'standard' ? '' : ucfirst($theme_name)."."); # standard 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);
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);
}
}
# use this loop to also populate the theme list output
# assumes that get_theme_xml created two themes per definition (light and dark)
foreach my $variant ('', 'Dark.') {
my $tvvar = ($variant eq '' ? 'light' : 'dark');
my $tvarr = join(",", map { $theme_ref->{$tvvar}->{$_} } qw(colorPrimaryDark _bg colorPrimary));
# user visible names of themes
push(@{$XML_ARRAYS->{'string-array'}->{theme_entries}}, $variant.ucfirst($theme_name));
# csv list of theme info, such as its id and the primary colors to show in preview
push(@{$XML_ARRAYS->{'string-array'}->{theme_values}}, ($THEME_ID).",".$tvarr);
$THEME_ID++;
}
}
open(OUT, ">", THEMES_LIST) or die "Cannot write theme list: $!\n";
print OUT << "EOLIST";
EOLIST
while(my($array_type, $lists) = each(%$XML_ARRAYS)) {
while(my($name, $items) = each(%$lists)) {
print OUT "\t<$array_type name=\"$name\">\n";
foreach my $item (@$items) {
print OUT "\t\t- $item
\n";
}
print OUT "\t$array_type>\n\n";
}
}
print OUT "\n";
close(OUT);
sub get_theme_xml {
my($this, $tid) = @_;
my $DATA = << "EOF";
EOF
return $DATA
}