1 // Copyright 2016 by Samsung Electronics, Inc.,
3 // This software is the confidential and proprietary information
4 // of Samsung Electronics, Inc. ("Confidential Information"). You
5 // shall not disclose such Confidential Information and shall use
6 // it only in accordance with the terms of the license agreement
7 // you entered into with Samsung.
11 using Tizen.Applications.CoreBackend;
13 namespace Tizen.Applications
16 /// Class that represents an application controlled lifecycles by the backend system.
18 public class CoreApplication : Application
20 private readonly ICoreBackend _backend;
21 private bool _disposedValue = false;
24 /// Initializes the CoreApplication class.
26 /// <param name="backend">The backend instance implementing ICoreBacked interface.</param>
27 public CoreApplication(ICoreBackend backend)
33 /// Occurs when the application is launched.
35 public event EventHandler Created;
38 /// Occurs when the application is about to shutdown.
40 public event EventHandler Terminated;
43 /// Occurs whenever the application receives the appcontrol message.
45 public event EventHandler<AppControlReceivedEventArgs> AppControlReceived;
48 /// Occurs when the system memory is low.
50 public event EventHandler<LowMemoryEventArgs> LowMemory;
53 /// Occurs when the system battery is low.
55 public event EventHandler<LowBatteryEventArgs> LowBattery;
58 /// Occurs when the system language is chagned.
60 public event EventHandler<LocaleChangedEventArgs> LocaleChanged;
63 /// Occurs when the region format is changed.
65 public event EventHandler<RegionFormatChangedEventArgs> RegionFormatChanged;
68 /// The backend instance.
70 protected ICoreBackend Backend { get { return _backend; } }
73 /// Runs the application's main loop.
75 /// <param name="args">Arguments from commandline.</param>
76 public override void Run(string[] args)
80 _backend.AddEventHandler(EventType.Created, OnCreate);
81 _backend.AddEventHandler(EventType.Terminated, OnTerminate);
82 _backend.AddEventHandler<AppControlReceivedEventArgs>(EventType.AppControlReceived, OnAppControlReceived);
83 _backend.AddEventHandler<LowMemoryEventArgs>(EventType.LowMemory, OnLowMemory);
84 _backend.AddEventHandler<LowBatteryEventArgs>(EventType.LowBattery, OnLowBattery);
85 _backend.AddEventHandler<LocaleChangedEventArgs>(EventType.LocaleChanged, OnLocaleChanged);
86 _backend.AddEventHandler<RegionFormatChangedEventArgs>(EventType.RegionFormatChanged, OnRegionFormatChanged);
92 /// Exits the main loop of the application.
94 public override void Exit()
100 /// Overrides this method if want to handle behavior when the application is launched.
101 /// If base.OnCreated() is not called, the event 'Created' will not be emitted.
103 protected virtual void OnCreate()
105 Created?.Invoke(this, EventArgs.Empty);
109 /// Overrides this method if want to handle behavior when the application is terminated.
110 /// If base.OnTerminate() is not called, the event 'Terminated' will not be emitted.
112 protected virtual void OnTerminate()
114 Terminated?.Invoke(this, EventArgs.Empty);
118 /// Overrides this method if want to handle behavior when the application receives the appcontrol message.
119 /// If base.OnAppControlReceived() is not called, the event 'AppControlReceived' will not be emitted.
121 /// <param name="e"></param>
122 protected virtual void OnAppControlReceived(AppControlReceivedEventArgs e)
124 AppControlReceived?.Invoke(this, e);
128 /// Overrides this method if want to handle behavior when the system memory is low.
129 /// If base.OnLowMemory() is not called, the event 'LowMemory' will not be emitted.
131 protected virtual void OnLowMemory(LowMemoryEventArgs e)
133 LowMemory?.Invoke(this, e);
137 /// Overrides this method if want to handle behavior when the system battery is low.
138 /// If base.OnLowBattery() is not called, the event 'LowBattery' will not be emitted.
140 protected virtual void OnLowBattery(LowBatteryEventArgs e)
142 LowBattery?.Invoke(this, e);
146 /// Overrides this method if want to handle behavior when the system language is changed.
147 /// If base.OnLocaleChanged() is not called, the event 'LocaleChanged' will not be emitted.
149 protected virtual void OnLocaleChanged(LocaleChangedEventArgs e)
151 LocaleChanged?.Invoke(this, e);
155 /// Overrides this method if want to handle behavior when the region format is changed.
156 /// If base.OnRegionFormatChanged() is not called, the event 'RegionFormatChanged' will not be emitted.
158 protected virtual void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
160 RegionFormatChanged?.Invoke(this, e);
164 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
166 /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param>
167 protected override void Dispose(bool disposing)
176 _disposedValue = true;
178 base.Dispose(disposing);