Use framework date and time pickers on Android 5+

pull/437/head
Alex Baker 8 years ago
parent 0329ba2fc4
commit f853e0806c

@ -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);

@ -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);

@ -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);

@ -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));

@ -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;
}

@ -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());
}

@ -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) {

@ -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() {

@ -17,6 +17,7 @@
<attr name="alpha_secondary" format="dimension" />
<attr name="alpha_disabled" format="dimension" />
<attr name="fab_text" format="color" />
<attr name="colorAccentDialog" format="color" />
<declare-styleable name="TimePreference">
<attr name="summary" format="string" />

@ -10,7 +10,9 @@
<item name="icon_tint">@color/icon_tint</item>
<item name="android:spinnerItemStyle">@style/SpinnerNoPadding</item>
<item name="android:actionModeBackground">?attr/colorPrimary</item>
<item name="alertDialogTheme">@style/TasksDialog</item>
<item name="dialogTheme">@style/TasksDialog</item>
<item name="android:dialogTheme">@style/TasksDialog</item>
<item name="alertDialogTheme">@style/TasksDialogAlert</item>
<item name="alpha_secondary">@dimen/alpha_secondary</item>
<item name="alpha_disabled">@dimen/alpha_disabled</item>
<item name="android:textColorPrimary">@color/text_primary</item>
@ -21,8 +23,16 @@
<style name="TasksOverride" parent="Tasks">
</style>
<style name="TasksDialogAlert" parent="@style/Theme.AppCompat.DayNight.Dialog.Alert">
<item name="android:windowBackground">@color/background_color_dialog</item>
<item name="colorAccent">?attr/colorAccentDialog</item>
<item name="asTextColor">@color/text_primary</item>
<item name="icon_tint">@color/icon_tint</item>
</style>
<style name="TasksDialog" parent="@style/Theme.AppCompat.DayNight.Dialog">
<item name="android:windowBackground">@color/background_color_dialog</item>
<item name="colorAccent">?attr/colorAccentDialog</item>
<item name="asTextColor">@color/text_primary</item>
<item name="icon_tint">@color/icon_tint</item>
</style>

@ -8,6 +8,7 @@
<style name="AmberAccent" parent="BlackTint">
<item name="colorAccent">@color/amber_a400</item>
<item name="colorAccentDialog">@color/amber_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="BlueAccent" parent="WhiteTint">
<item name="colorAccent">@color/blue_a400</item>
<item name="colorAccentDialog">@color/blue_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="BlueGreyAccent" parent="WhiteTint">
<item name="colorAccent">@color/blue_grey_400</item>
<item name="colorAccentDialog">@color/blue_grey_400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="CyanAccent" parent="BlackTint">
<item name="colorAccent">@color/cyan_a400</item>
<item name="colorAccentDialog">@color/cyan_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="DeepOrangeAccent" parent="WhiteTint">
<item name="colorAccent">@color/deep_orange_a400</item>
<item name="colorAccentDialog">@color/deep_orange_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="DeepPurpleAccent" parent="WhiteTint">
<item name="colorAccent">@color/deep_purple_a400</item>
<item name="colorAccentDialog">@color/deep_purple_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="GreenAccent" parent="BlackTint">
<item name="colorAccent">@color/green_a400</item>
<item name="colorAccentDialog">@color/green_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="IndigoAccent" parent="WhiteTint">
<item name="colorAccent">@color/indigo_a400</item>
<item name="colorAccentDialog">@color/indigo_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="LightBlueAccent" parent="BlackTint">
<item name="colorAccent">@color/light_blue_a400</item>
<item name="colorAccentDialog">@color/light_blue_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="LightGreenAccent" parent="BlackTint">
<item name="colorAccent">@color/light_green_a400</item>
<item name="colorAccentDialog">@color/light_green_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="LimeAccent" parent="BlackTint">
<item name="colorAccent">@color/lime_a400</item>
<item name="colorAccentDialog">@color/lime_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="OrangeAccent" parent="BlackTint">
<item name="colorAccent">@color/orange_a400</item>
<item name="colorAccentDialog">@color/orange_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="PinkAccent" parent="WhiteTint">
<item name="colorAccent">@color/pink_a400</item>
<item name="colorAccentDialog">@color/pink_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="PurpleAccent" parent="WhiteTint">
<item name="colorAccent">@color/purple_a400</item>
<item name="colorAccentDialog">@color/purple_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="RedAccent" parent="WhiteTint">
<item name="colorAccent">@color/red_a400</item>
<item name="colorAccentDialog">@color/red_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="TealAccent" parent="BlackTint">
<item name="colorAccent">@color/teal_a400</item>
<item name="colorAccentDialog">@color/teal_a400</item>
</style>
</resources>

@ -8,6 +8,7 @@
<style name="YellowAccent" parent="BlackTint">
<item name="colorAccent">@color/yellow_a400</item>
<item name="colorAccentDialog">@color/yellow_a400</item>
</style>
</resources>
Loading…
Cancel
Save