summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul DiPietro <pauldipietro@users.noreply.github.com>2016-07-12 14:59:32 (GMT)
committerRui Marinho <me@ruimarinho.net>2016-07-13 09:45:35 (GMT)
commit7e65138fbacde0de1e5e8768a6c26783d6636f2c (patch)
treef215a2a96c5d9e736699f2b10ff8ec0ed07a5823
parent3d431add50038f8f68f421872625831d42e2aaf9 (diff)
downloadxamarin-forms-7e65138fbacde0de1e5e8768a6c26783d6636f2c.zip
xamarin-forms-7e65138fbacde0de1e5e8768a6c26783d6636f2c.tar.gz
xamarin-forms-7e65138fbacde0de1e5e8768a6c26783d6636f2c.tar.bz2
[Android] TimePicker unfocuses on cancel (#238)
Related to the prior fix of the DatePicker not unfocusing on the cancel button being pressed, the TimePicker was not unfocusing, as well. A similar fix has been applied.
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla42074.cs61
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs17
3 files changed, 79 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla42074.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla42074.cs
new file mode 100644
index 0000000..04bcdf8
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla42074.cs
@@ -0,0 +1,61 @@
+´╗┐using System;
+
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Bugzilla, 42074, "[Android] Clicking cancel on a TimePicker does not cause it to unfocus", PlatformAffected.Android)]
+ public class Bugzilla42074 : TestContentPage
+ {
+ const string TimePicker = "TimePicker";
+
+ protected override void Init()
+ {
+ var timePicker = new TimePicker
+ {
+ AutomationId = TimePicker
+ };
+ var timePickerFocusButton = new Button
+ {
+ Text = "Click to focus TimePicker",
+ Command = new Command(() => timePicker.Focus())
+ };
+ Content = new StackLayout
+ {
+ Children =
+ {
+ timePicker,
+ timePickerFocusButton
+ }
+ };
+ }
+
+#if UITEST
+
+#if __ANDROID__
+ [Test]
+ public void TimePickerCancelShouldUnfocus()
+ {
+ RunningApp.Tap(q => q.Marked(TimePicker));
+ RunningApp.WaitForElement(q => q.Marked("Cancel"));
+
+ RunningApp.Tap(q => q.Marked("Cancel"));
+ RunningApp.WaitForElement(q => q.Marked("Click to focus TimePicker"));
+
+ RunningApp.Tap(q => q.Marked("Click to focus TimePicker"));
+ RunningApp.WaitForElement(q => q.Marked("Cancel"));
+
+ RunningApp.Tap(q => q.Marked("Cancel"));
+ }
+#endif
+
+#endif
+ }
+}
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index 10e0800..7a7db40 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -108,6 +108,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41078.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla40998.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla41424.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla42074.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla34727.cs" />
diff --git a/Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs
index 4cb5d2d..2b33acc 100644
--- a/Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs
@@ -27,6 +27,10 @@ namespace Xamarin.Forms.Platform.Android
ElementController.SetValueFromRenderer(TimePicker.TimeProperty, new TimeSpan(hourOfDay, minute, 0));
Control.ClearFocus();
+
+ if (Forms.IsLollipopOrNewer)
+ _dialog.CancelEvent -= OnCancelButtonClicked;
+
_dialog = null;
}
@@ -70,6 +74,10 @@ namespace Xamarin.Forms.Platform.Android
_dialog.Hide();
ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false);
Control.ClearFocus();
+
+ if (Forms.IsLollipopOrNewer)
+ _dialog.CancelEvent -= OnCancelButtonClicked;
+
_dialog = null;
}
}
@@ -80,9 +88,18 @@ namespace Xamarin.Forms.Platform.Android
ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, true);
_dialog = new TimePickerDialog(Context, this, view.Time.Hours, view.Time.Minutes, false);
+
+ if (Forms.IsLollipopOrNewer)
+ _dialog.CancelEvent += OnCancelButtonClicked;
+
_dialog.Show();
}
+ void OnCancelButtonClicked(object sender, EventArgs e)
+ {
+ Element.Unfocus();
+ }
+
void SetTime(TimeSpan time)
{
Control.Text = DateTime.Today.Add(time).ToString(Element.Format);