Skip to content
Browse files

implemented sharing contract

  • Loading branch information...
1 parent 46933c9 commit 85389c033a61f0b0e922646e8f24d405fec1a3b1 @jimoneil jimoneil committed Jun 20, 2013
View
56 ...s/APIMASH_TomTom_BingMaps_StarterKit/APIMASH-TomTom_BingMaps-StarterKit/LeftPanel.xaml.cs
@@ -4,11 +4,17 @@
using APIMASH_StarterKit.Mapping;
using Bing.Maps;
using System;
+using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Threading.Tasks;
+using Windows.ApplicationModel.DataTransfer;
+using Windows.Storage;
+using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
+using System.IO;
+using System.Runtime.InteropServices.WindowsRuntime;
//
// LICENSE: http://aka.ms/LicenseTerms-SampleApps
@@ -110,7 +116,55 @@ public LeftPanel()
this.DefaultViewModel["ApiViewModel"] = _tomTomApi.TomTomViewModel;
_tomTomApi.TomTomViewModel.Results.CollectionChanged += Results_CollectionChanged;
}
-
+
+ //
+ // TODO: implement code needed to share item from main page
+ //
+public async void GetSharedData(DataTransferManager sender, DataRequestedEventArgs args)
+{
+ try
+ {
+ var currentCam = MappableListView.SelectedItem as APIMASH_TomTom.TomTomCameraViewModel;
+ if (currentCam != null)
+ {
+
+ DataRequestDeferral deferral = args.Request.GetDeferral();
+
+ args.Request.Data.Properties.Title = String.Format("TomTom Camera: {0}", currentCam.CameraId);
+ args.Request.Data.Properties.Description = currentCam.Name;
+
+ // share a file
+ var file = await StorageFile.CreateStreamedFileAsync(
+ String.Format("{0}_{1}.jpg", currentCam.CameraId, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")),
+ async stream =>
+ {
+ await stream.WriteAsync(currentCam.ImageBytes.AsBuffer());
+ await stream.FlushAsync();
+ stream.Dispose();
+ },
+ null);
+ args.Request.Data.SetStorageItems(new List<IStorageItem> { file });
+
+ // share as bitmap
+ InMemoryRandomAccessStream raStream = new InMemoryRandomAccessStream();
+ await raStream.WriteAsync(currentCam.ImageBytes.AsBuffer());
+ await raStream.FlushAsync();
+ args.Request.Data.SetBitmap(RandomAccessStreamReference.CreateFromStream(raStream));
+
+ deferral.Complete();
+ }
+ else
+ {
+ args.Request.FailWithDisplayText("Select a camera to share its image.");
+ }
+ }
+ catch (Exception ex)
+ {
+ args.Request.FailWithDisplayText(ex.Message);
+ }
+}
+
+
/// <summary>
/// Carries out application-specific handling of the item selected in the listview. The synchronization with
/// the map display is already accomodated.
View
12 ...ts/APIMASH_TomTom_BingMaps_StarterKit/APIMASH-TomTom_BingMaps-StarterKit/MainPage.xaml.cs
@@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Threading.Tasks;
+using Windows.ApplicationModel.DataTransfer;
using Windows.ApplicationModel.Search;
using Windows.Devices.Geolocation;
using Windows.Storage;
@@ -250,6 +251,17 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
// reset map to last known view
TheMap.SetView(new Location(_pageState.MapCenter.Latitude, _pageState.MapCenter.Longitude), _pageState.Zoom, MapAnimationDuration.None);
}
+
+ DataTransferManager dtm = DataTransferManager.GetForCurrentView();
+ dtm.DataRequested += LeftPanel.GetSharedData;
+ }
+
+ protected override void OnNavigatedFrom(NavigationEventArgs e)
+ {
+ base.OnNavigatedFrom(e);
+
+ DataTransferManager dtm = DataTransferManager.GetForCurrentView();
+ dtm.DataRequested -= LeftPanel.GetSharedData;
}
/// <summary>
View
8 Windows Starter Kits/APIMASH_TomTom_BingMaps_StarterKit/APIMASH_APIs/APIMASH_TomTom.cs
@@ -34,6 +34,9 @@ public class TomTomCameraViewModel : BindableBase, IMappable
public String Orientation { get; set; }
public Int32 RefreshRate { get; set; }
+ private Byte[] _imageBytes;
+ public Byte[] ImageBytes { get; set; }
+
private BitmapImage _image;
public BitmapImage Image
{
@@ -130,9 +133,10 @@ public static Boolean PopulateViewModel(cameras model, ObservableCollection<TomT
return resultsWereTruncated;
}
- public static void PopulateViewModel(BitmapImage camImage, TomTomCameraViewModel viewModel)
+ public static void PopulateViewModel(BitmapImage camImage, Byte[] imageBytes, TomTomCameraViewModel viewModel)
{
viewModel.Image = camImage;
+ viewModel.ImageBytes = imageBytes;
viewModel.LastRefresh = DateTime.UtcNow;
}
}
@@ -259,7 +263,7 @@ protected override String _apiKey
}
// populate the ViewModel with the image
- TomTomCamerasModel.PopulateViewModel(cameraImage, camera);
+ TomTomCamerasModel.PopulateViewModel(cameraImage, apiResponse.RawResponse, camera);
// return a success status (there will always be an image returned)
return ApiResponseStatus.Default;

0 comments on commit 85389c0

Please sign in to comment.
Something went wrong with that request. Please try again.