From: hjhun <36876573+hjhun@users.noreply.github.com> Date: Wed, 6 Sep 2023 12:52:02 +0000 (+0900) Subject: [Applications.Common] Add TimeZoneChanged Event (#5527) X-Git-Tag: accepted/tizen/unified/20231205.024657~160 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ee3366a4791216f1434831f62c0d18dd5d09aa2;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Applications.Common] Add TimeZoneChanged Event (#5527) * [Applications.Common] Add TimeZoneChanged Event The TimeZoneChangedEventArgs class is added for Time Zone changed event. Signed-off-by: Hwankyu Jhun * [Applications.Common] Update descriptions related to TimeZone Event Signed-off-by: Hwankyu Jhun --------- Signed-off-by: Hwankyu Jhun --- diff --git a/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs b/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs index a117c30..c620853 100644 --- a/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs +++ b/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs @@ -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); } } diff --git a/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/DefaultCoreBackend.cs b/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/DefaultCoreBackend.cs index 85ffca8..d5d6e8c 100755 --- a/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/DefaultCoreBackend.cs +++ b/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/DefaultCoreBackend.cs @@ -61,7 +61,13 @@ namespace Tizen.Applications.CoreBackend /// /// The suspended state changed event of the application. /// - SuspendedStateChanged + SuspendedStateChanged, + + /// + /// The time zone changed event of the application. + /// + /// 11 + TimeZoneChanged = 7, } /// @@ -285,5 +291,26 @@ namespace Tizen.Applications.CoreBackend handler?.Invoke(new SuspendedStateEventArgs(state)); } } + + /// + /// Default implementation for the time zone changed event. + /// + /// + /// + /// 11 + [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; + handler?.Invoke(new TimeZoneChangedEventArgs(timeZone, timeZoneId)); + } + } } } diff --git a/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/EventType.cs b/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/EventType.cs index 0165eb5..1a3e374 100644 --- a/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/EventType.cs +++ b/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/EventType.cs @@ -94,6 +94,13 @@ namespace Tizen.Applications.CoreBackend /// 6 public static readonly EventType SuspendedStateChanged = "SuspendedStateChanged"; + /// + /// Pre-defined event type "TimeZoneChanged". + /// The class is an event argument class for this EventType. + /// + /// 11 + public static readonly EventType TimeZoneChanged = "TimeZoneChanged"; + private string _typeName; /// diff --git a/src/Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs b/src/Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs index 4bda902..916c739 100644 --- a/src/Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs +++ b/src/Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs @@ -110,6 +110,12 @@ namespace Tizen.Applications public event EventHandler DeviceOrientationChanged; /// + /// Occurs when the time zone is changed. + /// + /// 11 + public event EventHandler TimeZoneChanged; + + /// /// The backend instance. /// /// 3 @@ -132,6 +138,7 @@ namespace Tizen.Applications _backend.AddEventHandler(EventType.LocaleChanged, OnLocaleChanged); _backend.AddEventHandler(EventType.RegionFormatChanged, OnRegionFormatChanged); _backend.AddEventHandler(EventType.DeviceOrientationChanged, OnDeviceOrientationChanged); + _backend.AddEventHandler(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 } /// + /// 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. + /// + /// The time zone changed event argument + /// 11 + protected virtual void OnTimeZoneChanged(TimeZoneChangedEventArgs e) + { + TimeZoneChanged?.Invoke(this, e); + } + + /// /// Dispatches an asynchronous message to a main loop of the CoreApplication. /// /// diff --git a/src/Tizen.Applications.Common/Tizen.Applications/TimeZoneChangedEventArgs.cs b/src/Tizen.Applications.Common/Tizen.Applications/TimeZoneChangedEventArgs.cs new file mode 100644 index 0000000..aef1995 --- /dev/null +++ b/src/Tizen.Applications.Common/Tizen.Applications/TimeZoneChangedEventArgs.cs @@ -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 +{ + /// + /// The class for the argument of the TimeZoneChanged EventHandler. + /// + /// 11 + public class TimeZoneChangedEventArgs : EventArgs + { + + /// + /// Initializes TimeZoneChangedEventArgs class + /// + /// The information of the TimeZone + /// The information of the TimeZone ID + /// 11 + public TimeZoneChangedEventArgs(string timeZone, string timeZoneId) + { + TimeZone = timeZone; + TimeZoneId = timeZoneId; + } + + /// + /// The property to get the information of the TimeZone. + /// + /// The time zone. (e.g. "+9:00") + /// 11 + public string TimeZone { get; private set; } + + /// + /// The property to get the information of the TimeZone ID. + /// + /// The time zone ID. (e.g. "Asia/Seoul") + /// 11 + public string TimeZoneId { get; private set; } + } +}