aliozgur / Xamarin.Plugins

MIT License
16 stars 10 forks source link

UWP support? #7

Open tancevsasa opened 7 years ago

tancevsasa commented 7 years ago

Can you please add support for UWP or Windows Phone (none Silverlight platform) Here is proposal

using System; using Xamarin.Forms;

using Windows.Devices.Sensors; using System.Windows;

using Windows.UI.ViewManagement; using Windows.ApplicationModel; using Windows.ApplicationModel.Activation; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Media.Animation; using Windows.UI.Xaml.Navigation;

[assembly: Dependency(typeof(DeviceOrientationImplementation))] namespace MyRootNameSpace { ///

/// DeviceOrientation Implementation /// public class DeviceOrientationImplementation : IDeviceOrientation { /// /// Used for registration with dependency service /// public static void Init() { }

    /// <summary>
    /// Send orientation change message through MessagingCenter
    /// </summary>
    /// <param name="e">Orientation changed event args</param>
    public static void NotifyOrientationChange(SimpleOrientationSensorOrientationChangedEventArgs e)
    {
        ApplicationViewOrientation orientation = ApplicationView.GetForCurrentView().Orientation;
        //bool isLandscape = (e.Orientation & PageOrientation.Landscape) == PageOrientation.Landscape;
        var msg = new DeviceOrientationChangeMessage()
        {
            Orientation = orientation == ApplicationViewOrientation.Landscape ? DeviceOrientations.Landscape : DeviceOrientations.Portrait
//          Orientation = isLandscape ? DeviceOrientations.Landscape : DeviceOrientations.Portrait
        };
        MessagingCenter.Send<DeviceOrientationChangeMessage>(msg, DeviceOrientationChangeMessage.MessageId);
    }

    /// <summary>
    /// Gets the orientation.
    /// </summary>
    /// <returns>The orientation.</returns>
    public DeviceOrientations GetOrientation()
    {
        if (ApplicationView.GetForCurrentView() == null)
            return DeviceOrientations.Undefined;

        return ApplicationView.GetForCurrentView().Orientation == ApplicationViewOrientation.Landscape ? DeviceOrientations.Landscape : DeviceOrientations.Portrait;

    }
}

}

aliozgur commented 7 years ago

@tancevsasa pull requests are welcome. Please fork the repo and send me the pull request. Thanks