Add WidgetBackground palette to color picker

pull/437/head
Alex Baker 8 years ago
parent 98497e118f
commit 18d1ae5ec6

@ -33,7 +33,8 @@ public class ThemePickerDialog extends InjectingDialogFragment {
public enum ColorPalette {
THEMES,
COLORS,
ACCENTS
ACCENTS,
WIDGET_BACKGROUND
}
public static ThemePickerDialog newThemePickerDialog(ColorPalette palette) {
@ -64,7 +65,7 @@ public class ThemePickerDialog extends InjectingDialogFragment {
palette = (ColorPalette) savedInstanceState.getSerializable(EXTRA_COLOR_PALETTE);
}
if (palette == ColorPalette.THEMES) {
if (palette == ColorPalette.THEMES || palette == ColorPalette.WIDGET_BACKGROUND) {
theme = theme.withBaseTheme(themeCache.getThemeBase(2));
}
@ -115,6 +116,8 @@ public class ThemePickerDialog extends InjectingDialogFragment {
return R.array.colors;
case ACCENTS:
return R.array.accents;
case WIDGET_BACKGROUND:
return R.array.widget_background;
default:
return R.array.themes;
}
@ -126,6 +129,8 @@ public class ThemePickerDialog extends InjectingDialogFragment {
return themeCache.getThemeColor(index).getPrimaryColor();
case ACCENTS:
return themeCache.getThemeAccent(index).getAccentColor();
case WIDGET_BACKGROUND:
return themeCache.getWidgetBackground(index).getBackgroundColor();
default:
return themeCache.getThemeBase(index).getContentBackground();
}

@ -15,6 +15,7 @@ public class ThemeCache {
private final List<ThemeBase> themes = new ArrayList<>();
private final List<ThemeColor> colors = new ArrayList<>();
private final List<ThemeAccent> accents = new ArrayList<>();
private final List<WidgetBackground> widgetBackgrounds = new ArrayList<>();
private final ThemeColor untaggedColor;
public ThemeCache(Context context) {
@ -51,9 +52,18 @@ public class ThemeCache {
i,
resolveAttribute(theme, R.attr.colorAccent)));
}
String[] widgetBackgroundNames = resources.getStringArray(R.array.widget_background);
for (int i = 0 ; i < WidgetBackground.BACKGROUNDS.length ; i++) {
widgetBackgrounds.add(new WidgetBackground(
widgetBackgroundNames[i], i, resources.getColor(WidgetBackground.BACKGROUNDS[i])));
}
untaggedColor = new ThemeColor(null, 19, resources.getColor(R.color.tag_color_none_background), 0, resources.getColor(R.color.black_87), false);
}
public WidgetBackground getWidgetBackground(int index) {
return widgetBackgrounds.get(index);
}
public ThemeBase getThemeBase(int index) {
return themes.get(index);
}

@ -0,0 +1,32 @@
package org.tasks.themes;
import org.tasks.R;
public class WidgetBackground {
public static final int[] BACKGROUNDS = new int[] {
R.color.md_light_background,
android.R.color.black,
R.color.md_dark_background
};
private final String name;
private final int index;
private final int backgroundColor;
public WidgetBackground(String name, int index, int backgroundColor) {
this.name = name;
this.index = index;
this.backgroundColor = backgroundColor;
}
public int getBackgroundColor() {
return backgroundColor;
}
public String getName() {
return name;
}
public int getIndex() {
return index;
}
}

@ -21,9 +21,9 @@ import org.tasks.intents.TaskIntents;
import org.tasks.locale.Locale;
import org.tasks.preferences.DefaultFilterProvider;
import org.tasks.preferences.Preferences;
import org.tasks.themes.ThemeBase;
import org.tasks.themes.ThemeCache;
import org.tasks.themes.ThemeColor;
import org.tasks.themes.WidgetBackground;
import javax.inject.Inject;
@ -100,7 +100,7 @@ public class TasksWidget extends InjectingAppWidgetProvider {
rvIntent.putExtra(ScrollableWidgetUpdateService.FILTER_ID, filterId);
rvIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
rvIntent.setData(Uri.parse(rvIntent.toUri(Intent.URI_INTENT_SCHEME)));
ThemeBase theme = themeCache.getThemeBase(preferences.getInt(WidgetConfigActivity.PREF_THEME + id, 0));
WidgetBackground theme = themeCache.getWidgetBackground(preferences.getInt(WidgetConfigActivity.PREF_THEME + id, 0));
ThemeColor color = themeCache.getThemeColor(preferences.getInt(WidgetConfigActivity.PREF_COLOR + id, 0));
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.scrollable_widget);
if (atLeastJellybeanMR1()) {
@ -114,7 +114,7 @@ public class TasksWidget extends InjectingAppWidgetProvider {
}
int opacity = preferences.getInt(WidgetConfigActivity.PREF_WIDGET_OPACITY + id, WidgetConfigActivity.DEFAULT_OPACITY);
remoteViews.setImageViewBitmap(R.id.widget_background,
getSolidBackground(theme.getContentBackground()));
getSolidBackground(theme.getBackgroundColor()));
remoteViews.setImageViewBitmap(R.id.widget_header_background,
getSolidBackground(color.getPrimaryColor()));
remoteViews.setInt(R.id.widget_background, "setAlpha", opacity);

@ -83,7 +83,7 @@ public class WidgetConfigActivity extends InjectingAppCompatActivity implements
@Override
public void themePicked(ThemePickerDialog.ColorPalette palette, int index) {
if (palette == ThemePickerDialog.ColorPalette.THEMES) {
if (palette == ThemePickerDialog.ColorPalette.WIDGET_BACKGROUND) {
widgetConfigDialog.setThemeIndex(index);
} else {
widgetConfigDialog.setColorIndex(index);

@ -174,7 +174,7 @@ public class WidgetConfigDialog extends InjectingDialogFragment implements SeekB
}
private void updateTheme() {
selectedTheme.setText(themeCache.getThemeBase(themeIndex).getName());
selectedTheme.setText(themeCache.getWidgetBackground(themeIndex).getName());
}
private void updateColor() {
@ -192,7 +192,7 @@ public class WidgetConfigDialog extends InjectingDialogFragment implements SeekB
public void showThemeSelection() {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager.findFragmentByTag(FRAG_TAG_THEME_SELECTION) == null) {
newThemePickerDialog(ThemePickerDialog.ColorPalette.THEMES).show(fragmentManager, FRAG_TAG_THEME_SELECTION);
newThemePickerDialog(ThemePickerDialog.ColorPalette.WIDGET_BACKGROUND).show(fragmentManager, FRAG_TAG_THEME_SELECTION);
}
}

@ -130,6 +130,12 @@
<item>@string/theme_deep_orange</item>
</string-array>
<string-array name="widget_background">
<item>@string/theme_light</item>
<item>@string/theme_black</item>
<item>@string/theme_dark</item>
</string-array>
<string-array name="localization">
<item>ar</item>
<item>bg-bg</item>

Loading…
Cancel
Save