2 * Copyright (c) 2017 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.
19 using System.Collections.Generic;
21 using Tizen.Applications.CoreBackend;
22 using Tizen.Applications;
27 class NUICoreBackend : ICoreBackend
30 /// Application instance to connect event.
32 protected Application _application;
35 /// Dictionary to contain each type of event callback.
37 protected IDictionary<EventType, object> Handlers = new Dictionary<EventType, object>();
40 /// The default Constructor.
42 public NUICoreBackend()
44 _application = Application.NewApplication();
48 /// The constructor with stylesheet.
50 public NUICoreBackend(string stylesheet)
52 _application = Application.NewApplication(stylesheet);
56 /// The constructor with stylesheet and window mode.
58 public NUICoreBackend(string stylesheet, NUIApplication.WindowMode windowMode)
60 _application = Application.NewApplication(stylesheet, (Application.WindowMode)windowMode );
64 /// Add NUIApplication event to Application.
65 /// Put each type of event callback in Dictionary.
67 /// <param name="evType">Type of event</param>
68 /// <param name="handler">Event callback</param>
69 public void AddEventHandler(EventType evType, Action handler)
71 Handlers.Add(evType, handler);
75 /// Add NUIApplication event to Application.
76 /// Put each type of event callback in Dictionary.
78 /// <typeparam name="TEventArgs">Argument type for the event</typeparam>
79 /// <param name="evType">Type of event</param>
80 /// <param name="handler">Event callback</param>
81 public void AddEventHandler<TEventArgs>(EventType evType, Action<TEventArgs> handler) where TEventArgs : EventArgs
83 Handlers.Add(evType, handler);
92 _application.Dispose();
106 /// <param name="args">Arguments from commandline.</param>
107 public void Run(string[] args)
109 TizenSynchronizationContext.Initialize();
110 _application.BatteryLow += OnBatteryLow;
111 _application.LanguageChanged += OnLanguageChanged;
112 _application.MemoryLow += OnMemoryLow;
113 _application.RegionChanged += OnRegionChanged;
115 _application.Initialized += OnInitialized;
116 _application.Resumed += OnResumed;
117 _application.Terminating += OnTerminated;
118 _application.Paused += OnPaused;
119 _application.AppControl += OnAppControl;
121 _application.MainLoop();
125 /// Region changed event callback function.
127 /// <param name="source">Application instance</param>
128 /// <param name="e">Event argument for RegionChanged</param>
129 private void OnRegionChanged(object source, NUIApplicationRegionChangedEventArgs e)
131 Log.Debug("NUI", "NUICorebackend OnRegionChanged Called");
132 var handler = Handlers[EventType.RegionFormatChanged] as Action<RegionFormatChangedEventArgs>;
133 // Need to make new signal return in native to return right value.
134 handler?.Invoke( new RegionFormatChangedEventArgs(""));
138 /// Memory Low event callback function.
140 /// <param name="source">Application instance</param>
141 /// <param name="e">Event argument for MemoryLow</param>
142 private void OnMemoryLow(object source, NUIApplicationMemoryLowEventArgs e)
144 Log.Debug("NUI", "NUICorebackend OnMemoryLow Called");
145 var handler = Handlers[EventType.LowMemory] as Action<LowMemoryEventArgs>;
146 // Need to make new signal return in native to return right value.
147 handler?.Invoke( new LowMemoryEventArgs(LowMemoryStatus.None));
151 /// Language changed event callback function.
153 /// <param name="source">Application instance</param>
154 /// <param name="e">Event argument for LanguageChanged</param>
155 private void OnLanguageChanged(object source, NUIApplicationLanguageChangedEventArgs e)
157 Log.Debug("NUI", "NUICorebackend OnLanguageChanged Called");
158 var handler = Handlers[EventType.LocaleChanged] as Action<LocaleChangedEventArgs>;
159 // Need to make new signal return in native to return right value.
160 handler?.Invoke( new LocaleChangedEventArgs(""));
164 /// Battery low event callback function.
166 /// <param name="source">Application instance</param>
167 /// <param name="e">Event argument for BatteryLow</param>
168 private void OnBatteryLow(object source, NUIApplicationBatteryLowEventArgs e)
170 Log.Debug("NUI", "NUICorebackend OnBatteryLow Called");
171 var handler = Handlers[EventType.LowBattery] as Action<LowBatteryEventArgs>;
172 // Need to make new signal return in native to return right value.
173 handler?.Invoke(new LowBatteryEventArgs(LowBatteryStatus.None));
177 /// Initialized event callback function.
179 /// <param name="source">Application instance</param>
180 /// <param name="e">Event argument for Initialized</param>
181 private void OnInitialized(object source, NUIApplicationInitEventArgs e)
183 Log.Debug("NUI", "NUICorebackend OnPreCreated Called");
184 var preCreateHandler = Handlers[EventType.PreCreated] as Action;
185 preCreateHandler?.Invoke();
187 Log.Debug("NUI", "NUICorebackend OnCreate Called");
188 var createHandler = Handlers[EventType.Created] as Action;
189 createHandler?.Invoke();
193 /// Terminated event callback function.
195 /// <param name="source">Application instance</param>
196 /// <param name="e">Event argument for Terminated</param>
197 private void OnTerminated(object source, NUIApplicationTerminatingEventArgs e)
199 Log.Debug("NUI", "NUICorebackend OnTerminated Called");
200 var handler = Handlers[EventType.Terminated] as Action;
205 /// Resumed event callback function.
207 /// <param name="source">Application instance</param>
208 /// <param name="e">Event argument for Resumed</param>
209 private void OnResumed(object source, NUIApplicationResumedEventArgs e)
211 Log.Debug("NUI", "NUICorebackend OnResumed Called");
212 var handler = Handlers[EventType.Resumed] as Action;
217 /// App control event callback function.
219 /// <param name="source">Application instance</param>
220 /// <param name="e">Event argument for AppControl</param>
221 private void OnAppControl(object source, NUIApplicationAppControlEventArgs e)
223 Log.Debug("NUI", "NUICorebackend OnAppControl Called");
224 /* can invoke after making new api which getting control handle at application.
225 var handler = Handlers[EventType.AppControlReceived] as Action<AppControlReceivedEventArgs>;
231 /// Paused event callback function.
233 /// <param name="source">Application instance</param>
234 /// <param name="e">Event argument for Paused</param>
235 private void OnPaused(object source, NUIApplicationPausedEventArgs e)
237 Log.Debug("NUI", "NUICorebackend OnPaused Called");
238 var handler = Handlers[EventType.Paused] as Action;
243 internal Application ApplicationHandle