[Application] Add CurrentDeviceOrientation property on CoreUIApplication (#560)
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.UI / Tizen.Applications / CoreUIApplication.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 using System;
18
19 using Tizen.Applications.CoreBackend;
20
21 namespace Tizen.Applications
22 {
23     /// <summary>
24     /// Represents an application that has an UI screen. The events for resuming and pausing are provided.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     public class CoreUIApplication : CoreApplication
28     {
29         /// <summary>
30         /// Initializes the CoreUIApplication class.
31         /// </summary>
32         /// <remarks>
33         /// The default backend for the UI application will be used.
34         /// </remarks>
35         /// <since_tizen> 3 </since_tizen>
36         public CoreUIApplication() : base(new UICoreBackend())
37         {
38         }
39
40         /// <summary>
41         /// Initializes the CoreUIApplication class.
42         /// </summary>
43         /// <remarks>
44         /// If you want to change the backend, use this constructor.
45         /// </remarks>
46         /// <param name="backend">The backend instance implementing the ICoreBacked interface.</param>
47         /// <since_tizen> 3 </since_tizen>
48         public CoreUIApplication(ICoreBackend backend) : base(backend)
49         {
50         }
51
52         /// <summary>
53         /// Gets the current device orientation.
54         /// </summary>
55         /// <since_tizen> 6 </since_tizen>
56         static public DeviceOrientation CurrentDeviceOrientation
57         {
58             get
59             {
60                 return Interop.Application.AppGetDeviceOrientation();
61             }
62         }
63
64         /// <summary>
65         /// Occurs whenever the application is resumed.
66         /// </summary>
67         /// <since_tizen> 3 </since_tizen>
68         public event EventHandler Resumed;
69
70         /// <summary>
71         /// Occurs whenever the application is paused.
72         /// </summary>
73         /// <since_tizen> 3 </since_tizen>
74         public event EventHandler Paused;
75
76         /// <summary>
77         /// Runs the UI application's main loop.
78         /// </summary>
79         /// <param name="args">Arguments from the commandline.</param>
80         /// <since_tizen> 3 </since_tizen>
81         public override void Run(string[] args)
82         {
83             Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
84             Backend.AddEventHandler(EventType.Resumed, OnResume);
85             Backend.AddEventHandler(EventType.Paused, OnPause);
86             base.Run(args);
87         }
88
89         /// <summary>
90         /// Overrides this method if you want to handle the behavior before calling OnCreate().
91         /// </summary>
92         /// <since_tizen> 3 </since_tizen>
93         protected virtual void OnPreCreate()
94         {
95         }
96
97         /// <summary>
98         /// Overrides this method if you want to handle the behavior when the application is resumed.
99         /// If base.OnResume() is not called, the event 'Resumed' will not be emitted.
100         /// </summary>
101         /// <since_tizen> 3 </since_tizen>
102         protected virtual void OnResume()
103         {
104             Resumed?.Invoke(this, EventArgs.Empty);
105         }
106
107         /// <summary>
108         /// Overrides this method if you want to handle the behavior when the application is paused.
109         /// If base.OnPause() is not called, the event 'Paused' will not be emitted.
110         /// </summary>
111         /// <since_tizen> 3 </since_tizen>
112         protected virtual void OnPause()
113         {
114             Paused?.Invoke(this, EventArgs.Empty);
115         }
116     }
117 }