From: WonYoung Choi Date: Fri, 10 Jun 2016 07:43:38 +0000 (+0900) Subject: Add UIApplicationBase class X-Git-Tag: submit/trunk/20170823.075128~121^2~145 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=331714c54176026c55522e1d97748cdb8dd71238;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Add UIApplicationBase class UIApplicationBase class has only lifecycle functionalities except Window management. UIApplication extends this class and provides Window property. Change-Id: I0b166927dca68fd4207b17738a259ebf05b62878 --- diff --git a/Tizen.Applications/Tizen.Applications.csproj b/Tizen.Applications/Tizen.Applications.csproj index 209ab9e..8a2f12f 100644 --- a/Tizen.Applications/Tizen.Applications.csproj +++ b/Tizen.Applications/Tizen.Applications.csproj @@ -113,6 +113,7 @@ + diff --git a/Tizen.Applications/Tizen.Applications/UIApplication.cs b/Tizen.Applications/Tizen.Applications/UIApplication.cs index 9648ef0..e3e4d69 100644 --- a/Tizen.Applications/Tizen.Applications/UIApplication.cs +++ b/Tizen.Applications/Tizen.Applications/UIApplication.cs @@ -6,41 +6,15 @@ // it only in accordance with the terms of the license agreement // you entered into with Samsung. -using System; -using Tizen.Internals.Errors; using Tizen.UI; namespace Tizen.Applications { /// - /// Represents an application that have UI screen. It has additional events for handling 'Resumed' and 'Paused' states. + /// Represents an application that have UI screen. The UIApplication class has a default main window. /// - public class UIApplication : Application + public class UIApplication : UIApplicationBase { - private Interop.Application.UIAppLifecycleCallbacks _callbacks; - - /// - /// Initializes UIApplication class. - /// - public UIApplication() - { - _callbacks.OnCreate = new Interop.Application.AppCreateCallback(OnCreateNative); - _callbacks.OnTerminate = new Interop.Application.AppTerminateCallback(OnTerminateNative); - _callbacks.OnAppControl = new Interop.Application.AppControlCallback(OnAppControlNative); - _callbacks.OnResume = new Interop.Application.AppResumeCallback(OnResumeNative); - _callbacks.OnPause = new Interop.Application.AppPauseCallback(OnPauseNative); - } - - /// - /// Occurs whenever the application is resumed. - /// - public event EventHandler Resumed; - - /// - /// Occurs whenever the application is paused. - /// - public event EventHandler Paused; - /// /// The main window instance of the UIApplication. /// @@ -50,85 +24,16 @@ namespace Tizen.Applications public Window Window { get; private set; } /// - /// Runs the UI application's main loop. - /// - /// Arguments from commandline. - public override void Run(string[] args) - { - base.Run(args); - - ErrorCode err = Interop.Application.Main(args.Length, args, ref _callbacks, IntPtr.Zero); - if (err != ErrorCode.None) - { - Log.Error(LogTag, "Failed to run the application. Err = " + err); - } - } - - /// - /// Exits the main loop of the UI application. - /// - public override void Exit() - { - Interop.Application.Exit(); - } - - /// - /// Overrides this method if want to handle behavior when the application is resumed. - /// If base.OnResume() is not called, the event 'Resumed' will not be emitted. - /// - protected virtual void OnResume() - { - Resumed?.Invoke(this, EventArgs.Empty); - } - - /// - /// Overrides this method if want to handle behavior when the application is paused. - /// If base.OnPause() is not called, the event 'Paused' will not be emitted. + /// Overrides this method if want to handle behavior before calling OnCreate(). + /// Window property is initialized in this overrided method. /// - protected virtual void OnPause() - { - Paused?.Invoke(this, EventArgs.Empty); - } - - internal override ErrorCode AddEventHandler(out IntPtr handle, Interop.AppCommon.AppEventType type, Interop.AppCommon.AppEventCallback callback) - { - return Interop.Application.AddEventHandler(out handle, type, callback, IntPtr.Zero); - } - - internal override void RemoveEventHandler(IntPtr handle) - { - Interop.Application.RemoveEventHandler(handle); - } - - private bool OnCreateNative(IntPtr data) + protected override void OnPreCreate() { Window = new Window("C# UI Application"); Window.Closed += (s, e) => { Exit(); }; - OnCreate(); - return true; - } - - private void OnTerminateNative(IntPtr data) - { - OnTerminate(); - } - - private void OnAppControlNative(IntPtr appControlHandle, IntPtr data) - { - OnAppControlReceived(new AppControlReceivedEventArgs { ReceivedAppControl = new ReceivedAppControl(appControlHandle) }); - } - - private void OnResumeNative(IntPtr data) - { - OnResume(); - } - - private void OnPauseNative(IntPtr data) - { - OnPause(); } } } diff --git a/Tizen.Applications/Tizen.Applications/UIApplicationBase.cs b/Tizen.Applications/Tizen.Applications/UIApplicationBase.cs new file mode 100644 index 0000000..5ce4d1c --- /dev/null +++ b/Tizen.Applications/Tizen.Applications/UIApplicationBase.cs @@ -0,0 +1,128 @@ +// Copyright 2016 by Samsung Electronics, Inc., +// +// This software is the confidential and proprietary information +// of Samsung Electronics, Inc. ("Confidential Information"). You +// shall not disclose such Confidential Information and shall use +// it only in accordance with the terms of the license agreement +// you entered into with Samsung. + +using System; +using Tizen.Internals.Errors; + +namespace Tizen.Applications +{ + /// + /// Represents an application that have UI screen. It has additional events for handling 'Resumed' and 'Paused' states. + /// + public class UIApplicationBase : Application + { + private Interop.Application.UIAppLifecycleCallbacks _callbacks; + + /// + /// Initializes UIApplicationBase class. + /// + public UIApplicationBase() + { + _callbacks.OnCreate = new Interop.Application.AppCreateCallback(OnCreateNative); + _callbacks.OnTerminate = new Interop.Application.AppTerminateCallback(OnTerminateNative); + _callbacks.OnAppControl = new Interop.Application.AppControlCallback(OnAppControlNative); + _callbacks.OnResume = new Interop.Application.AppResumeCallback(OnResumeNative); + _callbacks.OnPause = new Interop.Application.AppPauseCallback(OnPauseNative); + } + + /// + /// Occurs whenever the application is resumed. + /// + public event EventHandler Resumed; + + /// + /// Occurs whenever the application is paused. + /// + public event EventHandler Paused; + + /// + /// Runs the UI application's main loop. + /// + /// Arguments from commandline. + public override void Run(string[] args) + { + base.Run(args); + + ErrorCode err = Interop.Application.Main(args.Length, args, ref _callbacks, IntPtr.Zero); + if (err != ErrorCode.None) + { + Log.Error(LogTag, "Failed to run the application. Err = " + err); + } + } + + /// + /// Exits the main loop of the UI application. + /// + public override void Exit() + { + Interop.Application.Exit(); + } + + /// + /// Overrides this method if want to handle behavior before calling OnCreate(). + /// + protected virtual void OnPreCreate() + { + } + + /// + /// Overrides this method if want to handle behavior when the application is resumed. + /// If base.OnResume() is not called, the event 'Resumed' will not be emitted. + /// + protected virtual void OnResume() + { + Resumed?.Invoke(this, EventArgs.Empty); + } + + /// + /// Overrides this method if want to handle behavior when the application is paused. + /// If base.OnPause() is not called, the event 'Paused' will not be emitted. + /// + protected virtual void OnPause() + { + Paused?.Invoke(this, EventArgs.Empty); + } + + internal override ErrorCode AddEventHandler(out IntPtr handle, Interop.AppCommon.AppEventType type, Interop.AppCommon.AppEventCallback callback) + { + return Interop.Application.AddEventHandler(out handle, type, callback, IntPtr.Zero); + } + + internal override void RemoveEventHandler(IntPtr handle) + { + Interop.Application.RemoveEventHandler(handle); + } + + private bool OnCreateNative(IntPtr data) + { + OnPreCreate(); + OnCreate(); + return true; + } + + private void OnTerminateNative(IntPtr data) + { + OnTerminate(); + } + + private void OnAppControlNative(IntPtr appControlHandle, IntPtr data) + { + OnAppControlReceived(new AppControlReceivedEventArgs { ReceivedAppControl = new ReceivedAppControl(appControlHandle) }); + } + + private void OnResumeNative(IntPtr data) + { + OnResume(); + } + + private void OnPauseNative(IntPtr data) + { + OnPause(); + } + } +}