diff --git a/NavCityBreda/App.xaml.cs b/NavCityBreda/App.xaml.cs index 96f495e..71f8d32 100644 --- a/NavCityBreda/App.xaml.cs +++ b/NavCityBreda/App.xaml.cs @@ -1,4 +1,5 @@ using NavCityBreda.Helpers; +using NavCityBreda.Model; using System; using System.Collections.Generic; using System.IO; @@ -6,6 +7,7 @@ using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using Windows.ApplicationModel; using Windows.ApplicationModel.Activation; +using Windows.Devices.Geolocation; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.Storage; @@ -25,6 +27,20 @@ namespace NavCityBreda /// sealed partial class App : Application { + + public static Frame rootFrame; + + private static GeoTracker geo = new GeoTracker(); + + public static GeoTracker Geo + { + get + { + return geo; + } + } + + /// /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). @@ -50,7 +66,7 @@ namespace NavCityBreda } #endif - Frame rootFrame = Window.Current.Content as Frame; + rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active diff --git a/NavCityBreda/MainPage.xaml b/NavCityBreda/MainPage.xaml index d632979..fc6dbf8 100644 --- a/NavCityBreda/MainPage.xaml +++ b/NavCityBreda/MainPage.xaml @@ -16,13 +16,31 @@ + + + + + + + @@ -38,14 +56,20 @@ - + - + ManipulationCompleted="MySplitviewPane_ManipulationCompleted" + Background="Transparent"> - + + + + + + + @@ -59,19 +83,38 @@ - + + + + + + + + + + + + + + + + + + + + - - + diff --git a/NavCityBreda/MainPage.xaml.cs b/NavCityBreda/MainPage.xaml.cs index 0bb633c..b6c1c82 100644 --- a/NavCityBreda/MainPage.xaml.cs +++ b/NavCityBreda/MainPage.xaml.cs @@ -1,4 +1,5 @@ using NavCityBreda.Helpers; +using NavCityBreda.ViewModel; using NavCityBreda.Views; using System; using System.Collections.Generic; @@ -33,6 +34,8 @@ namespace NavCityBreda Frame.Navigated += Frame_Navigated; SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested; Frame.Navigate(typeof(MapView)); + + this.DataContext = new MenuVM(); } private void OnBackRequested(object sender, BackRequestedEventArgs e) @@ -53,7 +56,6 @@ namespace NavCityBreda { //Dirty Hack string pagename = e.SourcePageType.ToString().Split('.').Last(); - Debug.WriteLine(pagename); NavList.SelectedIndex = -1; @@ -76,6 +78,7 @@ namespace NavCityBreda break; case "routeview": PageTitle.Text = Util.Loader.GetString("PageTitleRoute"); + NavListRoute.IsSelected = true; break; case "waypointview": PageTitle.Text = Util.Loader.GetString("PageTitleWaypoint"); @@ -93,18 +96,21 @@ namespace NavCityBreda NavView.IsPaneOpen = false; if (NavListHelp.IsSelected) - { Frame.Navigate(typeof(HelpView)); - } else if (NavListSettings.IsSelected) - { Frame.Navigate(typeof(SettingsView)); - } + else if(NavListRoute.IsSelected) + Frame.Navigate(typeof(RouteView)); + } + + private void NavList_Tapped(object sender, TappedRoutedEventArgs e) + { + NavView.IsPaneOpen = false; } private void Grid_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) { - if (e.Cumulative.Translation.X > 50) + if (e.Cumulative.Translation.X > 20) { NavView.IsPaneOpen = true; } @@ -112,10 +118,15 @@ namespace NavCityBreda private void MySplitviewPane_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) { - if (e.Cumulative.Translation.X < -50) + if (e.Cumulative.Translation.X < -20) { NavView.IsPaneOpen = false; } } + + private void GPSRefresh_Tapped(object sender, TappedRoutedEventArgs e) + { + App.Geo.ForceRefresh(); + } } } diff --git a/NavCityBreda/Model/GeoTracker.cs b/NavCityBreda/Model/GeoTracker.cs new file mode 100644 index 0000000..2538aab --- /dev/null +++ b/NavCityBreda/Model/GeoTracker.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.Devices.Geolocation; +using Windows.Foundation; +using Windows.System; + +namespace NavCityBreda.Model +{ + public class GeoTracker + { + private Geolocator geo; + + private string status; + public string Status { get { return status; } } + + private Geoposition pos; + public Geoposition Position { get { return pos; } } + + public bool Connected { get; private set; } + + public GeoTracker() + { + status = "Waiting..."; + Connected = false; + StartTracking(); + } + + public event TypedEventHandler StatusChanged + { + add { if(Connected)geo.StatusChanged += value; } + remove { geo.StatusChanged -= value; } + } + + public event TypedEventHandler PositionChanged + { + add { if (Connected) geo.PositionChanged += value; } + remove { geo.PositionChanged -= value; } + } + + public async void ForceRefresh() + { + pos = await geo.GetGeopositionAsync(); + } + + private async void StartTracking() + { + // Request permission to access location + var accessStatus = await Geolocator.RequestAccessAsync(); + + switch (accessStatus) + { + case GeolocationAccessStatus.Allowed: + geo = new Geolocator { + DesiredAccuracy = PositionAccuracy.High, + //MovementThreshold = 1 + ReportInterval = 500 + }; + + Connected = true; + + geo.PositionChanged += Geo_PositionChanged; + geo.StatusChanged += Geo_StatusChanged; + + status = "Waiting for update..."; + break; + + case GeolocationAccessStatus.Denied: + status = "Access Denied"; + bool result = await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location")); + break; + + default: + case GeolocationAccessStatus.Unspecified: + status = "Unspecified Error Occured"; + break; + } + } + + private void Geo_StatusChanged(Geolocator sender, StatusChangedEventArgs args) + { + status = args.Status.ToString(); + } + + private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args) + { + pos = args.Position; + } + } +} diff --git a/NavCityBreda/NavCityBreda.csproj b/NavCityBreda/NavCityBreda.csproj index 0daebe6..6cdca7b 100644 --- a/NavCityBreda/NavCityBreda.csproj +++ b/NavCityBreda/NavCityBreda.csproj @@ -90,10 +90,10 @@ - - + + - + @@ -105,7 +105,10 @@ MainPage.xaml + + + HelpView.xaml diff --git a/NavCityBreda/ViewModel/MapVM.cs b/NavCityBreda/ViewModel/MapVM.cs new file mode 100644 index 0000000..db2a932 --- /dev/null +++ b/NavCityBreda/ViewModel/MapVM.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.Devices.Geolocation; +using Windows.UI.Core; + +namespace NavCityBreda.ViewModel +{ + class MapVM : INotifyPropertyChanged + { + CoreDispatcher dispatcher; + + public MapVM() + { + dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher; + App.Geo.StatusChanged += Geo_StatusChanged; + App.Geo.PositionChanged += Geo_PositionChanged; + } + + public event PropertyChangedEventHandler PropertyChanged; + + private void NotifyPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + private void Geo_StatusChanged(Geolocator sender, StatusChangedEventArgs args) + { + dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => + { + + }); + + } + + private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args) + { + dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => + { + + }); + } + } +} diff --git a/NavCityBreda/ViewModel/MenuVM.cs b/NavCityBreda/ViewModel/MenuVM.cs new file mode 100644 index 0000000..7375fed --- /dev/null +++ b/NavCityBreda/ViewModel/MenuVM.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.Devices.Geolocation; +using Windows.UI.Core; + +namespace NavCityBreda.ViewModel +{ + public class MenuVM : INotifyPropertyChanged + { + CoreDispatcher dispatcher; + + public MenuVM() + { + dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher; + App.Geo.StatusChanged += Geo_StatusChanged; + App.Geo.PositionChanged += Geo_PositionChanged; + } + + public event PropertyChangedEventHandler PropertyChanged; + + private void NotifyPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + private void Geo_StatusChanged(Geolocator sender, StatusChangedEventArgs args) + { + dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => + { + NotifyPropertyChanged(nameof(Status)); + }); + + } + + private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args) + { + dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => + { + NotifyPropertyChanged(nameof(Source)); + NotifyPropertyChanged(nameof(Accuracy)); + }); + } + + public string Status + { + get + { + return App.Geo.Status; + } + } + + public string Source + { + get + { + if (App.Geo.Connected && App.Geo.Position != null) + return App.Geo.Position.Coordinate.PositionSource.ToString(); + else + return "N/A"; + } + } + + public string Accuracy + { + get + { + + if (App.Geo.Connected && App.Geo.Position != null) + return App.Geo.Position.Coordinate.Accuracy.ToString() + "m"; + else + return "0m"; + } + } + } +} diff --git a/NavCityBreda/Views/MapView.xaml.cs b/NavCityBreda/Views/MapView.xaml.cs index 2b9b996..4c72d21 100644 --- a/NavCityBreda/Views/MapView.xaml.cs +++ b/NavCityBreda/Views/MapView.xaml.cs @@ -1,4 +1,5 @@ -using System; +using NavCityBreda.ViewModel; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -12,6 +13,8 @@ using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; +using Windows.Devices.Geolocation; +using Windows.UI.Xaml.Controls.Maps; // The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 @@ -22,10 +25,36 @@ namespace NavCityBreda.Views /// public sealed partial class MapView : Page { + MapIcon CurrenPosition; + public MapView() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Enabled; + + this.DataContext = new MapVM(); + + CurrenPosition = new MapIcon(); + + App.Geo.PositionChanged += Geo_PositionChanged; + } + + private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args) + { + Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => + { + DrawCurrenPosition(new Geopoint(args.Position.Coordinate.Point.Position)); + }); + } + + private void DrawCurrenPosition(Geopoint p) + { + CurrenPosition.Location = p; + CurrenPosition.NormalizedAnchorPoint = new Point(0.5, 1.0); + CurrenPosition.Title = "Current Position"; + CurrenPosition.ZIndex = 999; + + Map.MapElements.Add(CurrenPosition); } } }