diff --git a/Windows Phone/VineCache/VineCache/App.xaml.cs b/Windows Phone/VineCache/VineCache/App.xaml.cs index 5ca7b4f..78e9817 100644 --- a/Windows Phone/VineCache/VineCache/App.xaml.cs +++ b/Windows Phone/VineCache/VineCache/App.xaml.cs @@ -6,6 +6,7 @@ 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.UI.Xaml; @@ -27,6 +28,7 @@ namespace VineCache public sealed partial class App : Application { private TransitionCollection transitions; + private static Geolocator s_GPS; /// /// Initializes the singleton application object. This is the first line of authored code @@ -152,7 +154,22 @@ protected override void OnActivated(IActivatedEventArgs args) /// private void OnFacebookAuthenticationFinished(AccessTokenData session) { - //TODO: Add transition to new page when authentication has finished + Frame rootFrame = Window.Current.Content as Frame; + rootFrame.Navigate(typeof(DisplayVideoPage)); + } + + internal static Geolocator GPS + { + get + { + if (s_GPS == null) + { + s_GPS = new Geolocator(); + s_GPS.DesiredAccuracy = PositionAccuracy.High; + s_GPS.MovementThreshold = 10; + } + return s_GPS; + } } } } \ No newline at end of file diff --git a/Windows Phone/VineCache/VineCache/Assets/Fountain.small.mp4 b/Windows Phone/VineCache/VineCache/Assets/Fountain.small.mp4 new file mode 100644 index 0000000..f362cf1 Binary files /dev/null and b/Windows Phone/VineCache/VineCache/Assets/Fountain.small.mp4 differ diff --git a/Windows Phone/VineCache/VineCache/DisplayVideoPage.xaml b/Windows Phone/VineCache/VineCache/DisplayVideoPage.xaml new file mode 100644 index 0000000..e77a807 --- /dev/null +++ b/Windows Phone/VineCache/VineCache/DisplayVideoPage.xaml @@ -0,0 +1,19 @@ + + + + + + + + + + + diff --git a/Windows Phone/VineCache/VineCache/DisplayVideoPage.xaml.cs b/Windows Phone/VineCache/VineCache/DisplayVideoPage.xaml.cs new file mode 100644 index 0000000..9f1d622 --- /dev/null +++ b/Windows Phone/VineCache/VineCache/DisplayVideoPage.xaml.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +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.Navigation; +using Windows.Devices.Geolocation; + +// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556 + +namespace VineCache +{ + /// + /// An empty page that can be used on its own or navigated to within a Frame. + /// + public sealed partial class DisplayVideoPage : Page + { + private Geopoint startingPoint; + private double m_startingDistance; + + public DisplayVideoPage() + { + this.InitializeComponent(); + App.GPS.PositionChanged += gps_PositionChanged; + } + + /// + /// Executes when the GPS Device detects that it's position has changed + /// + /// + /// + private void gps_PositionChanged(Geolocator sender, PositionChangedEventArgs args) + { + if (startingPoint != null) + { + UpdateProgress(args.Position.Coordinate.Point); + } + } + + /// + /// Update the progress bar + /// + /// The current location + private async void UpdateProgress(Geopoint point) + { + await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,() => + { + double currentDistance = GPSHelper.CalculateDistance(point, GetTargetCoordinates()); + this.distanceToObjectProgressBar.Value = GPSHelper.CalculateProgress(currentDistance, m_startingDistance); + if (GPSHelper.IsTargetClose(currentDistance)) + { + NavigateToUploadVideoPage(); + } + }); + } + + /// + /// Invoked when this page is about to be displayed in a Frame. + /// + /// Event data that describes how this page was reached. + /// This parameter is typically used to configure the page. + protected override void OnNavigatedTo(NavigationEventArgs e) + { + } + + private async void videoMediaElement_Tapped(object sender, TappedRoutedEventArgs e) + { + this.NavigateToUploadVideoPage(); + videoMediaElement.Play(); + distanceToObjectProgressBar.Value = 50; + if (this.startingPoint == null) + { + Geoposition position = await App.GPS.GetGeopositionAsync(); + if (position != null) + { + startingPoint = position.Coordinate.Point; + m_startingDistance = GPSHelper.CalculateDistance(startingPoint, GetTargetCoordinates()); + } + } + } + + private void NavigateToUploadVideoPage() + { + Frame rootFrame = Window.Current.Content as Frame; + rootFrame.Navigate(typeof(UploadVideoPage)); + } + + private Point GetTargetCoordinates() + { + //TODO: Get GPS Point from Node + return new Point(47.6455, -122.1286); + } + } +} diff --git a/Windows Phone/VineCache/VineCache/GPSHelper.cs b/Windows Phone/VineCache/VineCache/GPSHelper.cs new file mode 100644 index 0000000..68dd6dc --- /dev/null +++ b/Windows Phone/VineCache/VineCache/GPSHelper.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Windows.Devices.Geolocation; +using Windows.Foundation; + +namespace VineCache +{ + public class GPSHelper + { + /// + /// Calculates the distance (in meters) between GPS coordinates + /// + /// + /// + /// + public static double CalculateDistance(Geopoint startingPoint, Point targetPoint) + { + double i = (Math.Cos(DegreeToRadian(targetPoint.X)) * Math.Cos(DegreeToRadian(startingPoint.Position.Latitude)) + * Math.Cos(DegreeToRadian(targetPoint.Y)) * Math.Cos(DegreeToRadian(startingPoint.Position.Longitude)) + + Math.Cos(DegreeToRadian(targetPoint.X)) * Math.Sin(DegreeToRadian(targetPoint.Y)) + * Math.Cos(DegreeToRadian(startingPoint.Position.Latitude)) * Math.Sin(DegreeToRadian(startingPoint.Position.Longitude)) + + Math.Sin(DegreeToRadian(targetPoint.X)) * Math.Sin(DegreeToRadian(startingPoint.Position.Latitude))); + + double meters = (6371000 * (Math.Acos(i))); + return meters; + } + + /// + /// Calcuate the progess 0-100 (100complete) of traveling to the target location + /// + /// + /// + /// + public static double CalculateProgress(double currentDistance, double startingDistance) + { + double zeroDistance = startingDistance * 2; + double progressDistance = zeroDistance - currentDistance; + double progress = (progressDistance / zeroDistance) * 100; + return progress; + } + + /// + /// Converte Degrees to radians + /// + /// + /// + public static double DegreeToRadian(double angle) + { + return Math.PI * angle / 180.0; + } + + /// + /// Is the target within 25 meters? + /// + /// + /// + public static bool IsTargetClose(double distance) + { + return distance < 25; + } + } +} diff --git a/Windows Phone/VineCache/VineCache/MainPage.xaml b/Windows Phone/VineCache/VineCache/MainPage.xaml index 8c95f40..bd9a53f 100644 --- a/Windows Phone/VineCache/VineCache/MainPage.xaml +++ b/Windows Phone/VineCache/VineCache/MainPage.xaml @@ -15,9 +15,5 @@ - - - - diff --git a/Windows Phone/VineCache/VineCache/MainPage.xaml.cs b/Windows Phone/VineCache/VineCache/MainPage.xaml.cs index 974d871..24dc47f 100644 --- a/Windows Phone/VineCache/VineCache/MainPage.xaml.cs +++ b/Windows Phone/VineCache/VineCache/MainPage.xaml.cs @@ -47,7 +47,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e) private void facebookLoginButton_OnSessionStateChanged(object sender, Facebook.Client.Controls.SessionStateChangedEventArgs e) { - + } } } diff --git a/Windows Phone/VineCache/VineCache/Package.appxmanifest b/Windows Phone/VineCache/VineCache/Package.appxmanifest index c52d91f..2e74795 100644 --- a/Windows Phone/VineCache/VineCache/Package.appxmanifest +++ b/Windows Phone/VineCache/VineCache/Package.appxmanifest @@ -33,5 +33,9 @@ + + + + \ No newline at end of file diff --git a/Windows Phone/VineCache/VineCache/StoreManifest.xml b/Windows Phone/VineCache/VineCache/StoreManifest.xml new file mode 100644 index 0000000..2a93c86 --- /dev/null +++ b/Windows Phone/VineCache/VineCache/StoreManifest.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Windows Phone/VineCache/VineCache/UploadVideoPage.xaml b/Windows Phone/VineCache/VineCache/UploadVideoPage.xaml new file mode 100644 index 0000000..2a24ed1 --- /dev/null +++ b/Windows Phone/VineCache/VineCache/UploadVideoPage.xaml @@ -0,0 +1,25 @@ + + + + + + + + + + + + +