From f853e0806ccb411f3f1f497b6df2c2f7bdb0bfe8 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Thu, 28 Jul 2016 13:00:38 -0500 Subject: [PATCH] Use framework date and time pickers on Android 5+ --- .../tasks/activities/DateAndTimePickerActivity.java | 4 ++-- .../org/tasks/activities/DatePickerActivity.java | 4 ++-- .../org/tasks/activities/TimePickerActivity.java | 4 ++-- src/main/java/org/tasks/dialogs/DialogBuilder.java | 2 +- .../org/tasks/dialogs/NativeDatePickerDialog.java | 1 + .../org/tasks/dialogs/NativeTimePickerDialog.java | 6 ++++++ src/main/java/org/tasks/themes/Theme.java | 2 +- src/main/java/org/tasks/themes/ThemeBase.java | 4 ++-- src/main/res/values/attrs.xml | 1 + src/main/res/values/theme.xml | 12 +++++++++++- src/main/res/values/theme_amber.xml | 1 + src/main/res/values/theme_blue.xml | 1 + src/main/res/values/theme_blue_grey.xml | 1 + src/main/res/values/theme_cyan.xml | 1 + src/main/res/values/theme_deep_orange.xml | 1 + src/main/res/values/theme_deep_purple.xml | 1 + src/main/res/values/theme_green.xml | 1 + src/main/res/values/theme_indigo.xml | 1 + src/main/res/values/theme_light_blue.xml | 1 + src/main/res/values/theme_light_green.xml | 1 + src/main/res/values/theme_lime.xml | 1 + src/main/res/values/theme_orange.xml | 1 + src/main/res/values/theme_pink.xml | 1 + src/main/res/values/theme_purple.xml | 1 + src/main/res/values/theme_red.xml | 1 + src/main/res/values/theme_teal.xml | 1 + src/main/res/values/theme_yellow.xml | 1 + 27 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/tasks/activities/DateAndTimePickerActivity.java b/src/main/java/org/tasks/activities/DateAndTimePickerActivity.java index 5bcf60083..1b03355e0 100644 --- a/src/main/java/org/tasks/activities/DateAndTimePickerActivity.java +++ b/src/main/java/org/tasks/activities/DateAndTimePickerActivity.java @@ -17,7 +17,7 @@ import org.tasks.time.DateTime; import javax.inject.Inject; -import static com.todoroo.andlib.utility.AndroidUtilities.atLeastMarshmallow; +import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop; import static org.tasks.dialogs.NativeDatePickerDialog.newNativeDatePickerDialog; import static org.tasks.time.DateTimeUtils.currentTimeMillis; @@ -48,7 +48,7 @@ public class DateAndTimePickerActivity extends InjectingAppCompatActivity implem } FragmentManager fragmentManager = getFragmentManager(); - if (atLeastMarshmallow()) { + if (atLeastLollipop()) { if (fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER) == null) { newNativeDatePickerDialog(initial) .show(fragmentManager, FRAG_TAG_DATE_PICKER); diff --git a/src/main/java/org/tasks/activities/DatePickerActivity.java b/src/main/java/org/tasks/activities/DatePickerActivity.java index cd8733419..fab810f84 100644 --- a/src/main/java/org/tasks/activities/DatePickerActivity.java +++ b/src/main/java/org/tasks/activities/DatePickerActivity.java @@ -17,7 +17,7 @@ import org.tasks.time.DateTime; import javax.inject.Inject; -import static com.todoroo.andlib.utility.AndroidUtilities.atLeastMarshmallow; +import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop; import static org.tasks.dialogs.NativeDatePickerDialog.newNativeDatePickerDialog; import static org.tasks.time.DateTimeUtils.currentTimeMillis; @@ -38,7 +38,7 @@ public class DatePickerActivity extends InjectingAppCompatActivity implements Da DateTime initial = (timestamp > 0 ? new DateTime(timestamp) : new DateTime()).startOfDay(); FragmentManager fragmentManager = getFragmentManager(); - if (atLeastMarshmallow()) { + if (atLeastLollipop()) { if (fragmentManager.findFragmentByTag(FRAG_TAG_DATE_PICKER) == null) { newNativeDatePickerDialog(initial) .show(fragmentManager, FRAG_TAG_DATE_PICKER); diff --git a/src/main/java/org/tasks/activities/TimePickerActivity.java b/src/main/java/org/tasks/activities/TimePickerActivity.java index 76dd28544..9ee52f3fb 100644 --- a/src/main/java/org/tasks/activities/TimePickerActivity.java +++ b/src/main/java/org/tasks/activities/TimePickerActivity.java @@ -19,7 +19,7 @@ import org.tasks.time.DateTime; import javax.inject.Inject; -import static com.todoroo.andlib.utility.AndroidUtilities.atLeastMarshmallow; +import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop; import static org.tasks.dialogs.NativeTimePickerDialog.newNativeTimePickerDialog; import static org.tasks.time.DateTimeUtils.currentTimeMillis; @@ -42,7 +42,7 @@ public class TimePickerActivity extends InjectingAppCompatActivity implements Ti initial = new DateTime(getIntent().getLongExtra(EXTRA_TIMESTAMP, currentTimeMillis())); FragmentManager fragmentManager = getFragmentManager(); - if (atLeastMarshmallow()) { + if (atLeastLollipop()) { if (fragmentManager.findFragmentByTag(FRAG_TAG_TIME_PICKER) == null) { newNativeTimePickerDialog(initial) .show(fragmentManager, FRAG_TAG_TIME_PICKER); diff --git a/src/main/java/org/tasks/dialogs/DialogBuilder.java b/src/main/java/org/tasks/dialogs/DialogBuilder.java index ab53e49cb..9aa27d71b 100644 --- a/src/main/java/org/tasks/dialogs/DialogBuilder.java +++ b/src/main/java/org/tasks/dialogs/DialogBuilder.java @@ -37,7 +37,7 @@ public class DialogBuilder { } public ProgressDialog newProgressDialog() { - ProgressDialog progressDialog = new ProgressDialog(activity, theme.getThemeBase().getDialogStyle()); + ProgressDialog progressDialog = new ProgressDialog(activity, theme.getThemeBase().getAlertDialogStyle()); theme.applyToContext(progressDialog.getContext()); if (AndroidUtilities.preLollipop()) { progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.R.color.transparent)); diff --git a/src/main/java/org/tasks/dialogs/NativeDatePickerDialog.java b/src/main/java/org/tasks/dialogs/NativeDatePickerDialog.java index 08d25c959..bccdca4b5 100644 --- a/src/main/java/org/tasks/dialogs/NativeDatePickerDialog.java +++ b/src/main/java/org/tasks/dialogs/NativeDatePickerDialog.java @@ -39,6 +39,7 @@ public class NativeDatePickerDialog extends InjectingNativeDialogFragment implem if (initial != null) { datePickerDialog.updateDate(initial.getYear(), initial.getMonthOfYear() - 1, initial.getDayOfMonth()); } + datePickerDialog.setTitle(null); return datePickerDialog; } diff --git a/src/main/java/org/tasks/dialogs/NativeTimePickerDialog.java b/src/main/java/org/tasks/dialogs/NativeTimePickerDialog.java index 0658194ef..49593d30d 100644 --- a/src/main/java/org/tasks/dialogs/NativeTimePickerDialog.java +++ b/src/main/java/org/tasks/dialogs/NativeTimePickerDialog.java @@ -40,6 +40,12 @@ public class NativeTimePickerDialog extends InjectingNativeDialogFragment implem public Dialog onCreateDialog(Bundle savedInstanceState) { Context context = theme.wrap(getActivity()); TimePickerDialog timePickerDialog = new TimePickerDialog(context, this, 0, 0, DateUtilities.is24HourFormat(context)); + timePickerDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + callback.cancel(); + } + }); if (initial != null) { timePickerDialog.updateTime(initial.getHourOfDay(), initial.getMinuteOfHour()); } diff --git a/src/main/java/org/tasks/themes/Theme.java b/src/main/java/org/tasks/themes/Theme.java index b60cacf35..43f5e45be 100644 --- a/src/main/java/org/tasks/themes/Theme.java +++ b/src/main/java/org/tasks/themes/Theme.java @@ -41,7 +41,7 @@ public class Theme { } public ContextThemeWrapper getThemedDialog(Context context) { - return new ContextThemeWrapper(context, themeBase.getDialogStyle()); + return new ContextThemeWrapper(context, themeBase.getAlertDialogStyle()); } public void applyThemeAndStatusBarColor(Activity activity, AppCompatDelegate delegate) { diff --git a/src/main/java/org/tasks/themes/ThemeBase.java b/src/main/java/org/tasks/themes/ThemeBase.java index fbd432996..0e0dd74d5 100644 --- a/src/main/java/org/tasks/themes/ThemeBase.java +++ b/src/main/java/org/tasks/themes/ThemeBase.java @@ -32,8 +32,8 @@ public class ThemeBase { this.contentBackground = contentBackground; } - public int getDialogStyle() { - return R.style.TasksDialog; + public int getAlertDialogStyle() { + return R.style.TasksDialogAlert; } public String getName() { diff --git a/src/main/res/values/attrs.xml b/src/main/res/values/attrs.xml index 641eb7d4b..53fe24a31 100644 --- a/src/main/res/values/attrs.xml +++ b/src/main/res/values/attrs.xml @@ -17,6 +17,7 @@ + diff --git a/src/main/res/values/theme.xml b/src/main/res/values/theme.xml index a1eade6cc..2fd7a01fa 100644 --- a/src/main/res/values/theme.xml +++ b/src/main/res/values/theme.xml @@ -10,7 +10,9 @@ @color/icon_tint @style/SpinnerNoPadding ?attr/colorPrimary - @style/TasksDialog + @style/TasksDialog + @style/TasksDialog + @style/TasksDialogAlert @dimen/alpha_secondary @dimen/alpha_disabled @color/text_primary @@ -21,8 +23,16 @@ + + diff --git a/src/main/res/values/theme_amber.xml b/src/main/res/values/theme_amber.xml index 99dbd322e..5f8a2cb5d 100644 --- a/src/main/res/values/theme_amber.xml +++ b/src/main/res/values/theme_amber.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_blue.xml b/src/main/res/values/theme_blue.xml index 1c0d79dbf..e0b7d33c7 100644 --- a/src/main/res/values/theme_blue.xml +++ b/src/main/res/values/theme_blue.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_blue_grey.xml b/src/main/res/values/theme_blue_grey.xml index 282e03065..7ae7c80ad 100644 --- a/src/main/res/values/theme_blue_grey.xml +++ b/src/main/res/values/theme_blue_grey.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_cyan.xml b/src/main/res/values/theme_cyan.xml index c15099dc6..99cf8ac19 100644 --- a/src/main/res/values/theme_cyan.xml +++ b/src/main/res/values/theme_cyan.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_deep_orange.xml b/src/main/res/values/theme_deep_orange.xml index cc31de489..89c12e552 100644 --- a/src/main/res/values/theme_deep_orange.xml +++ b/src/main/res/values/theme_deep_orange.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_deep_purple.xml b/src/main/res/values/theme_deep_purple.xml index ef7bc5b5c..0fc1ece09 100644 --- a/src/main/res/values/theme_deep_purple.xml +++ b/src/main/res/values/theme_deep_purple.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_green.xml b/src/main/res/values/theme_green.xml index 0edc7720a..eead67c43 100644 --- a/src/main/res/values/theme_green.xml +++ b/src/main/res/values/theme_green.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_indigo.xml b/src/main/res/values/theme_indigo.xml index 393459011..9d24e23f0 100644 --- a/src/main/res/values/theme_indigo.xml +++ b/src/main/res/values/theme_indigo.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_light_blue.xml b/src/main/res/values/theme_light_blue.xml index 25e8d4b82..e5b4512e9 100644 --- a/src/main/res/values/theme_light_blue.xml +++ b/src/main/res/values/theme_light_blue.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_light_green.xml b/src/main/res/values/theme_light_green.xml index 91ae44484..ebe86c80c 100644 --- a/src/main/res/values/theme_light_green.xml +++ b/src/main/res/values/theme_light_green.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_lime.xml b/src/main/res/values/theme_lime.xml index 4da95ad7a..5b56cc986 100644 --- a/src/main/res/values/theme_lime.xml +++ b/src/main/res/values/theme_lime.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_orange.xml b/src/main/res/values/theme_orange.xml index 8653f328c..f2b0d0ad0 100644 --- a/src/main/res/values/theme_orange.xml +++ b/src/main/res/values/theme_orange.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_pink.xml b/src/main/res/values/theme_pink.xml index 5c66527a7..5bbd29e19 100644 --- a/src/main/res/values/theme_pink.xml +++ b/src/main/res/values/theme_pink.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_purple.xml b/src/main/res/values/theme_purple.xml index bef244246..e60d31229 100644 --- a/src/main/res/values/theme_purple.xml +++ b/src/main/res/values/theme_purple.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_red.xml b/src/main/res/values/theme_red.xml index 93703b7b4..8b6ae0c12 100644 --- a/src/main/res/values/theme_red.xml +++ b/src/main/res/values/theme_red.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_teal.xml b/src/main/res/values/theme_teal.xml index 6b2250e9a..47d1a7d93 100644 --- a/src/main/res/values/theme_teal.xml +++ b/src/main/res/values/theme_teal.xml @@ -8,6 +8,7 @@ \ No newline at end of file diff --git a/src/main/res/values/theme_yellow.xml b/src/main/res/values/theme_yellow.xml index 400dfb8a7..c375c57f4 100644 --- a/src/main/res/values/theme_yellow.xml +++ b/src/main/res/values/theme_yellow.xml @@ -8,6 +8,7 @@ \ No newline at end of file