Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Windows Phone/VineCache/VineCache/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,7 @@ namespace VineCache
public sealed partial class App : Application
{
private TransitionCollection transitions;
private static Geolocator s_GPS;

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
Expand Down Expand Up @@ -152,7 +154,22 @@ protected override void OnActivated(IActivatedEventArgs args)
/// <param name="session"></param>
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;
}
}
}
}
Binary file not shown.
19 changes: 19 additions & 0 deletions Windows Phone/VineCache/VineCache/DisplayVideoPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Page
x:Class="VineCache.DisplayVideoPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:VineCache"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid Background="White">
<TextBlock x:Name="gameNameTextBlock" Text="(Game name goes here)" Foreground="Green" FontSize="22" FontWeight="SemiBold" Margin="20,20,0,575"/>
<TextBlock Text="Find the location this video was taken:" Foreground="Green" FontSize="16" Margin="20,65,0,555"/>
<StackPanel Background="Black" Margin="20,90,20,0" VerticalAlignment="Top" >
<MediaElement x:Name="videoMediaElement" Source="Assets/Fountain.small.mp4" AutoPlay="False" Tapped="videoMediaElement_Tapped" VerticalAlignment="Top"/>
</StackPanel>
<ProgressBar x:Name="distanceToObjectProgressBar" FlowDirection="LeftToRight" HorizontalAlignment="Left" Height="20" VerticalAlignment="Bottom" Margin="20,0,0,20" Width="360" />
</Grid>
</Page>
102 changes: 102 additions & 0 deletions Windows Phone/VineCache/VineCache/DisplayVideoPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class DisplayVideoPage : Page
{
private Geopoint startingPoint;
private double m_startingDistance;

public DisplayVideoPage()
{
this.InitializeComponent();
App.GPS.PositionChanged += gps_PositionChanged;
}

/// <summary>
/// Executes when the GPS Device detects that it's position has changed
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private void gps_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
if (startingPoint != null)
{
UpdateProgress(args.Position.Coordinate.Point);
}
}

/// <summary>
/// Update the progress bar
/// </summary>
/// <param name="point">The current location</param>
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();
}
});
}

/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
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);
}
}
}
65 changes: 65 additions & 0 deletions Windows Phone/VineCache/VineCache/GPSHelper.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Calculates the distance (in meters) between GPS coordinates
/// </summary>
/// <param name="startingPoint"></param>
/// <param name="targetPoint"></param>
/// <returns></returns>
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;
}

/// <summary>
/// Calcuate the progess 0-100 (100complete) of traveling to the target location
/// </summary>
/// <param name="currentDistance"></param>
/// <param name="startingDistance"></param>
/// <returns></returns>
public static double CalculateProgress(double currentDistance, double startingDistance)
{
double zeroDistance = startingDistance * 2;
double progressDistance = zeroDistance - currentDistance;
double progress = (progressDistance / zeroDistance) * 100;
return progress;
}

/// <summary>
/// Converte Degrees to radians
/// </summary>
/// <param name="angle"></param>
/// <returns></returns>
public static double DegreeToRadian(double angle)
{
return Math.PI * angle / 180.0;
}

/// <summary>
/// Is the target within 25 meters?
/// </summary>
/// <param name="distance"></param>
/// <returns></returns>
public static bool IsTargetClose(double distance)
{
return distance < 25;
}
}
}
4 changes: 0 additions & 4 deletions Windows Phone/VineCache/VineCache/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,5 @@
<Image x:Name="bootImage" HorizontalAlignment="Center" Height="383" Margin="0,70,0,0" VerticalAlignment="Center" Width="380" Source="Assets/flower-vine-hi.png"/>
<facebookControls:LoginButton x:Name="facebookLoginButton" Grid.Row="2" Margin="0,0,0,80" Width="200" HorizontalAlignment="Center" VerticalAlignment="Bottom" SessionStateChanged="facebookLoginButton_OnSessionStateChanged" />
</Grid>

<Grid x:Name="ContentPanel" Background="Transparent" Visibility="Collapsed">

