DatePicker: Implement dark theme

Fixes #858
pull/884/head
Alinson S. Xavier 5 years ago
parent da018fc64d
commit fcff067b2e
No known key found for this signature in database
GPG Key ID: DCA0DAD4D2F58624

@ -27,6 +27,7 @@ import com.android.*;
import com.android.datetimepicker.*; import com.android.datetimepicker.*;
import org.isoron.uhabits.R; import org.isoron.uhabits.R;
import org.isoron.uhabits.utils.StyledResources;
import java.text.*; import java.text.*;
@ -73,10 +74,10 @@ public class AmPmCirclesView extends View {
return; return;
} }
StyledResources styledResources = new StyledResources(context);
mUnselectedColor = styledResources.getColor(R.attr.contrast0);
Resources res = context.getResources(); Resources res = context.getResources();
mUnselectedColor = res.getColor(R.color.white);
//mSelectedColor = res.getColor(R.color.blue);
//mAmPmTextColor = res.getColor(R.color.ampm_text_color);
mSelectedAlpha = SELECTED_ALPHA; mSelectedAlpha = SELECTED_ALPHA;
String typefaceFamily = res.getString(R.string.sans_serif); String typefaceFamily = res.getString(R.string.sans_serif);
Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL); Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL);
@ -98,21 +99,6 @@ public class AmPmCirclesView extends View {
mIsInitialized = true; mIsInitialized = true;
} }
/* package */ void setTheme(Context context, boolean themeDark) {
Resources res = context.getResources();
if (themeDark) {
mUnselectedColor = res.getColor(R.color.dark_gray);
mSelectedColor = res.getColor(R.color.red);
mAmPmTextColor = res.getColor(R.color.white);
mSelectedAlpha = SELECTED_ALPHA_THEME_DARK;
} else {
mUnselectedColor = res.getColor(R.color.white);
//mSelectedColor = res.getColor(R.color.blue);
//mAmPmTextColor = res.getColor(R.color.ampm_text_color);
mSelectedAlpha = SELECTED_ALPHA;
}
}
public void setAmOrPm(int amOrPm) { public void setAmOrPm(int amOrPm) {
mAmOrPm = amOrPm; mAmOrPm = amOrPm;
} }

