Day/Night theme improvements

pull/437/head
Alex Baker 10 years ago
parent 2e9227a97a
commit 12b9059159

@ -11,6 +11,7 @@ import android.app.FragmentTransaction;
import android.content.ContentValues;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Bundle;
import android.provider.Settings;
import android.support.design.widget.Snackbar;
@ -111,6 +112,7 @@ public class TaskListActivity extends InjectingAppCompatActivity implements
public static final String OPEN_FILTER = "open_filter"; //$NON-NLS-1$
public static final String LOAD_FILTER = "load_filter";
public static final String OPEN_TASK = "open_task"; //$NON-NLS-1$
private int currentNightMode;
private Filter filter;
@ -121,7 +123,9 @@ public class TaskListActivity extends InjectingAppCompatActivity implements
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
theme.applyTheme(this);
theme.applyTheme(this, getDelegate());
currentNightMode = getNightMode();
startupService.onStartupApplication(this);
@ -234,6 +238,12 @@ public class TaskListActivity extends InjectingAppCompatActivity implements
protected void onResume() {
super.onResume();
getDelegate().applyDayNight();
if (currentNightMode != getNightMode()) {
recreate();
return;
}
registerReceiver(
repeatConfirmationReceiver,
new IntentFilter(AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED));
@ -261,6 +271,10 @@ public class TaskListActivity extends InjectingAppCompatActivity implements
}
}
private int getNightMode() {
return getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
}
@Override
public void inject(ActivityComponent component) {
component.inject(this);

@ -102,14 +102,14 @@ public class HideUntilControlSet extends TaskEditControlFragment implements OnIt
if (value.setting == Task.HIDE_UNTIL_NONE) {
clearButton.setVisibility(View.GONE);
tv.setText(value.label);
tv.setTextColor(getContext().getColor(R.color.text_tertiary));
tv.setTextColor(getContext().getResources().getColor(R.color.text_tertiary));
} else {
String display = value.label;
if (value.setting != Task.HIDE_UNTIL_SPECIFIC_DAY && value.setting != Task.HIDE_UNTIL_SPECIFIC_DAY_TIME) {
display = display.toLowerCase();
}
tv.setText(getString(R.string.TEA_hideUntil_display, display));
tv.setTextColor(getContext().getColor(R.color.text_primary));
tv.setTextColor(getContext().getResources().getColor(R.color.text_primary));
}
return tv;
}

@ -48,7 +48,7 @@ public class Tasks extends InjectingApplication {
tracker.setTrackingEnabled(preferences.isTrackingEnabled());
themeCache.getThemeBase(preferences.getInt(R.string.p_theme, 0)).applyDayNightMode();
themeCache.getThemeBase(preferences.getInt(R.string.p_theme, 0)).setDefaultNightMode();
}
@Override

@ -49,7 +49,7 @@ public class DateAndTimePickerActivity extends InjectingAppCompatActivity implem
if (datePickerDialog == null) {
datePickerDialog = new MyDatePickerDialog();
datePickerDialog.initialize(null, initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth());
datePickerDialog.setThemeDark(themeBase.isDarkTheme());
datePickerDialog.setThemeDark(themeBase.isDarkTheme(this));
datePickerDialog.setAccentColor(themeAccent.getAccentColor());
datePickerDialog.show(fragmentManager, FRAG_TAG_DATE_PICKER);
}

@ -40,7 +40,7 @@ public class DatePickerActivity extends InjectingAppCompatActivity
if (dialog == null) {
dialog = new MyDatePickerDialog();
dialog.initialize(null, initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth());
dialog.setThemeDark(themeBase.isDarkTheme());
dialog.setThemeDark(themeBase.isDarkTheme(this));
dialog.setAccentColor(themeAccent.getAccentColor());
dialog.show(fragmentManager, FRAG_TAG_DATE_PICKER);
}

@ -44,7 +44,7 @@ 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.setThemeDark(themeBase.isDarkTheme());
dialog.setThemeDark(themeBase.isDarkTheme(this));
dialog.setAccentColor(themeAccent.getAccentColor());
dialog.show(fragmentManager, FRAG_TAG_TIME_PICKER);
}

@ -37,7 +37,7 @@ public class DialogBuilder {
}
public ProgressDialog newProgressDialog() {
ProgressDialog progressDialog = new ProgressDialog(activity, theme.getDialogStyle());
ProgressDialog progressDialog = new ProgressDialog(activity, theme.getThemeBase().getDialogStyle());
theme.applyToContext(progressDialog.getContext());
if (AndroidUtilities.preLollipop()) {
progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));

@ -22,7 +22,7 @@ public class MyFilePickerActivity extends FilePickerActivity {
.getComponent()
.plus(new ActivityModule(this))
.inject(this);
theme.applyThemeAndStatusBarColor(this);
theme.applyThemeAndStatusBarColor(this, getDelegate());
setTitle(null);
super.onCreate(savedInstanceState);
}

