summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2016-04-25 13:57:44 -0600
committerRui Marinho <me@ruimarinho.net>2016-04-25 15:57:44 -0400
commit843bc4727a40d6ca67127326facf2333f461da2d (patch)
tree5467ab3850df7f2368baa1290e983adba27f35d9 /Xamarin.Forms.Core
parent07df05ced2b43446c84d47f4b7a8325abcd0f767 (diff)
downloadxamarin-forms-843bc4727a40d6ca67127326facf2333f461da2d.tar.gz
xamarin-forms-843bc4727a40d6ca67127326facf2333f461da2d.tar.bz2
xamarin-forms-843bc4727a40d6ca67127326facf2333f461da2d.zip
Make core Ticker abstract and public (#116)
* Make core Ticker abstract and public Make the core Ticker abstract and public so it can be inherited by platform implementations; remove now-unused parts of original Ticker; add CreateTicker to IPlatformServices; remove unused CreateTimer methods from IPlatformServices * Add docs for Ticker * Remove unnecessary Ticker.Default set * Move Ticker into Internals * Update Ticker docs * Remove old Ticker docs * Remove commented code
Diffstat (limited to 'Xamarin.Forms.Core')
-rw-r--r--Xamarin.Forms.Core/AnimationExtensions.cs1
-rw-r--r--Xamarin.Forms.Core/IPlatformServices.cs8
-rw-r--r--Xamarin.Forms.Core/Internals/Ticker.cs (renamed from Xamarin.Forms.Core/Ticker.cs)33
-rw-r--r--Xamarin.Forms.Core/Tweener.cs1
-rw-r--r--Xamarin.Forms.Core/Xamarin.Forms.Core.csproj2
5 files changed, 11 insertions, 34 deletions
diff --git a/Xamarin.Forms.Core/AnimationExtensions.cs b/Xamarin.Forms.Core/AnimationExtensions.cs
index 957d002e..2256cb73 100644
--- a/Xamarin.Forms.Core/AnimationExtensions.cs
+++ b/Xamarin.Forms.Core/AnimationExtensions.cs
@@ -26,6 +26,7 @@
using System;
using System.Collections.Generic;
+using Xamarin.Forms.Internals;
namespace Xamarin.Forms
{
diff --git a/Xamarin.Forms.Core/IPlatformServices.cs b/Xamarin.Forms.Core/IPlatformServices.cs
index e4a3ce0b..a01baa02 100644
--- a/Xamarin.Forms.Core/IPlatformServices.cs
+++ b/Xamarin.Forms.Core/IPlatformServices.cs
@@ -3,6 +3,7 @@ using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
+using Xamarin.Forms.Internals;
namespace Xamarin.Forms
{
@@ -12,12 +13,7 @@ namespace Xamarin.Forms
void BeginInvokeOnMainThread(Action action);
- //this will go once Timer is included in Pcl profiles
- ITimer CreateTimer(Action<object> callback);
- ITimer CreateTimer(Action<object> callback, object state, int dueTime, int period);
- ITimer CreateTimer(Action<object> callback, object state, long dueTime, long period);
- ITimer CreateTimer(Action<object> callback, object state, TimeSpan dueTime, TimeSpan period);
- ITimer CreateTimer(Action<object> callback, object state, uint dueTime, uint period);
+ Ticker CreateTicker();
Assembly[] GetAssemblies();
diff --git a/Xamarin.Forms.Core/Ticker.cs b/Xamarin.Forms.Core/Internals/Ticker.cs
index ed828f8a..7fe60cc0 100644
--- a/Xamarin.Forms.Core/Ticker.cs
+++ b/Xamarin.Forms.Core/Internals/Ticker.cs
@@ -2,26 +2,21 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
-using System.Threading;
-namespace Xamarin.Forms
+namespace Xamarin.Forms.Internals
{
- internal class Ticker
+ public abstract class Ticker
{
static Ticker s_ticker;
readonly Stopwatch _stopwatch;
- readonly SynchronizationContext _sync;
readonly List<Tuple<int, Func<long, bool>>> _timeouts;
- readonly ITimer _timer;
int _count;
bool _enabled;
internal Ticker()
{
- _sync = SynchronizationContext.Current;
_count = 0;
- _timer = Device.PlatformServices.CreateTimer(HandleElapsed, null, Timeout.Infinite, Timeout.Infinite);
_timeouts = new List<Tuple<int, Func<long, bool>>>();
_stopwatch = new Stopwatch();
@@ -30,7 +25,7 @@ namespace Xamarin.Forms
public static Ticker Default
{
internal set { s_ticker = value; }
- get { return s_ticker ?? (s_ticker = new Ticker()); }
+ get { return s_ticker ?? (s_ticker = Device.PlatformServices.CreateTicker()); }
}
public virtual int Insert(Func<long, bool> timeout)
@@ -61,16 +56,10 @@ namespace Xamarin.Forms
});
}
- protected virtual void DisableTimer()
- {
- _timer.Change(Timeout.Infinite, Timeout.Infinite);
- }
-
- protected virtual void EnableTimer()
- {
- _timer.Change(16, 16);
- }
+ protected abstract void DisableTimer();
+ protected abstract void EnableTimer();
+
protected void SendSignals(int timestep = -1)
{
long step = timestep >= 0 ? timestep : _stopwatch.ElapsedMilliseconds;
@@ -103,15 +92,5 @@ namespace Xamarin.Forms
_stopwatch.Start();
EnableTimer();
}
-
- void HandleElapsed(object state)
- {
- if (_timeouts.Count > 0)
- {
- _sync.Post(o => SendSignals(), null);
- _stopwatch.Reset();
- _stopwatch.Start();
- }
- }
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Core/Tweener.cs b/Xamarin.Forms.Core/Tweener.cs
index 73ed7853..b90e7a8a 100644
--- a/Xamarin.Forms.Core/Tweener.cs
+++ b/Xamarin.Forms.Core/Tweener.cs
@@ -25,6 +25,7 @@
// THE SOFTWARE.
using System;
+using Xamarin.Forms.Internals;
namespace Xamarin.Forms
{
diff --git a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
index b1925578..c9f7a5bc 100644
--- a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
+++ b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
@@ -232,7 +232,7 @@
<Compile Include="TextChangedEventArgs.cs" />
<Compile Include="TextKeyboard.cs" />
<Compile Include="ThicknessTypeConverter.cs" />
- <Compile Include="Ticker.cs" />
+ <Compile Include="Internals\Ticker.cs" />
<Compile Include="ToggledEventArgs.cs" />
<Compile Include="ToolbarItemEventArgs.cs" />
<Compile Include="ToolbarItemOrder.cs" />