[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);
}
}
<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" />
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));
+ }
+ }
}
}
/// </summary>
public static readonly EventType RegionFormatChanged = "RegionFormatChanged";
+ /// <summary>
+ /// Pre-defined event type. "DeviceOrientationChanged"
+ /// </summary>
+ public static readonly EventType DeviceOrientationChanged = "DeviceOrientationChanged";
+
private string _typeName;
/// <summary>
/// </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>
_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;
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>
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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
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()
{
_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()
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)
{
Interop.Service.RemoveEventHandler(_regionChangedEventHandle);
}
+ if (_deviceOrientationChangedEventHandle != IntPtr.Zero)
+ {
+ Interop.Service.RemoveEventHandler(_deviceOrientationChangedEventHandle);
+ }
+
_disposedValue = true;
}
}
base.OnRegionChangedNative(infoHandle, data);
}
+ protected override void OnDeviceOrientationChangedNative(IntPtr infoHandle, IntPtr data)
+ {
+ base.OnDeviceOrientationChangedNative(infoHandle, data);
+ }
+
}
}
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()
{
_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()
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)
{
{
Interop.Application.RemoveEventHandler(_regionChangedEventHandle);
}
+ if (_deviceOrientationChangedEventHandle != IntPtr.Zero)
+ {
+ Interop.Application.RemoveEventHandler(_deviceOrientationChangedEventHandle);
+ }
_disposedValue = true;
}
{
base.OnRegionChangedNative(infoHandle, data);
}
+
+ protected override void OnDeviceOrientationChangedNative(IntPtr infoHandle, IntPtr data)
+ {
+ base.OnDeviceOrientationChangedNative(infoHandle, data);
+ }
}
}