[Applications.Common] Add TimeZoneChanged Event (#5527)
authorhjhun <36876573+hjhun@users.noreply.github.com>
Wed, 6 Sep 2023 12:52:02 +0000 (21:52 +0900)
committerGitHub <noreply@github.com>
Wed, 6 Sep 2023 12:52:02 +0000 (21:52 +0900)
* [Applications.Common] Add TimeZoneChanged Event

The TimeZoneChangedEventArgs class is added for Time Zone changed
event.

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* [Applications.Common] Update descriptions related to TimeZone Event

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
---------

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs
src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/DefaultCoreBackend.cs
src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/EventType.cs
src/Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs
src/Tizen.Applications.Common/Tizen.Applications/TimeZoneChangedEventArgs.cs [new file with mode: 0644]

index a117c30..c620853 100644 (file)
@@ -110,6 +110,9 @@ internal static partial class Interop
 
         [DllImport(Libraries.AppCommon, EntryPoint = "app_get_res_control_global_resource_path")]
         internal static extern AppCommonErrorCode AppGetResControlGlobalResourcePath(string applicationId, out string path);
+
+        [DllImport(Libraries.AppCommon, EntryPoint = "app_event_get_time_zone")]
+        internal static extern ErrorCode AppEventGetTimeZone(IntPtr handle, out string timeZone, out string timeZoneId);
     }
 }
 
index 85ffca8..d5d6e8c 100755 (executable)
@@ -61,7 +61,13 @@ namespace Tizen.Applications.CoreBackend
             /// <summary>
             /// The suspended state changed event of the application.
             /// </summary>
-            SuspendedStateChanged
+            SuspendedStateChanged,
+
+            /// <summary>
+            /// The time zone changed event of the application.
+            /// </summary>
+            /// <since_tizen> 11 </since_tizen>
+            TimeZoneChanged = 7,
         }
 
         /// <summary>
@@ -285,5 +291,26 @@ namespace Tizen.Applications.CoreBackend
                 handler?.Invoke(new SuspendedStateEventArgs(state));
             }
         }
+
+        /// <summary>
+        /// Default implementation for the time zone changed event.
+        /// </summary>
+        /// <param name="infoHandle"></param>
+        /// <param name="data"></param>
+        /// <since_tizen> 11 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected virtual void OnTimeZoneChangedNative(IntPtr infoHandle, IntPtr data)
+        {
+            ErrorCode err = Interop.AppCommon.AppEventGetTimeZone(infoHandle, out string timeZone, out string timeZoneId);
+            if (err != ErrorCode.None)
+            {
+                Log.Error(LogTag, "Failed to get time zone. Err = " + err);
+            }
+            if (Handlers.ContainsKey(EventType.TimeZoneChanged))
+            {
+                var handler = Handlers[EventType.TimeZoneChanged] as Action<TimeZoneChangedEventArgs>;
+                handler?.Invoke(new TimeZoneChangedEventArgs(timeZone, timeZoneId));
+            }
+        }
     }
 }
index 0165eb5..1a3e374 100644 (file)
@@ -94,6 +94,13 @@ namespace Tizen.Applications.CoreBackend
         /// <since_tizen> 6 </since_tizen>
         public static readonly EventType SuspendedStateChanged = "SuspendedStateChanged";
 
+        /// <summary>
+        /// Pre-defined event type "TimeZoneChanged".
+        /// The <see cref="TimeZoneChangedEventArgs"/> class is an event argument class for this EventType.
+        /// </summary>
+        /// <since_tizen> 11 </since_tizen>
+        public static readonly EventType TimeZoneChanged = "TimeZoneChanged";
+
         private string _typeName;
 
         /// <summary>
index 4bda902..916c739 100644 (file)
@@ -110,6 +110,12 @@ namespace Tizen.Applications
         public event EventHandler<DeviceOrientationEventArgs> DeviceOrientationChanged;
 
         /// <summary>
+        /// Occurs when the time zone is changed.
+        /// </summary>
+        /// <since_tizen> 11 </since_tizen>
+        public event EventHandler<TimeZoneChangedEventArgs> TimeZoneChanged;
+
+        /// <summary>
         /// The backend instance.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
@@ -132,6 +138,7 @@ namespace Tizen.Applications
             _backend.AddEventHandler<LocaleChangedEventArgs>(EventType.LocaleChanged, OnLocaleChanged);
             _backend.AddEventHandler<RegionFormatChangedEventArgs>(EventType.RegionFormatChanged, OnRegionFormatChanged);
             _backend.AddEventHandler<DeviceOrientationEventArgs>(EventType.DeviceOrientationChanged, OnDeviceOrientationChanged);
+            _backend.AddEventHandler<TimeZoneChangedEventArgs>(EventType.TimeZoneChanged, OnTimeZoneChanged);
 
             string[] argsClone = new string[args == null ? 1 : args.Length + 1];
             if (args != null && args.Length > 1)
@@ -308,6 +315,17 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Override this method if you want to handle behavior when the time zone is changed.
+        /// If base.OnTimeZoneChanged() is not called, the event "TimeZoneChanged" will not be emitted.
+        /// </summary>
+        /// <param name="e">The time zone changed event argument</param>
+        /// <since_tizen> 11 </since_tizen>
+        protected virtual void OnTimeZoneChanged(TimeZoneChangedEventArgs e)
+        {
+            TimeZoneChanged?.Invoke(this, e);
+        }
+
+        /// <summary>
         /// Dispatches an asynchronous message to a main loop of the CoreApplication.
         /// </summary>
         /// <remarks>
diff --git a/src/Tizen.Applications.Common/Tizen.Applications/TimeZoneChangedEventArgs.cs b/src/Tizen.Applications.Common/Tizen.Applications/TimeZoneChangedEventArgs.cs
new file mode 100644 (file)
index 0000000..aef1995
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Applications
+{
+    /// <summary>
+    /// The class for the argument of the TimeZoneChanged EventHandler.
+    /// </summary>
+    /// <since_tizen> 11 </since_tizen>
+    public class TimeZoneChangedEventArgs : EventArgs
+    {
+
+        /// <summary>
+        /// Initializes TimeZoneChangedEventArgs class
+        /// </summary>
+        /// <param name="timeZone">The information of the TimeZone</param>
+        /// <param name="timeZoneId">The information of the TimeZone ID</param>
+        /// <since_tizen> 11 </since_tizen>
+        public TimeZoneChangedEventArgs(string timeZone, string timeZoneId)
+        {
+            TimeZone = timeZone;
+            TimeZoneId = timeZoneId;
+        }
+
+        /// <summary>
+        /// The property to get the information of the TimeZone.
+        /// </summary>
+        /// <value> The time zone. (e.g. "+9:00") </value>
+        /// <since_tizen> 11 </since_tizen>
+        public string TimeZone { get; private set; }
+
+        /// <summary>
+        /// The property to get the information of the TimeZone ID.
+        /// </summary>
+        /// <value> The time zone ID. (e.g. "Asia/Seoul") </value>
+        /// <since_tizen> 11 </since_tizen>
+        public string TimeZoneId { get; private set; }
+    }
+}