Configurable accent color

pull/413/head
Alex Baker 10 years ago
parent 385afb0627
commit 1643ca397c

@ -47,7 +47,8 @@ public class DateAndTimePickerActivity extends InjectingAppCompatActivity implem
if (datePickerDialog == null) {
datePickerDialog = new MyDatePickerDialog();
datePickerDialog.initialize(null, initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth());
datePickerDialog.setAccentColor(themeManager.getAppTheme().getDateTimePickerAccent());
datePickerDialog.setThemeDark(themeManager.getAppTheme().isDark());
datePickerDialog.setAccentColor(themeManager.getAccentColor().getAccentColor());
datePickerDialog.show(fragmentManager, FRAG_TAG_DATE_PICKER);
}
datePickerDialog.setOnCancelListener(this);

@ -38,7 +38,8 @@ public class DatePickerActivity extends InjectingAppCompatActivity
if (dialog == null) {
dialog = new MyDatePickerDialog();
dialog.initialize(null, initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth());
dialog.setAccentColor(themeManager.getAppTheme().getDateTimePickerAccent());
dialog.setThemeDark(themeManager.getAppTheme().isDark());
dialog.setAccentColor(themeManager.getAccentColor().getAccentColor());
dialog.show(fragmentManager, FRAG_TAG_DATE_PICKER);
}
dialog.setOnDismissListener(this);

@ -42,7 +42,8 @@ public class TimePickerActivity extends InjectingAppCompatActivity implements Ti
if (dialog == null) {
dialog = new MyTimePickerDialog();
dialog.initialize(null, initial.getHourOfDay(), initial.getMinuteOfHour(), 0, DateFormat.is24HourFormat(this));
dialog.setAccentColor(themeManager.getAppTheme().getDateTimePickerAccent());
dialog.setThemeDark(themeManager.getAppTheme().isDark());
dialog.setAccentColor(themeManager.getAccentColor().getAccentColor());
dialog.show(fragmentManager, FRAG_TAG_TIME_PICKER);
}
dialog.setOnDismissListener(this);

