summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authoradrianknight89 <adrianknight89@outlook.com>2017-01-10 18:07:01 -0600
committerJason Smith <jason.smith@xamarin.com>2017-01-10 16:07:01 -0800
commitf78b328759bb673b695c6b0d1a1dac6d871d257a (patch)
tree53af7ed6bce1b2287ba7addd89f782dd4606d7c6 /Xamarin.Forms.Platform.Android
parentdcea6b4853f76dbc4661c42c56244e0a70d889ed (diff)
downloadxamarin-forms-f78b328759bb673b695c6b0d1a1dac6d871d257a.tar.gz
xamarin-forms-f78b328759bb673b695c6b0d1a1dac6d871d257a.tar.bz2
xamarin-forms-f78b328759bb673b695c6b0d1a1dac6d871d257a.zip
iOS and Android timers should be runnable from any thread and execute… (#374)
* iOS and Android timers should be runnable from any thread and executed on the main thread * removing unused Timer class declarations with minor refactoring efforts * iOS and Android timers should be runnable from any thread and executed on the main thread * removing bak file * switch to v7 * add test code
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/Forms.cs53
1 files changed, 8 insertions, 45 deletions
diff --git a/Xamarin.Forms.Platform.Android/Forms.cs b/Xamarin.Forms.Platform.Android/Forms.cs
index 3d2a735c..1ecf76d3 100644
--- a/Xamarin.Forms.Platform.Android/Forms.cs
+++ b/Xamarin.Forms.Platform.Android/Forms.cs
@@ -410,22 +410,15 @@ namespace Xamarin.Forms
public void StartTimer(TimeSpan interval, Func<bool> callback)
{
- Timer timer = null;
- bool invoking = false;
- TimerCallback onTimeout = o =>
+ var handler = new Handler(Looper.MainLooper);
+ handler.PostDelayed(() =>
{
- if (!invoking)
- {
- invoking = true;
- BeginInvokeOnMainThread(() =>
- {
- if (!callback())
- timer.Dispose();
- invoking = false;
- });
- }
- };
- timer = new Timer(onTimeout, null, interval, interval);
+ if (callback())
+ StartTimer(interval, callback);
+
+ handler.Dispose();
+ handler = null;
+ }, (long)interval.TotalMilliseconds);
}
double ConvertTextAppearanceToSize(int themeDefault, int deviceDefault, double defaultValue)
@@ -472,36 +465,6 @@ namespace Xamarin.Forms
return false;
}
- public class _Timer : ITimer
- {
- readonly Timer _timer;
-
- public _Timer(Timer timer)
- {
- _timer = timer;
- }
-
- public void Change(int dueTime, int period)
- {
- _timer.Change(dueTime, period);
- }
-
- public void Change(long dueTime, long period)
- {
- _timer.Change(dueTime, period);
- }
-
- public void Change(TimeSpan dueTime, TimeSpan period)
- {
- _timer.Change(dueTime, period);
- }
-
- public void Change(uint dueTime, uint period)
- {
- _timer.Change(dueTime, period);
- }
- }
-
public class _IsolatedStorageFile : IIsolatedStorageFile
{
readonly IsolatedStorageFile _isolatedStorageFile;