2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 Tizen.Applications.CoreBackend;
21 namespace Tizen.Applications
24 /// This class represents an application controlled lifecycles by the backend system.
26 /// <since_tizen> 3 </since_tizen>
27 public class CoreApplication : Application
29 private readonly ICoreBackend _backend;
30 private bool _disposedValue = false;
33 /// Initializes the CoreApplication class.
35 /// <param name="backend">The backend instance implementing ICoreBacked interface.</param>
36 /// <since_tizen> 3 </since_tizen>
37 public CoreApplication(ICoreBackend backend)
43 /// Occurs when the application is launched.
45 /// <since_tizen> 3 </since_tizen>
46 public event EventHandler Created;
49 /// Occurs when the application is about to shutdown.
51 /// <since_tizen> 3 </since_tizen>
52 public event EventHandler Terminated;
55 /// Occurs whenever the application receives the appcontrol message.
57 /// <since_tizen> 3 </since_tizen>
58 public event EventHandler<AppControlReceivedEventArgs> AppControlReceived;
61 /// Occurs when the system memory is low.
63 /// <since_tizen> 3 </since_tizen>
64 public event EventHandler<LowMemoryEventArgs> LowMemory;
67 /// Occurs when the system battery is low.
69 /// <since_tizen> 3 </since_tizen>
70 public event EventHandler<LowBatteryEventArgs> LowBattery;
73 /// Occurs when the system language is chagned.
75 /// <since_tizen> 3 </since_tizen>
76 public event EventHandler<LocaleChangedEventArgs> LocaleChanged;
79 /// Occurs when the region format is changed.
81 /// <since_tizen> 3 </since_tizen>
82 public event EventHandler<RegionFormatChangedEventArgs> RegionFormatChanged;
85 /// Occurs when the device orientation is changed.
87 /// <since_tizen> 3 </since_tizen>
88 public event EventHandler<DeviceOrientationEventArgs> DeviceOrientationChanged;
91 /// The backend instance.
93 /// <since_tizen> 3 </since_tizen>
94 protected ICoreBackend Backend { get { return _backend; } }
97 /// Runs the application's main loop.
99 /// <param name="args">Arguments from commandline.</param>
100 /// <since_tizen> 3 </since_tizen>
101 public override void Run(string[] args)
105 _backend.AddEventHandler(EventType.Created, OnCreate);
106 _backend.AddEventHandler(EventType.Terminated, OnTerminate);
107 _backend.AddEventHandler<AppControlReceivedEventArgs>(EventType.AppControlReceived, OnAppControlReceived);
108 _backend.AddEventHandler<LowMemoryEventArgs>(EventType.LowMemory, OnLowMemory);
109 _backend.AddEventHandler<LowBatteryEventArgs>(EventType.LowBattery, OnLowBattery);
110 _backend.AddEventHandler<LocaleChangedEventArgs>(EventType.LocaleChanged, OnLocaleChanged);
111 _backend.AddEventHandler<RegionFormatChangedEventArgs>(EventType.RegionFormatChanged, OnRegionFormatChanged);
112 _backend.AddEventHandler<DeviceOrientationEventArgs>(EventType.DeviceOrientationChanged, OnDeviceOrientationChanged);
114 string[] argsClone = null;
118 argsClone = new string[1];
122 argsClone = new string[args.Length + 1];
123 args.CopyTo(argsClone, 1);
125 argsClone[0] = string.Empty;
126 _backend.Run(argsClone);
130 /// Exits the main loop of the application.
132 /// <since_tizen> 3 </since_tizen>
133 public override void Exit()
139 /// Overrides this method if want to handle behavior when the application is launched.
140 /// If base.OnCreated() is not called, the event 'Created' will not be emitted.
142 /// <since_tizen> 3 </since_tizen>
143 protected virtual void OnCreate()
145 Created?.Invoke(this, EventArgs.Empty);
149 /// Overrides this method if want to handle behavior when the application is terminated.
150 /// If base.OnTerminate() is not called, the event 'Terminated' will not be emitted.
152 /// <since_tizen> 3 </since_tizen>
153 protected virtual void OnTerminate()
155 Terminated?.Invoke(this, EventArgs.Empty);
159 /// Overrides this method if want to handle behavior when the application receives the appcontrol message.
160 /// If base.OnAppControlReceived() is not called, the event 'AppControlReceived' will not be emitted.
162 /// <param name="e"></param>
163 /// <since_tizen> 3 </since_tizen>
164 protected virtual void OnAppControlReceived(AppControlReceivedEventArgs e)
166 AppControlReceived?.Invoke(this, e);
170 /// Overrides this method if want to handle behavior when the system memory is low.
171 /// If base.OnLowMemory() is not called, the event 'LowMemory' will not be emitted.
173 /// <since_tizen> 3 </since_tizen>
174 protected virtual void OnLowMemory(LowMemoryEventArgs e)
176 LowMemory?.Invoke(this, e);
181 /// Overrides this method if want to handle behavior when the system battery is low.
182 /// If base.OnLowBattery() is not called, the event 'LowBattery' will not be emitted.
184 /// <since_tizen> 3 </since_tizen>
185 protected virtual void OnLowBattery(LowBatteryEventArgs e)
187 LowBattery?.Invoke(this, e);
191 /// Overrides this method if want to handle behavior when the system language is changed.
192 /// If base.OnLocaleChanged() is not called, the event 'LocaleChanged' will not be emitted.
194 /// <since_tizen> 3 </since_tizen>
195 protected virtual void OnLocaleChanged(LocaleChangedEventArgs e)
197 LocaleChanged?.Invoke(this, e);
201 /// Overrides this method if want to handle behavior when the region format is changed.
202 /// If base.OnRegionFormatChanged() is not called, the event 'RegionFormatChanged' will not be emitted.
204 /// <since_tizen> 3 </since_tizen>
205 protected virtual void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
207 RegionFormatChanged?.Invoke(this, e);
211 /// Overrides this method if want to handle behavior when the device orientation is changed.
212 /// If base.OnRegionFormatChanged() is not called, the event 'RegionFormatChanged' will not be emitted.
214 /// <since_tizen> 3 </since_tizen>
215 protected virtual void OnDeviceOrientationChanged(DeviceOrientationEventArgs e)
217 DeviceOrientationChanged?.Invoke(this, e);
221 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
223 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
224 /// <since_tizen> 3 </since_tizen>
225 protected override void Dispose(bool disposing)
234 _disposedValue = true;
236 base.Dispose(disposing);