@ -8,6 +8,7 @@ public class Tracking {
SET_DEFAULT_LIST(R.string.tracking_category_preferences, R.string.p_default_list),
GTASK_DEFAULT_LIST(R.string.tracking_category_preferences, R.string.p_gtasks_default_list),
SET_THEME(R.string.tracking_category_preferences, R.string.p_theme),
SET_ACCENT(R.string.tracking_category_preferences, R.string.p_theme_accent),
WIDGET_ADD(R.string.tracking_category_widget, R.string.tracking_action_add),
TIMER_START(R.string.tracking_category_timer, R.string.tracking_action_start),
GTASK_ENABLED(R.string.tracking_category_google_tasks, R.string.tracking_action_on),

@ -4,6 +4,7 @@ import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AlertDialog;
import android.support.v7.view.ContextThemeWrapper;
import com.todoroo.andlib.utility.AndroidUtilities;
@ -22,7 +23,9 @@ public class DialogBuilder {
}
public AlertDialog.Builder newDialog() {
return new AlertDialog.Builder(activity, themeManager.getDialogThemeResId());
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(activity, themeManager.getDialogThemeResId());
contextThemeWrapper.getTheme().applyStyle(themeManager.getAccentColor().getResId(), true);
return new AlertDialog.Builder(contextThemeWrapper);
}
public AlertDialog.Builder newMessageDialog(int message, Object... formatArgs) {

@ -28,8 +28,25 @@ import javax.inject.Inject;
public class ThemePickerDialog extends InjectingDialogFragment {
private static final String EXTRA_COLOR_PALETTE = "extra_color_palette";
public enum ColorPalette {
THEMES,
ACCENTS
}
public static ThemePickerDialog newThemePickerDialog() {
return newThemePickerDialog(ColorPalette.THEMES);
}
public static ThemePickerDialog newThemePickerDialog(ColorPalette palette) {
ThemePickerDialog dialog = new ThemePickerDialog();
dialog.palette = palette;
return dialog;
}
public interface ThemePickerCallback {
void themePicked(Theme theme);
void themePicked(ColorPalette palette, Theme theme);
void initiateThemePurchase();
}
@ -40,11 +57,16 @@ public class ThemePickerDialog extends InjectingDialogFragment {
@Inject ThemeManager themeManager;
private ThemePickerCallback callback;
private ColorPalette palette;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final String[] themes = context.getResources().getStringArray(R.array.themes);
if (savedInstanceState != null) {
palette = (ColorPalette) savedInstanceState.getSerializable(EXTRA_COLOR_PALETTE);
}
final String[] themes = context.getResources().getStringArray(palette == ColorPalette.THEMES ? R.array.themes : R.array.accents);
final boolean purchasedThemes = preferences.hasPurchase(R.string.p_purchased_themes);
@ -59,13 +81,14 @@ public class ThemePickerDialog extends InjectingDialogFragment {
}
Resources resources = context.getResources();
Theme theme = themeManager.getTheme(position);
Theme theme = palette == ColorPalette.THEMES ? themeManager.getTheme(position) : themeManager.getAccent(position);
ImageView primary = (ImageView) row.findViewById(R.id.color_primary);
Drawable original = resources.getDrawable(purchasedThemes || position < 2
? R.drawable.ic_lens_black_24dp
: R.drawable.ic_vpn_key_black_24dp);
Drawable wrapped = DrawableCompat.wrap(original.mutate());
DrawableCompat.setTint(wrapped, theme.getPrimaryColor());
int colorResId = palette == ColorPalette.THEMES ? theme.getPrimaryColor() : theme.getAccentColor();
DrawableCompat.setTint(wrapped, colorResId);
primary.setImageDrawable(wrapped);
TextView text = (TextView) row.findViewById(android.R.id.text1);
@ -81,7 +104,7 @@ public class ThemePickerDialog extends InjectingDialogFragment {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (purchasedThemes || which < 2) {
callback.themePicked(themeManager.getTheme(which));
callback.themePicked(palette, themeManager.getTheme(which));
} else {
callback.initiateThemePurchase();
}
@ -90,6 +113,13 @@ public class ThemePickerDialog extends InjectingDialogFragment {
.show();
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable(EXTRA_COLOR_PALETTE, palette);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);

@ -17,10 +17,13 @@ import org.tasks.injection.InjectingPreferenceActivity;
import javax.inject.Inject;
import static org.tasks.dialogs.ThemePickerDialog.newThemePickerDialog;
public abstract class BaseBasicPreferences extends InjectingPreferenceActivity implements ThemePickerDialog.ThemePickerCallback {
private static final String EXTRA_RESULT = "extra_result";
private static final String FRAG_TAG_THEME_PICKER = "frag_tag_theme_picker";
private static final String FRAG_TAG_ACCENT_PICKER = "frag_tag_accent_picker";
private static final int RC_PREFS = 10001;
@Inject Tracker tracker;
@ -45,12 +48,25 @@ public abstract class BaseBasicPreferences extends InjectingPreferenceActivity i
public boolean onPreferenceClick(Preference preference) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager.findFragmentByTag(FRAG_TAG_THEME_PICKER) == null) {
new ThemePickerDialog()
newThemePickerDialog(ThemePickerDialog.ColorPalette.THEMES)
.show(fragmentManager, FRAG_TAG_THEME_PICKER);
}
return false;
}
});
Preference accentPreference = findPreference(getString(R.string.p_theme_accent));
accentPreference.setSummary(themeManager.getAccentColor().getName());
accentPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager.findFragmentByTag(FRAG_TAG_ACCENT_PICKER) == null) {
newThemePickerDialog(ThemePickerDialog.ColorPalette.ACCENTS)
.show(fragmentManager, FRAG_TAG_ACCENT_PICKER);
}
return false;
}
});
findPreference(getString(R.string.p_collect_statistics)).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
@ -96,10 +112,15 @@ public abstract class BaseBasicPreferences extends InjectingPreferenceActivity i
}
@Override
public void themePicked(Theme theme) {
public void themePicked(ThemePickerDialog.ColorPalette palette, Theme theme) {
int index = theme.getThemeIndex();
preferences.setInt(R.string.p_theme, index);
tracker.reportEvent(Tracking.Events.SET_THEME, Integer.toString(index));
if (palette == ThemePickerDialog.ColorPalette.THEMES) {
preferences.setInt(R.string.p_theme, index);
tracker.reportEvent(Tracking.Events.SET_THEME, Integer.toString(index));
} else if (palette == ThemePickerDialog.ColorPalette.ACCENTS) {
preferences.setInt(R.string.p_theme_accent, index);
tracker.reportEvent(Tracking.Events.SET_ACCENT, Integer.toString(index));
}
result.putBoolean(AppearancePreferences.EXTRA_RESTART, true);
recreate();
}

@ -40,6 +40,10 @@ public class Theme {
return resolveAttribute(R.attr.colorPrimary);
}
public int getAccentColor() {
return resolveAttribute(R.attr.colorAccent);
}
public int getContentBackground() {
return resolveAttribute(R.attr.asContentBackground);
}
@ -52,11 +56,7 @@ public class Theme {
return resolveAttribute(R.attr.asTextColor);
}
public int getDateTimePickerAccent() {
return resolveAttribute(R.attr.asDateTimePickerAccent);
}
public int getAppThemeResId() {
public int getResId() {
return themeRes;
}

@ -23,17 +23,14 @@ public class ThemeApplicator {
}
public void applyTheme() {
Theme appTheme = themeManager.getAppTheme();
applyTheme(appTheme.getAppThemeResId());
applyTheme(
themeManager.getAppTheme().getResId(),
themeManager.getAccentColor().getResId());
}
public void applyDialogTheme() {
Theme appTheme = themeManager.getAppTheme();
applyTheme(appTheme.getDialogThemeResId());
}
private void applyTheme(int theme) {
activity.setTheme(theme);
private void applyTheme(int themeResId, int accentResId) {
activity.setTheme(themeResId);
activity.getTheme().applyStyle(accentResId, true);
activity.getWindow().setFormat(PixelFormat.RGBA_8888);
}

@ -15,20 +15,30 @@ public class ThemeManager {
private final Context context;
private final Preferences preferences;
private final String[] themeNames;
private final String[] accentNames;
@Inject
public ThemeManager(@ForApplication Context context, Preferences preferences) {
this.context = context;
this.preferences = preferences;
themeNames = context.getResources().getStringArray(R.array.themes);
accentNames = context.getResources().getStringArray(R.array.accents);
}
public Theme getAppTheme() {
return getTheme(preferences.getInt(R.string.p_theme, 0));
}
public Theme getAccentColor() {
return getAccent(preferences.getInt(R.string.p_theme_accent, 1));
}
public Theme getTheme(int themeIndex) {
return new Theme(context, themeIndex, getStyle(themeIndex), themeNames[themeIndex]);
return new Theme(context, themeIndex, getThemeResId(themeIndex), themeNames[themeIndex]);
}
public Theme getAccent(int accentIndex) {
return new Theme(context, accentIndex, getAccentResId(accentIndex), accentNames[accentIndex]);
}
public Theme getWidgetTheme(int widgetId) {
@ -40,7 +50,7 @@ public class ThemeManager {
return getAppTheme().getDialogThemeResId();
}
private int getStyle(int index) {
private int getThemeResId(int index) {
switch (index) {
case 1:
return R.style.Black;
@ -85,4 +95,44 @@ public class ThemeManager {
return R.style.BlueGrey;
}
}
private int getAccentResId(int index) {
switch (index) {
case 1:
return R.style.RedAccent;
case 2:
return R.style.PinkAccent;
case 3:
return R.style.PurpleAccent;
case 4:
return R.style.DeepPurpleAccent;
case 5:
return R.style.IndigoAccent;
case 6:
return R.style.BlueAccent;
case 7:
return R.style.LightBlueAccent;
case 8:
return R.style.CyanAccent;
case 9:
return R.style.TealAccent;
case 10:
return R.style.GreenAccent;
case 11:
return R.style.LightGreenAccent;
case 12:
return R.style.LimeAccent;
case 13:
return R.style.YellowAccent;
case 14:
return R.style.AmberAccent;
case 15:
return R.style.OrangeAccent;
case 16:
return R.style.DeepOrangeAccent;
case 0:
default:
return R.style.BlueGreyAccent;
}
}
}

@ -76,7 +76,7 @@ public abstract class BaseWidgetConfigActivity extends InjectingAppCompatActivit
}
@Override
public void themePicked(Theme theme) {
public void themePicked(ThemePickerDialog.ColorPalette palette, Theme theme) {
widgetConfigDialog.setTheme(theme);
}

@ -35,6 +35,8 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import static org.tasks.dialogs.ThemePickerDialog.newThemePickerDialog;
public class WidgetConfigDialog extends InjectingDialogFragment implements SeekBar.OnSeekBarChangeListener {
private static final String FRAG_TAG_THEME_SELECTION = "frag_tag_theme_selection";
@ -176,7 +178,7 @@ public class WidgetConfigDialog extends InjectingDialogFragment implements SeekB
public void showThemeSelection() {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager.findFragmentByTag(FRAG_TAG_THEME_SELECTION) == null) {
new ThemePickerDialog().show(fragmentManager, FRAG_TAG_THEME_SELECTION);
newThemePickerDialog().show(fragmentManager, FRAG_TAG_THEME_SELECTION);
}
}

@ -48,7 +48,7 @@
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:src="@drawable/ic_add_24dp"
android:tint="?attr/fab_tint"
android:tint="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"

@ -91,4 +91,24 @@
<item>@string/theme_grey</item>
</string-array>
<string-array name="accents">
<item>@string/theme_blue_grey</item>
<item>@string/theme_red</item>
<item>@string/theme_pink</item>
<item>@string/theme_purple</item>
<item>@string/theme_deep_purple</item>
<item>@string/theme_indigo</item>
<item>@string/theme_blue</item>
<item>@string/theme_light_blue</item>
<item>@string/theme_cyan</item>
<item>@string/theme_teal</item>
<item>@string/theme_green</item>
<item>@string/theme_light_green</item>
<item>@string/theme_lime</item>
<item>@string/theme_yellow</item>
<item>@string/theme_amber</item>
<item>@string/theme_orange</item>
<item>@string/theme_deep_orange</item>
</string-array>
</resources>

@ -22,12 +22,10 @@
<attr name="asListDividerColor" format="color" />
<attr name="asThemeTextColor" format="color" />
<attr name="asEditTextBackground" format="reference" />
<attr name="fab_tint" format="color"/>
<attr name="icon_tint" format="color"/>
<attr name="toolbarSeparatorHeight" format="dimension" />
<attr name="separatorHeight" format="dimension" />
<attr name="popup_theme" format="reference" />
<attr name="asDateTimePickerAccent" format="color" />
<declare-styleable name="TimePreference">
<attr name="summary" format="string" />

@ -76,6 +76,7 @@
<color name="grey_500">#9e9e9e</color>
<color name="grey_700">#616161</color>
<color name="blue_grey_400">#78909c</color>
<color name="blue_grey_500">#607d8b</color>
<color name="blue_grey_700">#455a64</color>

@ -302,6 +302,7 @@
<string name="tasker_locale">Tasker/Locale</string>
<string name="dashclock">DashClock extension</string>
<string name="p_theme">selected_theme</string>
<string name="p_theme_accent">selected_theme_accent</string>
<string name="p_gtasks_default_list">default_gtasks_list</string>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/purple_a400</item>
</style>
<style name="AmberAccent">
<item name="colorAccent">@color/amber_a400</item>
</style>
</resources>

@ -23,11 +23,9 @@
<item name="asListDividerColor">#dddddd</item>
<item name="asThemeTextColor">@color/dark_blue_theme_color</item>
<item name="icon_tint">@android:color/black</item>
<item name="fab_tint">@android:color/white</item>
<item name="task_edit_divider">@color/task_edit_divider</item>
<item name="android:spinnerItemStyle">@style/SpinnerNoPadding</item>
<item name="android:actionModeBackground">?attr/colorPrimary</item>
<item name="asDateTimePickerAccent">?attr/colorAccent</item>
</style>
<style name="LightOverride" parent="LightBase">

@ -4,7 +4,6 @@
<item name="colorPrimary">@color/black_primary</item>
<item name="colorPrimaryDark">@color/black_primary_dark</item>
<item name="colorAccent">@color/red_500</item>
<item name="asDateTimePickerAccent">?attr/colorAccent</item>
<item name="popup_theme">@style/ThemeOverlay.AppCompat</item>
@ -22,7 +21,6 @@
<item name="icon_tint">@android:color/white</item>
<item name="task_edit_divider">@color/task_edit_divider</item>
<item name="asDueDateColor">#c3c3c3</item>
<item name="fab_tint">@android:color/black</item>
<item name="asEditTextBackground">@null</item>
<item name="windowActionModeOverlay">true</item>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/pink_a400</item>
</style>
<style name="BlueAccent">
<item name="colorAccent">@color/blue_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/red_500</item>
</style>
<style name="BlueGreyAccent">
<item name="colorAccent">@color/blue_grey_400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/amber_a400</item>
</style>
<style name="CyanAccent">
<item name="colorAccent">@color/cyan_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/indigo_a400</item>
</style>
<style name="DeepOrangeAccent">
<item name="colorAccent">@color/deep_orange_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/pink_a400</item>
</style>
<style name="DeepPurpleAccent">
<item name="colorAccent">@color/deep_purple_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/pink_a400</item>
</style>
<style name="GreenAccent">
<item name="colorAccent">@color/green_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/red_a400</item>
</style>
<style name="IndigoAccent">
<item name="colorAccent">@color/indigo_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/pink_a400</item>
</style>
<style name="LightBlueAccent">
<item name="colorAccent">@color/light_blue_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/purple_a400</item>
</style>
<style name="LightGreenAccent">
<item name="colorAccent">@color/light_green_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/cyan_a400</item>
</style>
<style name="LimeAccent">
<item name="colorAccent">@color/lime_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/deep_purple_a400</item>
</style>
<style name="OrangeAccent">
<item name="colorAccent">@color/orange_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/blue_a400</item>
</style>
<style name="PinkAccent">
<item name="colorAccent">@color/pink_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/light_blue_a400</item>
</style>
<style name="PurpleAccent">
<item name="colorAccent">@color/purple_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/blue_a400</item>
</style>
<style name="RedAccent">
<item name="colorAccent">@color/red_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/purple_a400</item>
</style>
<style name="TealAccent">
<item name="colorAccent">@color/teal_a400</item>
</style>
</resources>

@ -14,4 +14,8 @@
<item name="colorAccent">@color/red_a400</item>
</style>
<style name="YellowAccent">
<item name="colorAccent">@color/yellow_a400</item>
</style>
</resources>

@ -5,6 +5,10 @@
android:key="@string/p_theme"
android:title="@string/theme" />
<Preference
android:key="@string/p_theme_accent"
android:title="Accent" />
<Preference
android:key="@string/EPr_appearance_header"
android:title="@string/EPr_appearance_header" />

Loading…
Cancel
Save