Refactor Lifecycles
[platform/core/csapi/tizenfx.git] / Tizen.Applications / Tizen.Applications / UIController.cs
1 /// Copyright 2016 by Samsung Electronics, Inc.,
2 ///
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.
8
9
10 using System;
11 using Tizen.UI;
12
13 namespace Tizen.Applications
14 {
15     /// <summary>
16     /// 
17     /// </summary>
18     public abstract class UIController : Controller, IUIContext
19     {
20         private bool _isResumed = false;
21
22         /// <summary>
23         /// 
24         /// </summary>
25         public event EventHandler Resumed;
26
27         /// <summary>
28         /// 
29         /// </summary>
30         public event EventHandler Paused;
31
32         /// <summary>
33         /// 
34         /// </summary>
35         public Window Window { get; internal set; }
36
37         internal Guid TaskId { get; set; }
38
39         /// <summary>
40         /// 
41         /// </summary>
42         protected internal Page MainPage { get; set; }
43
44         public string ResolveResourcePath(string res)
45         {
46             throw new NotImplementedException();
47         }
48
49         internal override void SendCreate()
50         {
51             Window = OnPrepareWindow();
52             base.SendCreate();
53         }
54
55         internal void SendPause()
56         {
57             if (_isResumed)
58             {
59                 if (Paused != null)
60                 {
61                     OnPause();
62                     Paused(this, EventArgs.Empty);
63                 }
64                 _isResumed = false;
65             }
66         }
67
68         internal void SendResume()
69         {
70             if (!_isResumed)
71             {
72                 if (Resumed != null)
73                 {
74                     OnResume();
75                     Resumed(this, EventArgs.Empty);
76                 }
77                 _isResumed = true;
78                 MainPage.Show();
79             }
80         }
81
82         protected virtual Window OnPrepareWindow()
83         {
84             return Window;
85         }
86
87         protected virtual void OnResume()
88         {
89         }
90
91         protected virtual void OnPause()
92         {
93         }
94
95         protected override void Finish()
96         {
97             Application.StopController(this);
98         }
99     }
100 }
101