From f7035d73c8cdf9b97369425cebbeafe80de7218c Mon Sep 17 00:00:00 2001 From: Mahdi Parastesh Date: Wed, 31 May 2023 18:12:19 +0330 Subject: [PATCH] 2023.05.31 - 1 (migrated to theme colours with material library) --- README.md | 107 ------------------ gradle.properties | 4 +- library/build.gradle | 1 + .../ir/mahdiparastesh/mcdtp/McdtpUtils.java | 10 +- .../mcdtp/TextViewWithCircularIndicator.java | 27 +---- .../mcdtp/date/DatePickerController.java | 2 - .../mcdtp/date/DatePickerDialog.java | 68 ----------- .../mahdiparastesh/mcdtp/date/MonthView.java | 12 +- .../mcdtp/date/YearPickerView.java | 1 - .../mcdtp/time/AmPmCirclesView.java | 17 ++- .../mahdiparastesh/mcdtp/time/CircleView.java | 3 +- .../mcdtp/time/RadialSelectorView.java | 13 ++- .../mcdtp/time/RadialTextsView.java | 4 +- .../mcdtp/time/TimePickerController.java | 2 - .../mcdtp/time/TimePickerDialog.java | 73 +----------- .../mahdiparastesh/mcdtp/time/Timepoint.java | 6 +- .../color-night/date_picker_year_selector.xml | 6 + .../main/res/color/date_picker_selector.xml | 4 +- .../res/color/date_picker_year_selector.xml | 6 +- .../res/layout-land/date_picker_dialog.xml | 2 +- .../res/layout-land/date_picker_dialog_v2.xml | 2 +- .../date_picker_header_view_v2.xml | 3 +- .../res/layout-land/time_header_label.xml | 4 +- .../res/layout-land/time_picker_dialog.xml | 5 +- .../res/layout-land/time_picker_dialog_v2.xml | 5 +- .../res/layout-land/time_title_view_v2.xml | 4 +- .../date_picker_dialog.xml | 2 +- .../res/layout-sw600dp/date_picker_dialog.xml | 2 +- .../date_picker_dialog.xml | 2 +- .../layout/{done_button.xml => buttons.xml} | 9 +- .../main/res/layout/date_picker_dialog.xml | 2 +- .../main/res/layout/date_picker_dialog_v2.xml | 2 +- .../res/layout/date_picker_header_view.xml | 4 +- .../res/layout/date_picker_header_view_v2.xml | 4 +- .../res/layout/date_picker_selected_date.xml | 2 +- .../layout/date_picker_selected_date_v2.xml | 2 +- .../src/main/res/layout/time_header_label.xml | 4 +- .../main/res/layout/time_picker_dialog.xml | 3 +- .../main/res/layout/time_picker_dialog_v2.xml | 3 +- .../src/main/res/layout/time_title_view.xml | 4 +- .../main/res/layout/time_title_view_v2.xml | 4 +- .../main/res/layout/year_label_text_view.xml | 4 +- library/src/main/res/values-night/colors.xml | 4 +- .../src/main/res/values-sw600dp/dimens.xml | 4 +- library/src/main/res/values/colors.xml | 9 +- library/src/main/res/values/dimens.xml | 4 +- library/src/main/res/values/styles.xml | 4 +- sample/src/main/res/values-night/themes.xml | 14 +++ sample/src/main/res/values/themes.xml | 29 ++++- 49 files changed, 147 insertions(+), 365 deletions(-) create mode 100644 library/src/main/res/color-night/date_picker_year_selector.xml rename library/src/main/res/layout/{done_button.xml => buttons.xml} (76%) create mode 100644 sample/src/main/res/values-night/themes.xml diff --git a/README.md b/README.md index 90ada31..6c29bc2 100644 --- a/README.md +++ b/README.md @@ -85,62 +85,15 @@ You can set the layout version using the factory ```java dpd.setVersion(DatePickerDialog.Version.VERSION_2); -``` - -The pickers will be themed automatically based on the current theme where they are created, based on the -current `colorAccent`. You can also theme the dialogs via the `setAccentColor(int color)` method. Alternatively, you can -theme the pickers by overwriting the color resources `accent_color` and `accent_color_dark` in your project. - -```xml - -#009688 -#00796b -``` - -The exact order in which colors are selected is as follows: - -1. `setAccentColor(int color)` in java code -2. `android.R.attr.colorAccent` (if android 5.0+) -3. `R.attr.colorAccent` (eg. when using AppCompat) -4. `R.color.accent_color` and `R.color.accent_color_dark` if none of the others are set in your project - -The pickers also have a dark theme. This can be specified globablly using the `theme_dark` attribute in your theme -or the `setThemeDark(boolean themeDark)` functions. The function calls overwrite the XML setting. - -```xml - -true -``` ## Additional Options -### [All] `setThemeDark(boolean themeDark)` - -The dialogs have a dark theme that can be set by calling - -```java -dialog.setThemeDark(true); -``` - -### [All] `setAccentColor(String color)` and `setAccentColor(int color)` - -Set the accentColor to be used by the Dialog. The String version parses the color out using `Color.parseColor()`. The -int version requires a ColorInt bytestring. It will explicitly set the color to fully opaque. - -### [All] `setOkColor()` and `setCancelColor()` - -Set the text color for the OK or Cancel button. Behaves similar to `setAccentColor()` - ### [TimePickerDialog] `setTitle(String title)` Shows a title at the top of the `TimePickerDialog` ### [DatePickerDialog] `setTitle(String title)` -Shows a title at the top of the `DatePickerDialog` instead of the day of the week - -### [All] `setOkText()` and `setCancelText()` - Set a custom text for the dialog Ok and Cancel labels. Can take a resourceId of a String. Works in both the DatePickerDialog and TimePickerDialog @@ -391,66 +344,6 @@ class MyDateRangeLimiter implements DateRangeLimiter { When you provide a custom `DateRangeLimiter` the built-in methods for setting the enabled / disabled dates will no longer work. It will need to be completely handled by your implementation. -### Why do the OK and Cancel buttons have the accent color as a background when combined with the Material Components library - -[Material Components](https://github.com/material-components/material-components-android) replaces all instances -of `Button` with an instance of `MaterialButton` when using one of its regular -themes: https://github.com/material-components/material-components-android/blob/master/docs/getting-started.md#material-components-themes -The default version of `MaterialButton` uses `colorPrimary` as the background color. Because Material Components -replaces the View replacer with their own implementation there is not much I can do to fix this from this library. - -There are a few workarounds: - -* Use one of the bridge themes, which do not replace the View Inflater -* Overwrite the style of the mdtp buttons with one that inherits from Material Components text buttons, as - described [here](https://github.com/wdullaer/MaterialDateTimePicker/issues/523#issuecomment-477349333): - ```xml - @@ -36,7 +36,7 @@ @dimen/material_button_minwidth @dimen/material_button_textpadding_horizontal @dimen/material_button_textpadding_horizontal - @color/button_color + ?colorOnSecondary true \ No newline at end of file diff --git a/sample/src/main/res/values-night/themes.xml b/sample/src/main/res/values-night/themes.xml new file mode 100644 index 0000000..a90615e --- /dev/null +++ b/sample/src/main/res/values-night/themes.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/sample/src/main/res/values/themes.xml b/sample/src/main/res/values/themes.xml index 2db2e32..002a79c 100644 --- a/sample/src/main/res/values/themes.xml +++ b/sample/src/main/res/values/themes.xml @@ -1,5 +1,30 @@ - - \ No newline at end of file