Rewrite of backend and events
This commit is contained in:
@@ -11,8 +11,10 @@ using Windows.ApplicationModel.Activation;
|
||||
using Windows.Devices.Geolocation;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.Graphics.Display;
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.ViewManagement;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Controls.Primitives;
|
||||
@@ -35,7 +37,7 @@ namespace NavCityBreda
|
||||
// =======================
|
||||
// SINGLETONS
|
||||
// =======================
|
||||
private static GeoTracker geo;
|
||||
private static GeoTracker geo = new GeoTracker();
|
||||
|
||||
public static GeoTracker Geo
|
||||
{
|
||||
@@ -45,7 +47,7 @@ namespace NavCityBreda
|
||||
}
|
||||
}
|
||||
|
||||
private static RouteManager rm;
|
||||
private static RouteManager rm = new RouteManager();
|
||||
|
||||
public static RouteManager RouteManager
|
||||
{
|
||||
@@ -55,6 +57,66 @@ namespace NavCityBreda
|
||||
}
|
||||
}
|
||||
|
||||
private static CompassTracker cm = new CompassTracker();
|
||||
|
||||
public static CompassTracker CompassTracker
|
||||
{
|
||||
get
|
||||
{
|
||||
return cm;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// =========================
|
||||
// STATIC HELPER FUNCTIONS
|
||||
// =========================
|
||||
|
||||
public static string RouteWaypointsFolder
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Routes/Waypoints/";
|
||||
}
|
||||
}
|
||||
|
||||
public static string RouteImagesFolder
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Routes/Images/";
|
||||
}
|
||||
}
|
||||
|
||||
public static Size ScreenSize
|
||||
{
|
||||
get
|
||||
{
|
||||
var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
|
||||
var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
|
||||
Size size = new Size(bounds.Width * scaleFactor, bounds.Height * scaleFactor);
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
public static MainPage MainPage
|
||||
{
|
||||
get
|
||||
{
|
||||
Frame f = Window.Current.Content as Frame;
|
||||
MainPage mp = f.Content as MainPage;
|
||||
return mp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ===============================
|
||||
// NORMAL STUFF
|
||||
// ===============================
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
@@ -64,9 +126,6 @@ namespace NavCityBreda
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
geo = new GeoTracker();
|
||||
rm = new RouteManager();
|
||||
|
||||
this.Suspending += OnSuspending;
|
||||
}
|
||||
|
||||
@@ -111,6 +170,7 @@ namespace NavCityBreda
|
||||
// parameter
|
||||
rootFrame.Navigate(typeof(MainPage), e.Arguments);
|
||||
}
|
||||
|
||||
// Ensure the current window is active
|
||||
Window.Current.Activate();
|
||||
}
|
||||
|
||||
@@ -10,13 +10,22 @@ namespace NavCityBreda.Helpers
|
||||
{
|
||||
static class Settings
|
||||
{
|
||||
public static ApplicationDataContainer LOCAL_SETTINGS = ApplicationData.Current.LocalSettings;
|
||||
private static ApplicationDataContainer LOCAL_SETTINGS = ApplicationData.Current.LocalSettings;
|
||||
|
||||
public static bool Tracking {
|
||||
get
|
||||
{
|
||||
return (bool)LOCAL_SETTINGS.Values["tracking"];
|
||||
}
|
||||
set
|
||||
{
|
||||
LOCAL_SETTINGS.Values["tracking"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
static Settings()
|
||||
{
|
||||
//Define default settings here
|
||||
if (LOCAL_SETTINGS.Values["track"] == null)
|
||||
LOCAL_SETTINGS.Values["track"] = true;
|
||||
LOCAL_SETTINGS.Values["tracking"] = true;
|
||||
}
|
||||
|
||||
public static async void ChangeLanguage(string lang)
|
||||
|
||||
@@ -4,11 +4,13 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.ApplicationModel.Resources;
|
||||
using Windows.Data.Xml.Dom;
|
||||
using Windows.Devices.Geolocation;
|
||||
using Windows.Foundation;
|
||||
using Windows.Graphics.Display;
|
||||
using Windows.Services.Maps;
|
||||
using Windows.UI;
|
||||
using Windows.UI.Notifications;
|
||||
using Windows.UI.ViewManagement;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
@@ -25,42 +27,6 @@ namespace NavCityBreda.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
public static string RouteWaypointsFolder
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Routes/Waypoints/";
|
||||
}
|
||||
}
|
||||
|
||||
public static string RouteImagesFolder
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Routes/Images/";
|
||||
}
|
||||
}
|
||||
|
||||
public static Size ScreenSize
|
||||
{
|
||||
get
|
||||
{
|
||||
var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
|
||||
var scaleFactor = DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
|
||||
Size size = new Size(bounds.Width * scaleFactor, bounds.Height * scaleFactor);
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
public static MainPage MainPage
|
||||
{
|
||||
get {
|
||||
Frame f = Window.Current.Content as Frame;
|
||||
MainPage mp = f.Content as MainPage;
|
||||
return mp;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<MapLocation> FindLocation(string location, Geopoint reference)
|
||||
{
|
||||
MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(location, reference);
|
||||
@@ -191,5 +157,25 @@ namespace NavCityBreda.Helpers
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
public static void SendToastNotification(string title, string text)
|
||||
{
|
||||
ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
|
||||
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
|
||||
|
||||
XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
|
||||
toastTextElements[0].AppendChild(toastXml.CreateTextNode(title));
|
||||
toastTextElements[1].AppendChild(toastXml.CreateTextNode(text));
|
||||
|
||||
IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
|
||||
XmlElement audio = toastXml.CreateElement("audio");
|
||||
|
||||
audio.SetAttribute("src", "ms-winsoundevent:Notification.IM");
|
||||
|
||||
toastNode.AppendChild(audio);
|
||||
|
||||
ToastNotification toast = new ToastNotification(toastXml);
|
||||
ToastNotificationManager.CreateToastNotifier().Show(toast);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Devices.Sensors;
|
||||
|
||||
namespace NavCityBreda.Model
|
||||
{
|
||||
public class CompassTracker
|
||||
{
|
||||
public delegate void OnHeadingUpdatedHandler(object sender, HeadingUpdatedEventArgs e);
|
||||
public event OnHeadingUpdatedHandler OnHeadingUpdated;
|
||||
|
||||
private Compass comp;
|
||||
|
||||
private string status;
|
||||
public string Status { get { return status; } }
|
||||
|
||||
private CompassReading hdn;
|
||||
public CompassReading Heading { get { return hdn; } }
|
||||
|
||||
public CompassTracker()
|
||||
{
|
||||
status = "Waiting...";
|
||||
comp = Compass.GetDefault();
|
||||
|
||||
// Assign an event handler for the compass reading-changed event
|
||||
if (comp != null)
|
||||
{
|
||||
// Establish the report interval for all scenarios
|
||||
uint minReportInterval = comp.MinimumReportInterval;
|
||||
uint reportInterval = minReportInterval > 16 ? minReportInterval : 16;
|
||||
comp.ReportInterval = reportInterval;
|
||||
comp.ReadingChanged += Comp_ReadingChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void Comp_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args)
|
||||
{
|
||||
UpdateHeading(args.Reading);
|
||||
}
|
||||
|
||||
private void UpdateHeading(CompassReading r)
|
||||
{
|
||||
hdn = r;
|
||||
|
||||
//Make sure someone is listening
|
||||
if (OnHeadingUpdated == null) return;
|
||||
|
||||
OnHeadingUpdated(this, new HeadingUpdatedEventArgs(r));
|
||||
}
|
||||
}
|
||||
|
||||
public class HeadingUpdatedEventArgs : EventArgs
|
||||
{
|
||||
public CompassReading Heading;
|
||||
|
||||
public HeadingUpdatedEventArgs(CompassReading heading)
|
||||
{
|
||||
Heading = heading;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,46 +14,61 @@ namespace NavCityBreda.Model
|
||||
{
|
||||
private Geolocator geo;
|
||||
|
||||
private string status;
|
||||
public string Status { get { return status; } }
|
||||
private PositionStatus _status;
|
||||
public PositionStatus Status { get { return _status; } }
|
||||
|
||||
private Geoposition pos;
|
||||
public Geoposition Position { get { return pos; } }
|
||||
private Geoposition _position;
|
||||
public Geoposition Position { get { return _position; } }
|
||||
|
||||
public bool? Connected { get; private set; }
|
||||
|
||||
private List<Geoposition> _history;
|
||||
public List<Geoposition> History
|
||||
{
|
||||
get
|
||||
{
|
||||
return _history;
|
||||
}
|
||||
}
|
||||
|
||||
//Events
|
||||
public delegate void PositionUpdateHandler(object sender, PositionUpdatedEventArgs e);
|
||||
public event PositionUpdateHandler OnPositionUpdate;
|
||||
|
||||
public delegate void StatusUpdateHandler(object sender, StatusUpdatedEventArgs e);
|
||||
public event StatusUpdateHandler OnStatusUpdate;
|
||||
|
||||
public GeoTracker()
|
||||
{
|
||||
status = "Waiting...";
|
||||
_status = PositionStatus.NotInitialized;
|
||||
Connected = false;
|
||||
_history = new List<Geoposition>();
|
||||
StartTracking();
|
||||
}
|
||||
|
||||
public event TypedEventHandler<Geolocator, StatusChangedEventArgs> StatusChanged
|
||||
{
|
||||
add { if(Connected == true) geo.StatusChanged += value; }
|
||||
remove { geo.StatusChanged -= value; }
|
||||
}
|
||||
|
||||
public event TypedEventHandler<Geolocator, PositionChangedEventArgs> PositionChanged
|
||||
{
|
||||
add { if (Connected == true) geo.PositionChanged += value; }
|
||||
remove { geo.PositionChanged -= value; }
|
||||
}
|
||||
|
||||
public async void ForceRefresh()
|
||||
{
|
||||
if(geo != null)
|
||||
pos = await geo.GetGeopositionAsync();
|
||||
if (geo == null)
|
||||
StartTracking();
|
||||
else
|
||||
_position = await geo.GetGeopositionAsync();
|
||||
}
|
||||
|
||||
private async void StartTracking()
|
||||
public void ClearHistory()
|
||||
{
|
||||
_history.Clear();
|
||||
}
|
||||
|
||||
public async void StartTracking()
|
||||
{
|
||||
// Request permission to access location
|
||||
if (Status != PositionStatus.NotAvailable && Status != PositionStatus.NotInitialized)
|
||||
return;
|
||||
|
||||
var accessStatus = await Geolocator.RequestAccessAsync();
|
||||
|
||||
switch (accessStatus)
|
||||
{
|
||||
{
|
||||
case GeolocationAccessStatus.Allowed:
|
||||
geo = new Geolocator {
|
||||
DesiredAccuracy = PositionAccuracy.High,
|
||||
@@ -66,31 +81,75 @@ namespace NavCityBreda.Model
|
||||
geo.PositionChanged += Geo_PositionChanged;
|
||||
geo.StatusChanged += Geo_StatusChanged;
|
||||
|
||||
status = "Waiting for update...";
|
||||
_status = PositionStatus.Initializing;
|
||||
break;
|
||||
|
||||
case GeolocationAccessStatus.Denied:
|
||||
Connected = false;
|
||||
status = "Access Denied";
|
||||
_status = PositionStatus.NotAvailable;
|
||||
bool result = await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location"));
|
||||
break;
|
||||
|
||||
default:
|
||||
case GeolocationAccessStatus.Unspecified:
|
||||
Connected = false;
|
||||
status = "Unspecified Error Occured";
|
||||
_status = PositionStatus.NotAvailable;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void Geo_StatusChanged(Geolocator sender, StatusChangedEventArgs args)
|
||||
{
|
||||
status = args.Status.ToString();
|
||||
UpdateStatus(args.Status);
|
||||
}
|
||||
|
||||
private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
|
||||
{
|
||||
pos = args.Position;
|
||||
if (_history.Count > 0)
|
||||
UpdatePosition(_history.Last(), args.Position);
|
||||
else
|
||||
_position = args.Position;
|
||||
_history.Add(args.Position);
|
||||
}
|
||||
|
||||
private void UpdateStatus(PositionStatus s)
|
||||
{
|
||||
_status = s;
|
||||
|
||||
if (OnStatusUpdate == null) return;
|
||||
|
||||
OnStatusUpdate(this, new StatusUpdatedEventArgs(s));
|
||||
}
|
||||
|
||||
private void UpdatePosition(Geoposition old, Geoposition newp)
|
||||
{
|
||||
_position = newp;
|
||||
|
||||
if (OnPositionUpdate == null) return;
|
||||
|
||||
OnPositionUpdate(this, new PositionUpdatedEventArgs(old, newp));
|
||||
}
|
||||
}
|
||||
|
||||
public class PositionUpdatedEventArgs : EventArgs
|
||||
{
|
||||
public Geoposition Old { get; private set; }
|
||||
public Geoposition New { get; private set; }
|
||||
|
||||
public PositionUpdatedEventArgs(Geoposition old, Geoposition notold)
|
||||
{
|
||||
Old = old;
|
||||
New = notold;
|
||||
}
|
||||
}
|
||||
|
||||
public class StatusUpdatedEventArgs : EventArgs
|
||||
{
|
||||
public PositionStatus Status { get; private set; }
|
||||
|
||||
public StatusUpdatedEventArgs(PositionStatus status)
|
||||
{
|
||||
Status = status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@ namespace NavCityBreda.Model
|
||||
{
|
||||
_visited = false;
|
||||
Description = desc;
|
||||
if (image_loc == "" || !File.Exists(Util.RouteImagesFolder + image_loc))
|
||||
if (image_loc == "" || !File.Exists(App.RouteImagesFolder + image_loc))
|
||||
image_loc = "default.jpg";
|
||||
Image = "/" + Util.RouteImagesFolder + image_loc;
|
||||
Image = "/" + App.RouteImagesFolder + image_loc;
|
||||
Id = Name + "_" + Order;
|
||||
|
||||
Icon = new MapIcon();
|
||||
|
||||
@@ -6,6 +6,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Devices.Geolocation;
|
||||
using Windows.Devices.Geolocation.Geofencing;
|
||||
using Windows.Services.Maps;
|
||||
|
||||
namespace NavCityBreda.Model
|
||||
{
|
||||
@@ -14,8 +16,11 @@ namespace NavCityBreda.Model
|
||||
public delegate void StatusUpdateHandler(object sender, RouteStatusChangedEventArgs e);
|
||||
public event StatusUpdateHandler OnStatusUpdate;
|
||||
|
||||
public delegate void PositionUpdateHandler(object sender, RoutePositionChangedEventArgs e);
|
||||
public event PositionUpdateHandler OnPositionUpdate;
|
||||
public delegate void OnLandmarkVisitedHandler(object sender, LandmarkVisitedEventArgs e);
|
||||
public event OnLandmarkVisitedHandler OnLandmarkVisited;
|
||||
|
||||
public delegate void OnRouteChangedHandler (object sender, RouteChangedEventArgs e);
|
||||
public event OnRouteChangedHandler OnRouteChanged;
|
||||
|
||||
private List<Route> _routes;
|
||||
public List<Route> Routes { get { return _routes; } }
|
||||
@@ -25,40 +30,58 @@ namespace NavCityBreda.Model
|
||||
|
||||
public string LoadingElement;
|
||||
|
||||
public enum State { STOPPED, STARTED }
|
||||
public State RouteState;
|
||||
private Landmark _currentlandmark;
|
||||
|
||||
private List<Geoposition> _history;
|
||||
public List<Geoposition> History
|
||||
{
|
||||
get
|
||||
{
|
||||
return _history;
|
||||
}
|
||||
}
|
||||
private MapRoute _routetolandmark;
|
||||
public MapRoute RouteToLandmark { get { return _routetolandmark; } }
|
||||
|
||||
public enum RouteStatus { STOPPED, STARTED }
|
||||
public RouteStatus Status;
|
||||
|
||||
public RouteManager()
|
||||
{
|
||||
_routes = new List<Route>();
|
||||
_history = new List<Geoposition>();
|
||||
|
||||
LoadingElement = "Initializing...";
|
||||
App.Geo.PositionChanged += Geo_PositionChanged;
|
||||
RouteState = State.STOPPED;
|
||||
Status = RouteStatus.STOPPED;
|
||||
GeofenceMonitor.Current.GeofenceStateChanged += Current_GeofenceStateChanged;
|
||||
LoadRoutes();
|
||||
}
|
||||
|
||||
private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
|
||||
private void Current_GeofenceStateChanged(GeofenceMonitor sender, object args)
|
||||
{
|
||||
if (RouteState == State.STARTED)
|
||||
var reports = sender.ReadReports();
|
||||
|
||||
foreach (GeofenceStateChangeReport report in reports)
|
||||
{
|
||||
OnPositionUpdate(this, new RoutePositionChangedEventArgs(_history.Last(), args.Position));
|
||||
_history.Add(args.Position);
|
||||
GeofenceState state = report.NewState;
|
||||
Geofence geofence = report.Geofence;
|
||||
Landmark i = App.RouteManager.CurrentRoute.Landmarks.Where(t => t.Id == geofence.Id).First();
|
||||
|
||||
if (state == GeofenceState.Removed)
|
||||
{
|
||||
GeofenceMonitor.Current.Geofences.Remove(geofence);
|
||||
}
|
||||
|
||||
else if (state == GeofenceState.Entered)
|
||||
{
|
||||
i.Visited = true;
|
||||
_currentlandmark = i;
|
||||
LandmarkVisited(i, LandmarkVisitedEventArgs.VisitedStatus.ENTERED);
|
||||
Util.SendToastNotification(i.Name, "You have visited a landmark.");
|
||||
UpdateRoute();
|
||||
}
|
||||
|
||||
else if(state == GeofenceState.Exited)
|
||||
{
|
||||
LandmarkVisited(i, LandmarkVisitedEventArgs.VisitedStatus.EXITED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void LoadRoutes()
|
||||
{
|
||||
string[] routefiles = Directory.GetFiles(Util.RouteWaypointsFolder);
|
||||
string[] routefiles = Directory.GetFiles(App.RouteWaypointsFolder);
|
||||
|
||||
_routes.Clear();
|
||||
|
||||
@@ -73,54 +96,100 @@ namespace NavCityBreda.Model
|
||||
LoadingElement = "Done";
|
||||
}
|
||||
|
||||
private void UpdateStatus(State status)
|
||||
public async void UpdateRoute()
|
||||
{
|
||||
RouteState = status;
|
||||
if (App.Geo.Position == null) return;
|
||||
|
||||
_currentlandmark = _currentroute.Landmarks.FirstOrDefault(p => !p.Visited);
|
||||
_routetolandmark = await Util.FindWalkingRoute(App.Geo.Position.Coordinate.Point, _currentlandmark.Location);
|
||||
UpdateRoute(_routetolandmark, _currentlandmark);
|
||||
}
|
||||
|
||||
public void StartRoute(Route r)
|
||||
{
|
||||
Util.SendToastNotification("Test", "I am testing this shit.");
|
||||
|
||||
App.Geo.ClearHistory();
|
||||
_currentroute = r;
|
||||
UpdateRoute();
|
||||
UpdateStatus(RouteStatus.STARTED);
|
||||
}
|
||||
|
||||
public void StopRoute()
|
||||
{
|
||||
if (Status == RouteStatus.STARTED)
|
||||
{
|
||||
_currentroute.Reset();
|
||||
_currentroute = null;
|
||||
_currentlandmark = null;
|
||||
_routetolandmark = null;
|
||||
UpdateStatus(RouteStatus.STOPPED);
|
||||
}
|
||||
}
|
||||
|
||||
// =============
|
||||
// Handle Events
|
||||
// =============
|
||||
private void UpdateStatus(RouteStatus status)
|
||||
{
|
||||
Status = status;
|
||||
// Make sure someone is listening to event
|
||||
if (OnStatusUpdate == null) return;
|
||||
|
||||
OnStatusUpdate(this, new RouteStatusChangedEventArgs(status));
|
||||
}
|
||||
|
||||
public void StartRoute(Route r)
|
||||
//Handle Events
|
||||
private void LandmarkVisited(Landmark l, LandmarkVisitedEventArgs.VisitedStatus status)
|
||||
{
|
||||
_currentroute = r;
|
||||
_history.Add(App.Geo.Position);
|
||||
UpdateStatus(State.STARTED);
|
||||
// Make sure someone is listening to event
|
||||
if (OnLandmarkVisited == null) return;
|
||||
|
||||
OnLandmarkVisited(this, new LandmarkVisitedEventArgs(l, status));
|
||||
}
|
||||
|
||||
public void StopRoute()
|
||||
//Handle Events
|
||||
private void UpdateRoute(MapRoute route, Landmark l)
|
||||
{
|
||||
if (RouteState == State.STARTED)
|
||||
{
|
||||
_currentroute.Reset();
|
||||
_currentroute = null;
|
||||
UpdateStatus(State.STOPPED);
|
||||
}
|
||||
// Make sure someone is listening to event
|
||||
if (OnRouteChanged == null) return;
|
||||
|
||||
_history.Clear();
|
||||
OnRouteChanged(this, new RouteChangedEventArgs(route, l));
|
||||
}
|
||||
}
|
||||
|
||||
public class RouteStatusChangedEventArgs : EventArgs
|
||||
{
|
||||
public RouteManager.State Status { get; private set; }
|
||||
public RouteManager.RouteStatus Status { get; private set; }
|
||||
|
||||
public RouteStatusChangedEventArgs(RouteManager.State status)
|
||||
public RouteStatusChangedEventArgs(RouteManager.RouteStatus status)
|
||||
{
|
||||
Status = status;
|
||||
}
|
||||
}
|
||||
|
||||
public class RoutePositionChangedEventArgs : EventArgs
|
||||
public class LandmarkVisitedEventArgs : EventArgs
|
||||
{
|
||||
public Geoposition Old { get; private set; }
|
||||
public Geoposition New { get; private set; }
|
||||
public Landmark Landmark { get; private set; }
|
||||
public enum VisitedStatus { ENTERED, EXITED }
|
||||
public VisitedStatus Status { get; private set; }
|
||||
|
||||
public RoutePositionChangedEventArgs(Geoposition old, Geoposition notold)
|
||||
public LandmarkVisitedEventArgs(Landmark landmark, VisitedStatus status)
|
||||
{
|
||||
Old = old;
|
||||
New = notold;
|
||||
Landmark = landmark;
|
||||
Status = status;
|
||||
}
|
||||
}
|
||||
|
||||
public class RouteChangedEventArgs : EventArgs
|
||||
{
|
||||
public Landmark Landmark { get; private set; }
|
||||
public MapRoute Route { get; private set; }
|
||||
|
||||
public RouteChangedEventArgs(MapRoute newroute, Landmark tolandmark)
|
||||
{
|
||||
Route = newroute;
|
||||
Landmark = tolandmark;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +135,7 @@
|
||||
<Compile Include="MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Model\CompassTracker.cs" />
|
||||
<Compile Include="Model\GeoTracker.cs" />
|
||||
<Compile Include="Model\Landmark.cs" />
|
||||
<Compile Include="Model\Route.cs" />
|
||||
|
||||
@@ -16,8 +16,25 @@ namespace NavCityBreda.ViewModel
|
||||
public MenuVM()
|
||||
{
|
||||
dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
|
||||
App.Geo.StatusChanged += Geo_StatusChanged;
|
||||
App.Geo.PositionChanged += Geo_PositionChanged;
|
||||
App.Geo.OnPositionUpdate += Geo_OnPositionUpdate;
|
||||
App.Geo.OnStatusUpdate += Geo_OnStatusUpdate;
|
||||
}
|
||||
|
||||
private void Geo_OnStatusUpdate(object sender, Model.StatusUpdatedEventArgs e)
|
||||
{
|
||||
dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
NotifyPropertyChanged(nameof(Status));
|
||||
});
|
||||
}
|
||||
|
||||
private void Geo_OnPositionUpdate(object sender, Model.PositionUpdatedEventArgs e)
|
||||
{
|
||||
dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
NotifyPropertyChanged(nameof(Source));
|
||||
NotifyPropertyChanged(nameof(Accuracy));
|
||||
});
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
@@ -27,29 +44,11 @@ namespace NavCityBreda.ViewModel
|
||||
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;
|
||||
return App.Geo.Status.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace NavCityBreda.Views
|
||||
{
|
||||
landmark = e.Parameter as Landmark;
|
||||
this.DataContext = landmark;
|
||||
Util.MainPage.Title = landmark.Name;
|
||||
App.MainPage.Title = landmark.Name;
|
||||
LoadStreet();
|
||||
}
|
||||
|
||||
|
||||
@@ -48,72 +48,67 @@ namespace NavCityBreda.Views
|
||||
CurrentPosition.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/CurrentLocationRound.png"));
|
||||
Map.MapElements.Add(CurrentPosition);
|
||||
|
||||
App.Geo.PositionChanged += Geo_PositionChanged;
|
||||
GeofenceMonitor.Current.GeofenceStateChanged += Current_GeofenceStateChanged;
|
||||
App.RouteManager.OnPositionUpdate += RouteManager_OnPositionUpdate;
|
||||
App.Geo.OnPositionUpdate += Geo_OnPositionUpdate;
|
||||
App.RouteManager.OnStatusUpdate += RouteManager_OnStatusUpdate;
|
||||
App.RouteManager.OnRouteChanged += RouteManager_OnRouteChanged;
|
||||
App.RouteManager.OnLandmarkVisited += RouteManager_OnLandmarkVisited;
|
||||
App.CompassTracker.OnHeadingUpdated += CompassTracker_OnHeadingUpdated;
|
||||
}
|
||||
|
||||
private void Current_GeofenceStateChanged(GeofenceMonitor sender, object args)
|
||||
private void CompassTracker_OnHeadingUpdated(object sender, HeadingUpdatedEventArgs e)
|
||||
{
|
||||
var reports = sender.ReadReports();
|
||||
|
||||
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
foreach (GeofenceStateChangeReport report in reports)
|
||||
{
|
||||
GeofenceState state = report.NewState;
|
||||
Geofence geofence = report.Geofence;
|
||||
|
||||
if (state == GeofenceState.Removed)
|
||||
{
|
||||
GeofenceMonitor.Current.Geofences.Remove(geofence);
|
||||
}
|
||||
|
||||
else if (state == GeofenceState.Entered)
|
||||
{
|
||||
Landmark i = App.RouteManager.CurrentRoute.Landmarks.Where(t => t.Id == geofence.Id).First();
|
||||
i.Visited = true;
|
||||
Util.MainPage.Navigate(typeof(LandmarkView), i);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (Settings.Tracking && e.Heading.HeadingTrueNorth.HasValue) return;
|
||||
// Map.TryRotateToAsync((double)e.Heading.HeadingTrueNorth);
|
||||
}
|
||||
|
||||
private void RouteManager_OnPositionUpdate(object sender, RoutePositionChangedEventArgs e)
|
||||
private void RouteManager_OnLandmarkVisited(object sender, LandmarkVisitedEventArgs e)
|
||||
{
|
||||
if(e.Status == LandmarkVisitedEventArgs.VisitedStatus.ENTERED)
|
||||
App.MainPage.Navigate(typeof(LandmarkView), e.Landmark);
|
||||
}
|
||||
|
||||
private void RouteManager_OnRouteChanged(object sender, RouteChangedEventArgs e)
|
||||
{
|
||||
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
MapPolyline linebit = Util.GetRouteLine(e.Old.Coordinate.Point.Position, e.New.Coordinate.Point.Position, Color.FromArgb(255, 155, 155, 155));
|
||||
MapPolyline linebit = Util.GetRouteLine(e.Route, Color.FromArgb(255, 255, 100, 100));
|
||||
Map.MapElements.Add(linebit);
|
||||
});
|
||||
}
|
||||
|
||||
private void Geo_OnPositionUpdate(object sender, PositionUpdatedEventArgs e)
|
||||
{
|
||||
if (App.RouteManager.Status == RouteManager.RouteStatus.STARTED)
|
||||
{
|
||||
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
MapPolyline linebit = Util.GetRouteLine(e.Old.Coordinate.Point.Position, e.New.Coordinate.Point.Position, Color.FromArgb(255, 155, 155, 155));
|
||||
Map.MapElements.Add(linebit);
|
||||
});
|
||||
}
|
||||
|
||||
Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
|
||||
{
|
||||
DrawCurrenPosition(e.New.Coordinate.Point);
|
||||
});
|
||||
}
|
||||
|
||||
private void RouteManager_OnStatusUpdate(object sender, RouteStatusChangedEventArgs e)
|
||||
{
|
||||
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
if (e.Status == RouteManager.State.STARTED)
|
||||
if (e.Status == RouteManager.RouteStatus.STARTED)
|
||||
DrawRoute();
|
||||
else
|
||||
RemoveRoute();
|
||||
});
|
||||
}
|
||||
|
||||
private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
|
||||
{
|
||||
Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
|
||||
{
|
||||
DrawCurrenPosition(args.Position.Coordinate.Point);
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawRoute()
|
||||
{
|
||||
Route r = App.RouteManager.CurrentRoute;
|
||||
|
||||
Settings.LOCAL_SETTINGS.Values["track"] = false;
|
||||
Settings.Tracking = false;
|
||||
|
||||
GeofenceMonitor.Current.Geofences.Clear();
|
||||
Map.MapElements.Clear();
|
||||
@@ -133,7 +128,7 @@ namespace NavCityBreda.Views
|
||||
|
||||
private void RemoveRoute()
|
||||
{
|
||||
Settings.LOCAL_SETTINGS.Values["track"] = true;
|
||||
Settings.Tracking = true;
|
||||
Map.MapElements.Clear();
|
||||
DrawCurrenPosition(App.Geo.Position.Coordinate.Point);
|
||||
}
|
||||
@@ -144,7 +139,7 @@ namespace NavCityBreda.Views
|
||||
Map.MapElements.Add(CurrentPosition);
|
||||
|
||||
CurrentPosition.Location = p;
|
||||
if ((bool)Settings.LOCAL_SETTINGS.Values["track"])
|
||||
if (Settings.Tracking)
|
||||
Zoom();
|
||||
}
|
||||
|
||||
@@ -163,6 +158,7 @@ namespace NavCityBreda.Views
|
||||
private void Map_MapElementClick(MapControl sender, MapElementClickEventArgs args)
|
||||
{
|
||||
MapIcon i = args.MapElements.Where(p => p is MapIcon).Cast<MapIcon>().First();
|
||||
if (i == null) return;
|
||||
|
||||
Waypoint w = App.RouteManager.CurrentRoute.Get(i);
|
||||
if (w == null || !(w is Landmark))
|
||||
@@ -170,7 +166,7 @@ namespace NavCityBreda.Views
|
||||
|
||||
Landmark l = w as Landmark;
|
||||
|
||||
Util.MainPage.Navigate(typeof(LandmarkView), l);
|
||||
App.MainPage.Navigate(typeof(LandmarkView), l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace NavCityBreda.Views
|
||||
route = r;
|
||||
vm = new RouteDetailVM(route);
|
||||
this.DataContext = vm;
|
||||
Util.MainPage.Title = route.Name;
|
||||
App.MainPage.Title = route.Name;
|
||||
|
||||
Map.MapElements.Clear();
|
||||
|
||||
@@ -62,13 +62,8 @@ namespace NavCityBreda.Views
|
||||
MapPolyline m = Util.GetRouteLine(route.RouteObject, Color.FromArgb(255, 100, 100, 255));
|
||||
Map.MapElements.Add(m);
|
||||
|
||||
Random rand = new Random();
|
||||
|
||||
foreach (Landmark l in route.Landmarks)
|
||||
{
|
||||
int randint = rand.Next(0,20);
|
||||
if (randint > 15)
|
||||
l.Visited = true;
|
||||
l.UpdateIconImage();
|
||||
Map.MapElements.Add(l.Icon);
|
||||
}
|
||||
@@ -82,20 +77,20 @@ namespace NavCityBreda.Views
|
||||
|
||||
private void LandmarkList_ItemClick(object sender, ItemClickEventArgs e)
|
||||
{
|
||||
MainPage mp = Util.MainPage;
|
||||
MainPage mp = App.MainPage;
|
||||
mp.Navigate(typeof(LandmarkView), e.ClickedItem as Landmark);
|
||||
}
|
||||
|
||||
private void StartRouteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App.RouteManager.StartRoute(route);
|
||||
Util.MainPage.Navigate(typeof(MapView));
|
||||
App.MainPage.Navigate(typeof(MapView));
|
||||
}
|
||||
|
||||
private void StopRouteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
App.RouteManager.StopRoute();
|
||||
Util.MainPage.Navigate(typeof(MapView));
|
||||
App.MainPage.Navigate(typeof(MapView));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace NavCityBreda.Views
|
||||
|
||||
private void RouteList_ItemClick(object sender, ItemClickEventArgs e)
|
||||
{
|
||||
MainPage mp = Util.MainPage;
|
||||
MainPage mp = App.MainPage;
|
||||
mp.Navigate(typeof(RouteDetailView), e.ClickedItem as Route);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace NavCityBreda.Views
|
||||
public SettingsView()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
throw new NotImplementedException("Tracking");
|
||||
throw new NotImplementedException("Tracking + tilemaps");
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user