Add State property of NUIApplication (#5989)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Application / NUIApplication.cs
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20 using System.Diagnostics.CodeAnalysis;
21 using System.Threading;
22 using System.Reflection;
23 using Tizen.Applications;
24 using Tizen.Applications.CoreBackend;
25 using Tizen.NUI.Xaml;
26
27 namespace Tizen.NUI
28 {
29
30     /// <summary>
31     /// Represents an application that have a UI screen. The NUIApplication class has a default stage.
32     /// </summary>
33     /// <since_tizen> 3 </since_tizen>
34     public class NUIApplication : CoreApplication
35     {
36         /// <summary>
37         /// The instance of ResourceManager.
38         /// </summary>
39         private static System.Resources.ResourceManager resourceManager = null;
40         private static string currentLoadedXaml = null;
41
42         /// <summary>
43         /// The border window
44         /// </summary>
45         private bool borderEnabled = false;
46         private IBorderInterface borderInterface = null;
47
48         private State currentState = State.Invalid;
49
50         /// <summary>
51         /// Xaml loaded delegate.
52         /// </summary>
53         [EditorBrowsable(EditorBrowsableState.Never)]
54         public delegate void XamlLoadedHandler(string xamlName);
55
56         static NUIApplication()
57         {
58             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
59         }
60
61         /// <summary>
62         /// The default constructor.
63         /// </summary>
64         /// <since_tizen> 3 </since_tizen>
65         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
66         public NUIApplication() : base(new NUICoreBackend())
67         {
68             currentState = State.Ready;
69         }
70
71         /// <summary>
72         /// The constructor with window size and position.
73         /// </summary>
74         /// <param name="windowSize">The window size.</param>
75         /// <param name="windowPosition">The window position.</param>
76         /// <since_tizen> 5 </since_tizen>
77         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
78         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
79         [EditorBrowsable(EditorBrowsableState.Never)]
80         public NUIApplication(Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend("", NUIApplication.WindowMode.Opaque, windowSize, windowPosition))
81         {
82             currentState = State.Ready;
83         }
84
85         /// <summary>
86         /// The constructor with a stylesheet.
87         /// </summary>
88         /// <param name="styleSheet">The styleSheet url.</param>
89         /// <since_tizen> 3 </since_tizen>
90         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
91         public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
92         {
93             currentState = State.Ready;
94         }
95
96         /// <summary>
97         /// The constructor with a stylesheet, window size, and position.
98         /// </summary>
99         /// <param name="styleSheet">The styleSheet URL.</param>
100         /// <param name="windowSize">The window size.</param>
101         /// <param name="windowPosition">The window position.</param>
102         /// <since_tizen> 5 </since_tizen>
103         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
104         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public NUIApplication(string styleSheet, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, WindowMode.Opaque, windowSize, windowPosition))
107         {
108             currentState = State.Ready;
109         }
110
111         /// <summary>
112         /// The constructor with a stylesheet and window mode.
113         /// </summary>
114         /// <param name="styleSheet">The styleSheet url.</param>
115         /// <param name="windowMode">The windowMode.</param>
116         /// <since_tizen> 3 </since_tizen>
117         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
118         public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
119         {
120             currentState = State.Ready;
121         }
122
123         /// <summary>
124         /// The constructor with a stylesheet, window mode, window size, and position.
125         /// </summary>
126         /// <param name="styleSheet">The styleSheet URL.</param>
127         /// <param name="windowMode">The windowMode.</param>
128         /// <param name="windowSize">The window size.</param>
129         /// <param name="windowPosition">The window position.</param>
130         /// <since_tizen> 5 </since_tizen>
131         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
132         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
133         [EditorBrowsable(EditorBrowsableState.Never)]
134         public NUIApplication(string styleSheet, WindowMode windowMode, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
135         {
136             currentState = State.Ready;
137         }
138
139         /// <summary>
140         /// Internal inhouse constructor with Graphics Backend Type
141         /// </summary>
142         /// <param name="backend"></param>
143         /// <param name="windowMode"></param>
144         /// <param name="windowSize"></param>
145         /// <param name="windowPosition"></param>
146         /// <param name="styleSheet"></param>
147         /// InhouseAPI, this could be opened in NextTizen
148         [Obsolete("Do not use! This will be deprecated!")]
149         [EditorBrowsable(EditorBrowsableState.Never)]
150         public NUIApplication(Graphics.BackendType backend, WindowMode windowMode = WindowMode.Opaque, Size2D windowSize = null, Position2D windowPosition = null, string styleSheet = "") : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
151         {
152             //windowMode and styleSheet will be added later. currently it's not working as expected.
153             currentState = State.Ready;
154             Graphics.Backend = backend;
155             Tizen.Log.Error("NUI", "Plaese DO NOT set graphical backend type with this constructor! This will give no effect!");
156         }
157
158         /// <summary>
159         /// The constructor with theme option.
160         /// </summary>
161         /// <param name="option">The theme option.</param>
162         [EditorBrowsable(EditorBrowsableState.Never)]
163         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
164         public NUIApplication(ThemeOptions option) : base(new NUICoreBackend())
165         {
166             currentState = State.Ready;
167             ApplyThemeOption(option);
168         }
169
170         /// <summary>
171         /// The constructor with window size and position and theme option.
172         /// </summary>
173         /// <param name="windowSize">The window size.</param>
174         /// <param name="windowPosition">The window position.</param>
175         /// <param name="option">The theme option.</param>
176         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
177         [EditorBrowsable(EditorBrowsableState.Never)]
178         public NUIApplication(Size2D windowSize, Position2D windowPosition, ThemeOptions option) : base(new NUICoreBackend("", NUIApplication.WindowMode.Opaque, windowSize, windowPosition))
179         {
180             currentState = State.Ready;
181             ApplyThemeOption(option);
182         }
183
184         /// <summary>
185         /// The constructor with a stylesheet, window mode and default window type.
186         /// It is the only way to create an IME window.
187         /// </summary>
188         /// <param name="styleSheet">The styleSheet URL.</param>
189         /// <param name="windowMode">The windowMode.</param>
190         /// <param name="type">The default window type.</param>
191         /// <since_tizen> 9 </since_tizen>
192         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
193         public NUIApplication(string styleSheet, WindowMode windowMode, WindowType type) : base(new NUICoreBackend(styleSheet, windowMode, type))
194         {
195             currentState = State.Ready;
196             ExternalThemeManager.Initialize();
197         }
198
199         /// <summary>
200         /// The constructor with a stylesheet, size, position, boderInterface and window mode
201         /// </summary>
202         /// <param name="styleSheet">The styleSheet URL.</param>
203         /// <param name="windowSize">The window size.</param>
204         /// <param name="windowPosition">The window position.</param>
205         /// <param name="borderInterface"><see cref="Tizen.NUI.IBorderInterface"/>If borderInterface is null, defaultBorder is enabled.</param>
206         /// <param name="windowMode">The windowMode.</param>
207         [EditorBrowsable(EditorBrowsableState.Never)]
208         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
209         public NUIApplication(string styleSheet, Size2D windowSize, Position2D windowPosition, IBorderInterface borderInterface, WindowMode windowMode = WindowMode.Opaque) : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
210         {
211             currentState = State.Ready;
212             EnableBorder(borderInterface);
213         }
214
215         /// <summary>
216         /// The constructor with theme option and borderInterface.
217         /// </summary>
218         /// <param name="option">The theme option.</param>
219         /// <param name="borderInterface"><see cref="Tizen.NUI.IBorderInterface"/>If borderInterface is null, defaultBorder is enabled.</param>
220         [EditorBrowsable(EditorBrowsableState.Never)]
221         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
222         public NUIApplication(ThemeOptions option, IBorderInterface borderInterface) : base(new NUICoreBackend())
223         {
224             currentState = State.Ready;
225             EnableBorder(borderInterface);
226             ApplyThemeOption(option);
227         }
228
229         /// <summary>
230         /// The constructor with window size, position, theme option and borderInterface.
231         /// </summary>
232         /// <param name="windowSize">The window size.</param>
233         /// <param name="windowPosition">The window position.</param>
234         /// <param name="option">The theme option.</param>
235         /// <param name="borderInterface"><see cref="Tizen.NUI.IBorderInterface"/>If borderInterface is null, defaultBorder is enabled.</param>
236         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
237         [EditorBrowsable(EditorBrowsableState.Never)]
238         public NUIApplication(Size2D windowSize, Position2D windowPosition, ThemeOptions option, IBorderInterface borderInterface) : base(new NUICoreBackend("", NUIApplication.WindowMode.Opaque, windowSize, windowPosition))
239         {
240             currentState = State.Ready;
241             EnableBorder(borderInterface);
242             ApplyThemeOption(option);
243         }
244
245         /// <summary>
246         /// The constructor with a stylesheet, window mode, coretask
247         /// </summary>
248         /// <note>
249         /// There is the UI thread feature.
250         /// UI thread is an additional thread that an Application object creates. The thread is for UI events.
251         /// To enable the UI Thread, you have to pass CoreTask object using this contructor.
252         /// When the UI thread feature is enabled, The methods of CoreTask are emitted on the main thread,
253         /// and the NUIApplication's events are emitted on the UI thread.
254         /// If you want to handle windows or actors in cases like when the memory level of the device is low, you have to use the NUIApplication events, not the CoreTask methods.
255         /// The CoreTask is not for handling GUI.
256         /// Callbacks of the all events in NUIApplication except the CoreTask are emitted on the UI thread.
257         /// </note>
258         /// <param name="styleSheet">The styleSheet URL.</param>
259         /// <param name="windowMode">The windowMode.</param>
260         /// <param name="task">True If app creates a UI Thread</param>
261         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
262         [EditorBrowsable(EditorBrowsableState.Never)]
263         public NUIApplication(string styleSheet, WindowMode windowMode, CoreTask task) : base(new NUICoreBackend(styleSheet, windowMode), task)
264         {
265             currentState = State.Ready;
266         }
267
268         /// <summary>
269         /// The constructor with a stylesheet, window mode, window size, position, coretask
270         /// </summary>
271         /// <param name="styleSheet">The styleSheet URL.</param>
272         /// <param name="windowMode">The windowMode.</param>
273         /// <param name="windowSize">The window size.</param>
274         /// <param name="windowPosition">The window position.</param>
275         /// <param name="task">True If app creates a UI Thread</param>
276         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
277         [EditorBrowsable(EditorBrowsableState.Never)]
278         public NUIApplication(string styleSheet, WindowMode windowMode, Size2D windowSize, Position2D windowPosition, CoreTask task) : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition), task)
279         {
280             currentState = State.Ready;
281         }
282
283         /// <summary>
284         /// The constructor with a ThemeOptions, WindowData
285         /// </summary>
286         /// <param name="option">The theme option.</param>
287         /// <param name="windowData">The default window data</param>
288         [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
289         [EditorBrowsable(EditorBrowsableState.Never)]
290         public NUIApplication(ThemeOptions option, WindowData windowData) : base(new NUICoreBackend(windowData))
291         {
292             currentState = State.Ready;
293             if (windowData.BorderInterface != null)
294             {
295                 EnableBorder(windowData.BorderInterface);
296             }
297             ApplyThemeOption(option);
298         }
299
300         /// <summary>
301         /// Occurs whenever the application is resumed.
302         /// </summary>
303         /// <since_tizen> 4 </since_tizen>
304         public event EventHandler Resumed;
305
306         /// <summary>
307         /// Occurs whenever the application is paused.
308         /// </summary>
309         /// <since_tizen> 4 </since_tizen>
310         public event EventHandler Paused;
311
312         /// <summary>
313         /// Xaml loaded event.
314         /// </summary>
315         [EditorBrowsable(EditorBrowsableState.Never)]
316         public static event XamlLoadedHandler XamlLoaded;
317
318         /// <summary>
319         /// Enumeration for deciding whether a NUI application window is opaque or transparent.
320         /// </summary>
321         /// <since_tizen> 3 </since_tizen>
322         public enum WindowMode
323         {
324             /// <summary>
325             /// Opaque
326             /// </summary>
327             /// <since_tizen> 3 </since_tizen>
328             Opaque = 0,
329             /// <summary>
330             /// Transparent
331             /// </summary>
332             /// <since_tizen> 3 </since_tizen>
333             Transparent = 1
334         }
335
336         /// <summary>
337         /// Enumeration for theme options of the NUIApplication.
338         /// </summary>
339         [Flags]
340         [EditorBrowsable(EditorBrowsableState.Never)]
341         public enum ThemeOptions : int
342         {
343             /// <summary>
344             /// No option specified.
345             /// </summary>
346             [EditorBrowsable(EditorBrowsableState.Never)]
347             None = 0,
348
349             /// <summary>
350             /// Enable platform theme.
351             /// When this option is on, all views in the NUIApplication is affected by platform theme (e.g. light/dark).
352             /// </summary>
353             [EditorBrowsable(EditorBrowsableState.Never)]
354             PlatformThemeEnabled = 1 << 0,
355
356             /// <summary>
357             /// Sets the default value of View.ThemeChangeSensitive.
358             /// when this option is on, all views are made sensitive on theme changing by default.
359             /// </summary>
360             [EditorBrowsable(EditorBrowsableState.Never)]
361             ThemeChangeSensitive = 1 << 1,
362         };
363
364         /// <summary>
365         /// Current loaded xaml's full name.
366         /// </summary>
367         [EditorBrowsable(EditorBrowsableState.Never)]
368         public static string CurrentLoadedXaml
369         {
370             get
371             {
372                 return currentLoadedXaml;
373             }
374             set
375             {
376                 if (currentLoadedXaml != value)
377                 {
378                     currentLoadedXaml = value;
379                     XamlLoaded?.Invoke(value);
380                 }
381             }
382         }
383
384         /// <summary>
385         /// ResourceManager to handle multilingual.
386         /// </summary>
387         /// <since_tizen> 4 </since_tizen>
388         public static System.Resources.ResourceManager MultilingualResourceManager
389         {
390             get
391             {
392                 return resourceManager;
393             }
394             set
395             {
396                 resourceManager = value;
397             }
398         }
399
400         /// <summary>
401         /// Gets the window instance.
402         /// </summary>
403         /// <since_tizen> 3 </since_tizen>
404         [Obsolete("Do not use! This will be deprecated!")]
405         [EditorBrowsable(EditorBrowsableState.Never)]
406         public Window Window
407         {
408             get
409             {
410                 return GetDefaultWindow();
411             }
412         }
413
414         /// <summary>
415         /// Gets the Application Id.
416         /// </summary>
417         /// <since_tizen> 6 </since_tizen>
418         [EditorBrowsable(EditorBrowsableState.Never)]
419         public string AppId
420         {
421             get
422             {
423                 return Tizen.Applications.Application.Current.ApplicationInfo.ApplicationId;
424             }
425         }
426
427
428         /// <summary>
429         /// Gets the state of current application.
430         /// </summary>
431         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
432         [EditorBrowsable(EditorBrowsableState.Never)]
433         public State State
434         {
435             get
436             {
437                 return currentState;
438             }
439         } 
440
441         /// <summary>
442         /// Gets the default window.
443         /// </summary>
444         /// <returns>The default Window.</returns>
445         /// <since_tizen> 6 </since_tizen>
446         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
447         [EditorBrowsable(EditorBrowsableState.Never)]
448         public static Window GetDefaultWindow()
449         {
450             return Window.Instance;
451         }
452
453         internal Application ApplicationHandle
454         {
455             get
456             {
457                 return ((NUICoreBackend)this.Backend).ApplicationHandle;
458             }
459         }
460
461         /// <summary>
462         /// Register the assembly to XAML.
463         /// </summary>
464         /// <since_tizen> 5 </since_tizen>
465         public static void RegisterAssembly(Assembly assembly)
466         {
467             XamlParser.s_assemblies.Add(assembly);
468         }
469
470         /// <summary>
471         /// Runs the NUIApplication.
472         /// </summary>
473         /// <param name="args">Arguments from commandline.</param>
474         /// <since_tizen> 4 </since_tizen>
475         public override void Run(string[] args)
476         {
477             Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
478             Backend.AddEventHandler(EventType.Resumed, OnResume);
479             Backend.AddEventHandler(EventType.Paused, OnPause);
480             base.Run(args);
481         }
482
483         /// <summary>
484         /// Exits the NUIApplication.
485         /// </summary>
486         /// <since_tizen> 4 </since_tizen>
487         public override void Exit()
488         {
489             base.Exit();
490         }
491
492         /// <summary>
493         /// Ensures that the function passed in is called from the main loop when it is idle.
494         /// </summary>
495         /// <param name="func">The function to call</param>
496         /// <returns>true if added successfully, false otherwise</returns>
497         /// <since_tizen> 4 </since_tizen>
498         public bool AddIdle(System.Delegate func)
499         {
500             return ((NUICoreBackend)this.Backend).AddIdle(func);
501         }
502
503         /// <summary>
504         /// Flush render/update thread messages synchronously.
505         /// </summary>
506         /// <remarks>
507         /// This function will relayout forcibily.
508         /// This function is used for advanced developer. It will make main-thread overhead if you call this function frequencely.
509         /// </remarks>
510         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
511         [EditorBrowsable(EditorBrowsableState.Never)]
512         public void FlushUpdateMessages()
513         {
514             ApplicationHandle.FlushUpdateMessages();
515         }
516
517         /// <summary>
518         /// Sets the number of frames per render.
519         /// </summary>
520         /// <param name="numberOfVSyncsPerRender">The number of vsyncs between successive renders.</param>
521         /// <remarks>
522         /// Suggest this is a power of two:
523         /// 1 - render each vsync frame.
524         /// 2 - render every other vsync frame.
525         /// 4 - render every fourth vsync frame.
526         /// 8 - render every eighth vsync frame. <br />
527         /// For example, if an application runs on 60 FPS and SetRenderRefreshRate(2) is called, the frames per second will be changed to 30.
528         ///</remarks>
529         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
530         [EditorBrowsable(EditorBrowsableState.Never)]
531         public static void SetRenderRefreshRate(uint numberOfVSyncsPerRender)
532         {
533             Adaptor.Instance.SetRenderRefreshRate(numberOfVSyncsPerRender);
534         }
535
536         /// <summary>
537         /// Gets the screen size
538         /// </summary>
539         /// <returns>Screen size</returns>
540         [EditorBrowsable(EditorBrowsableState.Never)]
541         static public Size GetScreenSize()
542         {
543             var ret = new Size(Interop.Application.GetScreenSize(), true);
544             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
545             return ret;
546         }
547
548         /// <summary>
549         /// Overrides this method if you want to handle behavior.
550         /// </summary>
551         /// <since_tizen> 3 </since_tizen>
552         protected override void OnLocaleChanged(LocaleChangedEventArgs e)
553         {
554             base.OnLocaleChanged(e);
555         }
556
557         /// <summary>
558         /// Overrides this method if you want to handle behavior.
559         /// </summary>
560         /// <since_tizen> 3 </since_tizen>
561         protected override void OnLowBattery(LowBatteryEventArgs e)
562         {
563             base.OnLowBattery(e);
564         }
565
566         /// <summary>
567         /// Overrides this method if you want to handle behavior.
568         /// </summary>
569         /// <since_tizen> 3 </since_tizen>
570         protected override void OnLowMemory(LowMemoryEventArgs e)
571         {
572             base.OnLowMemory(e);
573         }
574
575         /// <summary>
576         /// Overrides this method if you want to handle behavior.
577         /// </summary>
578         /// <since_tizen> 3 </since_tizen>
579         protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
580         {
581             base.OnRegionFormatChanged(e);
582         }
583
584         /// <summary>
585         /// This method is to handle behavior when the device orientation is changed.
586         ///
587         /// When device is rotated to ccw or cw, this event occurs.
588         /// In addition, this event is different to window orientation changed event.
589         /// The window orientation event is for per a window and occurs when some flags should be set before.
590         /// </summary>
591         /// <param name="e">The device orientation changed event argument</param>
592         [EditorBrowsable(EditorBrowsableState.Never)]
593         protected override void OnDeviceOrientationChanged(DeviceOrientationEventArgs e)
594         {
595             base.OnDeviceOrientationChanged(e);
596         }
597
598         /// <summary>
599         /// Overrides this method if you want to handle behavior.
600         /// </summary>
601         /// <since_tizen> 3 </since_tizen>
602         protected override void OnTerminate()
603         {
604             currentState = State.Terminated;
605             base.OnTerminate();
606         }
607
608         /// <summary>
609         /// Overrides this method if you want to handle behavior.
610         /// </summary>
611         /// <since_tizen> 3 </since_tizen>
612         protected virtual void OnPause()
613         {
614             currentState = State.Paused;
615             Paused?.Invoke(this, EventArgs.Empty);
616         }
617
618         /// <summary>
619         /// Overrides this method if you want to handle behavior.
620         /// </summary>
621         /// <since_tizen> 3 </since_tizen>
622         protected virtual void OnResume()
623         {
624             currentState = State.Resumed;
625             Resumed?.Invoke(this, EventArgs.Empty);
626         }
627
628         /// <summary>
629         /// Overrides this method if you want to handle behavior.
630         /// </summary>
631         /// <since_tizen> 3 </since_tizen>
632         protected virtual void OnPreCreate()
633         {
634             Tizen.Tracer.Begin("[NUI] OnPreCreate()");
635
636             currentState = State.PreCreated;
637             if (borderEnabled && GetDefaultWindow() != null)
638             {
639                 GetDefaultWindow().EnableBorder(borderInterface, new Window.BorderCloseDelegate(Exit));
640             }
641             Tizen.Tracer.End();
642         }
643
644         /// <summary>
645         /// Overrides this method if you want to handle behavior.
646         /// </summary>
647         /// <since_tizen> 3 </since_tizen>
648         protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
649         {
650             if (e != null && e.ReceivedAppControl != null)
651             {
652                 Log.Info("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
653                 Log.Info("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + "   IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
654             }
655             base.OnAppControlReceived(e);
656         }
657
658         /// <summary>
659         /// Overrides this method if you want to handle behavior.
660         /// </summary>
661         /// <since_tizen> 3 </since_tizen>
662         protected override void OnCreate()
663         {
664             Tizen.Tracer.Begin("[NUI] OnCreate()");
665             currentState = State.Created;
666
667             base.OnCreate();
668
669             Tizen.Tracer.End();
670         }
671
672         /// <summary>
673         /// This is used to improve application launch performance.
674         /// </summary>
675         [EditorBrowsable(EditorBrowsableState.Never)]
676         static public void Preload()
677         {
678             Interop.Application.PreInitialize();
679
680             // Initialize some static utility
681             var disposalbeQueue = DisposeQueue.Instance;
682             var registry = Registry.Instance;
683
684             // Initialize some BaseComponent static variables now
685             BaseComponents.View.Preload();
686             BaseComponents.ImageView.Preload();
687             BaseComponents.TextLabel.Preload();
688             BaseComponents.TextEditor.Preload();
689             BaseComponents.TextField.Preload();
690             Disposable.Preload();
691
692             // Initialize exception tasks. It must be called end of Preload()
693             NDalicPINVOKE.Preload();
694
695             IsPreload = true;
696         }
697
698         /// <summary>
699         /// Check if it is loaded as dotnet-loader-nui.
700         /// </summary>
701         static internal bool IsPreload { get; set; }
702
703         private void ApplyThemeOption(ThemeOptions option)
704         {
705             if ((option & ThemeOptions.PlatformThemeEnabled) != 0)
706             {
707                 ThemeManager.PlatformThemeEnabled = true;
708             }
709
710             if ((option & ThemeOptions.ThemeChangeSensitive) != 0)
711             {
712                 ThemeManager.ApplicationThemeChangeSensitive = true;
713             }
714         }
715
716         private void EnableBorder(IBorderInterface borderInterface)
717         {
718             borderEnabled = true;
719             this.borderInterface = borderInterface;
720         }
721     }
722
723     /// <summary>
724     /// Graphics Backend Type.
725     /// </summary>
726     [SuppressMessage("Microsoft.Design", "CA1052:StaticHolderTypesShouldBeStaticOrNotInheritable")]
727     [EditorBrowsable(EditorBrowsableState.Never)]
728     [Obsolete("Do not use! This will be deprecated!")]
729     public class Graphics
730     {
731         /// <summary>
732         /// Graphics Backend Type.
733         /// </summary>
734         public enum BackendType
735         {
736             /// <summary>
737             /// The GLES backend.
738             /// </summary>
739             Gles,
740             /// <summary>
741             /// The Vulkan backend.
742             /// </summary>
743             Vulkan
744         }
745
746         /// <summary>
747         /// The backend used by the NUIApplication.
748         /// </summary>
749         [EditorBrowsable(EditorBrowsableState.Never)]
750         internal static BackendType Backend = BackendType.Gles;
751
752         internal const string GlesCSharpBinder = NDalicPINVOKE.Lib;
753         internal const string VulkanCSharpBinder = "libdali-csharp-binder-vk.so";
754     }
755
756     /// <summary>
757     /// Enum of Application status
758     /// </summary>
759     // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
760     [EditorBrowsable(EditorBrowsableState.Never)]
761     public enum State
762     {
763         /// <summary>
764         /// Invalid
765         /// </summary>
766         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
767         [EditorBrowsable(EditorBrowsableState.Never)]
768         Invalid = -1,
769         /// <summary>
770         /// Ready
771         /// </summary>
772         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
773         [EditorBrowsable(EditorBrowsableState.Never)]
774         Ready,
775         /// <summary>
776         /// PreCreated
777         /// </summary>
778         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
779         [EditorBrowsable(EditorBrowsableState.Never)]
780         PreCreated,
781         /// <summary>
782         /// Created
783         /// </summary>
784         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
785         [EditorBrowsable(EditorBrowsableState.Never)]
786         Created,
787         /// <summary>
788         /// Resumed
789         /// </summary>
790         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
791         [EditorBrowsable(EditorBrowsableState.Never)]
792         Resumed,
793         /// <summary>
794         /// Paused
795         /// </summary>
796         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
797         [EditorBrowsable(EditorBrowsableState.Never)]
798         Paused,
799         /// <summary>
800         /// Terminated
801         /// </summary>
802         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
803         [EditorBrowsable(EditorBrowsableState.Never)]
804         Terminated
805     }
806 }