</Grid>
</Grid>
</Page>
2 changes: 1 addition & 1 deletion Windows Phone/VineCache/VineCache/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)

private void facebookLoginButton_OnSessionStateChanged(object sender, Facebook.Client.Controls.SessionStateChangedEventArgs e)
{

}
}
}
4 changes: 4 additions & 0 deletions Windows Phone/VineCache/VineCache/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,9 @@
</Applications>
<Capabilities>
<Capability Name="internetClientServer" />
<Capability Name="videosLibrary" />
<DeviceCapability Name="location" />
<DeviceCapability Name="microphone" />
<DeviceCapability Name="webcam" />
</Capabilities>
</Package>
7 changes: 7 additions & 0 deletions Windows Phone/VineCache/VineCache/StoreManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<StoreManifest xmlns="http://schemas.microsoft.com/appx/2010/StoreManifest">
<ProductFeatures>
<HardwareRequirements>
<Requirement Name="ID_REQ_FRONTCAMERA" />
</HardwareRequirements>
</ProductFeatures>
</StoreManifest>
25 changes: 25 additions & 0 deletions Windows Phone/VineCache/VineCache/UploadVideoPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Page
x:Class="VineCache.UploadVideoPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:VineCache"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid Background="White">
<TextBlock x:Name="gameNameTextBlock" Text="(Game name goes here)" Foreground="Green" FontSize="22" FontWeight="SemiBold" Margin="20,20,0,575"/>
<TextBlock Text="Upload your video to collect your points:" Foreground="Green" FontSize="19" Margin="20,115,0,0" VerticalAlignment="Top" />

<!--Camera viewfinder -->
<StackPanel Background="Black" Margin="20,150,20,0" VerticalAlignment="Top" >
<CaptureElement x:Name="videoPreviewElement" Width="360" Height="270" HorizontalAlignment="Left" />
<MediaElement x:Name="videoMediaElement" Source="Assets/Fountain.small.mp4" AutoPlay="False" Tapped="videoMediaElement_Tapped" VerticalAlignment="Top" Visibility="Collapsed"/>
</StackPanel>
<GridView Margin="20,0,20,140" VerticalAlignment="Bottom" HorizontalContentAlignment="Center">
<Button Content="Click to Record" Background="Green" Margin="30,0,0,0" Click="StartRecordingButton_Click"/>
<Button Content="Upload it!" Background="Green" Margin="0,0,0,0" Click="UploadRecordingButton_Click"/>
</GridView>
</Grid>
</Page>
88 changes: 88 additions & 0 deletions Windows Phone/VineCache/VineCache/UploadVideoPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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.Media.Capture;
using Windows.Media.MediaProperties;
using Windows.Phone.UI.Input;
using Windows.Storage;
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;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556

namespace VineCache
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class UploadVideoPage : Page
{
private MediaCapture mediaCapture;
private const string VideoFileName = "vinecache.mp4";

public UploadVideoPage()
{
this.InitializeComponent();
}

private async void InitVideoCapture()
{
this.mediaCapture = new MediaCapture();
await this.mediaCapture.InitializeAsync();
this.mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
this.mediaCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);
this.videoPreviewElement.Source = mediaCapture;
await this.mediaCapture.StartPreviewAsync();
}

private async void StartRecordingVideo()
{
if (this.mediaCapture != null)
{
StorageFile videoStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync(VideoFileName, CreationCollisionOption.ReplaceExisting);
MediaEncodingProfile encodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.HD720p);
await this.mediaCapture.StartRecordToStorageFileAsync(encodingProfile, videoStorageFile);
}
}

private async void StopRecordingVideo()
{
await this.mediaCapture.StopRecordAsync();
}


/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.InitVideoCapture();
}

private void StartRecordingButton_Click(object sender, RoutedEventArgs e)
{
StartRecordingVideo();
}

private void UploadRecordingButton_Click(object sender, RoutedEventArgs e)
{
StopRecordingVideo();
}

private void videoMediaElement_Tapped(object sender, RoutedEventArgs e)
{

}
}
}
Loading