From a2818fa7d7ef2eec21be7672f16e12a5ed084ccc Mon Sep 17 00:00:00 2001 From: hjhun <36876573+hjhun@users.noreply.github.com> Date: Mon, 11 Sep 2023 13:17:59 +0900 Subject: [PATCH] [ComponentBased] Add TimeZoneChanged EventHandler (#5537) This patch adds the TimeZoneChanged EventHandler. The component-based application can monitors the time zone changed event using the event handler. Signed-off-by: Hwankyu Jhun --- .../Interop/Interop.CBApplication.cs | 7 +++++++ .../BaseComponent.cs | 11 +++++++++++ .../ComponentStateManger.cs | 11 +++++++++++ .../FrameComponentStateManager.cs | 3 ++- .../ServiceComponentStateManager.cs | 3 ++- .../WidgetComponentStateManager.cs | 1 + 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Tizen.Applications.ComponentBased/Interop/Interop.CBApplication.cs b/src/Tizen.Applications.ComponentBased/Interop/Interop.CBApplication.cs index eaad727ac14..4cf77ea3efa 100644 --- a/src/Tizen.Applications.ComponentBased/Interop/Interop.CBApplication.cs +++ b/src/Tizen.Applications.ComponentBased/Interop/Interop.CBApplication.cs @@ -84,6 +84,7 @@ internal enum NativeDisplayStatus { internal delegate void FrameLowBatteryCallback(IntPtr context, int status, IntPtr userData); internal delegate void FrameLowMemoryCallback(IntPtr context, int status, IntPtr userData); internal delegate void FrameSuspendedStateCallback(IntPtr context, int state, IntPtr userData); + internal delegate void FrameTimeZoneChangedCallback(IntPtr context, string timeZone, string timeZoneId, IntPtr userData); internal struct FrameLifecycleCallbacks { @@ -102,6 +103,7 @@ internal struct FrameLifecycleCallbacks public FrameLowBatteryCallback OnLowBattery; public FrameLowMemoryCallback OnLowMemory; public FrameSuspendedStateCallback OnSuspendedState; + public FrameTimeZoneChangedCallback OnTimeZoneChanged; } internal delegate bool ServiceCreateCallback(IntPtr context, IntPtr userData); @@ -116,6 +118,7 @@ internal struct FrameLifecycleCallbacks internal delegate void ServiceLowBatteryCallback(IntPtr context, int status, IntPtr userData); internal delegate void ServiceLowMemoryCallback(IntPtr context, int status, IntPtr userData); internal delegate void ServiceSuspendedStateCallback(IntPtr context, int state, IntPtr userData); + internal delegate void ServiceTimeZoneChangedCallback(IntPtr context, string timeZone, string timeZoneId, IntPtr userData); internal struct ServiceLifecycleCallbacks { @@ -131,6 +134,7 @@ internal struct ServiceLifecycleCallbacks public ServiceLowBatteryCallback OnLowBattery; public ServiceLowMemoryCallback OnLowMemory; public ServiceSuspendedStateCallback OnSuspendedState; + public ServiceTimeZoneChangedCallback OnTimeZoneChanged; } internal delegate IntPtr WidgetCreateCallback(IntPtr context, int width, int height, IntPtr userData); @@ -147,6 +151,7 @@ internal struct ServiceLifecycleCallbacks internal delegate void WidgetLowBatteryCallback(IntPtr context, int status, IntPtr userData); internal delegate void WidgetLowMemoryCallback(IntPtr context, int status, IntPtr userData); internal delegate void WidgetSuspendedStateCallback(IntPtr context, int state, IntPtr userData); + internal delegate void WidgetTimeZoneChangedCallback(IntPtr context, string timeZone, string timeZoneId, IntPtr userData); internal struct WidgetLifecycleCallbacks { @@ -164,6 +169,7 @@ internal struct WidgetLifecycleCallbacks public WidgetLowBatteryCallback OnLowBattery; public WidgetLowMemoryCallback OnLowMemory; public WidgetSuspendedStateCallback OnSuspendedState; + public WidgetTimeZoneChangedCallback OnTimeZoneChanged; } internal delegate IntPtr BaseCreateCallback(IntPtr context, IntPtr userData); @@ -176,6 +182,7 @@ internal struct WidgetLifecycleCallbacks internal delegate void BaseLowBatteryCallback(IntPtr context, int status, IntPtr userData); internal delegate void BaseLowMemoryCallback(IntPtr context, int status, IntPtr userData); internal delegate void BaseSuspendedStateCallback(IntPtr context, int state, IntPtr userData); + internal delegate void BaseTimeZoneChangedCallback(IntPtr context, string timeZone, string timeZoneId, IntPtr userData); [DllImport(Libraries.CompCoreBase, EntryPoint = "component_based_app_base_main")] internal static extern ErrorCode BaseMain(int argc, string[] argv, ref CBAppLifecycleCallbacks callback, IntPtr userData); diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/BaseComponent.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/BaseComponent.cs index 8724be0e1c0..1940a3ff776 100755 --- a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/BaseComponent.cs +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/BaseComponent.cs @@ -68,6 +68,12 @@ public abstract class BaseComponent /// 6 public event EventHandler SuspendedStateChanged; + /// + /// Occurs when the time zone is changed. + /// + /// 11 + public event EventHandler TimeZoneChanged; + /// /// A component instance ID. /// It will be created after OnCreate method is invoked. @@ -169,6 +175,11 @@ internal void OnSuspendedStateCallback(int state) SuspendedStateChanged?.Invoke(this, new SuspendedStateEventArgs((SuspendedState)state)); } + internal void OnTimeZoneChangedCallback(string timeZone, string timeZoneId) + { + TimeZoneChanged?.Invoke(this, new TimeZoneChangedEventArgs(timeZone, timeZoneId)); + } + /// /// Sends the launch request asynchronously. /// diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentStateManger.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentStateManger.cs index 936f23bf819..16533296f5d 100644 --- a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentStateManger.cs +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ComponentStateManger.cs @@ -114,6 +114,17 @@ protected void OnSuspendedStateCallback(IntPtr context, int state, IntPtr userDa } } + protected void OnTimeZoneChangedCallback(IntPtr context, string timeZone, string timeZoneId, IntPtr userData) + { + foreach (BaseComponent com in ComponentInstances) + { + if (com.Handle == context) + { + com.OnTimeZoneChangedCallback(timeZone, timeZoneId); + } + } + } + protected void OnRestoreCallback(IntPtr context, IntPtr content, IntPtr userData) { foreach (BaseComponent com in ComponentInstances) diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/FrameComponentStateManager.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/FrameComponentStateManager.cs index b4c5de138c2..b3328396d8d 100644 --- a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/FrameComponentStateManager.cs +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/FrameComponentStateManager.cs @@ -42,6 +42,7 @@ internal FrameComponentStateManager(Type ctype, string id, ComponentBasedApplica _callbacks.OnResume = new Interop.CBApplication.FrameResumeCallback(OnResumeCallback); _callbacks.OnStart = new Interop.CBApplication.FrameStartCallback(OnStartCallback); _callbacks.OnStop = new Interop.CBApplication.FrameStopCallback(OnStopCallback); + _callbacks.OnTimeZoneChanged = new Interop.CBApplication.FrameTimeZoneChangedCallback(OnTimeZoneChangedCallback); Parent = parent; } @@ -81,7 +82,7 @@ private void OnStartCallback(IntPtr context, IntPtr appControl, bool restarted, { if (fc.Handle == context) { - SafeAppControlHandle handle = new SafeAppControlHandle(appControl, false); + using SafeAppControlHandle handle = new SafeAppControlHandle(appControl, false); AppControl control = new AppControl(handle); fc.OnStart(control, restarted); break; diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ServiceComponentStateManager.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ServiceComponentStateManager.cs index fc918a1f092..690fa7fc42c 100644 --- a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ServiceComponentStateManager.cs +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/ServiceComponentStateManager.cs @@ -36,6 +36,7 @@ internal ServiceComponentStateManager(Type ctype, string id, ComponentBasedAppli _callbacks.OnCreate = new Interop.CBApplication.ServiceCreateCallback(OnCreateCallback); _callbacks.OnDestroy = new Interop.CBApplication.ServiceDestroyCallback(OnDestroyCallback); _callbacks.OnStart = new Interop.CBApplication.ServiceStartCommandCallback(OnStartCallback); + _callbacks.OnTimeZoneChanged = new Interop.CBApplication.ServiceTimeZoneChangedCallback(OnTimeZoneChangedCallback); Parent = parent; } @@ -64,7 +65,7 @@ private void OnStartCallback(IntPtr context, IntPtr appControl, bool restarted, { if (sc.Handle == context) { - SafeAppControlHandle handle = new SafeAppControlHandle(appControl, false); + using SafeAppControlHandle handle = new SafeAppControlHandle(appControl, false); AppControl control = new AppControl(handle); sc.OnStartCommand(control, restarted); break; diff --git a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/WidgetComponentStateManager.cs b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/WidgetComponentStateManager.cs index 8e6512c6a37..c0f402636ef 100644 --- a/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/WidgetComponentStateManager.cs +++ b/src/Tizen.Applications.ComponentBased/Tizen.Applications.ComponentBased.Common/WidgetComponentStateManager.cs @@ -41,6 +41,7 @@ internal WidgetComponentStateManager(Type ctype, string id, ComponentBasedApplic _callbacks.OnResume = new Interop.CBApplication.WidgetResumeCallback(OnResumeCallback); _callbacks.OnStart = new Interop.CBApplication.WidgetStartCallback(OnStartCallback); _callbacks.OnStop = new Interop.CBApplication.WidgetStopCallback(OnStopCallback); + _callbacks.OnTimeZoneChanged = new Interop.CBApplication.WidgetTimeZoneChangedCallback(OnTimeZoneChangedCallback); Parent = parent; }