@ -42,7 +42,7 @@ public abstract class InjectingPreferenceActivity extends AppCompatPreferenceAct
.plus(new ActivityModule(this));
inject(activityComponent);
theme.applyThemeAndStatusBarColor(this);
theme.applyThemeAndStatusBarColor(this, getDelegate());
super.onCreate(savedInstanceState);

@ -14,6 +14,6 @@ public abstract class ThemedInjectingAppCompatActivity extends InjectingAppCompa
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
theme.applyThemeAndStatusBarColor(this);
theme.applyThemeAndStatusBarColor(this, getDelegate());
}
}

@ -42,7 +42,6 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
getDelegate().applyDayNight();
super.onCreate(savedInstanceState);
}

@ -4,7 +4,6 @@ import android.app.Activity;
import android.app.FragmentManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.Preference;
@ -176,8 +175,7 @@ public abstract class BaseBasicPreferences extends InjectingPreferenceActivity i
switch (palette) {
case THEMES:
preferences.setInt(R.string.p_theme, index);
themeBase = themeCache.getThemeBase(index);
themeBase.applyDayNightMode(getDelegate());
themeCache.getThemeBase(index).setDefaultNightMode();
tracker.reportEvent(Tracking.Events.SET_THEME, Integer.toString(index));
break;
case COLORS:

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.PixelFormat;
import android.support.v7.app.AppCompatDelegate;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
@ -35,25 +36,22 @@ public class Theme {
return themeColor;
}
public int getDialogStyle() {
return R.style.TasksDialog;
}
public LayoutInflater getLayoutInflater(Context context) {
return (LayoutInflater) wrap(context).getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public ContextThemeWrapper getThemedDialog(Context context) {
return new ContextThemeWrapper(context, getDialogStyle());
return new ContextThemeWrapper(context, themeBase.getDialogStyle());
}
public void applyThemeAndStatusBarColor(Activity activity) {
applyTheme(activity);
public void applyThemeAndStatusBarColor(Activity activity, AppCompatDelegate delegate) {
applyTheme(activity, delegate);
themeColor.applyStatusBarColor(activity);
themeColor.applyTaskDescription(activity, activity.getString(R.string.app_name));
}
public void applyTheme(Activity activity) {
public void applyTheme(Activity activity, AppCompatDelegate delegate) {
delegate.applyDayNight();
themeBase.set(activity);
applyToContext(activity);
activity.getWindow().setFormat(PixelFormat.RGBA_8888);

@ -2,6 +2,7 @@ package org.tasks.themes;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.support.v7.app.AppCompatDelegate;
import android.view.ContextThemeWrapper;
@ -23,12 +24,16 @@ public class ThemeBase {
private final int contentBackground;
private final int dayNightMode;
public ThemeBase(String name, int index, int dayNightMode) {
public ThemeBase(String name, int index, int contentBackground, int dayNightMode) {
this.name = name;
this.index = index;
this.dayNightMode = dayNightMode;
this.style = THEMES[index];
this.contentBackground = 0;
this.contentBackground = contentBackground;
}
public int getDialogStyle() {
return R.style.TasksDialog;
}
public String getName() {
@ -43,8 +48,10 @@ public class ThemeBase {
return contentBackground;
}
public boolean isDarkTheme() {
return index > 0;
public boolean isDarkTheme(Activity activity) {
return index == 4
? Configuration.UI_MODE_NIGHT_YES == (activity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
: index > 0;
}
public ContextThemeWrapper wrap(Context context) {
@ -55,12 +62,7 @@ public class ThemeBase {
activity.setTheme(style);
}
public void applyDayNightMode() {
public void setDefaultNightMode() {
AppCompatDelegate.setDefaultNightMode(dayNightMode);
}
public void applyDayNightMode(AppCompatDelegate delegate) {
applyDayNightMode();
delegate.setLocalNightMode(dayNightMode);
}
}

@ -22,11 +22,11 @@ public class ThemeCache {
public ThemeCache(Context context) {
Resources resources = context.getResources();
themes.add(new ThemeBase(context.getString(R.string.theme_light), 0, AppCompatDelegate.MODE_NIGHT_NO));
themes.add(new ThemeBase(context.getString(R.string.theme_black), 1, AppCompatDelegate.MODE_NIGHT_YES));
themes.add(new ThemeBase(context.getString(R.string.theme_dark), 2, AppCompatDelegate.MODE_NIGHT_YES));
themes.add(new ThemeBase(context.getString(R.string.theme_wallpaper), 3, AppCompatDelegate.MODE_NIGHT_YES));
themes.add(new ThemeBase(context.getString(R.string.theme_day_night), 4, AppCompatDelegate.MODE_NIGHT_AUTO));
themes.add(new ThemeBase(context.getString(R.string.theme_light), 0, resources.getColor(R.color.md_background_light), AppCompatDelegate.MODE_NIGHT_NO));
themes.add(new ThemeBase(context.getString(R.string.theme_black), 1, resources.getColor(R.color.widget_background_black), AppCompatDelegate.MODE_NIGHT_YES));
themes.add(new ThemeBase(context.getString(R.string.theme_dark), 2, resources.getColor(R.color.md_background_dark), AppCompatDelegate.MODE_NIGHT_YES));
themes.add(new ThemeBase(context.getString(R.string.theme_wallpaper), 3, resources.getColor(R.color.black_38), AppCompatDelegate.MODE_NIGHT_YES));
themes.add(new ThemeBase(context.getString(R.string.theme_day_night), 4, resources.getColor(R.color.md_background_light), AppCompatDelegate.MODE_NIGHT_AUTO));
String[] colorNames = resources.getStringArray(R.array.colors);
for (int i = 0 ; i < ThemeColor.COLORS.length ; i++) {

@ -4,9 +4,9 @@ import org.tasks.R;
public class WidgetTheme {
public static final int[] BACKGROUNDS = new int[] {
R.color.widget_background_light,
R.color.md_background_light,
R.color.widget_background_black,
R.color.widget_background_dark
R.color.md_background_dark
};
private final String name;
private final int index;

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background_color">#303030</color>
<color name="background_color_dialog">#424242</color>
<color name="icon_tint">#ffffff</color>
<color name="drawer_color">#303030</color>
<color name="drawer_color_selected">#202020</color>
<color name="text_primary">#ffffffff</color> <!-- 100% white -->
<color name="text_secondary">#b3ffffff</color> <!-- 70% white -->
<color name="text_tertiary">#80ffffff</color> <!-- 50% white -->
<color name="divider">#1fffffff</color> <!-- 12% white -->
<color name="background_color">@color/md_background_dark</color>
<color name="background_color_dialog">@color/md_background_dark_dialog</color>
<color name="icon_tint">@color/icon_tint_dark</color>
<color name="drawer_color">@color/drawer_background_dark</color>
<color name="drawer_color_selected">@color/drawer_background_dark_selected</color>
<color name="text_primary">@color/white_100</color>
<color name="text_secondary">@color/white_70</color>
<color name="text_tertiary">@color/white_50</color>
<color name="divider">@color/white_12</color>
</resources>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background_color">@color/md_background_light</color>
<color name="background_color_dialog">@color/md_background_light_dialog</color>
<color name="icon_tint">@color/icon_tint_light</color>
<color name="drawer_color">@color/drawer_background_light</color>
<color name="drawer_color_selected">@color/drawer_background_light_selected</color>
<color name="text_primary">@color/black_87</color>
<color name="text_secondary">@color/black_54</color>
<color name="text_tertiary">@color/black_38</color>
<color name="divider">@color/black_12</color>
</resources>

@ -90,28 +90,28 @@
<color name="task_list_done">#ff777777</color>
<color name="task_edit_deadline_gray">#888888</color>
<color name="background_color">#fafafa</color>
<color name="background_color_dialog">#ffffff</color>
<color name="icon_tint">#000000</color>
<color name="text_primary">#de000000</color> <!-- 87% black -->
<color name="text_secondary">#8a000000</color> <!-- 54% black -->
<color name="text_tertiary">#61000000</color> <!-- 38% black -->
<color name="divider">#1f000000</color> <!-- 12% black -->
<color name="black_87">#de000000</color> <!-- 87% black -->
<color name="black_54">#8a000000</color> <!-- 54% black -->
<color name="black_38">#61000000</color> <!-- 38% black -->
<color name="white_100">#ffffffff</color> <!-- 100% white -->
<color name="white_70">#b3ffffff</color> <!-- 70% white -->
<color name="white_50">#80ffffff</color> <!-- 50% white -->
<color name="widget_background_light">#fafafa</color>
<color name="black_87">#de000000</color>
<color name="black_54">#8a000000</color>
<color name="black_38">#61000000</color>
<color name="black_12">#1f000000</color>
<color name="white_100">#ffffffff</color>
<color name="white_70">#b3ffffff</color>
<color name="white_50">#80ffffff</color>
<color name="white_12">#1fffffff</color>
<color name="md_background_light">#fafafa</color>
<color name="md_background_light_dialog">#ffffff</color>
<color name="md_background_dark">#303030</color>
<color name="md_background_dark_dialog">#424242</color>
<color name="widget_background_black">#000000</color>
<color name="widget_background_dark">#303030</color>
<color name="icon_tint_light">@android:color/black</color>
<color name="icon_tint_dark">@android:color/white</color>
<color name="drawer_color">#f9f9f9</color>
<color name="drawer_color_selected">#e8e8e8</color>
<color name="drawer_background_light">#f9f9f9</color>
<color name="drawer_background_light_selected">#e8e8e8</color>
<color name="drawer_background_dark">#303030</color>
<color name="drawer_background_dark_selected">#202020</color>
<color name="importance_1">@color/red_500</color>
<color name="importance_2">@color/amber_500</color>

Loading…
Cancel
Save