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 /// Class that represents an application controlled lifecycles by the backend system.
26 public class CoreApplication : Application
28 private readonly ICoreBackend _backend;
29 private bool _disposedValue = false;
32 /// Initializes the CoreApplication class.
34 /// <param name="backend">The backend instance implementing ICoreBacked interface.</param>
35 public CoreApplication(ICoreBackend backend)
41 /// Occurs when the application is launched.
43 public event EventHandler Created;
46 /// Occurs when the application is about to shutdown.
48 public event EventHandler Terminated;
51 /// Occurs whenever the application receives the appcontrol message.
53 public event EventHandler<AppControlReceivedEventArgs> AppControlReceived;
56 /// Occurs when the system memory is low.
58 public event EventHandler<LowMemoryEventArgs> LowMemory;
61 /// Occurs when the system battery is low.
63 public event EventHandler<LowBatteryEventArgs> LowBattery;
66 /// Occurs when the system language is chagned.
68 public event EventHandler<LocaleChangedEventArgs> LocaleChanged;
71 /// Occurs when the region format is changed.
73 public event EventHandler<RegionFormatChangedEventArgs> RegionFormatChanged;
76 /// The backend instance.
78 protected ICoreBackend Backend { get { return _backend; } }
81 /// Runs the application's main loop.
83 /// <param name="args">Arguments from commandline.</param>
84 public override void Run(string[] args)
88 _backend.AddEventHandler(EventType.Created, OnCreate);
89 _backend.AddEventHandler(EventType.Terminated, OnTerminate);
90 _backend.AddEventHandler<AppControlReceivedEventArgs>(EventType.AppControlReceived, OnAppControlReceived);
91 _backend.AddEventHandler<LowMemoryEventArgs>(EventType.LowMemory, OnLowMemory);
92 _backend.AddEventHandler<LowBatteryEventArgs>(EventType.LowBattery, OnLowBattery);
93 _backend.AddEventHandler<LocaleChangedEventArgs>(EventType.LocaleChanged, OnLocaleChanged);
94 _backend.AddEventHandler<RegionFormatChangedEventArgs>(EventType.RegionFormatChanged, OnRegionFormatChanged);
96 string[] argsClone = new string[args.Length + 1];
97 argsClone[0] = string.Empty;
98 args.CopyTo(argsClone, 1);
99 _backend.Run(argsClone);
103 /// Exits the main loop of the application.
105 public override void Exit()
111 /// Overrides this method if want to handle behavior when the application is launched.
112 /// If base.OnCreated() is not called, the event 'Created' will not be emitted.
114 protected virtual void OnCreate()
116 Created?.Invoke(this, EventArgs.Empty);
120 /// Overrides this method if want to handle behavior when the application is terminated.
121 /// If base.OnTerminate() is not called, the event 'Terminated' will not be emitted.
123 protected virtual void OnTerminate()
125 Terminated?.Invoke(this, EventArgs.Empty);
129 /// Overrides this method if want to handle behavior when the application receives the appcontrol message.
130 /// If base.OnAppControlReceived() is not called, the event 'AppControlReceived' will not be emitted.
132 /// <param name="e"></param>
133 protected virtual void OnAppControlReceived(AppControlReceivedEventArgs e)
135 AppControlReceived?.Invoke(this, e);
139 /// Overrides this method if want to handle behavior when the system memory is low.
140 /// If base.OnLowMemory() is not called, the event 'LowMemory' will not be emitted.
142 protected virtual void OnLowMemory(LowMemoryEventArgs e)
144 LowMemory?.Invoke(this, e);
149 /// Overrides this method if want to handle behavior when the system battery is low.
150 /// If base.OnLowBattery() is not called, the event 'LowBattery' will not be emitted.
152 protected virtual void OnLowBattery(LowBatteryEventArgs e)
154 LowBattery?.Invoke(this, e);
158 /// Overrides this method if want to handle behavior when the system language is changed.
159 /// If base.OnLocaleChanged() is not called, the event 'LocaleChanged' will not be emitted.
161 protected virtual void OnLocaleChanged(LocaleChangedEventArgs e)
163 LocaleChanged?.Invoke(this, e);
167 /// Overrides this method if want to handle behavior when the region format is changed.
168 /// If base.OnRegionFormatChanged() is not called, the event 'RegionFormatChanged' will not be emitted.
170 protected virtual void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
172 RegionFormatChanged?.Invoke(this, e);
176 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
178 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
179 protected override void Dispose(bool disposing)
188 _disposedValue = true;
190 base.Dispose(disposing);