@ -25,6 +25,7 @@ import android.util.Log;
import android.view.View; import android.view.View;
import org.isoron.uhabits.R; import org.isoron.uhabits.R;
import org.isoron.uhabits.utils.StyledResources;
/** /**
* Draws a simple white circle on which the numbers will be drawn. * Draws a simple white circle on which the numbers will be drawn.
@ -48,9 +49,9 @@ public class CircleView extends View {
public CircleView(Context context) { public CircleView(Context context) {
super(context); super(context);
Resources res = context.getResources(); StyledResources styledResources = new StyledResources(context);
mCircleColor = res.getColor(R.color.white); mCircleColor = styledResources.getColor(R.attr.contrast0);
mDotColor = res.getColor(R.color.numbers_text_color); mDotColor = mCircleColor;
mPaint.setAntiAlias(true); mPaint.setAntiAlias(true);
mIsInitialized = false; mIsInitialized = false;
@ -77,17 +78,6 @@ public class CircleView extends View {
mIsInitialized = true; mIsInitialized = true;
} }
/* package */ void setTheme(Context context, boolean dark) {
Resources res = context.getResources();
if (dark) {
mCircleColor = res.getColor(R.color.dark_gray);
mDotColor = res.getColor(R.color.light_gray);
} else {
mCircleColor = res.getColor(R.color.white);
mDotColor = res.getColor(R.color.numbers_text_color);
}
}
@Override @Override
public void onDraw(Canvas canvas) { public void onDraw(Canvas canvas) {

@ -219,15 +219,6 @@ public class RadialPickerLayout extends FrameLayout implements OnTouchListener {
mTimeInitialized = true; mTimeInitialized = true;
} }
/* package */ void setTheme(Context context, boolean themeDark) {
mCircleView.setTheme(context, themeDark);
mAmPmCirclesView.setTheme(context, themeDark);
mHourRadialTextsView.setTheme(context, themeDark);
mMinuteRadialTextsView.setTheme(context, themeDark);
mHourRadialSelectorView.setTheme(context, themeDark);
mMinuteRadialSelectorView.setTheme(context, themeDark);
}
public void setTime(int hours, int minutes) { public void setTime(int hours, int minutes) {
setItem(HOUR_INDEX, hours); setItem(HOUR_INDEX, hours);
setItem(MINUTE_INDEX, minutes); setItem(MINUTE_INDEX, minutes);

@ -140,15 +140,6 @@ public class RadialSelectorView extends View {
mIsInitialized = true; mIsInitialized = true;
} }
/* package */ void setTheme(Context context, boolean themeDark) {
Resources res = context.getResources();
if (themeDark) {
mSelectionAlpha = SELECTED_ALPHA_THEME_DARK;
} else {
mSelectionAlpha = SELECTED_ALPHA;
}
}
/** /**
* Set the selection. * Set the selection.
* @param selectionDegrees The degrees to be selected. * @param selectionDegrees The degrees to be selected.

@ -31,6 +31,7 @@ import android.util.Log;
import android.view.View; import android.view.View;
import org.isoron.uhabits.R; import org.isoron.uhabits.R;
import org.isoron.uhabits.utils.StyledResources;
/** /**
* A view to show a series of numbers in a circular pattern. * A view to show a series of numbers in a circular pattern.
@ -87,7 +88,8 @@ public class RadialTextsView extends View {
} }
// Set up the paint. // Set up the paint.
int numbersTextColor = res.getColor(R.color.numbers_text_color); StyledResources styledResources = new StyledResources(getContext());
int numbersTextColor = styledResources.getColor(R.attr.contrast80);
mPaint.setColor(numbersTextColor); mPaint.setColor(numbersTextColor);
String typefaceFamily = res.getString(R.string.radial_numbers_typeface); String typefaceFamily = res.getString(R.string.radial_numbers_typeface);
mTypefaceLight = Typeface.create(typefaceFamily, Typeface.NORMAL); mTypefaceLight = Typeface.create(typefaceFamily, Typeface.NORMAL);
@ -143,17 +145,6 @@ public class RadialTextsView extends View {
mIsInitialized = true; mIsInitialized = true;
} }
/* package */ void setTheme(Context context, boolean themeDark) {
Resources res = context.getResources();
int textColor;
if (themeDark) {
textColor = res.getColor(R.color.white);
} else {
textColor = res.getColor(R.color.numbers_text_color);
}
mPaint.setColor(textColor);
}
/** /**
* Allows for smoother animation. * Allows for smoother animation.
*/ */

@ -23,6 +23,7 @@ import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.KeyCharacterMap; import android.view.KeyCharacterMap;
@ -44,6 +45,7 @@ import com.android.datetimepicker.Utils;
import com.android.datetimepicker.time.RadialPickerLayout.OnValueSelectedListener; import com.android.datetimepicker.time.RadialPickerLayout.OnValueSelectedListener;
import org.isoron.uhabits.R; import org.isoron.uhabits.R;
import org.isoron.uhabits.utils.StyledResources;
import java.text.DateFormatSymbols; import java.text.DateFormatSymbols;
import java.util.ArrayList; import java.util.ArrayList;
@ -101,7 +103,6 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue
private int mInitialHourOfDay; private int mInitialHourOfDay;
private int mInitialMinute; private int mInitialMinute;
private boolean mIs24HourMode; private boolean mIs24HourMode;
private boolean mThemeDark;
// For hardware IME input. // For hardware IME input.
private char mPlaceholderText; private char mPlaceholderText;
@ -173,23 +174,9 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue
mInitialMinute = minute; mInitialMinute = minute;
mIs24HourMode = is24HourMode; mIs24HourMode = is24HourMode;
mInKbMode = false; mInKbMode = false;
mThemeDark = false;
mSelectedColor = color; mSelectedColor = color;
} }
/**
* Set a dark or light theme. NOTE: this will only take effect for the next onCreateView.
*/
public void setThemeDark(boolean dark)
{
mThemeDark = dark;
}
public boolean isThemeDark()
{
return mThemeDark;
}
public void setOnTimeSetListener(OnTimeSetListener callback) public void setOnTimeSetListener(OnTimeSetListener callback)
{ {
mCallback = callback; mCallback = callback;
@ -213,7 +200,6 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue
mInitialMinute = savedInstanceState.getInt(KEY_MINUTE); mInitialMinute = savedInstanceState.getInt(KEY_MINUTE);
mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW); mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW);
mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE); mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE);
mThemeDark = savedInstanceState.getBoolean(KEY_DARK_THEME);
mSelectedColor = savedInstanceState.getInt(KEY_SELECTED_COLOR); mSelectedColor = savedInstanceState.getInt(KEY_SELECTED_COLOR);
} }
} }
@ -239,8 +225,6 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue
mSelectHours = res.getString(R.string.select_hours); mSelectHours = res.getString(R.string.select_hours);
mMinutePickerDescription = res.getString(R.string.minute_picker_description); mMinutePickerDescription = res.getString(R.string.minute_picker_description);
mSelectMinutes = res.getString(R.string.select_minutes); mSelectMinutes = res.getString(R.string.select_minutes);
//mSelectedColor = res.getColor(mThemeDark ? R.color.red : R.color.blue);
mUnselectedColor = res.getColor(mThemeDark ? R.color.white : R.color.numbers_text_color);
mHourView = (TextView) view.findViewById(R.id.hours); mHourView = (TextView) view.findViewById(R.id.hours);
mHourView.setOnKeyListener(keyboardListener); mHourView.setOnKeyListener(keyboardListener);
@ -374,31 +358,25 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue
} }
// // Set the theme at the end so that the initialize()s above don't counteract the theme. StyledResources styledResources = new StyledResources(getActivity());
// mTimePicker.setTheme(getActivity().getApplicationContext(), mThemeDark); int contrast0 = styledResources.getColor(R.attr.contrast0);
// // Prepare some palette to use. int contrast20 = styledResources.getColor(R.attr.contrast20);
// int white = res.getColor(R.color.white); int contrast60 = styledResources.getColor(R.attr.contrast60);
// int circleBackground = res.getColor(R.color.circle_background); int contrast80 = styledResources.getColor(R.attr.contrast80);
// int line = res.getColor(R.color.line_background); view.findViewById(R.id.time_display_background).setBackgroundColor(Color.BLUE);
// int timeDisplay = res.getColor(R.color.numbers_text_color); view.findViewById(R.id.time_display).setBackgroundColor(contrast0);
// ColorStateList doneTextColor = res.getColorStateList(R.color.done_text_color); ((TextView) view.findViewById(R.id.separator)).setTextColor(contrast80);
// int doneBackground = R.drawable.done_background_color; ((TextView) view.findViewById(R.id.ampm_label)).setTextColor(contrast80);
// view.findViewById(R.id.line).setBackgroundColor(contrast20);
// int darkGray = res.getColor(R.color.dark_gray); mDoneButton.setTextColor(contrast80);
// int lightGray = res.getColor(R.color.light_gray); mDoneButton.setBackgroundColor(contrast0);
// int darkLine = res.getColor(R.color.line_dark); mClearButton.setTextColor(contrast80);
// ColorStateList darkDoneTextColor = res.getColorStateList(R.color.done_text_color_dark); mClearButton.setBackgroundColor(contrast0);
// int darkDoneBackground = R.drawable.done_background_color_dark; mTimePicker.setBackgroundColor(contrast20);
mUnselectedColor = contrast80;
// Set the palette for each view based on the theme. mMinuteView.setTextColor(mUnselectedColor);
// view.findViewById(R.id.time_display_background).setBackgroundColor(mThemeDark? darkGray : white); mHourView.setTextColor(mSelectedColor);
// view.findViewById(R.id.time_display).setBackgroundColor(mThemeDark? darkGray : white);
// ((TextView) view.findViewById(R.id.separator)).setTextColor(mThemeDark? white : timeDisplay);
// ((TextView) view.findViewById(R.id.ampm_label)).setTextColor(mThemeDark? white : timeDisplay);
// view.findViewById(R.id.line).setBackgroundColor(mThemeDark? darkLine : line);
// mDoneButton.setTextColor(mThemeDark? darkDoneTextColor : doneTextColor);
// mTimePicker.setBackgroundColor(mThemeDark? lightGray : circleBackground);
// mDoneButton.setBackgroundResource(mThemeDark? darkDoneBackground : doneBackground);
return view; return view;
} }
@ -448,7 +426,6 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue
if (mInKbMode) { if (mInKbMode) {
outState.putIntegerArrayList(KEY_TYPED_TIMES, mTypedTimes); outState.putIntegerArrayList(KEY_TYPED_TIMES, mTypedTimes);
} }
outState.putBoolean(KEY_DARK_THEME, mThemeDark);
outState.putInt(KEY_SELECTED_COLOR, mSelectedColor); outState.putInt(KEY_SELECTED_COLOR, mSelectedColor);
} }
} }

