Add to get orientation event
authorSukHyung, Kang <shine.kang@samsung.com>
Mon, 6 Mar 2017 06:45:08 +0000 (15:45 +0900)
committerSukHyung, Kang <shine.kang@samsung.com>
Thu, 16 Mar 2017 01:38:51 +0000 (10:38 +0900)
Change-Id: I128730161613d28ac3e2cdb9d392dad0feee1041
Signed-off-by: SukHyung, Kang <shine.kang@samsung.com>
src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs
src/Tizen.Applications.Common/Tizen.Applications.Common.csproj
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 [changed mode: 0644->0755]
src/Tizen.Applications.Common/Tizen.Applications/DeviceOrientation.cs [new file with mode: 0755]
src/Tizen.Applications.Common/Tizen.Applications/DeviceOrientationEventArgs.cs [new file with mode: 0755]
src/Tizen.Applications.Service/Tizen.Applications.CoreBackend/ServiceCoreBackend.cs
src/Tizen.Applications.UI/Tizen.Applications.CoreBackend/UICoreBackend.cs

index a221828bfd51760f16581c0b409c7044ce0ec967..41603d20baeb12638db009b78203e9a2ed47de8a 100755 (executable)
@@ -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);
     }
 }
 
index 5b0bd9e70671c964ed5b35910c1546ef21621dd0..2278de13a5a10046e9b2aed5ab39763cd97c5fe1 100755 (executable)
@@ -66,6 +66,8 @@
     <Compile Include="Tizen.Applications\AppControlReplyCallback.cs" />
     <Compile Include="Tizen.Applications\ApplicationType.cs" />
     <Compile Include="Tizen.Applications\CoreApplication.cs" />
+    <Compile Include="Tizen.Applications\DeviceOrientation.cs" />
+    <Compile Include="Tizen.Applications\DeviceOrientationEventArgs.cs" />
     <Compile Include="Tizen.Applications\DirectoryInfo.cs" />
     <Compile Include="Tizen.Applications\ResourceManager.cs" />
     <Compile Include="Tizen.Applications\LocaleChangedEventArgs.cs" />
index 32918a167341082a72ea06197e71b9663b67d992..aabbbeb968fd10fce6bdc074f8d9d9a281d71f9b 100755 (executable)
@@ -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<DeviceOrientationEventArgs>;
+                handler?.Invoke(new DeviceOrientationEventArgs(orientation));
+            }
+        }
     }
 }
index 6985ae8f6f1e88d6a1cc90c2fd58e88b63609ef0..e24cddfb96531b0bbb676a44c3172277b38c6db5 100755 (executable)
@@ -70,6 +70,11 @@ namespace Tizen.Applications.CoreBackend
         /// </summary>
         public static readonly EventType RegionFormatChanged = "RegionFormatChanged";
 
+        /// <summary>
+        /// Pre-defined event type. "DeviceOrientationChanged"
+        /// </summary>
+        public static readonly EventType DeviceOrientationChanged = "DeviceOrientationChanged";
+
         private string _typeName;
 
         /// <summary>
old mode 100644 (file)
new mode 100755 (executable)
index f37b310..5bf6e39
@@ -72,6 +72,11 @@ namespace Tizen.Applications
         /// </summary>
         public event EventHandler<RegionFormatChangedEventArgs> RegionFormatChanged;
 
+        /// <summary>
+        /// Occurs when the device orientation is changed.
+        /// </summary>
+        public event EventHandler<DeviceOrientationEventArgs> DeviceOrientationChanged;
+
         /// <summary>
         /// The backend instance.
         /// </summary>
@@ -92,6 +97,7 @@ namespace Tizen.Applications
             _backend.AddEventHandler<LowBatteryEventArgs>(EventType.LowBattery, OnLowBattery);
             _backend.AddEventHandler<LocaleChangedEventArgs>(EventType.LocaleChanged, OnLocaleChanged);
             _backend.AddEventHandler<RegionFormatChangedEventArgs>(EventType.RegionFormatChanged, OnRegionFormatChanged);
+            _backend.AddEventHandler<DeviceOrientationEventArgs>(EventType.DeviceOrientationChanged, OnDeviceOrientationChanged);
 
             string[] argsClone = null;
 
@@ -181,6 +187,15 @@ namespace Tizen.Applications
             RegionFormatChanged?.Invoke(this, e);
         }
 
+        /// <summary>
+        /// 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.
+        /// </summary>
+        protected virtual void OnDeviceOrientationChanged(DeviceOrientationEventArgs e)
+        {
+            DeviceOrientationChanged?.Invoke(this, e);
+        }
+
         /// <summary>
         /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
         /// </summary>
diff --git a/src/Tizen.Applications.Common/Tizen.Applications/DeviceOrientation.cs b/src/Tizen.Applications.Common/Tizen.Applications/DeviceOrientation.cs
new file mode 100755 (executable)
index 0000000..5b41aea
--- /dev/null
@@ -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
+{
+    /// <summary>
+    /// Enumeration for device orientation.
+    /// </summary>
+    public enum DeviceOrientation
+    {
+        /// <summary>
+        /// The device orientation is 0
+        /// </summary>
+        Orientation_0 = 0,
+
+        /// <summary>
+        /// The device orientation is 90
+        /// </summary>
+        Orientation_90 = 90,
+
+        /// <summary>
+        /// The device orientation is 180
+        /// </summary>
+        Orientation_180 = 180,
+
+        /// <summary>
+        /// The device orientation is 270
+        /// </summary>
+        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 (executable)
index 0000000..e042e32
--- /dev/null
@@ -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
+{
+    /// <summary>
+    /// The class for event arguments of the DeviceOrientationChanged
+    /// </summary>
+    public class DeviceOrientationEventArgs : EventArgs
+    {
+        /// <summary>
+        ///  Initializes DeviceOrientationEventArgs class
+        /// </summary>
+        /// <param name="orientation"></param>
+        public DeviceOrientationEventArgs(DeviceOrientation orientation)
+        {
+            DeviceOrientation = orientation;
+        }
+
+        /// <summary>
+        /// The received DeviceOrientation
+        /// </summary>
+        public DeviceOrientation DeviceOrientation { get; private set; }
+    }
+}
\ No newline at end of file
index bf6746ccc89248fbe458d9b2a09a05bd3f0f7c4b..bc1a0968f6c0001e8634776641d5fee258783d74 100755 (executable)
@@ -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);
+        }
+
     }
 }
index 50af98b8f95b90824ad447faea5870843cdd4e50..933a4e0583eb81fb25ddf87b788f7ae6db52006b 100755 (executable)
@@ -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);
+        }
     }
 }