From: SukHyung, Kang Date: Mon, 6 Mar 2017 06:45:08 +0000 (+0900) Subject: Add to get orientation event X-Git-Tag: submit/trunk/20170823.075128~121^2~86 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4aa5decfe0c0787efbdc8e897be8ff5e62d1a5c9;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Add to get orientation event Change-Id: I128730161613d28ac3e2cdb9d392dad0feee1041 Signed-off-by: SukHyung, Kang --- diff --git a/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs b/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs index a221828bf..41603d20b 100755 --- a/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs +++ b/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs @@ -85,6 +85,9 @@ internal static partial class Interop [DllImport(Libraries.AppCommon, EntryPoint = "app_resource_manager_get")] internal static extern ErrorCode AppResourceManagerGet(ResourceCategory category, string id, out string path); + + [DllImport(Libraries.AppCommon, EntryPoint = "app_event_get_device_orientation")] + internal static extern ErrorCode AppEventGetDeviceOrientation(IntPtr handle, out DeviceOrientation orientation); } } diff --git a/src/Tizen.Applications.Common/Tizen.Applications.Common.csproj b/src/Tizen.Applications.Common/Tizen.Applications.Common.csproj index 5b0bd9e70..2278de13a 100755 --- a/src/Tizen.Applications.Common/Tizen.Applications.Common.csproj +++ b/src/Tizen.Applications.Common/Tizen.Applications.Common.csproj @@ -66,6 +66,8 @@ + + diff --git a/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/DefaultCoreBackend.cs b/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/DefaultCoreBackend.cs index 32918a167..aabbbeb96 100755 --- a/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/DefaultCoreBackend.cs +++ b/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/DefaultCoreBackend.cs @@ -136,5 +136,20 @@ namespace Tizen.Applications.CoreBackend handler?.Invoke(new RegionFormatChangedEventArgs(region)); } } + + protected virtual void OnDeviceOrientationChangedNative(IntPtr infoHandle, IntPtr data) + { + DeviceOrientation orientation; + ErrorCode err = Interop.AppCommon.AppEventGetDeviceOrientation(infoHandle, out orientation); + if (err != ErrorCode.None) + { + Log.Error(LogTag, "Failed to get deivce orientation. Err = " + err); + } + if (Handlers.ContainsKey(EventType.DeviceOrientationChanged)) + { + var handler = Handlers[EventType.DeviceOrientationChanged] as Action; + handler?.Invoke(new DeviceOrientationEventArgs(orientation)); + } + } } } diff --git a/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/EventType.cs b/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/EventType.cs index 6985ae8f6..e24cddfb9 100755 --- a/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/EventType.cs +++ b/src/Tizen.Applications.Common/Tizen.Applications.CoreBackend/EventType.cs @@ -70,6 +70,11 @@ namespace Tizen.Applications.CoreBackend /// public static readonly EventType RegionFormatChanged = "RegionFormatChanged"; + /// + /// Pre-defined event type. "DeviceOrientationChanged" + /// + public static readonly EventType DeviceOrientationChanged = "DeviceOrientationChanged"; + private string _typeName; /// diff --git a/src/Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs b/src/Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs old mode 100644 new mode 100755 index f37b310d7..5bf6e396d --- a/src/Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs +++ b/src/Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs @@ -72,6 +72,11 @@ namespace Tizen.Applications /// public event EventHandler RegionFormatChanged; + /// + /// Occurs when the device orientation is changed. + /// + public event EventHandler DeviceOrientationChanged; + /// /// The backend instance. /// @@ -92,6 +97,7 @@ namespace Tizen.Applications _backend.AddEventHandler(EventType.LowBattery, OnLowBattery); _backend.AddEventHandler(EventType.LocaleChanged, OnLocaleChanged); _backend.AddEventHandler(EventType.RegionFormatChanged, OnRegionFormatChanged); + _backend.AddEventHandler(EventType.DeviceOrientationChanged, OnDeviceOrientationChanged); string[] argsClone = null; @@ -181,6 +187,15 @@ namespace Tizen.Applications RegionFormatChanged?.Invoke(this, e); } + /// + /// Overrides this method if want to handle behavior when the device orientation is changed. + /// If base.OnRegionFormatChanged() is not called, the event 'RegionFormatChanged' will not be emitted. + /// + protected virtual void OnDeviceOrientationChanged(DeviceOrientationEventArgs e) + { + DeviceOrientationChanged?.Invoke(this, e); + } + /// /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. /// diff --git a/src/Tizen.Applications.Common/Tizen.Applications/DeviceOrientation.cs b/src/Tizen.Applications.Common/Tizen.Applications/DeviceOrientation.cs new file mode 100755 index 000000000..5b41aea90 --- /dev/null +++ b/src/Tizen.Applications.Common/Tizen.Applications/DeviceOrientation.cs @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 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. + */ + +namespace Tizen.Applications +{ + /// + /// Enumeration for device orientation. + /// + public enum DeviceOrientation + { + /// + /// The device orientation is 0 + /// + Orientation_0 = 0, + + /// + /// The device orientation is 90 + /// + Orientation_90 = 90, + + /// + /// The device orientation is 180 + /// + Orientation_180 = 180, + + /// + /// The device orientation is 270 + /// + Orientation_270 = 270, + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Common/Tizen.Applications/DeviceOrientationEventArgs.cs b/src/Tizen.Applications.Common/Tizen.Applications/DeviceOrientationEventArgs.cs new file mode 100755 index 000000000..e042e326f --- /dev/null +++ b/src/Tizen.Applications.Common/Tizen.Applications/DeviceOrientationEventArgs.cs @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 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 event arguments of the DeviceOrientationChanged + /// + public class DeviceOrientationEventArgs : EventArgs + { + /// + /// Initializes DeviceOrientationEventArgs class + /// + /// + public DeviceOrientationEventArgs(DeviceOrientation orientation) + { + DeviceOrientation = orientation; + } + + /// + /// The received DeviceOrientation + /// + public DeviceOrientation DeviceOrientation { get; private set; } + } +} \ No newline at end of file diff --git a/src/Tizen.Applications.Service/Tizen.Applications.CoreBackend/ServiceCoreBackend.cs b/src/Tizen.Applications.Service/Tizen.Applications.CoreBackend/ServiceCoreBackend.cs index bf6746ccc..bc1a0968f 100755 --- a/src/Tizen.Applications.Service/Tizen.Applications.CoreBackend/ServiceCoreBackend.cs +++ b/src/Tizen.Applications.Service/Tizen.Applications.CoreBackend/ServiceCoreBackend.cs @@ -27,11 +27,13 @@ namespace Tizen.Applications.CoreBackend private IntPtr _lowBatteryEventHandle = IntPtr.Zero; private IntPtr _localeChangedEventHandle = IntPtr.Zero; private IntPtr _regionChangedEventHandle = IntPtr.Zero; + private IntPtr _deviceOrientationChangedEventHandle = IntPtr.Zero; private bool _disposedValue = false; private Interop.Service.AppEventCallback _onLowMemoryNative; private Interop.Service.AppEventCallback _onLowBatteryNative; private Interop.Service.AppEventCallback _onLocaleChangedNative; private Interop.Service.AppEventCallback _onRegionChangedNative; + private Interop.Service.AppEventCallback _onDeviceOrientationChangedNative; public ServiceCoreBackend() { @@ -43,6 +45,7 @@ namespace Tizen.Applications.CoreBackend _onLowBatteryNative = new Interop.Service.AppEventCallback(OnLowBatteryNative); _onLocaleChangedNative = new Interop.Service.AppEventCallback(OnLocaleChangedNative); _onRegionChangedNative = new Interop.Service.AppEventCallback(OnRegionChangedNative); + _onDeviceOrientationChangedNative = new Interop.Service.AppEventCallback(OnDeviceOrientationChangedNative); } public override void Exit() @@ -78,6 +81,12 @@ namespace Tizen.Applications.CoreBackend Log.Error(LogTag, "Failed to add event handler for RegionFormatChanged event. Err = " + err); } + err = Interop.Service.AddEventHandler(out _deviceOrientationChangedEventHandle, AppEventType.DeviceOrientationChanged, _onDeviceOrientationChangedNative, IntPtr.Zero); + if (err != ErrorCode.None) + { + Log.Error(LogTag, "Failed to add event handler for DeviceOrientationChanged event. Err = " + err); + } + err = Interop.Service.Main(args.Length, args, ref _callbacks, IntPtr.Zero); if (err != ErrorCode.None) { @@ -111,6 +120,11 @@ namespace Tizen.Applications.CoreBackend Interop.Service.RemoveEventHandler(_regionChangedEventHandle); } + if (_deviceOrientationChangedEventHandle != IntPtr.Zero) + { + Interop.Service.RemoveEventHandler(_deviceOrientationChangedEventHandle); + } + _disposedValue = true; } } @@ -167,5 +181,10 @@ namespace Tizen.Applications.CoreBackend base.OnRegionChangedNative(infoHandle, data); } + protected override void OnDeviceOrientationChangedNative(IntPtr infoHandle, IntPtr data) + { + base.OnDeviceOrientationChangedNative(infoHandle, data); + } + } } diff --git a/src/Tizen.Applications.UI/Tizen.Applications.CoreBackend/UICoreBackend.cs b/src/Tizen.Applications.UI/Tizen.Applications.CoreBackend/UICoreBackend.cs index 50af98b8f..933a4e058 100755 --- a/src/Tizen.Applications.UI/Tizen.Applications.CoreBackend/UICoreBackend.cs +++ b/src/Tizen.Applications.UI/Tizen.Applications.CoreBackend/UICoreBackend.cs @@ -27,11 +27,13 @@ namespace Tizen.Applications.CoreBackend private IntPtr _lowBatteryEventHandle = IntPtr.Zero; private IntPtr _localeChangedEventHandle = IntPtr.Zero; private IntPtr _regionChangedEventHandle = IntPtr.Zero; + private IntPtr _deviceOrientationChangedEventHandle = 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; public UICoreBackend() { @@ -45,6 +47,7 @@ namespace Tizen.Applications.CoreBackend _onLowBatteryNative = new Interop.Application.AppEventCallback(OnLowBatteryNative); _onLocaleChangedNative = new Interop.Application.AppEventCallback(OnLocaleChangedNative); _onRegionChangedNative = new Interop.Application.AppEventCallback(OnRegionChangedNative); + _onDeviceOrientationChangedNative = new Interop.Application.AppEventCallback(OnDeviceOrientationChangedNative); } public override void Exit() @@ -80,6 +83,12 @@ namespace Tizen.Applications.CoreBackend Log.Error(LogTag, "Failed to add event handler for RegionFormatChanged event. Err = " + err); } + err = Interop.Application.AddEventHandler(out _deviceOrientationChangedEventHandle, AppEventType.DeviceOrientationChanged, _onDeviceOrientationChangedNative, IntPtr.Zero); + if (err != ErrorCode.None) + { + Log.Error(LogTag, "Failed to add event handler for DeviceOrientationChanged event. Err = " + err); + } + err = Interop.Application.Main(args.Length, args, ref _callbacks, IntPtr.Zero); if (err != ErrorCode.None) { @@ -112,6 +121,10 @@ namespace Tizen.Applications.CoreBackend { Interop.Application.RemoveEventHandler(_regionChangedEventHandle); } + if (_deviceOrientationChangedEventHandle != IntPtr.Zero) + { + Interop.Application.RemoveEventHandler(_deviceOrientationChangedEventHandle); + } _disposedValue = true; } @@ -192,5 +205,10 @@ namespace Tizen.Applications.CoreBackend { base.OnRegionChangedNative(infoHandle, data); } + + protected override void OnDeviceOrientationChangedNative(IntPtr infoHandle, IntPtr data) + { + base.OnDeviceOrientationChangedNative(infoHandle, data); + } } }