diff --git a/uhabits-android/src/main/java/com/android/datetimepicker/time/AmPmCirclesView.java b/uhabits-android/src/main/java/com/android/datetimepicker/time/AmPmCirclesView.java index 599f6d1f0..ad9f6ce2e 100644 --- a/uhabits-android/src/main/java/com/android/datetimepicker/time/AmPmCirclesView.java +++ b/uhabits-android/src/main/java/com/android/datetimepicker/time/AmPmCirclesView.java @@ -27,6 +27,7 @@ import com.android.*; import com.android.datetimepicker.*; import org.isoron.uhabits.R; +import org.isoron.uhabits.utils.StyledResources; import java.text.*; @@ -73,10 +74,10 @@ public class AmPmCirclesView extends View { return; } + StyledResources styledResources = new StyledResources(context); + mUnselectedColor = styledResources.getColor(R.attr.contrast0); + 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; String typefaceFamily = res.getString(R.string.sans_serif); Typeface tf = Typeface.create(typefaceFamily, Typeface.NORMAL); @@ -98,21 +99,6 @@ public class AmPmCirclesView extends View { 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) { mAmOrPm = amOrPm; } diff --git a/uhabits-android/src/main/java/com/android/datetimepicker/time/CircleView.java b/uhabits-android/src/main/java/com/android/datetimepicker/time/CircleView.java index 4f4498a85..5e1e2f134 100644 --- a/uhabits-android/src/main/java/com/android/datetimepicker/time/CircleView.java +++ b/uhabits-android/src/main/java/com/android/datetimepicker/time/CircleView.java @@ -25,6 +25,7 @@ import android.util.Log; import android.view.View; import org.isoron.uhabits.R; +import org.isoron.uhabits.utils.StyledResources; /** * 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) { super(context); - Resources res = context.getResources(); - mCircleColor = res.getColor(R.color.white); - mDotColor = res.getColor(R.color.numbers_text_color); + StyledResources styledResources = new StyledResources(context); + mCircleColor = styledResources.getColor(R.attr.contrast0); + mDotColor = mCircleColor; mPaint.setAntiAlias(true); mIsInitialized = false; @@ -77,17 +78,6 @@ public class CircleView extends View { 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 public void onDraw(Canvas canvas) { diff --git a/uhabits-android/src/main/java/com/android/datetimepicker/time/RadialPickerLayout.java b/uhabits-android/src/main/java/com/android/datetimepicker/time/RadialPickerLayout.java index bb6be1300..e18ee1143 100644 --- a/uhabits-android/src/main/java/com/android/datetimepicker/time/RadialPickerLayout.java +++ b/uhabits-android/src/main/java/com/android/datetimepicker/time/RadialPickerLayout.java @@ -219,15 +219,6 @@ public class RadialPickerLayout extends FrameLayout implements OnTouchListener { 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) { setItem(HOUR_INDEX, hours); setItem(MINUTE_INDEX, minutes); diff --git a/uhabits-android/src/main/java/com/android/datetimepicker/time/RadialSelectorView.java b/uhabits-android/src/main/java/com/android/datetimepicker/time/RadialSelectorView.java index 7af032433..7099a1e36 100644 --- a/uhabits-android/src/main/java/com/android/datetimepicker/time/RadialSelectorView.java +++ b/uhabits-android/src/main/java/com/android/datetimepicker/time/RadialSelectorView.java @@ -140,15 +140,6 @@ public class RadialSelectorView extends View { 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. * @param selectionDegrees The degrees to be selected. diff --git a/uhabits-android/src/main/java/com/android/datetimepicker/time/RadialTextsView.java b/uhabits-android/src/main/java/com/android/datetimepicker/time/RadialTextsView.java index 607d93a61..8063f65cd 100644 --- a/uhabits-android/src/main/java/com/android/datetimepicker/time/RadialTextsView.java +++ b/uhabits-android/src/main/java/com/android/datetimepicker/time/RadialTextsView.java @@ -31,6 +31,7 @@ import android.util.Log; import android.view.View; import org.isoron.uhabits.R; +import org.isoron.uhabits.utils.StyledResources; /** * 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. - int numbersTextColor = res.getColor(R.color.numbers_text_color); + StyledResources styledResources = new StyledResources(getContext()); + int numbersTextColor = styledResources.getColor(R.attr.contrast80); mPaint.setColor(numbersTextColor); String typefaceFamily = res.getString(R.string.radial_numbers_typeface); mTypefaceLight = Typeface.create(typefaceFamily, Typeface.NORMAL); @@ -143,17 +145,6 @@ public class RadialTextsView extends View { 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. */ diff --git a/uhabits-android/src/main/java/com/android/datetimepicker/time/TimePickerDialog.java b/uhabits-android/src/main/java/com/android/datetimepicker/time/TimePickerDialog.java index 0dc48ea6e..88e78203f 100644 --- a/uhabits-android/src/main/java/com/android/datetimepicker/time/TimePickerDialog.java +++ b/uhabits-android/src/main/java/com/android/datetimepicker/time/TimePickerDialog.java @@ -23,6 +23,7 @@ import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.res.Resources; +import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.KeyCharacterMap; @@ -44,6 +45,7 @@ import com.android.datetimepicker.Utils; import com.android.datetimepicker.time.RadialPickerLayout.OnValueSelectedListener; import org.isoron.uhabits.R; +import org.isoron.uhabits.utils.StyledResources; import java.text.DateFormatSymbols; import java.util.ArrayList; @@ -101,7 +103,6 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue private int mInitialHourOfDay; private int mInitialMinute; private boolean mIs24HourMode; - private boolean mThemeDark; // For hardware IME input. private char mPlaceholderText; @@ -173,23 +174,9 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue mInitialMinute = minute; mIs24HourMode = is24HourMode; mInKbMode = false; - mThemeDark = false; 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) { mCallback = callback; @@ -213,7 +200,6 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue mInitialMinute = savedInstanceState.getInt(KEY_MINUTE); mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW); mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE); - mThemeDark = savedInstanceState.getBoolean(KEY_DARK_THEME); mSelectedColor = savedInstanceState.getInt(KEY_SELECTED_COLOR); } } @@ -239,8 +225,6 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue mSelectHours = res.getString(R.string.select_hours); mMinutePickerDescription = res.getString(R.string.minute_picker_description); 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.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. -// mTimePicker.setTheme(getActivity().getApplicationContext(), mThemeDark); -// // Prepare some palette to use. -// int white = res.getColor(R.color.white); -// int circleBackground = res.getColor(R.color.circle_background); -// int line = res.getColor(R.color.line_background); -// int timeDisplay = res.getColor(R.color.numbers_text_color); -// ColorStateList doneTextColor = res.getColorStateList(R.color.done_text_color); -// int doneBackground = R.drawable.done_background_color; -// -// int darkGray = res.getColor(R.color.dark_gray); -// int lightGray = res.getColor(R.color.light_gray); -// int darkLine = res.getColor(R.color.line_dark); -// ColorStateList darkDoneTextColor = res.getColorStateList(R.color.done_text_color_dark); -// int darkDoneBackground = R.drawable.done_background_color_dark; - - // Set the palette for each view based on the theme. -// view.findViewById(R.id.time_display_background).setBackgroundColor(mThemeDark? darkGray : white); -// 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); + StyledResources styledResources = new StyledResources(getActivity()); + int contrast0 = styledResources.getColor(R.attr.contrast0); + int contrast20 = styledResources.getColor(R.attr.contrast20); + int contrast60 = styledResources.getColor(R.attr.contrast60); + int contrast80 = styledResources.getColor(R.attr.contrast80); + view.findViewById(R.id.time_display_background).setBackgroundColor(Color.BLUE); + view.findViewById(R.id.time_display).setBackgroundColor(contrast0); + ((TextView) view.findViewById(R.id.separator)).setTextColor(contrast80); + ((TextView) view.findViewById(R.id.ampm_label)).setTextColor(contrast80); + view.findViewById(R.id.line).setBackgroundColor(contrast20); + mDoneButton.setTextColor(contrast80); + mDoneButton.setBackgroundColor(contrast0); + mClearButton.setTextColor(contrast80); + mClearButton.setBackgroundColor(contrast0); + mTimePicker.setBackgroundColor(contrast20); + mUnselectedColor = contrast80; + mMinuteView.setTextColor(mUnselectedColor); + mHourView.setTextColor(mSelectedColor); + return view; } @@ -448,7 +426,6 @@ public class TimePickerDialog extends AppCompatDialogFragment implements OnValue if (mInKbMode) { outState.putIntegerArrayList(KEY_TYPED_TIMES, mTypedTimes); } - outState.putBoolean(KEY_DARK_THEME, mThemeDark); outState.putInt(KEY_SELECTED_COLOR, mSelectedColor); } } diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/notifications/SnoozeDelayPickerActivity.kt b/uhabits-android/src/main/java/org/isoron/uhabits/notifications/SnoozeDelayPickerActivity.kt index ee6453442..36295779e 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/notifications/SnoozeDelayPickerActivity.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/notifications/SnoozeDelayPickerActivity.kt @@ -20,10 +20,8 @@ package org.isoron.uhabits.notifications import android.app.AlertDialog import android.content.ContentUris -import android.graphics.Color import android.os.Bundle import android.text.format.DateFormat -import android.view.ContextThemeWrapper import android.view.View import android.widget.AdapterView import android.widget.AdapterView.OnItemClickListener @@ -32,21 +30,33 @@ import com.android.datetimepicker.time.RadialPickerLayout import com.android.datetimepicker.time.TimePickerDialog import org.isoron.uhabits.HabitsApplication import org.isoron.uhabits.R +import org.isoron.uhabits.activities.AndroidThemeSwitcher 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.utils.StyledResources import org.isoron.uhabits.utils.SystemUtils +import org.isoron.uhabits.utils.toThemedAndroidColor import java.util.Calendar class SnoozeDelayPickerActivity : FragmentActivity(), OnItemClickListener { private var habit: Habit? = null private var reminderController: ReminderController? = null private var dialog: AlertDialog? = null + private var color: Int = 0 + override fun onCreate(bundle: Bundle?) { super.onCreate(bundle) val intent = intent if (intent == null) finish() val app = applicationContext as HabitsApplication 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 if (data == null) { finish() @@ -54,9 +64,9 @@ class SnoozeDelayPickerActivity : FragmentActivity(), OnItemClickListener { habit = appComponent.habitList.getById(ContentUris.parseId(data)) } if (habit == null) finish() + color = habit!!.color.toThemedAndroidColor(this) reminderController = appComponent.reminderController - val theme = R.style.Theme_AppCompat_Light_Dialog_Alert - dialog = AlertDialog.Builder(ContextThemeWrapper(this, theme)) + dialog = AlertDialog.Builder(this) .setTitle(R.string.select_snooze_delay) .setItems(R.array.snooze_picker_names, null) .create() @@ -76,7 +86,7 @@ class SnoozeDelayPickerActivity : FragmentActivity(), OnItemClickListener { calendar[Calendar.HOUR_OF_DAY], calendar[Calendar.MINUTE], DateFormat.is24HourFormat(this), - Color.BLUE + color ) dialog.show(supportFragmentManager, "timePicker") } diff --git a/uhabits-android/src/main/res/values/styles.xml b/uhabits-android/src/main/res/values/styles.xml index 7e029b5dd..4d588fa2a 100644 --- a/uhabits-android/src/main/res/values/styles.xml +++ b/uhabits-android/src/main/res/values/styles.xml @@ -125,6 +125,26 @@ @color/black + + + +