Fix lifecycles
[platform/core/csapi/tizenfx.git] / Tizen.Applications / Tizen.Applications / Actor.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 Actor : Context
19     {
20         private ActorState _state = ActorState.None;
21
22         /// <summary>
23         /// 
24         /// </summary>
25         public event EventHandler Created;
26
27         /// <summary>
28         /// 
29         /// </summary>
30         public event EventHandler Started;
31
32         /// <summary>
33         /// 
34         /// </summary>
35         public event EventHandler Resumed;
36
37         /// <summary>
38         /// 
39         /// </summary>
40         public event EventHandler Paused;
41
42         /// <summary>
43         /// 
44         /// </summary>
45         public event EventHandler Destroyed;
46
47         private enum ActorState
48         {
49             None = 0,
50             Created = 1,
51             Started = 2,
52             Resumed = 3,
53             Pasued = 4
54         }
55
56         internal Guid TaskId { get; set; }
57
58         /// <summary>
59         /// 
60         /// </summary>
61         internal protected Page MainPage { get; set; }
62         
63         internal void OnCreate(Guid taskId, AppControl control)
64         {
65             if (_state != ActorState.Created)
66             {
67                 TaskId = taskId;
68                 _control = control;
69                 _state = ActorState.Created;
70                 if (Created != null)
71                 {
72                     Created(this, EventArgs.Empty);
73                 }
74             }
75         }
76
77         internal void OnStart()
78         {
79             if (_state != ActorState.Started)
80             {
81                 _state = ActorState.Started;
82                 if (Started != null)
83                 {
84                     Started(this, EventArgs.Empty);
85                 }
86             }
87         }
88
89         internal void OnPause()
90         {
91             if (_state != ActorState.Pasued)
92             {
93                 _state = ActorState.Pasued;
94                 if (Paused != null)
95                 {
96                     Paused(this, EventArgs.Empty);
97                 }
98             }
99         }
100
101         internal void OnResume()
102         {
103             if (_state != ActorState.Resumed)
104             {
105                 _state = ActorState.Resumed;
106                 if (Resumed != null)
107                 {
108                     Resumed(this, EventArgs.Empty);
109                 }
110                 MainPage.Show();
111             }
112         }
113
114         internal void OnDestroy()
115         {
116             if (_state != ActorState.None)
117             {
118                 _state = ActorState.None;
119                 if (Destroyed != null)
120                 {
121                     Destroyed(this, EventArgs.Empty);
122                 }
123             }
124         }
125     }
126 }
127