2 using System.Collections.Generic;
3 using System.ComponentModel;
5 using System.Reflection;
6 using System.Threading;
7 using System.Threading.Tasks;
8 using Tizen.NUI.Binding.Internals;
10 namespace Tizen.NUI.Binding
12 internal static class Device
14 public const string iOS = "iOS";
15 public const string Android = "Android";
16 public const string UWP = "UWP";
17 public const string macOS = "macOS";
18 public const string GTK = "GTK";
19 public const string Tizen = "Tizen";
20 public const string WPF = "WPF";
22 [EditorBrowsable(EditorBrowsableState.Never)]
23 public static DeviceInfo info;
25 static IPlatformServices s_platformServices;
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public static void SetIdiom(TargetIdiom value) => Idiom = value;
29 public static TargetIdiom Idiom { get; internal set; }
31 //TODO: Why are there two of these? This is never used...?
32 [EditorBrowsable(EditorBrowsableState.Never)]
33 public static void SetTargetIdiom(TargetIdiom value) => Idiom = value;
35 [Obsolete("TargetPlatform is obsolete as of version 2.3.4. Please use RuntimePlatform instead.")]
36 #pragma warning disable 0618
37 public static TargetPlatform OS
41 TargetPlatform platform;
42 if (Enum.TryParse(RuntimePlatform, out platform))
45 // In the old TargetPlatform, there was no distinction between WinRT/UWP
46 if (RuntimePlatform == UWP)
48 return TargetPlatform.Windows;
51 return TargetPlatform.Other;
54 #pragma warning restore 0618
56 public static string RuntimePlatform => PlatformServices?.RuntimePlatform;
58 [EditorBrowsable(EditorBrowsableState.Never)]
59 public static DeviceInfo Info
64 // throw new InvalidOperationException("You MUST call Xamarin.Forms.Init(); prior to using it.");
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 public static void SetFlowDirection(FlowDirection value) => FlowDirection = value;
72 public static FlowDirection FlowDirection { get; internal set; }
74 [EditorBrowsable(EditorBrowsableState.Never)]
75 public static bool IsInvokeRequired
77 get { return PlatformServices.IsInvokeRequired; }
80 [EditorBrowsable(EditorBrowsableState.Never)]
81 public static IPlatformServices PlatformServices
85 if (s_platformServices == null)
86 throw new InvalidOperationException("You MUST call Tizen.NUI.Init(); prior to using it.");
87 return s_platformServices;
91 s_platformServices = value;
92 Console.WriteLine("Device s_platformServices : " + s_platformServices );
96 [EditorBrowsable(EditorBrowsableState.Never)]
97 public static IReadOnlyList<string> Flags { get; private set; }
99 [EditorBrowsable(EditorBrowsableState.Never)]
100 public static void SetFlags(IReadOnlyList<string> flags)
105 public static void BeginInvokeOnMainThread(Action action)
107 PlatformServices?.BeginInvokeOnMainThread(action);
109 Console.WriteLine("Device BeginInvokeOnMainThread action called");
112 // public static double GetNamedSize(NamedSize size, Element targetElement)
114 // return GetNamedSize(size, targetElement.GetType());
117 // public static double GetNamedSize(NamedSize size, Type targetElementType)
119 // return GetNamedSize(size, targetElementType, false);
122 [Obsolete("OnPlatform is obsolete as of version 2.3.4. Please use switch(RuntimePlatform) instead.")]
123 public static void OnPlatform(Action iOS = null, Action Android = null, Action WinPhone = null, Action Default = null)
127 case TargetPlatform.iOS:
130 else if (Default != null)
133 case TargetPlatform.Android:
136 else if (Default != null)
139 case TargetPlatform.Windows:
140 case TargetPlatform.WinPhone:
141 if (WinPhone != null)
143 else if (Default != null)
146 case TargetPlatform.Other:
153 [Obsolete("OnPlatform<> (generic) is obsolete as of version 2.3.4. Please use switch(RuntimePlatform) instead.")]
154 public static T OnPlatform<T>(T iOS, T Android, T WinPhone)
158 case TargetPlatform.iOS:
160 case TargetPlatform.Android:
162 case TargetPlatform.Windows:
163 case TargetPlatform.WinPhone:
170 public static void OpenUri(Uri uri)
172 // PlatformServices?.OpenUriAction(uri);
175 public static void StartTimer(TimeSpan interval, Func<bool> callback)
177 PlatformServices.StartTimer(interval, callback);
180 [EditorBrowsable(EditorBrowsableState.Never)]
181 public static Assembly[] GetAssemblies()
183 return PlatformServices?.GetAssemblies();
186 // [EditorBrowsable(EditorBrowsableState.Never)]
187 // public static double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSizes)
189 // return PlatformServices.GetNamedSize(size, targetElementType, useOldSizes);
192 internal static Task<Stream> GetStreamAsync(Uri uri, CancellationToken cancellationToken)
194 return PlatformServices?.GetStreamAsync(uri, cancellationToken);
197 public static class Styles
199 public static readonly string TitleStyleKey = "TitleStyle";
201 public static readonly string SubtitleStyleKey = "SubtitleStyle";
203 public static readonly string BodyStyleKey = "BodyStyle";
205 public static readonly string ListItemTextStyleKey = "ListItemTextStyle";
207 public static readonly string ListItemDetailTextStyleKey = "ListItemDetailTextStyle";
209 public static readonly string CaptionStyleKey = "CaptionStyle";
211 public static readonly Style TitleStyle = new Style(typeof(Tizen.NUI.BaseComponents.TextLabel)) { BaseResourceKey = TitleStyleKey };
213 public static readonly Style SubtitleStyle = new Style(typeof(Tizen.NUI.BaseComponents.TextLabel)) { BaseResourceKey = SubtitleStyleKey };
215 public static readonly Style BodyStyle = new Style(typeof(Tizen.NUI.BaseComponents.TextLabel)) { BaseResourceKey = BodyStyleKey };
217 public static readonly Style ListItemTextStyle = new Style(typeof(Tizen.NUI.BaseComponents.TextLabel)) { BaseResourceKey = ListItemTextStyleKey };
219 public static readonly Style ListItemDetailTextStyle = new Style(typeof(Tizen.NUI.BaseComponents.TextLabel)) { BaseResourceKey = ListItemDetailTextStyleKey };
221 public static readonly Style CaptionStyle = new Style(typeof(Tizen.NUI.BaseComponents.TextLabel)) { BaseResourceKey = CaptionStyleKey };