Skip to content

Commit

Permalink
[Applications.UI] Modify UICoreBackend for time zone event (#5542)
Browse files Browse the repository at this point in the history
This patch registers and unregister the time zone changed event.

Signed-off-by: Hwankyu Jhun <[email protected]>
  • Loading branch information
hjhun authored and JoogabYun committed Sep 11, 2023
1 parent 706b47d commit 7148102
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ internal class UICoreBackend : DefaultCoreBackend
private IntPtr _localeChangedEventHandle = IntPtr.Zero;
private IntPtr _regionChangedEventHandle = IntPtr.Zero;
private IntPtr _deviceOrientationChangedEventHandle = IntPtr.Zero;
private IntPtr _timeZoneChangedEventHandle = IntPtr.Zero;
private bool _disposedValue = false;
private Interop.Application.AppEventCallback _onLowMemoryNative;
private Interop.Application.AppEventCallback _onLowBatteryNative;
private Interop.Application.AppEventCallback _onLocaleChangedNative;
private Interop.Application.AppEventCallback _onRegionChangedNative;
private Interop.Application.AppEventCallback _onDeviceOrientationChangedNative;
private Interop.Application.AppEventCallback _onTimeZoneChangedNative;

public UICoreBackend()
{
Expand All @@ -48,6 +50,7 @@ public UICoreBackend()
_onLocaleChangedNative = new Interop.Application.AppEventCallback(OnLocaleChangedNative);
_onRegionChangedNative = new Interop.Application.AppEventCallback(OnRegionChangedNative);
_onDeviceOrientationChangedNative = new Interop.Application.AppEventCallback(OnDeviceOrientationChangedNative);
_onTimeZoneChangedNative = new Interop.Application.AppEventCallback(OnTimeZoneChangedNative);
}

public override void Exit()
Expand Down Expand Up @@ -89,6 +92,12 @@ public override void Run(string[] args)
Log.Error(LogTag, "Failed to add event handler for DeviceOrientationChanged event. Err = " + err);
}

err = Interop.Application.AddEventHandler(out _timeZoneChangedEventHandle, AppEventType.TimeZoneChanged, _onTimeZoneChangedNative, IntPtr.Zero);
if (err != ErrorCode.None)
{
Log.Error(LogTag, "Failed to add event handler for TimeZoneChanged event. Err = " + err);
}

err = Interop.Application.Main(args.Length, args, ref _callbacks, IntPtr.Zero);
if (err != ErrorCode.None)
{
Expand Down Expand Up @@ -125,6 +134,10 @@ protected override void Dispose(bool disposing)
{
Interop.Application.RemoveEventHandler(_deviceOrientationChangedEventHandle);
}
if (_timeZoneChangedEventHandle != IntPtr.Zero)
{
Interop.Application.RemoveEventHandler(_timeZoneChangedEventHandle);
}

_disposedValue = true;
}
Expand Down Expand Up @@ -161,8 +174,7 @@ private void OnAppControlNative(IntPtr appControlHandle, IntPtr data)
{
// Create a SafeAppControlHandle but the ownsHandle is false,
// because the appControlHandle will be closed by native appfw after this method automatically.
SafeAppControlHandle safeHandle = new SafeAppControlHandle(appControlHandle, false);

using SafeAppControlHandle safeHandle = new SafeAppControlHandle(appControlHandle, false);
var handler = Handlers[EventType.AppControlReceived] as Action<AppControlReceivedEventArgs>;
handler?.Invoke(new AppControlReceivedEventArgs(new ReceivedAppControl(safeHandle)));
}
Expand Down Expand Up @@ -210,5 +222,10 @@ protected override void OnDeviceOrientationChangedNative(IntPtr infoHandle, IntP
{
base.OnDeviceOrientationChangedNative(infoHandle, data);
}

protected override void OnTimeZoneChangedNative(IntPtr infoHandle, IntPtr data)
{
base.OnTimeZoneChangedNative(infoHandle, data);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public class CoreUIApplication : CoreApplication
/// The default backend for the UI application will be used.
/// </remarks>
/// <since_tizen> 3 </since_tizen>
#pragma warning disable CA2000
public CoreUIApplication() : base(new UICoreBackend())
#pragma warning restore CA2000
{
}

Expand Down

0 comments on commit 7148102

Please sign in to comment.