This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathTizenPlatformServices.cs
191 lines (166 loc) · 4.89 KB
/
TizenPlatformServices.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
using ElmSharp;
using Xamarin.Forms.Internals;
using TAppControl = Tizen.Applications.AppControl;
namespace Xamarin.Forms.Platform.Tizen
{
internal class TizenPlatformServices : IPlatformServices
{
static SynchronizationContext s_context;
public TizenPlatformServices()
{
s_context = SynchronizationContext.Current;
}
public class TizenTicker : Ticker
{
readonly Timer _timer;
public TizenTicker()
{
_timer = new Timer((object o) => HandleElapsed(o), this, Timeout.Infinite, Timeout.Infinite);
}
protected override void EnableTimer()
{
_timer.Change(16, 16);
}
protected override void DisableTimer()
{
_timer.Change(-1, -1);
}
void HandleElapsed(object state)
{
s_context.Post((o) => SendSignals(-1), null);
}
}
#region IPlatformServices implementation
public double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSizes)
{
int pt;
// Actual font size depends on the target idiom.
switch (size)
{
case NamedSize.Micro:
pt = Device.Idiom == TargetIdiom.TV || Device.Idiom == TargetIdiom.Watch ? 24 : 19;
break;
case NamedSize.Small:
pt = Device.Idiom == TargetIdiom.TV ? 26 : (Device.Idiom == TargetIdiom.Watch ? 30 : 22);
break;
case NamedSize.Default:
case NamedSize.Medium:
pt = Device.Idiom == TargetIdiom.TV ? 28 : (Device.Idiom == TargetIdiom.Watch ? 32 : 25);
break;
case NamedSize.Large:
pt = Device.Idiom == TargetIdiom.TV ? 32 : (Device.Idiom == TargetIdiom.Watch ? 36 : 31);
break;
case NamedSize.Body:
pt = Device.Idiom == TargetIdiom.TV ? 30 : (Device.Idiom == TargetIdiom.Watch ? 32 : 28);
break;
case NamedSize.Caption:
pt = Device.Idiom == TargetIdiom.TV ? 26 : (Device.Idiom == TargetIdiom.Watch ? 24 : 22);
break;
case NamedSize.Header:
pt = Device.Idiom == TargetIdiom.TV ? 84 : (Device.Idiom == TargetIdiom.Watch ? 36 : 138);
break;
case NamedSize.Subtitle:
pt = Device.Idiom == TargetIdiom.TV ? 30 : (Device.Idiom == TargetIdiom.Watch ? 30 : 28);
break;
case NamedSize.Title:
pt = Device.Idiom == TargetIdiom.TV ? 42 : (Device.Idiom == TargetIdiom.Watch ? 36 : 40);
break;
default:
throw new ArgumentOutOfRangeException(nameof(size));
}
return Forms.ConvertToDPFont(pt);
}
public Color GetNamedColor(string name)
{
// Not supported on this platform
return Color.Default;
}
public void OpenUriAction(Uri uri)
{
if (uri == null || uri.AbsoluteUri == null)
{
throw new ArgumentNullException(nameof(uri));
}
TAppControl tAppControl = new TAppControl() { Operation = "%", Uri = uri.AbsoluteUri };
var matchedApplications = TAppControl.GetMatchedApplicationIds(tAppControl);
if (matchedApplications.Any())
{
TAppControl.SendLaunchRequest(tAppControl);
return;
}
throw new PlatformNotSupportedException();
}
public void BeginInvokeOnMainThread(Action action)
{
s_context.Post((o) => action(), null);
}
public Ticker CreateTicker()
{
return new TizenTicker();
}
public void StartTimer(TimeSpan interval, Func<bool> callback)
{
Timer timer = null;
bool invoking = false;
TimerCallback onTimeout = o =>
{
if (!invoking)
{
invoking = true;
BeginInvokeOnMainThread(() =>
{
if (!callback())
{
timer.Dispose();
}
invoking = false;
}
);
}
};
timer = new Timer(onTimeout, null, Timeout.Infinite, Timeout.Infinite);
// set interval separarately to prevent calling onTimeout before `timer' is assigned
timer.Change(interval, interval);
}
public async Task<Stream> GetStreamAsync(Uri uri, CancellationToken cancellationToken)
{
using (var client = new HttpClient())
using (HttpResponseMessage response = await client.GetAsync(uri, cancellationToken))
return await response.Content.ReadAsStreamAsync();
}
public Assembly[] GetAssemblies()
{
return AppDomain.CurrentDomain.GetAssemblies();
}
public IIsolatedStorageFile GetUserStoreForApplication()
{
return new TizenIsolatedStorageFile();
}
public string GetHash(string input) => Crc64.GetHash(input);
string IPlatformServices.GetMD5Hash(string input) => GetHash(input);
public void QuitApplication()
{
Forms.Context.Exit();
}
public bool IsInvokeRequired => !EcoreMainloop.IsMainThread;
public string RuntimePlatform => Device.Tizen;
#endregion
public SizeRequest GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint)
{
return Platform.GetNativeSize(view, widthConstraint, heightConstraint);
}
public OSAppTheme RequestedTheme => OSAppTheme.Unspecified;
static MD5 CreateChecksum()
{
return MD5.Create();
}
}
}