#!/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', _bg => '#fff0f0f0' }, dark => { colorAccent => '#ff3e677a', colorPrimary => '#ff37474f', colorPrimaryDark => '#ff263238', _bg => '#ff2a2a2a' }, }, { _name => 'greyish', light => { colorAccent => '#ff212121', colorPrimary => '#ff212121', colorPrimaryDark => '#ff090909', _bg => '#fff0f0f0' }, dark => { colorAccent => '#ffececec', colorPrimary => '#ff212121', colorPrimaryDark => '#ff090909', _bg => '#ff2a2a2a' }, }, { _name => 'orange', light => { colorAccent => '#FFF57F17', colorPrimary => '#FFE65100', colorPrimaryDark => '#FFBF360C', _bg => '#fff0f0f0' }, dark => { colorAccent => '#FFF57F17', colorPrimary => '#FFE65100', colorPrimaryDark => '#FFBF360C', _bg => '#ff2a2a2a' }, }, ]; my $BUFF_TENTRIES = ''; my $BUFF_TVALS = ''; my $BUFF_TSTYLES = ''; 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); # 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)); $BUFF_TENTRIES .= "\t\t$variant".ucfirst($theme_name)."\n"; $BUFF_TVALS .= "\t\t".($THEME_ID).",$tvarr\n"; $BUFF_TSTYLES .= "\t\t\@style/${theme_id}${variant}VanillaBase\n"; $THEME_ID++; } } open(OUT, ">", THEMES_LIST) or die "Cannot write theme list: $!\n"; print OUT << "EOLIST"; $BUFF_TENTRIES $BUFF_TVALS $BUFF_TSTYLES EOLIST close(OUT); sub get_theme_xml { my($this, $tid) = @_; my $DATA = << "EOF"; EOF return $DATA }