diff --git a/generate-themes.pl b/generate-themes.pl
index d89d85d8..5b98b60c 100644
--- a/generate-themes.pl
+++ b/generate-themes.pl
@@ -5,39 +5,23 @@ 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' },
- },
+ { name=>"standard_light", id=>0, dark=>0, colorAccent => '#ff3e677a', colorPrimary => '#ff37474f', colorPrimaryDark => '#ff263238', controlsNormal=>'@color/material_grey_900', _bg => '#fff0f0f0' },
+ { name=>"standard_dark", id=>1, dark=>1, colorAccent => '#ff3e677a', colorPrimary => '#ff37474f', colorPrimaryDark => '#ff263238', controlsNormal=>'@color/material_grey_300', _bg => '#ff2a2a2a' },
+ { name=>"grey_light", id=>2, dark=>0, colorAccent => '#ff000000', colorPrimary => '#ff212121', colorPrimaryDark => '#ff090909', controlsNormal=>'@color/material_grey_600', _bg => '#fff0f0f0' },
+ { name=>"grey_dark", id=>3, dark=>1, colorAccent => '#ffd8d8d8', colorPrimary => '#ff212121', colorPrimaryDark => '#ff090909', controlsNormal=>'@color/material_grey_600', _bg => '#ff2a2a2a' },
+ { name=>"orange_light", id=>4, dark=>0, colorAccent => '#FFF57F17', colorPrimary => '#FFE65100', colorPrimaryDark => '#FFBF360C', controlsNormal=>'@color/material_grey_900', _bg => '#fff0f0f0' },
+ { name=>"orange_dark", id=>5, dark=>1, colorAccent => '#FFF57F17', colorPrimary => '#FFE65100', colorPrimaryDark => '#FFBF360C', controlsNormal=>'@color/material_grey_300', _bg => '#ff2a2a2a' },
+ { name=>"blue_light", id=>6, dark=>0, colorAccent => '#FF03A9F4', colorPrimary => '#FF0277BD', colorPrimaryDark => '#FF01579B', controlsNormal=>'@color/material_grey_900', _bg => '#fff0f0f0' },
+ { name=>"blue_dark", id=>7, dark=>1, colorAccent => '#FF03A9F4', colorPrimary => '#FF0277BD', colorPrimaryDark => '#FF01579B', controlsNormal=>'@color/material_grey_300', _bg => '#ff2a2a2a' },
+ { name=>"red_light", id=>8, dark=>0, colorAccent => '#ffd50000', colorPrimary => '#ffc62828', colorPrimaryDark => '#ffb71c1c', controlsNormal=>'@color/material_grey_900', _bg => '#fff0f0f0' },
+ { name=>"red_dark", id=>9, dark=>1, 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 $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);
@@ -45,6 +29,7 @@ foreach my $theme_ref (@$THEMES) {
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]);
@@ -52,18 +37,15 @@ foreach my $theme_ref (@$THEMES) {
}
}
- # 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++;
- }
+ 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}}, $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');
}
@@ -115,18 +97,22 @@ my $DATA = << "EOF";
-->
+EOF
+
+ if($this->{dark} == 0) {
+ $DATA .= << "EOF"
-
+EOF
+ } else {
+ $DATA .= << "EOF"
-
-
-
-
-
-
-
EOF
+ }
+$DATA .= "\n\n";
return $DATA
}
diff --git a/res/values-v21/theme-blue.xml b/res/values-v21/theme-blue_dark.xml
similarity index 52%
rename from res/values-v21/theme-blue.xml
rename to res/values-v21/theme-blue_dark.xml
index 26b7c369..17dcf525 100644
--- a/res/values-v21/theme-blue.xml
+++ b/res/values-v21/theme-blue_dark.xml
@@ -18,41 +18,8 @@
-->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/res/values-v21/theme-greyish.xml b/res/values-v21/theme-grey_dark.xml
similarity index 50%
rename from res/values-v21/theme-greyish.xml
rename to res/values-v21/theme-grey_dark.xml
index 4dfe3666..a7b6e01d 100644
--- a/res/values-v21/theme-greyish.xml
+++ b/res/values-v21/theme-grey_dark.xml
@@ -18,41 +18,8 @@
-->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/res/values-v21/theme-orange.xml b/res/values-v21/theme-orange_dark.xml
similarity index 52%
rename from res/values-v21/theme-orange.xml
rename to res/values-v21/theme-orange_dark.xml
index 732ef460..662eb288 100644
--- a/res/values-v21/theme-orange.xml
+++ b/res/values-v21/theme-orange_dark.xml
@@ -18,41 +18,8 @@
-->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/res/values-v21/theme-red.xml b/res/values-v21/theme-red_dark.xml
similarity index 52%
rename from res/values-v21/theme-red.xml
rename to res/values-v21/theme-red_dark.xml
index 2cf39768..9acc78a8 100644
--- a/res/values-v21/theme-red.xml
+++ b/res/values-v21/theme-red_dark.xml
@@ -18,41 +18,8 @@
-->
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/res/values-v21/theme-standard_dark.xml b/res/values-v21/theme-standard_dark.xml
new file mode 100644
index 00000000..f0b3aa22
--- /dev/null
+++ b/res/values-v21/theme-standard_dark.xml
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/res/values-v21/theme-standard.xml b/res/values-v21/theme-standard_light.xml
similarity index 59%
rename from res/values-v21/theme-standard.xml
rename to res/values-v21/theme-standard_light.xml
index a2c96783..b7fb9854 100644
--- a/res/values-v21/theme-standard.xml
+++ b/res/values-v21/theme-standard_light.xml
@@ -51,38 +51,4 @@
- #ff3e677a
-
-
-
-
-
-
-
-
-
-
-
diff --git a/res/values-v21/themes-list.xml b/res/values-v21/themes-list.xml
index b84a52ac..b5ca78dd 100644
--- a/res/values-v21/themes-list.xml
+++ b/res/values-v21/themes-list.xml
@@ -3,93 +3,119 @@
- @style/Library
- - @style/Dark.Library
- - @style/Greyish.Library
- - @style/Greyish.Dark.Library
- - @style/Orange.Library
- - @style/Orange.Dark.Library
- - @style/Blue.Library
- - @style/Blue.Dark.Library
- - @style/Red.Library
- - @style/Red.Dark.Library
-
-
-
- - @style/BackActionBar
- - @style/Dark.BackActionBar
- - @style/Greyish.BackActionBar
- - @style/Greyish.Dark.BackActionBar
- - @style/Orange.BackActionBar
- - @style/Orange.Dark.BackActionBar
- - @style/Blue.BackActionBar
- - @style/Blue.Dark.BackActionBar
- - @style/Red.BackActionBar
- - @style/Red.Dark.BackActionBar
-
-
-
- - @style/Playback
- - @style/Dark.Playback
- - @style/Greyish.Playback
- - @style/Greyish.Dark.Playback
- - @style/Orange.Playback
- - @style/Orange.Dark.Playback
- - @style/Blue.Playback
- - @style/Blue.Dark.Playback
- - @style/Red.Playback
- - @style/Red.Dark.Playback
-
-
-
- - @style/VanillaBase
- - @style/Dark.VanillaBase
- - @style/Greyish.VanillaBase
- - @style/Greyish.Dark.VanillaBase
- - @style/Orange.VanillaBase
- - @style/Orange.Dark.VanillaBase
- - @style/Blue.VanillaBase
- - @style/Blue.Dark.VanillaBase
- - @style/Red.VanillaBase
- - @style/Red.Dark.VanillaBase
+ - @style/Standard_dark.Library
+ - @style/Grey_light.Library
+ - @style/Grey_dark.Library
+ - @style/Orange_light.Library
+ - @style/Orange_dark.Library
+ - @style/Blue_light.Library
+ - @style/Blue_dark.Library
+ - @style/Red_light.Library
+ - @style/Red_dark.Library
- @style/PopupDialog
- - @style/Dark.PopupDialog
- - @style/Greyish.PopupDialog
- - @style/Greyish.Dark.PopupDialog
- - @style/Orange.PopupDialog
- - @style/Orange.Dark.PopupDialog
- - @style/Blue.PopupDialog
- - @style/Blue.Dark.PopupDialog
- - @style/Red.PopupDialog
- - @style/Red.Dark.PopupDialog
+ - @style/Standard_dark.PopupDialog
+ - @style/Grey_light.PopupDialog
+ - @style/Grey_dark.PopupDialog
+ - @style/Orange_light.PopupDialog
+ - @style/Orange_dark.PopupDialog
+ - @style/Blue_light.PopupDialog
+ - @style/Blue_dark.PopupDialog
+ - @style/Red_light.PopupDialog
+ - @style/Red_dark.PopupDialog
+
+ - @style/BackActionBar
+ - @style/Standard_dark.BackActionBar
+ - @style/Grey_light.BackActionBar
+ - @style/Grey_dark.BackActionBar
+ - @style/Orange_light.BackActionBar
+ - @style/Orange_dark.BackActionBar
+ - @style/Blue_light.BackActionBar
+ - @style/Blue_dark.BackActionBar
+ - @style/Red_light.BackActionBar
+ - @style/Red_dark.BackActionBar
+
+
+
+ - @style/VanillaBase
+ - @style/Standard_dark.VanillaBase
+ - @style/Grey_light.VanillaBase
+ - @style/Grey_dark.VanillaBase
+ - @style/Orange_light.VanillaBase
+ - @style/Orange_dark.VanillaBase
+ - @style/Blue_light.VanillaBase
+ - @style/Blue_dark.VanillaBase
+ - @style/Red_light.VanillaBase
+ - @style/Red_dark.VanillaBase
+
+
+
+ - @style/Playback
+ - @style/Standard_dark.Playback
+ - @style/Grey_light.Playback
+ - @style/Grey_dark.Playback
+ - @style/Orange_light.Playback
+ - @style/Orange_dark.Playback
+ - @style/Blue_light.Playback
+ - @style/Blue_dark.Playback
+ - @style/Red_light.Playback
+ - @style/Red_dark.Playback
+
+
+
+ - light
+ - dark
+ - light
+ - dark
+ - light
+ - dark
+ - light
+ - dark
+ - light
+ - dark
+
+
- - 0,#ff263238,#fff0f0f0,#ff37474f
- - 1,#ff263238,#ff2a2a2a,#ff37474f
- - 2,#ff090909,#fff0f0f0,#ff212121
- - 3,#ff090909,#ff2a2a2a,#ff212121
- - 4,#FFBF360C,#fff0f0f0,#FFE65100
- - 5,#FFBF360C,#ff2a2a2a,#FFE65100
- - 6,#FF01579B,#fff0f0f0,#FF0277BD
- - 7,#FF01579B,#ff2a2a2a,#FF0277BD
- - 8,#ffb71c1c,#fff0f0f0,#ffc62828
- - 9,#ffb71c1c,#ff2a2a2a,#ffc62828
+ - #ff263238,#fff0f0f0,#ff37474f
+ - #ff263238,#ff2a2a2a,#ff37474f
+ - #ff090909,#fff0f0f0,#ff212121
+ - #ff090909,#ff2a2a2a,#ff212121
+ - #FFBF360C,#fff0f0f0,#FFE65100
+ - #FFBF360C,#ff2a2a2a,#FFE65100
+ - #FF01579B,#fff0f0f0,#FF0277BD
+ - #FF01579B,#ff2a2a2a,#FF0277BD
+ - #ffb71c1c,#fff0f0f0,#ffc62828
+ - #ffb71c1c,#ff2a2a2a,#ffc62828
- - Standard
- - Dark.Standard
- - Greyish
- - Dark.Greyish
- - Orange
- - Dark.Orange
- - Blue
- - Dark.Blue
- - Red
- - Dark.Red
+ - standard_light
+ - standard_dark
+ - grey_light
+ - grey_dark
+ - orange_light
+ - orange_dark
+ - blue_light
+ - blue_dark
+ - red_light
+ - red_dark
+
+
+
+ - 0
+ - 1
+ - 2
+ - 3
+ - 4
+ - 5
+ - 6
+ - 7
+ - 8
+ - 9
diff --git a/src/ch/blinkenlights/android/vanilla/PreferencesTheme.java b/src/ch/blinkenlights/android/vanilla/PreferencesTheme.java
index 9050020c..ece55c06 100644
--- a/src/ch/blinkenlights/android/vanilla/PreferencesTheme.java
+++ b/src/ch/blinkenlights/android/vanilla/PreferencesTheme.java
@@ -47,6 +47,8 @@ public class PreferencesTheme extends PreferenceFragment
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(mContext);
final String[] entries = getResources().getStringArray(R.array.theme_entries);
final String[] values = getResources().getStringArray(R.array.theme_values);
+ final String[] ids = getResources().getStringArray(R.array.theme_ids);
+
for (int i = 0; i < entries.length; i++) {
int[] attrs = decodeValue(values[i]);
@@ -55,7 +57,7 @@ public class PreferencesTheme extends PreferenceFragment
pref.setPersistent(false);
pref.setOnPreferenceClickListener(this);
pref.setTitle(entries[i]);
- pref.setKey(Long.toString(attrs[0])); // that's actually our value
+ pref.setKey(ids[i]); // preference value of this theme
pref.setIcon(generateThemePreview(attrs));
screen.addPreference(pref);
}
@@ -83,16 +85,16 @@ public class PreferencesTheme extends PreferenceFragment
private Drawable generateThemePreview(int[] colors) {
final int size = (int) getResources().getDimension(R.dimen.cover_size);
- final int step = size / (colors.length - 1);
+ final int step = size / colors.length;
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
- for (int i=1; i < colors.length; i++) {
+ for (int i=0; i < colors.length; i++) {
paint.setColor(colors[i]);
- canvas.drawRect(0, step*(i-1), size, size, paint);
+ canvas.drawRect(0, step*i, size, size, paint);
}
Drawable d = new BitmapDrawable(mContext.getResources(), bitmap);
diff --git a/src/ch/blinkenlights/android/vanilla/ThemeHelper.java b/src/ch/blinkenlights/android/vanilla/ThemeHelper.java
index c52ed6f1..f5f9e25b 100644
--- a/src/ch/blinkenlights/android/vanilla/ThemeHelper.java
+++ b/src/ch/blinkenlights/android/vanilla/ThemeHelper.java
@@ -50,7 +50,7 @@ public class ThemeHelper {
default:
throw new IllegalArgumentException("setTheme() called with unknown theme!");
}
- theme = ar.getResourceId(getSelectedTheme(context), -1);
+ theme = ar.getResourceId(getSelectedThemeIndex(context), -1);
ar.recycle();
}
@@ -82,20 +82,30 @@ public class ThemeHelper {
{
boolean useDark = false;
if(usesHoloTheme() == false) {
- useDark = (getSelectedTheme(context) % 2 != 0); // odd values are always dark
+ final int idx = getSelectedThemeIndex(context);
+ final String[] variants = context.getResources().getStringArray(R.array.theme_variant);
+ useDark = variants[idx].equals("dark");
}
return useDark;
}
/**
- * Returns the user-selected theme id from the shared peferences provider
+ * Returns the user-selected theme index from the shared peferences provider
*
* @param context the context to use
* @return integer of the selected theme
*/
- final private static int getSelectedTheme(Context context) {
+ final private static int getSelectedThemeIndex(Context context) {
SharedPreferences settings = PlaybackService.getSettings(context);
- return Integer.parseInt(settings.getString(PrefKeys.SELECTED_THEME, PrefDefaults.SELECTED_THEME));
+ String prefValue = settings.getString(PrefKeys.SELECTED_THEME, PrefDefaults.SELECTED_THEME);
+
+ final String[] ids = context.getResources().getStringArray(R.array.theme_ids);
+ for (int i = 0; i < ids.length; i++) {
+ if (ids[i].equals(prefValue))
+ return i;
+ }
+ // no theme found? return default theme.
+ return 0;
}
/**