Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.UI / Tizen.Applications / CoreUIApplication.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18
19 using Tizen.Applications.CoreBackend;
20
21 namespace Tizen.Applications
22 {
23     /// <summary>
24     /// Represents an application that have UI screen. The events for resuming and pausing are provided.
25     /// </summary>
26     public class CoreUIApplication : CoreApplication
27     {
28         /// <summary>
29         /// Initializes the CoreUIApplication class.
30         /// </summary>
31         /// <remarks>
32         /// Default backend for UI application will be used.
33         /// </remarks>
34         public CoreUIApplication() : base(new UICoreBackend())
35         {
36         }
37
38         /// <summary>
39         /// Initializes the CoreUIApplication class.
40         /// </summary>
41         /// <remarks>
42         /// If want to change the backend, use this constructor.
43         /// </remarks>
44         /// <param name="backend">The backend instance implementing ICoreBacked interface.</param>
45         public CoreUIApplication(ICoreBackend backend) : base(backend)
46         {
47         }
48
49         /// <summary>
50         /// Occurs whenever the application is resumed.
51         /// </summary>
52         public event EventHandler Resumed;
53
54         /// <summary>
55         /// Occurs whenever the application is paused.
56         /// </summary>
57         public event EventHandler Paused;
58
59         /// <summary>
60         /// Runs the UI application's main loop.
61         /// </summary>
62         /// <param name="args">Arguments from commandline.</param>
63         public override void Run(string[] args)
64         {
65             Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
66             Backend.AddEventHandler(EventType.Resumed, OnResume);
67             Backend.AddEventHandler(EventType.Paused, OnPause);
68             base.Run(args);
69         }
70
71         /// <summary>
72         /// Overrides this method if want to handle behavior before calling OnCreate().
73         /// </summary>
74         protected virtual void OnPreCreate()
75         {
76         }
77
78         /// <summary>
79         /// Overrides this method if want to handle behavior when the application is resumed.
80         /// If base.OnResume() is not called, the event 'Resumed' will not be emitted.
81         /// </summary>
82         protected virtual void OnResume()
83         {
84             Resumed?.Invoke(this, EventArgs.Empty);
85         }
86
87         /// <summary>
88         /// Overrides this method if want to handle behavior when the application is paused.
89         /// If base.OnPause() is not called, the event 'Paused' will not be emitted.
90         /// </summary>
91         protected virtual void OnPause()
92         {
93             Paused?.Invoke(this, EventArgs.Empty);
94         }
95     }
96 }