Fixed the issue that X.F app creates two windows (#219)
[platform/core/csapi/xsf.git] / src / XSF / Xamarin.Forms.Platform.Tizen / Forms.cs
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Linq;
5 using System.Linq.Expressions;
6 using System.Reflection;
7 using Xamarin.Forms.Internals;
8 using Xamarin.Forms.Platform.Tizen;
9 using ElmSharp;
10 using Tizen.Applications;
11 using TSystemInfo = Tizen.System.Information;
12 using TSystemSetting = Tizen.System.SystemSettings;
13 using EWindow = ElmSharp.Window;
14 using ELayout = ElmSharp.Layout;
15 using DeviceOrientation = Xamarin.Forms.Internals.DeviceOrientation;
16 using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
17 using PTizen = Xamarin.Forms.Platform.Tizen;
18 using ElmSharp.Wearable;
19 using Tizen.Wearable.CircularUI.Forms;
20
21 namespace Xamarin.Forms
22 {
23         public enum StaticRegistrarStrategy
24         {
25                 None,
26                 StaticRegistrarOnly,
27                 All,
28         }
29
30         public enum PlatformType
31         {
32                 Defalut,
33                 Lightweight,
34         }
35
36         public class InitializationOptions
37         {
38                 public CoreApplication Context { get; set; }
39                 public bool UseDeviceIndependentPixel { get; set; }
40                 public HandlerAttribute[] Handlers { get; set; }
41                 public Dictionary<Type, Func<IRegisterable>> CustomHandlers { get; set; } // for static registers
42                 public Assembly[] Assemblies { get; set; }
43                 public EffectScope[] EffectScopes { get; set; }
44                 public InitializationFlags Flags { get; set; }
45                 public StaticRegistrarStrategy StaticRegistarStrategy { get; set; }
46                 public PlatformType PlatformType { get; set; }
47                 public bool UseMessagingCenter { get; set; } = true;
48                 public bool UseStyle { get; set; } = true;
49                 public bool UseShell { get; set; } = true;
50                 public bool UseVisual { get; set; } = true;
51
52
53                 public struct EffectScope
54                 {
55                         public string Name;
56                         public ExportEffectAttribute[] Effects;
57                 }
58
59                 public InitializationOptions(CoreApplication application)
60                 {
61                         Context = application;
62                 }
63
64                 public InitializationOptions(CoreApplication application, bool useDeviceIndependentPixel, HandlerAttribute[] handlers)
65                 {
66                         Context = application;
67                         UseDeviceIndependentPixel = useDeviceIndependentPixel;
68                         Handlers = handlers;
69                 }
70
71                 public InitializationOptions(CoreApplication application, bool useDeviceIndependentPixel, params Assembly[] assemblies)
72                 {
73                         Context = application;
74                         UseDeviceIndependentPixel = useDeviceIndependentPixel;
75                         Assemblies = assemblies;
76                 }
77
78                 public void UseStaticRegistrar(StaticRegistrarStrategy strategy, Dictionary<Type, Func<IRegisterable>> customHandlers = null, bool disableCss = false)
79                 {
80                         StaticRegistarStrategy = strategy;
81                         CustomHandlers = customHandlers;
82                         if (disableCss) // about 10ms
83                                 Flags = InitializationFlags.DisableCss;
84                 }
85         }
86
87         public static class Forms
88         {
89                 static Lazy<string> s_profile = new Lazy<string>(() =>
90                 {
91                         //TODO : Fix me if elm_config_profile_get() unavailable
92                         return Elementary.GetProfile();
93                 });
94
95                 static Lazy<int> s_dpi = new Lazy<int>(() =>
96                 {
97                         int dpi = 0;
98                         if (s_profile.Value == "tv")
99                         {
100                                 // Use fixed DPI value (72) if TV profile
101                                 return 72;
102                         }
103                         TSystemInfo.TryGetValue<int>("http://tizen.org/feature/screen.dpi", out dpi);
104                         return dpi;
105                 });
106
107                 static Lazy<double> s_elmScale = new Lazy<double>(() =>
108                 {
109                         // 72.0 is from EFL which is using fixed DPI value (72.0) to determine font size internally. Thus, we are restoring the size by deviding the DPI by 72.0 here.
110                         return s_dpi.Value / 72.0 / Elementary.GetScale();
111                 });
112
113                 class TizenDeviceInfo : DeviceInfo
114                 {
115                         readonly Size pixelScreenSize;
116
117                         readonly Size scaledScreenSize;
118
119                         readonly double scalingFactor;
120
121                         readonly string profile;
122
123                         public override Size PixelScreenSize
124                         {
125                                 get
126                                 {
127                                         return this.pixelScreenSize;
128                                 }
129                         }
130
131                         public override Size ScaledScreenSize
132                         {
133                                 get
134                                 {
135                                         return this.scaledScreenSize;
136                                 }
137                         }
138
139                         public override double ScalingFactor
140                         {
141                                 get
142                                 {
143                                         return this.scalingFactor;
144                                 }
145                         }
146
147                         public string Profile
148                         {
149                                 get
150                                 {
151                                         return this.profile;
152                                 }
153                         }
154
155                         public TizenDeviceInfo() : this(getScreenWidth(), getScreenHeight())
156                         {
157                         }
158
159                         static int getScreenWidth()
160                         {
161                                 if (TSystemInfo.TryGetValue("http://tizen.org/feature/screen.width", out int width))
162                                 {
163                                         return width;
164                                 }
165                                 else
166                                 {
167                                         throw new InvalidOperationException("Can not get screen.Width");
168                                 }
169                         }
170                         static int getScreenHeight()
171                         {
172                                 if (TSystemInfo.TryGetValue("http://tizen.org/feature/screen.height", out int height))
173                                 {
174                                         return height;
175                                 }
176                                 else
177                                 {
178                                         throw new InvalidOperationException("Can not get screen.Height");
179                                 }
180                         }
181                         TizenDeviceInfo(int width, int height)
182                         {
183                                 pixelScreenSize = new Size(width, height);
184
185                                 scalingFactor = 1.0;  // scaling is disabled, we're using pixels as Xamarin's geometry units
186                                 if (s_useDeviceIndependentPixel)
187                                 {
188                                         scalingFactor = s_dpi.Value / 160.0;
189                                 }
190
191                                 scaledScreenSize = new Size(width / scalingFactor, height / scalingFactor);
192                                 profile = s_profile.Value;
193                         }
194
195                         public TizenDeviceInfo RefreshByDIP()
196                         {
197                                 return new TizenDeviceInfo((int)pixelScreenSize.Width, (int)pixelScreenSize.Height);
198                         }
199                 }
200
201                 static bool s_useDeviceIndependentPixel = false;
202
203                 static StaticRegistrarStrategy s_staticRegistrarStrategy = StaticRegistrarStrategy.None;
204
205                 static PlatformType s_platformType = PlatformType.Defalut;
206
207                 static bool s_useMessagingCenter = true;
208
209                 public static event EventHandler<ViewInitializedEventArgs> ViewInitialized;
210
211                 public static CoreApplication Context
212                 {
213                         get;
214                         internal set;
215                 }
216
217                 public static EvasObject NativeParent
218                 {
219                         get; internal set;
220                 }
221
222                 public static ELayout BaseLayout => NativeParent as ELayout;
223
224                 public static CircleSurface CircleSurface
225                 {
226                         get; internal set;
227                 }
228
229                 [EditorBrowsable(EditorBrowsableState.Never)]
230                 public static Element RotaryFocusObject
231                 {
232                         get; internal set;
233                 }
234
235                 public static bool IsInitialized
236                 {
237                         get;
238                         private set;
239                 }
240
241                 public static bool IsPreloaded
242                 {
243                         get;
244                         private set;
245                 }
246
247                 public static DeviceOrientation NaturalOrientation { get; } = GetDeviceOrientation();
248
249                 public static StaticRegistrarStrategy StaticRegistrarStrategy => s_staticRegistrarStrategy;
250
251                 public static PlatformType PlatformType => s_platformType;
252
253                 public static bool UseMessagingCenter => s_useMessagingCenter;
254
255                 internal static TizenTitleBarVisibility TitleBarVisibility
256                 {
257                         get;
258                         private set;
259                 }
260
261                 static DeviceOrientation GetDeviceOrientation()
262                 {
263                         int width = 0;
264                         int height = 0;
265                         TSystemInfo.TryGetValue<int>("http://tizen.org/feature/screen.width", out width);
266                         TSystemInfo.TryGetValue<int>("http://tizen.org/feature/screen.height", out height);
267
268                         if (height >= width)
269                         {
270                                 return DeviceOrientation.Portrait;
271                         }
272                         else
273                         {
274                                 return DeviceOrientation.Landscape;
275                         }
276                 }
277
278                 internal static void SendViewInitialized(this VisualElement self, EvasObject nativeView)
279                 {
280                         EventHandler<ViewInitializedEventArgs> viewInitialized = Forms.ViewInitialized;
281                         if (viewInitialized != null)
282                         {
283                                 viewInitialized.Invoke(self, new ViewInitializedEventArgs
284                                 {
285                                         View = self,
286                                         NativeView = nativeView
287                                 });
288                         }
289                 }
290
291                 static IReadOnlyList<string> s_flags;
292                 public static IReadOnlyList<string> Flags => s_flags ?? (s_flags = new string[0]);
293
294                 public static void SetFlags(params string[] flags)
295                 {
296                         if (IsInitialized)
297                         {
298                                 throw new InvalidOperationException($"{nameof(SetFlags)} must be called before {nameof(Init)}");
299                         }
300
301                         s_flags = (string[])flags.Clone();
302                         if (s_flags.Contains("Profile"))
303                                 Profile.Enable();
304                 }
305
306                 public static void SetTitleBarVisibility(TizenTitleBarVisibility visibility)
307                 {
308                         TitleBarVisibility = visibility;
309                 }
310
311                 public static TOut GetHandler<TOut>(Type type, params object[] args) where TOut : class, IRegisterable
312                 {
313                         if (s_staticRegistrarStrategy == StaticRegistrarStrategy.None)
314                         {
315                                 // Find hander in internal registrar, that is using reflection (default).
316                                 return Internals.Registrar.Registered.GetHandler<TOut>(type, args);
317                         }
318                         else
319                         {
320                                 // 1. Find hander in static registrar first
321                                 TOut ret = StaticRegistrar.Registered.GetHandler<TOut>(type, args);
322
323                                 // 2. If there is no handler, try to find hander in internal registrar, that is using reflection.
324                                 if (ret == null && s_staticRegistrarStrategy == StaticRegistrarStrategy.All)
325                                 {
326                                         ret = Internals.Registrar.Registered.GetHandler<TOut>(type, args);
327                                 }
328                                 return ret;
329                         }
330                 }
331
332                 public static TOut GetHandlerForObject<TOut>(object obj) where TOut : class, IRegisterable
333                 {
334                         if (s_staticRegistrarStrategy == StaticRegistrarStrategy.None)
335                         {
336                                 // Find hander in internal registrar, that is using reflection (default).
337                                 return Internals.Registrar.Registered.GetHandlerForObject<TOut>(obj);
338                         }
339                         else
340                         {
341                                 // 1. Find hander in static registrar first
342                                 TOut ret = StaticRegistrar.Registered.GetHandlerForObject<TOut>(obj);
343
344                                 // 2. If there is no handler, try to find hander in internal registrar, that is using reflection.
345                                 if (ret == null && s_staticRegistrarStrategy == StaticRegistrarStrategy.All)
346                                 {
347                                         ret = Internals.Registrar.Registered.GetHandlerForObject<TOut>(obj);
348                                 }
349                                 return ret;
350                         }
351                 }
352
353                 public static TOut GetHandlerForObject<TOut>(object obj, params object[] args) where TOut : class, IRegisterable
354                 {
355                         if (s_staticRegistrarStrategy == StaticRegistrarStrategy.None)
356                         {
357                                 // Find hander in internal registrar, that is using reflection (default).
358                                 return Internals.Registrar.Registered.GetHandlerForObject<TOut>(obj, args);
359                         }
360                         else
361                         {
362                                 // 1. Find hander in static registrar first without fallback handler.
363                                 TOut ret = StaticRegistrar.Registered.GetHandlerForObject<TOut>(obj, args);
364
365                                 // 2. If there is no handler, try to find hander in internal registrar, that is using reflection.
366                                 if (ret == null && s_staticRegistrarStrategy == StaticRegistrarStrategy.All)
367                                 {
368                                         ret = StaticRegistrar.Registered.GetHandlerForObject<TOut>(obj, args);
369                                 }
370                                 return ret;
371                         }
372                 }
373
374                 public static void Init(CoreApplication application)
375                 {
376                         Init(application, false);
377                 }
378
379                 public static void Init(CoreApplication application, bool useDeviceIndependentPixel)
380                 {
381                         s_useDeviceIndependentPixel = useDeviceIndependentPixel;
382                         SetupInit(application);
383                 }
384
385                 public static void Init(InitializationOptions options)
386                 {
387                         SetupInit(Context, options);
388                 }
389
390                 static void SetupInit(CoreApplication application, InitializationOptions options = null)
391                 {
392                         Context = application;
393
394                         if (!IsInitialized)
395                         {
396                                 Internals.Log.Listeners.Add(new XamarinLogListener());
397                                 if (System.Threading.SynchronizationContext.Current == null)
398                                 {
399                                         TizenSynchronizationContext.Initialize();
400                                 }
401                                 Elementary.Initialize();
402                                 Elementary.ThemeOverlay();
403                                 Utility.AppendGlobalFontPath(@"/usr/share/fonts");
404
405                                 Device.PlatformServices = new TizenPlatformServices();
406                                 if (Device.info != null)
407                                 {
408                                         ((TizenDeviceInfo)Device.info).Dispose();
409                                         Device.info = null;
410                                 }
411
412                                 Device.Info = new Forms.TizenDeviceInfo();
413                                 Device.SetFlags(s_flags);
414                         }
415                         else if (Device.info != null)
416                         {
417                                 var info = ((TizenDeviceInfo)Device.info).RefreshByDIP();
418                                 ((TizenDeviceInfo)Device.info).Dispose();
419                                 Device.info = info;
420                         }
421
422                         string profile = ((TizenDeviceInfo)Device.Info).Profile;
423                         if (profile == "mobile")
424                         {
425                                 Device.SetIdiom(TargetIdiom.Phone);
426                         }
427                         else if (profile == "tv")
428                         {
429                                 Device.SetIdiom(TargetIdiom.TV);
430                         }
431                         else if (profile == "desktop")
432                         {
433                                 Device.SetIdiom(TargetIdiom.Desktop);
434                         }
435                         else if (profile == "wearable")
436                         {
437                                 Device.SetIdiom(TargetIdiom.Watch);
438                         }
439                         else
440                         {
441                                 Device.SetIdiom(TargetIdiom.Unsupported);
442                         }
443
444                         if (!Forms.IsInitialized && !Forms.IsPreloaded)
445                         {
446                                 StaticRegistrar.RegisterHandlers(CircularUIForms.StaticHandlers);
447                                 CircularUIForms.RegisterDependencyService();
448                                 TizenPlatformServices.AppDomain.CurrentDomain.AddAssembly(Assembly.GetAssembly(typeof(Xamarin.Forms.View)));
449                         }
450
451                         if (!Forms.IsInitialized || Forms.IsPreloaded)
452                         {
453                                 if (options != null)
454                                 {
455                                         s_useDeviceIndependentPixel = options.UseDeviceIndependentPixel;
456                                         s_platformType = options.PlatformType;
457                                         s_useMessagingCenter = options.UseMessagingCenter;
458                                         OptionalFeatureValues.UseStyle = options.UseStyle;
459                                         OptionalFeatureValues.UseShell = options.UseShell;
460                                         OptionalFeatureValues.UseVisual = options.UseVisual;
461
462                                         if (options.Assemblies != null && options.Assemblies.Length > 0)
463                                         {
464                                                 TizenPlatformServices.AppDomain.CurrentDomain.AddAssemblies(options.Assemblies);
465                                         }
466
467                                         // renderers
468                                         if (options.Handlers != null)
469                                         {
470                                                 Internals.Registrar.RegisterRenderers(options.Handlers);
471                                         }
472                                         else
473                                         {
474                                                 // Add Xamarin.Forms.Core assembly by default to apply the styles.
475                                                 if (!Forms.IsPreloaded)
476                                                 {
477                                                         TizenPlatformServices.AppDomain.CurrentDomain.AddAssembly(Assembly.GetAssembly(typeof(Xamarin.Forms.View)));
478                                                 }
479
480                                                 // static registrar
481                                                 if (options.StaticRegistarStrategy != StaticRegistrarStrategy.None)
482                                                 {
483                                                         s_staticRegistrarStrategy = options.StaticRegistarStrategy;
484                                                         StaticRegistrar.RegisterHandlers(options.CustomHandlers);
485
486                                                         if (options.StaticRegistarStrategy == StaticRegistrarStrategy.All)
487                                                         {
488                                                                 Registrar.RegisterAll(new Type[]
489                                                                 {
490                                                                                 typeof(ExportRendererAttribute),
491                                                                                 typeof(ExportImageSourceHandlerAttribute),
492                                                                                 typeof(ExportCellAttribute),
493                                                                                 typeof(ExportHandlerAttribute),
494                                                                                 typeof(ExportFontAttribute)
495                                                                 });
496                                                         }
497                                                 }
498                                                 else
499                                                 {
500                                                         // In .NETCore, AppDomain feature is not supported.
501                                                         // The list of assemblies returned by AppDomain.GetAssemblies() method should be registered manually.
502                                                         // The assembly of the executing application and referenced assemblies of it are added into the list here.
503                                                         TizenPlatformServices.AppDomain.CurrentDomain.RegisterAssemblyRecursively(application.GetType().GetTypeInfo().Assembly);
504
505                                                         Registrar.RegisterAll(new Type[]
506                                                         {
507                                                                 typeof(ExportRendererAttribute),
508                                                                 typeof(ExportImageSourceHandlerAttribute),
509                                                                 typeof(ExportCellAttribute),
510                                                                 typeof(ExportHandlerAttribute),
511                                                                 typeof(ExportFontAttribute)
512                                                         });
513                                                 }
514                                         }
515
516                                         // effects
517                                         var effectScopes = options.EffectScopes;
518                                         if (effectScopes != null)
519                                         {
520                                                 for (var i = 0; i < effectScopes.Length; i++)
521                                                 {
522                                                         var effectScope = effectScopes[i];
523                                                         Internals.Registrar.RegisterEffects(effectScope.Name, effectScope.Effects);
524                                                 }
525                                         }
526
527                                         // css
528                                         var flags = options.Flags;
529                                         var noCss = (flags & InitializationFlags.DisableCss) != 0;
530                                         if (!noCss)
531                                                 Internals.Registrar.RegisterStylesheets();
532                                 }
533                                 else
534                                 {
535                                         // In .NETCore, AppDomain feature is not supported.
536                                         // The list of assemblies returned by AppDomain.GetAssemblies() method should be registered manually.
537                                         // The assembly of the executing application and referenced assemblies of it are added into the list here.
538                                         TizenPlatformServices.AppDomain.CurrentDomain.RegisterAssemblyRecursively(application.GetType().GetTypeInfo().Assembly);
539
540                                         Registrar.RegisterAll(new Type[]
541                                         {
542                                                 typeof(ExportRendererAttribute),
543                                                 typeof(ExportImageSourceHandlerAttribute),
544                                                 typeof(ExportCellAttribute),
545                                                 typeof(ExportHandlerAttribute),
546                                                 typeof(ExportFontAttribute)
547                                         });
548                                 }
549                         }
550
551                         Color.SetAccent(GetAccentColor(profile));
552                         ExpressionSearch.Default = new TizenExpressionSearch();
553                         IsInitialized = true;
554                 }
555
556                 static Color GetAccentColor(string profile)
557                 {
558                         // On Windows Phone, this is the complementary color chosen by the user.
559                         // Good Windows Phone applications use this as part of their styling to provide a native look and feel.
560                         // On iOS and Android this instance is set to a contrasting color that is visible on the default
561                         // background but is not the same as the default text color.
562
563                         switch (profile)
564                         {
565                                 case "mobile":
566                                         // [Tizen_3.0]Basic_Interaction_GUI_[REF].xlsx Theme 001 (Default) 1st HSB: 188 70 80
567                                         return Color.FromRgba(61, 185, 204, 255);
568                                 case "tv":
569                                         return Color.FromRgba(15, 15, 15, 230);
570                                 case "wearable":
571                                         // Theme A (Default) 1st HSB: 207 75 16
572                                         return Color.FromRgba(10, 27, 41, 255);
573                                 default:
574                                         return Color.Black;
575                         }
576                 }
577
578                 /// <summary>
579                 /// Converts the dp into pixel considering current DPI value.
580                 /// </summary>
581                 /// <remarks>
582                 /// Use this API if you want to get pixel size without scaling factor.
583                 /// </remarks>
584                 /// <param name="dp"></param>
585                 /// <returns></returns>
586                 public static int ConvertToPixel(double dp)
587                 {
588                         return (int)Math.Round(dp * s_dpi.Value / 160.0);
589                 }
590
591                 /// <summary>
592                 /// Converts the dp into pixel by using scaling factor.
593                 /// </summary>
594                 /// <remarks>
595                 /// Use this API if you want to get pixel size from dp by using scaling factor.
596                 /// If the scaling factor is 1.0 by user setting, the same value is returned. This is mean that user doesn't want to pixel independent metric.
597                 /// </remarks>
598                 /// <param name="dp"></param>
599                 /// <returns></returns>
600                 public static int ConvertToScaledPixel(double dp)
601                 {
602                         return (int)Math.Round(dp * Device.Info.ScalingFactor);
603                 }
604
605                 /// <summary>
606                 /// Converts the pixel into dp value by using scaling factor.
607                 /// </summary>
608                 /// <remarks>
609                 /// If the scaling factor is 1.0 by user setting, the same value is returned. This is mean that user doesn't want to pixel independent metric.
610                 /// </remarks>
611                 /// <param name="pixel"></param>
612                 /// <returns></returns>
613                 public static double ConvertToScaledDP(int pixel)
614                 {
615                         return pixel / Device.Info.ScalingFactor;
616                 }
617
618                 /// <summary>
619                 /// Converts the pixel into dp value by using scaling factor.
620                 /// </summary>
621                 /// <remarks>
622                 /// If the scaling factor is 1.0 by user setting, the same value is returned. This is mean that user doesn't want to pixel independent metric.
623                 /// </remarks>
624                 /// <param name="pixel"></param>
625                 /// <returns></returns>
626                 public static double ConvertToScaledDP(double pixel)
627                 {
628                         return pixel / Device.Info.ScalingFactor;
629                 }
630
631                 /// <summary>
632                 /// Converts the sp into EFL's font size metric (EFL point).
633                 /// </summary>
634                 /// <param name="sp"></param>
635                 /// <returns></returns>
636                 public static int ConvertToEflFontPoint(double sp)
637                 {
638                         return (int)Math.Round(sp * s_elmScale.Value);
639                 }
640
641                 /// <summary>
642                 /// Convert the EFL's point into sp.
643                 /// </summary>
644                 /// <param name="eflPt"></param>
645                 /// <returns></returns>
646                 public static double ConvertToDPFont(int eflPt)
647                 {
648                         return eflPt / s_elmScale.Value;
649                 }
650
651                 /// <summary>
652                 /// Get the EFL's profile
653                 /// </summary>
654                 /// <returns></returns>
655                 public static string GetProfile()
656                 {
657                         return s_profile.Value;
658                 }
659
660                 // for internal use only
661                 [EditorBrowsable(EditorBrowsableState.Never)]
662                 public static EvasObject Preload()
663                 {
664                         var dummyApp = new DummyFormsApplication();
665                         Init(dummyApp, false);
666                         IsPreloaded = true;
667
668                         var locale = TSystemSetting.LocaleLanguage;
669                         TSystemSetting.LocaleLanguageChanged += DummyHandler;
670                         TSystemSetting.LocaleLanguageChanged -= DummyHandler;
671                         void DummyHandler(object sender, System.EventArgs e) { }
672
673                         var types = new[]
674                         {
675                                 typeof(Application),
676                                 typeof(ContentPage),
677                                 typeof(NavigationPage),
678                                 typeof(Shell),
679                                 typeof(ContentPresenter),
680                                 typeof(ContentView),
681                                 typeof(ScrollView),
682                                 typeof(Frame),
683                                 typeof(TemplatedView),
684                                 typeof(StackLayout),
685                                 typeof(AbsoluteLayout),
686                                 typeof(RelativeLayout),
687                                 typeof(Grid),
688                                 typeof(FlexLayout),
689                                 typeof(Image),
690                                 typeof(Label),
691                                 typeof(BoxView),
692                                 typeof(Button),
693                                 typeof(ImageButton),
694                                 typeof(CheckBox),
695                                 typeof(Slider),
696                                 typeof(Stepper),
697                                 typeof(Switch),
698                                 typeof(DatePicker),
699                                 typeof(TimePicker),
700                                 typeof(Entry),
701                                 typeof(Editor),
702                                 typeof(ActivityIndicator),
703                                 typeof(ProgressBar),
704                                 typeof(CarouselView),
705                                 typeof(CollectionView),
706                                 typeof(ListView),
707                                 typeof(Picker),
708                                 typeof(TableView),
709                                 typeof(TextCell),
710                                 typeof(ImageCell),
711                                 typeof(SwitchCell),
712                                 typeof(EntryCell),
713                                 typeof(VisualElement),
714                                 typeof(Page),
715                                 typeof(View),
716                                 typeof(Element),
717                                 typeof(NavigableElement),
718                                 typeof(Layout),
719                                 typeof(Span),
720                                 typeof(TapGestureRecognizer),
721                                 typeof(PropertyCondition),
722                                 typeof(RefreshView),
723                                 typeof(StructuredItemsView),
724                                 typeof(SearchHandler),
725                         };
726
727                         foreach (var type in types)
728                         {
729                                 System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type.TypeHandle);
730                         }
731
732                         PTizen.PreloadedWindow preloadedWindow = new PTizen.PreloadedWindow();
733                         if (preloadedWindow.Window != null)
734                         {
735                                 global::Xamarin.Forms.Platform.Tizen.Native.NativeFactory.PrecreateNatives(preloadedWindow.Window);
736                                 global::Tizen.Wearable.CircularUI.Forms.CircularUIForms.Preload(preloadedWindow.Window);
737                         }
738                         else
739                         {
740                                 Console.WriteLine("PreloadedWindow is null");
741                         }
742                         return preloadedWindow.Window;
743                 }
744         }
745
746         class TizenExpressionSearch : ExpressionVisitor, IExpressionSearch
747         {
748                 List<object> _results;
749                 Type _targetType;
750
751                 public List<T> FindObjects<T>(Expression expression) where T : class
752                 {
753                         _results = new List<object>();
754                         _targetType = typeof(T);
755                         Visit(expression);
756                         return _results.Select(o => o as T).ToList();
757                 }
758
759                 protected override Expression VisitMember(MemberExpression node)
760                 {
761                         if (node.Expression is ConstantExpression && node.Member is FieldInfo)
762                         {
763                                 var container = ((ConstantExpression)node.Expression).Value;
764                                 var value = ((FieldInfo)node.Member).GetValue(container);
765
766                                 if (_targetType.IsInstanceOfType(value))
767                                         _results.Add(value);
768                         }
769                         return base.VisitMember(node);
770                 }
771         }
772
773         class DummyFormsApplication : FormsApplication { }
774 }