From 21359428a941b46fe47aff41b6b047db04d28e57 Mon Sep 17 00:00:00 2001 From: WonYoung Choi Date: Thu, 10 Mar 2016 22:06:20 +0900 Subject: [PATCH] Remove ActorGroup Change-Id: I6a80d0520eefab1129591e753146caa36add7fa5 --- Tizen.Applications/Interop/Interop.Bundle.cs | 1 + Tizen.Applications/Tizen.Applications.csproj | 3 +- Tizen.Applications/Tizen.Applications/Actor.cs | 80 +++++++++++-- .../Tizen.Applications/ActorGroup.cs | 103 ---------------- .../Tizen.Applications/Application.cs | 131 +++++++++++++-------- Tizen.Applications/Tizen.Applications/Bundle.cs | 2 +- Tizen.Applications/Tizen.Applications/Context.cs | 35 +----- Tizen.Applications/Tizen.Applications/Service.cs | 32 ++++- Tizen.Applications/Tizen.UI/Page.cs | 2 +- 9 files changed, 187 insertions(+), 202 deletions(-) mode change 100644 => 100755 Tizen.Applications/Interop/Interop.Bundle.cs mode change 100644 => 100755 Tizen.Applications/Tizen.Applications.csproj delete mode 100755 Tizen.Applications/Tizen.Applications/ActorGroup.cs mode change 100644 => 100755 Tizen.Applications/Tizen.Applications/Bundle.cs diff --git a/Tizen.Applications/Interop/Interop.Bundle.cs b/Tizen.Applications/Interop/Interop.Bundle.cs old mode 100644 new mode 100755 index 86ddaf6..11097f9 --- a/Tizen.Applications/Interop/Interop.Bundle.cs +++ b/Tizen.Applications/Interop/Interop.Bundle.cs @@ -6,6 +6,7 @@ /// it only in accordance with the terms of the license agreement /// you entered into with Samsung. + using System; using System.Runtime.InteropServices; diff --git a/Tizen.Applications/Tizen.Applications.csproj b/Tizen.Applications/Tizen.Applications.csproj old mode 100644 new mode 100755 index b819bfd..489d94d --- a/Tizen.Applications/Tizen.Applications.csproj +++ b/Tizen.Applications/Tizen.Applications.csproj @@ -62,7 +62,6 @@ - @@ -79,4 +78,4 @@ --> - + \ No newline at end of file diff --git a/Tizen.Applications/Tizen.Applications/Actor.cs b/Tizen.Applications/Tizen.Applications/Actor.cs index 3886320..000df9b 100755 --- a/Tizen.Applications/Tizen.Applications/Actor.cs +++ b/Tizen.Applications/Tizen.Applications/Actor.cs @@ -18,7 +18,18 @@ namespace Tizen.Applications /// public abstract class Actor : Context { - private ActorGroup _group; + internal Guid TaskId { get; set; } + + private enum ActorState + { + None = 0, + Created = 1, + Started = 2, + Resumed = 3, + Pasued = 4 + } + + private ActorState _state = ActorState.None; /// /// @@ -28,28 +39,72 @@ namespace Tizen.Applications /// /// /// - protected virtual void OnPaused() { } + protected virtual void OnCreate() { } + + /// + /// + /// + protected virtual void OnStart() { } + + /// + /// + /// + protected virtual void OnPause() { } + + /// + /// + /// + protected virtual void OnResume() { } /// /// /// - protected virtual void OnResumed() { } + protected virtual void OnDestroy() { } - internal void Create(ActorGroup group) + internal void Create() { - _group = group; - base.Create(); + if (_state != ActorState.Created) + { + OnCreate(); + _state = ActorState.Created; + } + } + + internal void Start() + { + if (_state != ActorState.Started) + { + OnStart(); + _state = ActorState.Started; + } } internal void Pause() { - OnPaused(); + if (_state != ActorState.Pasued) + { + OnPause(); + _state = ActorState.Pasued; + } } internal void Resume() { - OnResumed(); - MainPage.Show(); + if (_state != ActorState.Resumed) + { + OnResume(); + _state = ActorState.Resumed; + MainPage.Show(); + } + } + + internal void Destroy() + { + if (_state != ActorState.None) + { + OnDestroy(); + _state = ActorState.None; + } } /// @@ -59,7 +114,7 @@ namespace Tizen.Applications /// protected void StartActor(Actor actor, AppControl control) { - _group.StartActor(actor, control); + throw new NotImplementedException(); } /// @@ -69,7 +124,8 @@ namespace Tizen.Applications /// protected override void StartActor(Type actorType, AppControl control) { - Application.StartActor(_group, actorType, control); + + Application.StartActor(TaskId, actorType, control); } /// @@ -77,7 +133,7 @@ namespace Tizen.Applications /// protected override void Finish() { - Application.StopActor(_group, this); + Application.StopActor(this); } } } diff --git a/Tizen.Applications/Tizen.Applications/ActorGroup.cs b/Tizen.Applications/Tizen.Applications/ActorGroup.cs deleted file mode 100755 index f2efd86..0000000 --- a/Tizen.Applications/Tizen.Applications/ActorGroup.cs +++ /dev/null @@ -1,103 +0,0 @@ -/// 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 System.Collections.Generic; -using System.Linq; - -namespace Tizen.Applications -{ - internal class ActorGroup - { - private readonly List _actorList; - - public bool IsEmpty - { - get - { - return _actorList.Count == 0; - } - } - - public Actor TopActor - { - get - { - return _actorList.LastOrDefault(null); - } - } - - public ActorGroup() - { - _actorList = new List(); - } - - public void StartActor(Type actorType, AppControl control) - { - Actor actor = (Actor)Activator.CreateInstance(actorType); - actor.Create(this); - if (actor.MainPage == null) - { - throw new ArgumentNullException("Actor's MainPage is not set."); - } - - Actor prevTop = TopActor; - _actorList.Add(actor); - if (prevTop != null) - { - prevTop.Pause(); - } - actor.Start(control); - actor.Resume(); - } - - public void StartActor(Actor actor, AppControl control) - { - if (actor.MainPage == null) - { - throw new ArgumentNullException("Actor's MainPage is not set."); - } - - Actor prevTop = TopActor; - _actorList.Remove(actor); - _actorList.Add(actor); - if (prevTop != actor) - { - prevTop.Pause(); - } - actor.Start(control); - actor.Resume(); - } - - public void StopActor(Actor actor) - { - Actor prevTop = TopActor; - _actorList.Remove(actor); - actor.Pause(); - actor.Terminate(); - if (prevTop == actor) - { - if (TopActor != null) - { - TopActor.Resume(); - } - } - } - - public Actor FindActor(Type type) - { - return _actorList.Find(s => s.GetType() == type); - } - - public Actor FindActor(Actor actor) - { - return _actorList.Find(s => s == actor); - } - } -} diff --git a/Tizen.Applications/Tizen.Applications/Application.cs b/Tizen.Applications/Tizen.Applications/Application.cs index d7b224c..e997b1b 100755 --- a/Tizen.Applications/Tizen.Applications/Application.cs +++ b/Tizen.Applications/Tizen.Applications/Application.cs @@ -23,18 +23,18 @@ namespace Tizen.Applications { private static readonly Dictionary s_filterMap = new Dictionary(); private static readonly List s_serviceList = new List(); - private static readonly List s_actorGroupList = new List(); + private static readonly List s_actorList = new List(); - private static readonly Window s_window = null; - - private static ActorGroup CurrentActorGroup + private static Actor ForegroundActor { get { - return s_actorGroupList.LastOrDefault(null); + return s_actorList.LastOrDefault(null); } } + private static readonly Window s_window = null; + /// /// Occurs when the application starts. /// @@ -59,24 +59,16 @@ namespace Tizen.Applications }; ops.OnPause = (userData) => { - if (CurrentActorGroup != null && CurrentActorGroup.TopActor != null) + if (ForegroundActor != null) { - Actor actor = CurrentActorGroup.TopActor as Actor; - if (actor != null) - { - actor.Pause(); - } + ForegroundActor.Pause(); } }; ops.OnResume = (userData) => { - if (CurrentActorGroup != null && CurrentActorGroup.TopActor != null) + if (ForegroundActor != null) { - Actor actor = CurrentActorGroup.TopActor as Actor; - if (actor != null) - { - actor.Resume(); - } + ForegroundActor.Resume(); } }; ops.OnAppControl = (appControlHandle, userData) => @@ -99,9 +91,9 @@ namespace Tizen.Applications { if (item.Key.IsMatch(appControl) && item.Value.IsSubclassOf(typeof(Actor))) { - if (CurrentActorGroup == null || !appControl.IsLaunchOperation()) + if (ForegroundActor == null || !appControl.IsLaunchOperation()) { - StartActor(null, item.Value, appControl); + StartActor(Guid.Empty, item.Value, appControl); } break; } @@ -133,7 +125,7 @@ namespace Tizen.Applications /// public static void Exit() { - Exited(null, null); + Exited(null, null); // TODO: clear context and group Interop.Application.UIAppExit(); } @@ -224,49 +216,89 @@ namespace Tizen.Applications } } - internal static void StartActor(ActorGroup group, Type actorType, AppControl control) + internal static void StartActor(Guid taskId, Type actorType, AppControl control) { if (!actorType.IsSubclassOf(typeof(Actor))) { throw new ArgumentException(actorType.FullName + " is not a subclass of Actor."); } - // Window was created when the first UI Actor was created - //if (s_window == null) - //{ - // s_window = new Window(); - //} + if (taskId != Guid.Empty && ForegroundActor != null && taskId != ForegroundActor.TaskId) + { + throw new InvalidOperationException("StartActor() should be called from the foreground task."); + } + + Actor actor = (Actor)Activator.CreateInstance(actorType); + actor.TaskId = taskId == Guid.Empty ? Guid.NewGuid() : taskId; + actor._control = control; + actor.Create(); - ActorGroup actorGroup = group; - if (actorGroup == null) + if (ForegroundActor != null) { - actorGroup = new ActorGroup(); - s_actorGroupList.Add(actorGroup); + ForegroundActor.Pause(); } - actorGroup.StartActor(actorType, control); - - // TODO: consider resume operation - //if (!s_window.Visible) - //{ - // s_window.Active(); - // s_window.Show(); - // actor.Resume(); - //} + + s_actorList.Add(actor); + actor.Start(); + + if (!s_window.Visible) + { + s_window.Active(); + s_window.Show(); + } + actor.Resume(); } - internal static void StopActor(ActorGroup group, Actor actor) + internal static void StartActor(Actor actor, AppControl control) { - group.StopActor(actor); - if (group.IsEmpty) + if (ForegroundActor == null) + { + throw new ArgumentNullException("ForegroundActor", "The Actor stack is empty."); + } + + if (actor.TaskId != ForegroundActor.TaskId) { - s_actorGroupList.Remove(group); - if (s_actorGroupList.Count == 0 && s_serviceList.Count == 0) + throw new InvalidOperationException("StartActor() should be called from the foreground task."); + } + + while (actor != ForegroundActor) + { + Actor popped = ForegroundActor; + s_actorList.Remove(popped); + popped.Pause(); + popped.Destroy(); + } + actor.Resume(); + } + + internal static void StopActor(Actor actor) + { + if (ForegroundActor == null) + { + throw new ArgumentNullException("ForegroundActor", "The Actor stack is empty."); + } + + Guid prevForegroundTaskId = ForegroundActor.TaskId; + + s_actorList.Remove(actor); + actor.Pause(); + actor.Destroy(); + + if (actor.TaskId == prevForegroundTaskId) + { + if (ForegroundActor.TaskId == actor.TaskId) { - Exit(); + ForegroundActor.Resume(); } else { - Hide(); + if (s_actorList.Count == 0 && s_serviceList.Count == 0) + { + Exit(); + } + else { + Hide(); + } } } } @@ -285,7 +317,8 @@ namespace Tizen.Applications s_serviceList.Add(svc); svc.Create(); } - svc.Start(control); + svc._control = control; + svc.Start(); } internal static void StopService(Type serviceType) @@ -298,9 +331,9 @@ namespace Tizen.Applications Service svc = s_serviceList.Find(s => s.GetType() == serviceType); if (svc != null) { - svc.Terminate(); + svc.Destroy(); s_serviceList.Remove(svc); - if (s_actorGroupList.Count == 0 && s_serviceList.Count == 0) + if (ForegroundActor == null && s_serviceList.Count == 0) { Exit(); } diff --git a/Tizen.Applications/Tizen.Applications/Bundle.cs b/Tizen.Applications/Tizen.Applications/Bundle.cs old mode 100644 new mode 100755 index c53efe3..ab09285 --- a/Tizen.Applications/Tizen.Applications/Bundle.cs +++ b/Tizen.Applications/Tizen.Applications/Bundle.cs @@ -15,7 +15,7 @@ namespace Tizen.Applications { internal IntPtr _handle; private bool _disposed = false; - private List _keys; + private readonly List _keys; private enum BundleTypeProperty { diff --git a/Tizen.Applications/Tizen.Applications/Context.cs b/Tizen.Applications/Tizen.Applications/Context.cs index e359bda..016d8a8 100755 --- a/Tizen.Applications/Tizen.Applications/Context.cs +++ b/Tizen.Applications/Tizen.Applications/Context.cs @@ -16,12 +16,12 @@ namespace Tizen.Applications /// public abstract class Context { - private AppControl _control; + internal AppControl _control; /// /// /// - protected AppControl ReceivedAppControl + protected AppControl AppControl { get { @@ -32,37 +32,6 @@ namespace Tizen.Applications /// /// /// - protected virtual void OnCreated() { } - - /// - /// - /// - protected virtual void OnStarted() { } - - /// - /// - /// - protected virtual void OnTerminated() { } - - internal void Create() - { - OnCreated(); - } - - internal void Start(AppControl control) - { - _control = control; - OnStarted(); - } - - internal void Terminate() - { - OnTerminated(); - } - - /// - /// - /// /// /// protected abstract void StartActor(Type actorType, AppControl control); diff --git a/Tizen.Applications/Tizen.Applications/Service.cs b/Tizen.Applications/Tizen.Applications/Service.cs index 10c23cc..d6a9e8a 100755 --- a/Tizen.Applications/Tizen.Applications/Service.cs +++ b/Tizen.Applications/Tizen.Applications/Service.cs @@ -19,11 +19,41 @@ namespace Tizen.Applications /// /// /// + protected virtual void OnCreate() { } + + /// + /// + /// + protected virtual void OnStart() { } + + /// + /// + /// + protected virtual void OnDestroy() { } + + internal void Create() + { + OnCreate(); + } + + internal void Start() + { + OnStart(); + } + + internal void Destroy() + { + OnDestroy(); + } + + /// + /// + /// /// /// protected override void StartActor(Type actorType, AppControl control) { - Application.StartActor(null, actorType, control); + Application.StartActor(Guid.Empty, actorType, control); } /// diff --git a/Tizen.Applications/Tizen.UI/Page.cs b/Tizen.Applications/Tizen.UI/Page.cs index 390d5a7..bd5e48a 100755 --- a/Tizen.Applications/Tizen.UI/Page.cs +++ b/Tizen.Applications/Tizen.UI/Page.cs @@ -6,6 +6,7 @@ /// it only in accordance with the terms of the license agreement /// you entered into with Samsung. + using System; using System.Collections.Generic; using System.Linq; @@ -18,7 +19,6 @@ namespace Tizen.UI { internal void Show() { - } } } -- 2.7.4