summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorPaul DiPietro <pauldipietro@users.noreply.github.com>2017-08-29 10:32:50 (GMT)
committerKangho Hur <kangho.hur@samsung.com>2017-10-23 04:29:51 (GMT)
commite8a3d4b84139853dc57670a519a7683a23dcc8b3 (patch)
tree5785d894f07e16eacd46b36619f2eb8baf72e45f /Xamarin.Forms.Platform.Android
parent784ba3d725fd747f884bd464150b606a89a9551e (diff)
downloadxamarin-forms-e8a3d4b84139853dc57670a519a7683a23dcc8b3.zip
xamarin-forms-e8a3d4b84139853dc57670a519a7683a23dcc8b3.tar.gz
xamarin-forms-e8a3d4b84139853dc57670a519a7683a23dcc8b3.tar.bz2
[Android] Use 24-hour time format on TimePicker text if enabled (#1082)
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs13
1 files changed, 8 insertions, 5 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs
index 453fdf4..6ded75d 100644
--- a/Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs
@@ -14,6 +14,8 @@ namespace Xamarin.Forms.Platform.Android
{
AlertDialog _dialog;
TextColorSwitcher _textColorSwitcher;
+ bool _is24HourFormat;
+ string _timeFormat;
public TimePickerRenderer()
{
@@ -50,7 +52,9 @@ namespace Xamarin.Forms.Platform.Android
textField.SetOnClickListener(TimePickerListener.Instance);
SetNativeControl(textField);
- _textColorSwitcher = new TextColorSwitcher(textField.TextColors);
+ _textColorSwitcher = new TextColorSwitcher(textField.TextColors);
+ _is24HourFormat = DateFormat.Is24HourFormat(Context);
+ _timeFormat = _is24HourFormat ? "HH:mm" : Element.Format;
}
SetTime(e.NewElement.Time);
@@ -92,9 +96,8 @@ namespace Xamarin.Forms.Platform.Android
{
TimePicker view = Element;
ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, true);
-
- bool is24HourFormat = DateFormat.Is24HourFormat(Context);
- _dialog = new TimePickerDialog(Context, this, view.Time.Hours, view.Time.Minutes, is24HourFormat);
+
+ _dialog = new TimePickerDialog(Context, this, view.Time.Hours, view.Time.Minutes, _is24HourFormat);
if (Forms.IsLollipopOrNewer)
_dialog.CancelEvent += OnCancelButtonClicked;
@@ -109,7 +112,7 @@ namespace Xamarin.Forms.Platform.Android
void SetTime(TimeSpan time)
{
- Control.Text = DateTime.Today.Add(time).ToString(Element.Format);
+ Control.Text = DateTime.Today.Add(time).ToString(_timeFormat);
}
void UpdateTextColor()