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.
12 namespace Tizen.Applications
15 /// The Application handles an application state change or system events and provides mechanisms that launch other applications.
17 public abstract class Application
19 private static Application s_CurrentApplication = null;
21 private Interop.AppEvent.SafeAppEventHandle _lowMemoryNativeHandle;
22 private Interop.AppEvent.SafeAppEventHandle _localeChangedNativeHandle;
25 /// The low memory event.
27 public event EventHandler<LowMemoryEventArgs> LowMemory;
30 /// The system language changed event.
32 public event EventHandler<LocaleChangedEventArgs> LocaleChanged;
37 public static Application Current { get { return s_CurrentApplication; } }
42 public ApplicationInfo ApplicationInfo { get; internal set; }
45 /// Runs the application's main loop.
47 /// <param name="args"></param>
48 public virtual void Run(string[] args)
50 s_CurrentApplication = this;
52 Interop.AppEvent.AddEventHandler(Interop.AppEvent.EventNames.LowMemory, HandleAppEvent, IntPtr.Zero, out _lowMemoryNativeHandle);
53 Interop.AppEvent.AddEventHandler(Interop.AppEvent.EventNames.LanguageSet, HandleAppEvent, IntPtr.Zero, out _localeChangedNativeHandle);
57 /// Exits the main loop of application.
59 public abstract void Exit();
64 protected virtual void OnCreate()
71 protected virtual void OnTerminate()
78 /// <param name="control"></param>
79 protected virtual void OnAppControlReceived(ReceivedAppControl control)
86 /// <param name="e"></param>
87 protected virtual void OnLowMemory(LowMemoryEventArgs e)
89 EventHandler<LowMemoryEventArgs> eh = LowMemory;
99 /// <param name="e"></param>
100 protected virtual void OnLocaleChanged(LocaleChangedEventArgs e)
102 EventHandler<LocaleChangedEventArgs> eh = LocaleChanged;
109 internal void SendCreate()
111 ApplicationInfo = new ApplicationInfo();
115 private void HandleAppEvent(string eventName, IntPtr eventData, IntPtr data)
117 Console.WriteLine("HandleAppEvent!! eventName={0}, eventData={1}", eventName, eventData);
118 Bundle b = new Bundle(eventData);
119 if (eventName == Interop.AppEvent.EventNames.LowMemory)
121 string value = b.GetItem<string>(Interop.AppEvent.EventKeys.LowMemory);
122 LowMemoryStatus status = LowMemoryStatus.Normal;
123 if (value == Interop.AppEvent.EventValues.MemorySoftWarning)
125 status = LowMemoryStatus.SoftWarning;
127 else if (value == Interop.AppEvent.EventValues.MemoryHardWarning)
129 status = LowMemoryStatus.HardWarning;
131 OnLowMemory(new LowMemoryEventArgs { LowMemoryStatus = status });
133 else if (eventName == Interop.AppEvent.EventNames.LanguageSet)
135 string value = b.GetItem<string>(Interop.AppEvent.EventKeys.LanguageSet);
136 OnLocaleChanged(new LocaleChangedEventArgs { Locale = value });