Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Windows 市集應⽤用程式實例解說 (使⽤ JavaScript)

Windows 市集應⽤用程式實例解說 (使⽤ JavaScript)

MSDN 講座

Ping-Yen Tsai

January 07, 2013
Tweet

More Decks by Ping-Yen Tsai

Other Decks in Technology

Transcript

  1. 今天的範圍 ▪7 個 Sample ▪Snap sample ▪Web authentication broker sample

    ▪Search contract sample ▪Sharing content source app sample ▪Sharing content target app sample ▪Lock screen apps sample ▪Background task sample
  2. SNAP SAMPLE ▪4 種 View State ▪snapped 貼⿑齊 ▪filled 填滿

    ▪full screen landscape 全螢幕橫向 ▪full screen portrait 全螢幕直向 ▪寬度 ▪snapped 320 px ▪splitter 22 px
  3. SNAP SAMPLE 重點 ▪判斷 App 現在的 View State ▪什麼時候重新判斷 View

    State ▪⽤用程式取消 Snap View ▪寫 Snap View 專⽤用的 CSS
  4. 判斷 APP 現在的 VIEW STATE ▪ var value = Windows.UI.ViewManagement.ApplicationView.value,


    viewStates = Windows.UI.ViewManagement.ApplicationViewState;
 
 switch (value) {
 case viewStates.snapped :
 case viewStates.filled :
 case viewStates.fullScreenLandscape :
 case viewStates.fullScreenPortrait :
 default :
 }
  5. 寫 SNAP VIEW 專⽤用的 CSS ▪@media screen and (-ms-view-state: snapped)

    { /* ... */ } ▪snapped ▪filled ▪fullscreen-landscape ▪fullscreen-portrait
  6. SNAP SAMPLE 架構 ▪Single-page navigation ▪default.html #contentHost ▪Page Control ⾴頁⾯面控制項

    ▪檔案擺放⽅方式 ▪與 Visual Studio 2012 預設不同 ▪ html/snap.html 、 js/snap.js 、 css/snap.css ▪Visual Studio 2012 預設應是 ▪ pages/snap/snap.html 、 pages/snap/snap.js 、 pages/snap/snap.css
  7. SNAP SAMPLE 架構 ▪sample-utils ▪footer.html 、 header.html 、
 sample-utils.css 、

    sample-utils.js 、
 scenario-select.html ▪每個 Sample 架構⼤大同⼩小異
  8. GUIDELINE 規定 APP 要有 SNAP VIEW ▪市集 App 的 Snap

    View ▪320 px 恰與⼿手機寬度相同 ▪Windows Phone 8 不⽀支援 JavaScript 開發 App
  9. WEB AUTHENTICATION BROKER SAMPLE ▪App 裡⽤用 OAuth 做 Single Sign-On

    ▪先看 App 外⽤用 OAuth 做 Single Sign-On
  10. WEB AUTHENTICATION BROKER ▪Windows.Security.Authentication.Web
 .WebAuthenticationBroker.authenticateAsync ▪傳⼊入三個參數 ▪options 、 startURI 、

    endURI ▪⽤用 endURI 判斷 OAuth Single Sign-On 完成 ▪吐回 Promise 物件 ▪.done(function(result) { /* … */ })
  11. WEB AUTHENTICATION BROKER 重點 ▪⽰示範兜出 Facebook 、 Twitter 、 Google

    、 Flickr 的 startURI 、 endURI ▪抄 ▪authzInProgress ▪避免 Single Sign-On 進⾏行中,重複做
  12. SEARCH CONTRACT SAMPLE ▪Charms Bar 常⽤用⼯工具列 ▪App 內 、 App

    外 ▪Search Contract 搜尋協定 ▪可是本 Sample 著重搜尋建議
  13. 搜尋建議⼊入⾨門 ▪ var view = Windows.ApplicationModel.Search.SearchPane.getForCurrentView();
 
 view.onsuggestionsrequested = function(e)

    {
 var q = e.queryText;
 
 e.request.searchSuggestionCollection.appendQuerySuggestion(q + 'ABC');
 }
  14. 外部抓取搜尋建議 ▪⾮非同步 ▪var deferral = request.getDeferral();
 deferral.complete(); ▪⽰示範格式 ▪OpenSearch Suggestions

    format ▪ http://www.opensearch.org/Specifications/OpenSearch/Extensions/ Suggestions/1.0 ▪XML Search Suggestions Format ▪ http://msdn.microsoft.com/en-us/library/cc848863(v=vs.85).aspx
  15. SHARING CONTENT SOURCE APP SAMPLE ▪分辨 Source App 、 Target

    App ▪Target App 向 Source App 要資料
  16. SHARING CONTENT SOURCE APP SAMPLE ▪⽰示範 ▪分享⽂文字、連結 ▪分享圖⽚片、檔案 ▪FileOpenPicker ▪分享

    HTML ▪使⽤用 DataProvider 分享 ▪⾃自訂分享資料型態 ▪分享失敗
  17. 分享⽂文字、連結 ▪ var DataTransfer = Windows.ApplicationModel.DataTransfer,
 dataTransferManager = DataTransfer.DataTransferManager.getForCurrentView();
 


    dataTransferManager.addEventListener('datarequested', function(e) {
 var request = e.request;
 
 request.data.properties.title = 'title';
 request.data.properties.description = 'description';
 request.data.setText('text');
 request.data.setUri(new Windows.Foundation.Uri('http://www.fabrikam.com'));
 });
  18. FILEOPENPICKER ▪ var imageFile,
 picker = new Windows.Storage.Pickers.FileOpenPicker();
 
 picker.fileTypeFilter.replaceAll([".jpg",

    ".bmp", ".gif", ".png"]);
 picker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail;
 
 picker.pickSingleFileAsync().done(function (file) {
 if (file)
 imageFile = file;
 });
 
 /* picker.pickMultipleFileAsync().done(function (files) { }); */
  19. TARGET.JS ▪接收各種分享資料型態 ▪皆是 Asyc ▪可能 Data Provider 抓取 ▪注意 HTML

    圖⽚片 ResourceMap ▪QuickLink ▪shareOperation.reportCompleted() ▪回報 Source App ▪Google 搜尋 shareOperation
  20. LOCK SCREEN APPS SAMPLE ▪什麼是 Badge 、 Tile 、 Notification

    ? ▪什麼是 Secondary tile ? ▪什麼是 Lock Screen App ?
  21. LOCK SCREEN APPS SAMPLE ▪ var Background = Windows.ApplicationModel.Background;
 


    Background.BackgroundExecutionManager.requestAccessAsync();
 
 /* App 只能主動詢問⼀一次 */
 
 
 Background.BackgroundExecutionManager.removeAccess();
 
 var result = Background.BackgroundExecutionManager.getAccessStatus();

  22. BADGE 、 TILE 、 NOTIFICATION ▪badge ▪http://msdn.microsoft.com/zh-tw/library/windows/apps/ br212849.aspx ▪The tile

    template catalog ▪http://msdn.microsoft.com/en-us/library/windows/apps/ Hh761491 ▪The toast template catalog ▪http://msdn.microsoft.com/en-us/library/windows/apps/ Hh761494
  23. BACKGROUND TASK SAMPLE ▪Background Task ▪開發選擇 ▪JavaScript ▪C# 、 VB.Net

    、C++ ▪JavaScript 開發的 App 也能⽤用 ▪package.appxmanifest ▪宣告 ▪背景⼯工作 ▪ JavaScript 起始⾴頁、 C# 進⼊入點