173ad5cb9e1ac178ffd33242b5c0bb1422c16550
[platform/core/csapi/nui.git] / Tizen.NUI / src / public / NUIApplication.cs
1 /*
2  * Copyright (c) 2016 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 Tizen.Applications;
20 using Tizen.Applications.CoreBackend;
21 using Tizen.NUI;
22
23 namespace Tizen.NUI
24 {
25
26     /// <summary>
27     /// Represents an application that have UI screen. The NUIApplication class has a default stage.
28     /// </summary>
29     public class NUIApplication : CoreApplication
30     {
31         /// <summary>
32         /// The default constructor.
33         /// </summary>
34         public NUIApplication() : base(new NUICoreBackend())
35         {
36         }
37
38         /// <summary>
39         /// The constructor with stylesheet.
40         /// </summary>
41         public NUIApplication(string stylesheet) : base(new NUICoreBackend(stylesheet))
42         {
43         }
44
45         /// <summary>
46         /// The constructor with stylesheet and window mode.
47         /// </summary>
48         public NUIApplication(string stylesheet, WindowMode windowMode) : base(new NUICoreBackend(stylesheet,windowMode))
49         {
50         }
51
52         /// <summary>
53         /// Overrides this method if want to handle behavior.
54         /// </summary>
55         protected override void OnLocaleChanged(LocaleChangedEventArgs e)
56         {
57         }
58
59         /// <summary>
60         /// Overrides this method if want to handle behavior.
61         /// </summary>
62         protected override void OnLowBattery(LowBatteryEventArgs e)
63         {
64             Log.Debug("NUI", "OnLowBattery() is called!");
65         }
66
67         /// <summary>
68         /// Overrides this method if want to handle behavior.
69         /// </summary>
70         protected override void OnLowMemory(LowMemoryEventArgs e)
71         {
72             Log.Debug("NUI", "OnLowMemory() is called!");
73         }
74
75         /// <summary>
76         /// Overrides this method if want to handle behavior.
77         /// </summary>
78         protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
79         {
80             Log.Debug("NUI", "OnRegionFormatChanged() is called!");
81         }
82
83         /// <summary>
84         /// Overrides this method if want to handle behavior.
85         /// </summary>
86         protected override void OnTerminate()
87         {
88             Log.Debug("NUI", "OnTerminate() is called!");
89         }
90
91         /// <summary>
92         /// Overrides this method if want to handle behavior.
93         /// </summary>
94         protected void OnPause()
95         {
96         }
97
98         /// <summary>
99         /// Overrides this method if want to handle behavior.
100         /// </summary>
101         protected void OnResume()
102         {
103             Log.Debug("NUI", "OnResume() is called!");
104         }
105
106         /// <summary>
107         /// Overrides this method if want to handle behavior.
108         /// </summary>
109         protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
110         {
111             Log.Debug("NUI", "OnAppControlReceived() is called!");
112             if (e != null)
113             {
114                 Log.Debug("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
115                 Log.Debug("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + "   IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
116             }
117         }
118
119         /// <summary>
120         /// Overrides this method if want to handle behavior.
121         /// </summary>
122         protected override void OnCreate()
123         {
124             // This is also required to create DisposeQueue on main thread.
125             DisposeQueue disposeQ = DisposeQueue.Instance;
126             disposeQ.Initialize();
127             Log.Debug("NUI","OnCreate() is called!");
128         }
129
130         /// <summary>
131         /// Run NUIApplication.
132         /// </summary>
133         /// <param name="args">Arguments from commandline.</param>
134         public override void Run(string[] args)
135         {
136             string[] argsClone = null;
137
138             if (args == null)
139             {
140                 argsClone = new string[1];
141             }
142             else
143             {
144                 argsClone = new string[args.Length + 1];
145                 args.CopyTo(argsClone, 1);
146             }
147             argsClone[0] = string.Empty;
148
149             Backend.AddEventHandler(EventType.Resumed, OnResume);
150             Backend.AddEventHandler<AppControlReceivedEventArgs>(EventType.AppControlReceived, OnAppControlReceived);
151             Backend.AddEventHandler(EventType.Paused, OnPause);
152             Backend.AddEventHandler(EventType.Terminated, OnTerminate);
153             Backend.AddEventHandler<RegionFormatChangedEventArgs>(EventType.RegionFormatChanged, OnRegionFormatChanged);
154             Backend.AddEventHandler<LowMemoryEventArgs>(EventType.LowMemory, OnLowMemory);
155             Backend.AddEventHandler<LowBatteryEventArgs>(EventType.LowBattery, OnLowBattery);
156             Backend.AddEventHandler<LocaleChangedEventArgs>(EventType.LocaleChanged, OnLocaleChanged);
157             Backend.AddEventHandler(EventType.Created, OnCreate);
158
159             Backend.Run(argsClone);
160         }
161
162         /// <summary>
163         /// Exit NUIApplication.
164         /// </summary>
165         public override void Exit()
166         {
167             Backend.Exit();
168         }
169
170         /// <summary>
171         /// Enumeration for deciding whether a NUI application window is opaque or transparent.
172         /// </summary>
173         public enum WindowMode
174         {
175             Opaque = 0,
176             Transparent = 1
177         }
178     }
179 }