2 * Copyright(c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using System.ComponentModel;
21 using System.Reflection;
22 using System.Threading;
23 using System.Threading.Tasks;
24 using Tizen.NUI.Binding.Internals;
26 namespace Tizen.NUI.Binding
28 internal static class Device
30 public const string iOS = "iOS";
31 public const string Android = "Android";
32 public const string UWP = "UWP";
33 public const string macOS = "macOS";
34 public const string GTK = "GTK";
35 public const string Tizen = "Tizen";
36 public const string WPF = "WPF";
38 [EditorBrowsable(EditorBrowsableState.Never)]
39 public static DeviceInfo info;
41 static IPlatformServices s_platformServices;
43 [EditorBrowsable(EditorBrowsableState.Never)]
44 public static void SetIdiom(TargetIdiom value) => Idiom = value;
45 public static TargetIdiom Idiom { get; internal set; }
47 //TODO: Why are there two of these? This is never used...?
48 [EditorBrowsable(EditorBrowsableState.Never)]
49 public static void SetTargetIdiom(TargetIdiom value) => Idiom = value;
51 [Obsolete("TargetPlatform is obsolete as of version 2.3.4. Please use RuntimePlatform instead.")]
52 #pragma warning disable 0618
53 public static TargetPlatform OS
57 TargetPlatform platform;
58 if (Enum.TryParse(RuntimePlatform, out platform))
61 // In the old TargetPlatform, there was no distinction between WinRT/UWP
62 if (RuntimePlatform == UWP)
64 return TargetPlatform.Windows;
67 return TargetPlatform.Other;
70 #pragma warning restore 0618
72 public static string RuntimePlatform => PlatformServices?.RuntimePlatform;
74 [EditorBrowsable(EditorBrowsableState.Never)]
75 public static DeviceInfo Info
80 // throw new InvalidOperationException("You MUST call Tizen.NUI.Xaml.Init(); prior to using it.");
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public static void SetFlowDirection(FlowDirection value) => FlowDirection = value;
88 public static FlowDirection FlowDirection { get; internal set; }
90 [EditorBrowsable(EditorBrowsableState.Never)]
91 public static bool IsInvokeRequired
93 get { return PlatformServices.IsInvokeRequired; }
96 [EditorBrowsable(EditorBrowsableState.Never)]
97 public static IPlatformServices PlatformServices
101 if (s_platformServices == null)
102 throw new InvalidOperationException("You MUST call Tizen.NUI.Init(); prior to using it.");
103 return s_platformServices;
107 s_platformServices = value;
108 Console.WriteLine("Device s_platformServices : " + s_platformServices );
112 [EditorBrowsable(EditorBrowsableState.Never)]
113 public static IReadOnlyList<string> Flags { get; private set; }
115 [EditorBrowsable(EditorBrowsableState.Never)]
116 public static void SetFlags(IReadOnlyList<string> flags)
121 public static void BeginInvokeOnMainThread(Action action)
123 PlatformServices?.BeginInvokeOnMainThread(action);
125 Console.WriteLine("Device BeginInvokeOnMainThread action called");
128 // public static double GetNamedSize(NamedSize size, Element targetElement)
130 // return GetNamedSize(size, targetElement.GetType());
133 // public static double GetNamedSize(NamedSize size, Type targetElementType)
135 // return GetNamedSize(size, targetElementType, false);
138 [Obsolete("OnPlatform is obsolete as of version 2.3.4. Please use switch(RuntimePlatform) instead.")]
139 public static void OnPlatform(Action iOS = null, Action Android = null, Action WinPhone = null, Action Default = null)
143 case TargetPlatform.iOS:
146 else if (Default != null)
149 case TargetPlatform.Android:
152 else if (Default != null)
155 case TargetPlatform.Windows:
156 case TargetPlatform.WinPhone:
157 if (WinPhone != null)
159 else if (Default != null)
162 case TargetPlatform.Other:
169 [Obsolete("OnPlatform<> (generic) is obsolete as of version 2.3.4. Please use switch(RuntimePlatform) instead.")]
170 public static T OnPlatform<T>(T iOS, T Android, T WinPhone)
174 case TargetPlatform.iOS:
176 case TargetPlatform.Android:
178 case TargetPlatform.Windows:
179 case TargetPlatform.WinPhone:
186 public static void OpenUri(Uri uri)
188 // PlatformServices?.OpenUriAction(uri);
191 public static void StartTimer(TimeSpan interval, Func<bool> callback)
193 PlatformServices.StartTimer(interval, callback);
196 [EditorBrowsable(EditorBrowsableState.Never)]
197 public static Assembly[] GetAssemblies()
199 return PlatformServices?.GetAssemblies();
202 // [EditorBrowsable(EditorBrowsableState.Never)]
203 // public static double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSizes)
205 // return PlatformServices.GetNamedSize(size, targetElementType, useOldSizes);
208 internal static Task<Stream> GetStreamAsync(Uri uri, CancellationToken cancellationToken)
210 return PlatformServices?.GetStreamAsync(uri, cancellationToken);