Do not use resource-magic to select themes.
Gradle uses a completely different resources-order, so calculating the theme id will fail. We are therefore emiting all theme styles into integer-array's.
This commit is contained in:
parent
30ccbb3b29
commit
919ddc5f75
@ -27,10 +27,8 @@ my $THEMES = [
|
||||
},
|
||||
];
|
||||
|
||||
my $BUFF_TENTRIES = '';
|
||||
my $BUFF_TVALS = '';
|
||||
my $BUFF_TSTYLES = '';
|
||||
|
||||
my $XML_ARRAYS = {};
|
||||
my $THEME_ID = 0;
|
||||
foreach my $theme_ref (@$THEMES) {
|
||||
my $theme_name = $theme_ref->{_name};
|
||||
@ -42,14 +40,23 @@ foreach my $theme_ref (@$THEMES) {
|
||||
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));
|
||||
$BUFF_TENTRIES .= "\t\t<item>$variant".ucfirst($theme_name)."</item>\n";
|
||||
$BUFF_TVALS .= "\t\t<item>".($THEME_ID).",$tvarr</item>\n";
|
||||
$BUFF_TSTYLES .= "\t\t<item>\@style/${theme_id}${variant}VanillaBase</item>\n";
|
||||
|
||||
# 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++;
|
||||
}
|
||||
}
|
||||
@ -60,19 +67,18 @@ print OUT << "EOLIST";
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- THIS FILE IS AUTOGENERATED BY generate-themes.pl - DO NOT TOUCH! -->
|
||||
<resources>
|
||||
<!-- human visible names of the themes -->
|
||||
<string-array name="theme_entries">
|
||||
$BUFF_TENTRIES </string-array>
|
||||
|
||||
<!-- the value stored in the shared preferences for each theme -->
|
||||
<string-array name="theme_values">
|
||||
$BUFF_TVALS </string-array>
|
||||
|
||||
<!-- the style id for each theme -->
|
||||
<integer-array name="theme_styles">
|
||||
$BUFF_TSTYLES </integer-array>
|
||||
</resources>
|
||||
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>$item</item>\n";
|
||||
}
|
||||
print OUT "\t</$array_type>\n\n";
|
||||
}
|
||||
}
|
||||
print OUT "</resources>\n";
|
||||
|
||||
close(OUT);
|
||||
|
||||
|
||||
|
@ -1,19 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- THIS FILE IS AUTOGENERATED BY generate-themes.pl - DO NOT TOUCH! -->
|
||||
<resources>
|
||||
<!-- human visible names of the themes -->
|
||||
<string-array name="theme_entries">
|
||||
<item>Standard</item>
|
||||
<item>Dark.Standard</item>
|
||||
<item>Greyish</item>
|
||||
<item>Dark.Greyish</item>
|
||||
<item>Orange</item>
|
||||
<item>Dark.Orange</item>
|
||||
<item>Blue</item>
|
||||
<item>Dark.Blue</item>
|
||||
</string-array>
|
||||
|
||||
<!-- the value stored in the shared preferences for each theme -->
|
||||
<string-array name="theme_values">
|
||||
<item>0,#ff263238,#fff0f0f0,#ff37474f</item>
|
||||
<item>1,#ff263238,#ff2a2a2a,#ff37474f</item>
|
||||
@ -25,8 +12,62 @@
|
||||
<item>7,#FF01579B,#ff2a2a2a,#FF0277BD</item>
|
||||
</string-array>
|
||||
|
||||
<!-- the style id for each theme -->
|
||||
<integer-array name="theme_styles">
|
||||
<string-array name="theme_entries">
|
||||
<item>Standard</item>
|
||||
<item>Dark.Standard</item>
|
||||
<item>Greyish</item>
|
||||
<item>Dark.Greyish</item>
|
||||
<item>Orange</item>
|
||||
<item>Dark.Orange</item>
|
||||
<item>Blue</item>
|
||||
<item>Dark.Blue</item>
|
||||
</string-array>
|
||||
|
||||
<integer-array name="theme_category_popupdialog">
|
||||
<item>@style/PopupDialog</item>
|
||||
<item>@style/Dark.PopupDialog</item>
|
||||
<item>@style/Greyish.PopupDialog</item>
|
||||
<item>@style/Greyish.Dark.PopupDialog</item>
|
||||
<item>@style/Orange.PopupDialog</item>
|
||||
<item>@style/Orange.Dark.PopupDialog</item>
|
||||
<item>@style/Blue.PopupDialog</item>
|
||||
<item>@style/Blue.Dark.PopupDialog</item>
|
||||
</integer-array>
|
||||
|
||||
<integer-array name="theme_category_backactionbar">
|
||||
<item>@style/BackActionBar</item>
|
||||
<item>@style/Dark.BackActionBar</item>
|
||||
<item>@style/Greyish.BackActionBar</item>
|
||||
<item>@style/Greyish.Dark.BackActionBar</item>
|
||||
<item>@style/Orange.BackActionBar</item>
|
||||
<item>@style/Orange.Dark.BackActionBar</item>
|
||||
<item>@style/Blue.BackActionBar</item>
|
||||
<item>@style/Blue.Dark.BackActionBar</item>
|
||||
</integer-array>
|
||||
|
||||
<integer-array name="theme_category_playback">
|
||||
<item>@style/Playback</item>
|
||||
<item>@style/Dark.Playback</item>
|
||||
<item>@style/Greyish.Playback</item>
|
||||
<item>@style/Greyish.Dark.Playback</item>
|
||||
<item>@style/Orange.Playback</item>
|
||||
<item>@style/Orange.Dark.Playback</item>
|
||||
<item>@style/Blue.Playback</item>
|
||||
<item>@style/Blue.Dark.Playback</item>
|
||||
</integer-array>
|
||||
|
||||
<integer-array name="theme_category_library">
|
||||
<item>@style/Library</item>
|
||||
<item>@style/Dark.Library</item>
|
||||
<item>@style/Greyish.Library</item>
|
||||
<item>@style/Greyish.Dark.Library</item>
|
||||
<item>@style/Orange.Library</item>
|
||||
<item>@style/Orange.Dark.Library</item>
|
||||
<item>@style/Blue.Library</item>
|
||||
<item>@style/Blue.Dark.Library</item>
|
||||
</integer-array>
|
||||
|
||||
<integer-array name="theme_category_vanillabase">
|
||||
<item>@style/VanillaBase</item>
|
||||
<item>@style/Dark.VanillaBase</item>
|
||||
<item>@style/Greyish.VanillaBase</item>
|
||||
@ -36,4 +77,5 @@
|
||||
<item>@style/Blue.VanillaBase</item>
|
||||
<item>@style/Blue.Dark.VanillaBase</item>
|
||||
</integer-array>
|
||||
|
||||
</resources>
|
||||
|
@ -29,32 +29,33 @@ public class ThemeHelper {
|
||||
* Will automatically swap the theme with an alternative
|
||||
* version if the user requested us to use it
|
||||
*/
|
||||
final public static int setTheme(Context context, int theme)
|
||||
final public static void setTheme(Context context, int theme)
|
||||
{
|
||||
if(usesHoloTheme() == false) {
|
||||
TypedArray ar = context.getResources().obtainTypedArray(R.array.theme_styles);
|
||||
int themeBase = ar.getResourceId(getSelectedTheme(context), R.style.VanillaBase);
|
||||
ar.recycle();
|
||||
TypedArray ar = null;
|
||||
|
||||
switch (theme) {
|
||||
case R.style.Playback:
|
||||
theme = themeBase + (R.style.Playback - R.style.VanillaBase);
|
||||
//theme = themeBase + (R.style.Playback - R.style.VanillaBase);
|
||||
ar = context.getResources().obtainTypedArray(R.array.theme_category_playback);
|
||||
break;
|
||||
case R.style.Library:
|
||||
theme = themeBase + (R.style.Library - R.style.VanillaBase);
|
||||
ar = context.getResources().obtainTypedArray(R.array.theme_category_library);
|
||||
break;
|
||||
case R.style.BackActionBar:
|
||||
theme = themeBase + (R.style.BackActionBar - R.style.VanillaBase);
|
||||
ar = context.getResources().obtainTypedArray(R.array.theme_category_backactionbar);
|
||||
break;
|
||||
case R.style.PopupDialog:
|
||||
theme = themeBase + (R.style.PopupDialog - R.style.VanillaBase);
|
||||
ar = context.getResources().obtainTypedArray(R.array.theme_category_popupdialog);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("setTheme() called with unknown theme!");
|
||||
}
|
||||
theme = ar.getResourceId(getSelectedTheme(context), -1);
|
||||
ar.recycle();
|
||||
}
|
||||
|
||||
context.setTheme(theme);
|
||||
return theme;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user