Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Windows 8 metro applications

5,947 views

Published on

Presentation from vNext meeting at March 13 - Windows 8 Metro apps development using XAML/C#

Published in: Technology, Art & Photos

Windows 8 metro applications

  1. 1. demo
  2. 2. demo
  3. 3. demo
  4. 4. // Application manifest capabilities required to access cameraand microphone<Capabilities> <DeviceCapability Name="webcam" /> <DeviceCapability Name="microphone" /></Capabilities>
  5. 5. CameraCaptureUI dialog = new CameraCaptureUI();Size aspectRatio = new Size(16, 9);dialog.PhotoSettings.CroppedAspectRatio = aspectRatio;StorageFile file = awaitdialog.CaptureFileAsync(CameraCaptureUIMode.Photo);if (file != null){ BitmapImage bitmapImage = new BitmapImage(); using (IRandomAccessStream fileStream = awaitfile.OpenAsync(Windows.Storage.FileAccessMode.Read)) bitmapImage.SetSource(fileStream); image.Source = bitmapImage;}
  6. 6. demo
  7. 7. <Capabilities> <Capability Name= "???_Library" /></Capabilities>StorageFile sampleFile = await KnownFolders.VideosLibrary.GetFileAsync("vNext.txt");var doc = await XmlDocument.LoadFromFileAsync(sampleFile);
  8. 8. demo
  9. 9. <Extensions> <Extension Category="windows.shareTarget" Executable="SampleShareTarget.exe" EntryPoint="SampleShareTarget.App"> <ShareTarget> <SupportedFileTypes> <SupportsAnyFileType /> </SupportedFileTypes> <DataFormat>text</DataFormat> <DataFormat>bitmap</DataFormat> <DataFormat>uri</DataFormat> <DataFormat>html</DataFormat> <DataFormat>Valentine-Love-Catcher</DataFormat> </ShareTarget> </Extension></Extensions>
  10. 10. protected override async voidOnShareTargetActivated(ShareTargetActivatedEventArgs args){ BlankPage shareTargetPage = new BlankPage(); await shareTargetPage.ActivateAsync(args);}
  11. 11. public async Task ActivateAsync(ShareTargetActivatedEventArgs args){ if (args.Kind == ActivationKind.ShareTarget) { shareOperation = args.ShareOperation; txtTitle.Text = shareOperation.Data.Properties.Title; txtDesc.Text = shareOperation.Data.Properties.Description; if (shareOperation.Data.Contains(StandardDataFormats.Text)) { string text = await this.shareOperation.Data.GetTextAsync(); if (text != null) { txtText.Text = text; } } }}
  12. 12. DataTransferManager DataTransferManager new DataTransferManager DataRequestedEventArgs//[OPTIONALLY] If application makes distinction between targetapplications, subscribe to this event//[OPTIONALLY] Force showing share UIDataTransferManager
  13. 13. private async void DataTransferManagerDataRequestedEventArgs "Sample share source app" "Spread the word about this lovely application" RandomAccessStreamReference new Uri "ms-appx:///Images/Love.png" "Sample text" RandomAccessStreamReference new Uri "ms-appx:///Images/test.png"
  14. 14. Capabilities Seamless Performantdriven data accessHigh isolation Data Native Roaming platform
  15. 15. demo
  16. 16. ITileWideSmallImageAndText03 tileContent = TileContentFactory.CreateTileWideSmallImageAndText03();tileContent.TextBodyWrap.Text = "Main tile updated fromapplication!";tileContent.Image.Src = "ms-appx:///Images/Bouquet.png";tileContent.RequireSquareContent = false;TileUpdateManager.CreateTileUpdaterForApplication().Update( tileContent.CreateNotification());
  17. 17. IToastImageAndText02 templateContent = ToastContentFactory.CreateToastImageAndText02();templateContent.TextHeading.Text = "Toast sample";templateContent.TextBodyWrap.Text = "Toast message fromapplication!";templateContent.Image.Src = "Images/NewYear.png";templateContent.Image.Alt = "Placeholder image";IToastNotificationContent toastContent = templateContent;ToastNotification toast = toastContent.CreateNotification();ToastNotificationManager.CreateToastNotifier().Show(toast);
  18. 18. BadgeNumericNotificationContent badgeContent = new BadgeNumericNotificationContent();badgeContent.Number = 23;BadgeUpdateManager.CreateBadgeUpdaterForApplication().Update( badgeContent.CreateNotification());
  19. 19. Uri logo = new Uri("ms-appx:///images/LoveIcon.png");Uri wideLogo = new Uri("ms-appx:///images/WideSecondary.png");SecondaryTile secondaryTile = newSecondaryTile("LiveTilesAndToastsSample.SecondaryTile", "Secondary tile", "Secondary tile from app", "argumets=Alex,123", TileOptions.ShowNameOnWideLogo | TileOptions.ShowNameOnLogo, logo, wideLogo);bool isPinned = await secondaryTile.RequestCreateForSelectionAsync( new Rect(10,10,100,100));
  20. 20. ITileWideSmallImageAndText03 tileContent = TileContentFactory.CreateTileWideSmallImageAndText03();tileContent.TextBodyWrap.Text = "Secondary tile updated fromapplication!";tileContent.Image.Src = "ms-appx:///Images/NewYear.png";tileContent.RequireSquareContent = false;TileUpdateManager.CreateTileUpdaterForSecondaryTile( "LiveTilesAndToastsSample.SecondaryTile").Update( tileContent.CreateNotification());
  21. 21. 1. Request Channel URI2. Register with your Cloud Service3. Authenticate & Push Notification
  22. 22. demo
  23. 23. var pushNotificationChannel = awaitPushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();var channelUri = pushNotificationChannel.Uri;//Optional channel for Secondary tileif (SecondaryTile.Exists(SecondaryTileID)){ var secondaryPushNotificationChannel = awaitPushNotificationChannelManager.CreatePushNotificationChannelForSecondaryTileAsync(SecondaryTileID); var secondaryChannelUri = secondaryPushNotificationChannel.Uri;}
  24. 24. private static Stream GetAccessToken(string sid, string secret){ string url = "https://login.live.com/accesstoken.srf"; var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; string content ="grant_type=client_credentials&client_id={0}&client_secret={1}&scope=notify.windows.com"; string data = string.Format(content, sid, secret); byte[] notificationMessage = Encoding.Default.GetBytes(data);
  25. 25. request.ContentLength = notificationMessage.Length; using (Stream requestStream = request.GetRequestStream()) requestStream.Write(notificationMessage, 0, notificationMessage.Length); var response = (HttpWebResponse)request.GetResponse(); Stream result = response.GetResponseStream(); return result;}
  26. 26. private static HttpStatusCode Push(string pushUri, stringaccessToken, string type, string notificationData){ var subscriptionUri = new Uri(pushUri); var request = (HttpWebRequest)WebRequest.Create(subscriptionUri); request.Method = "POST"; request.ContentType = "text/xml"; request.Headers = new WebHeaderCollection(); request.Headers.Add("X-WNS-Type", type); request.Headers.Add("Authorization", "Bearer " + accessToken);
  27. 27. byte[] notificationMessage = Encoding.Default.GetBytes(notificationData); request.ContentLength = notificationMessage.Length; using (Stream requestStream = request.GetRequestStream()) requestStream.Write(notificationMessage, 0, notificationMessage.Length); var response = (HttpWebResponse)request.GetResponse(); return response.StatusCode;}
  28. 28. string pushUri = "https://db3.notify.windows.com/...";string secret = HttpUtility.UrlEncode("2A...");string sid = HttpUtility.UrlEncode("ms-app://s-...");var obj =System.Json.JsonObject.Load(GetAccessToken(sid, secret));string accessToken = obj["access_token"].ToString();//Send Badge notificationstring badgeNotification = "<?xml version=1.0 encoding=utf-8?><badge value="13"/>";HttpStatusCode status =Push(pushUri, accessToken, "wns/badge", badgeNotification);
  29. 29. //Send Toast notificationstring tostNotification = "<?xml version=1.0 encoding=utf-8?><toast><visual><bindingtemplate="ToastImageAndText02"><image id="1"src="Assets/Logo.png" alt="Placeholder image"/><textid="1">Urgent news</text><text id="2">New vNext meetupscheduled!</text></binding></visual></toast>";status = Push(pushUri, accessToken, "wns/toast",tostNotification);
  30. 30. //Send Tile notificationstring tileNotification = "<?xml version=1.0 encoding=utf-8?><tile><visual><bindingtemplate="TileWideSmallImageAndText03"><image id="1"src="ms-appx:///Images/Meetup.png"/><text id="1">New vNextmeetup scheduled!</text></binding></visual></tile>";status =Push(pushUri, accessToken, "wns/tile", tileNotification);
  31. 31. //Send Secondary Tile notificationpushUri = "https://db3.notify.windows.com/...";string secondaryTileNotification = "<?xml version=1.0encoding=utf-8?><tile><visual lang="en-US"><bindingtemplate="TileWidePeekImage05"><image id="1" src="ms-appx:///Images/Blog.png"/><image id="2" src="ms-appx:///Images/Avatar.png"/><text id="1">Visit myblog!</text><textid="2">http://blogs.microsoft.co.il/blogs/alex_golesh/</text></binding></visual></tile>";status =Push(pushUri, accessToken, "wns/tile", secondaryTileNotification);
  32. 32. • •• •• •• • alex@sela.co.il

×