@ -20,10 +20,8 @@ package org.isoron.uhabits.notifications
import android.app.AlertDialog import android.app.AlertDialog
import android.content.ContentUris import android.content.ContentUris
import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.text.format.DateFormat import android.text.format.DateFormat
import android.view.ContextThemeWrapper
import android.view.View import android.view.View
import android.widget.AdapterView import android.widget.AdapterView
import android.widget.AdapterView.OnItemClickListener import android.widget.AdapterView.OnItemClickListener
@ -32,21 +30,33 @@ import com.android.datetimepicker.time.RadialPickerLayout
import com.android.datetimepicker.time.TimePickerDialog import com.android.datetimepicker.time.TimePickerDialog
import org.isoron.uhabits.HabitsApplication import org.isoron.uhabits.HabitsApplication
import org.isoron.uhabits.R import org.isoron.uhabits.R
import org.isoron.uhabits.activities.AndroidThemeSwitcher
import org.isoron.uhabits.core.models.Habit import org.isoron.uhabits.core.models.Habit
import org.isoron.uhabits.core.ui.ThemeSwitcher.Companion.THEME_LIGHT
import org.isoron.uhabits.receivers.ReminderController import org.isoron.uhabits.receivers.ReminderController
import org.isoron.uhabits.utils.StyledResources
import org.isoron.uhabits.utils.SystemUtils import org.isoron.uhabits.utils.SystemUtils
import org.isoron.uhabits.utils.toThemedAndroidColor
import java.util.Calendar import java.util.Calendar
class SnoozeDelayPickerActivity : FragmentActivity(), OnItemClickListener { class SnoozeDelayPickerActivity : FragmentActivity(), OnItemClickListener {
private var habit: Habit? = null private var habit: Habit? = null
private var reminderController: ReminderController? = null private var reminderController: ReminderController? = null
private var dialog: AlertDialog? = null private var dialog: AlertDialog? = null
private var color: Int = 0
override fun onCreate(bundle: Bundle?) { override fun onCreate(bundle: Bundle?) {
super.onCreate(bundle) super.onCreate(bundle)
val intent = intent val intent = intent
if (intent == null) finish() if (intent == null) finish()
val app = applicationContext as HabitsApplication val app = applicationContext as HabitsApplication
val appComponent = app.component val appComponent = app.component
val themeSwitcher = AndroidThemeSwitcher(this, appComponent.preferences)
if (themeSwitcher.getSystemTheme() == THEME_LIGHT) {
setTheme(R.style.BaseDialog)
} else {
setTheme(R.style.BaseDialogDark)
}
val data = intent.data val data = intent.data
if (data == null) { if (data == null) {
finish() finish()
@ -54,9 +64,9 @@ class SnoozeDelayPickerActivity : FragmentActivity(), OnItemClickListener {
habit = appComponent.habitList.getById(ContentUris.parseId(data)) habit = appComponent.habitList.getById(ContentUris.parseId(data))
} }
if (habit == null) finish() if (habit == null) finish()
color = habit!!.color.toThemedAndroidColor(this)
reminderController = appComponent.reminderController reminderController = appComponent.reminderController
val theme = R.style.Theme_AppCompat_Light_Dialog_Alert dialog = AlertDialog.Builder(this)
dialog = AlertDialog.Builder(ContextThemeWrapper(this, theme))
.setTitle(R.string.select_snooze_delay) .setTitle(R.string.select_snooze_delay)
.setItems(R.array.snooze_picker_names, null) .setItems(R.array.snooze_picker_names, null)
.create() .create()
@ -76,7 +86,7 @@ class SnoozeDelayPickerActivity : FragmentActivity(), OnItemClickListener {
calendar[Calendar.HOUR_OF_DAY], calendar[Calendar.HOUR_OF_DAY],
calendar[Calendar.MINUTE], calendar[Calendar.MINUTE],
DateFormat.is24HourFormat(this), DateFormat.is24HourFormat(this),
Color.BLUE color
) )
dialog.show(supportFragmentManager, "timePicker") dialog.show(supportFragmentManager, "timePicker")
} }

@ -125,6 +125,26 @@
<item name="windowBackgroundColor">@color/black</item> <item name="windowBackgroundColor">@color/black</item>
</style> </style>
<style name="BaseDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="contrast0">@color/white</item>
<item name="contrast20">@color/grey_300</item>
<item name="contrast40">@color/grey_350</item>
<item name="contrast60">@color/grey_500</item>
<item name="contrast80">@color/grey_700</item>
<item name="contrast100">@color/grey_800</item>
<item name="palette">@array/lightPalette</item>
</style>
<style name="BaseDialogDark" parent="Theme.AppCompat.Dialog">
<item name="contrast0">@color/grey_900</item>
<item name="contrast20">@color/grey_800</item>
<item name="contrast40">@color/grey_750</item>
<item name="contrast60">@color/grey_500</item>
<item name="contrast80">@color/grey_300</item>
<item name="contrast100">@color/grey_100</item>
<item name="palette">@array/darkPalette</item>
</style>
<style name="WidgetTheme" parent="AppBaseThemeDark"> <style name="WidgetTheme" parent="AppBaseThemeDark">
<item name="cardBgColor">@color/grey_850</item> <item name="cardBgColor">@color/grey_850</item>
<item name="contrast0">@color/white</item> <item name="contrast0">@color/white</item>

Loading…
Cancel
Save