SlideShare uma empresa Scribd logo
1 de 35
Baixar para ler offline
Programming Windows Store Apps with
       JavaScript and WinRT

         Rainer Stropek
           software architects gmbh
Introduction

• software architects gmbh
• Rainer Stropek
  • Developer, Speaker, Trainer
  • MVP for Windows Azure
  • rainer@timecockpit.com
  •              @rstropek




                                                             http://www.timecockpit.com



Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript                           2
WinRT System Architecture




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   3
WinRT System Architecture




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   4
Windows Store Apps in JavaScript?

Goals…                                                Prerequisites…

 • Reuse existing knowledge                             • Use all the technologies you
    from the web for developing                            know from IE 10: HTML5 +
    Windows applications                                   CSS3 + JavaScript

 • HTML + JavaScript are 1st                            • Full access to platform API
    class citizens for developing                          (WinRT)
    Windows Store Apps

 • "Fast and Fluid" also with                           • Hardware Acceleration,
    HTML + JavaScript                                      Plugin-Free, etc.




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript                          5
Goals of This Session

• Build a Windows Store App from scratch using HTML + JavaScript
• Introduce the WinJS Library
• Access API of Windows 8 (WinRT) from JavaScript
• One integrated demo used throughout the entire session


Non-Goals of the Session:
• General HTML/CSS/JavaScript introduction
• Training about WinJS, WinRT or Windows Store Apps


Tip: Download slides and check hidden slides for code snippets




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript    6
Important Notice

• For demo purposes the sample has been simplified compared
  to a real-world Windows Store app
• In practise you have to remember additional requirements in
  order to get your app into the Windows Store, e.g.:
  • Handle different screen resolutions and view modes (e.g.
     portrait/landscape, snapped, etc.; read more)
  • Support navigation patterns (e.g. links, back/forward, etc.;
     read more)
  • App Lifecycle (e.g. launch, activation, suspend, etc.; read more)




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript         7
JavaScript Module Pattern
(function ( ) {
    // create variable
    // var name = "Andi und Rainer";

    //     create method
    //     var sayHello = function ( ) {
    //        alert(name);
    //     };
})( );     // calling this method.




                                                                  It is plain old JavaScript,
                                                                   also for Windows Store
                                                                             Apps!


Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript                        8
Demo

• Structure of a JavaScript Windows Store App
• Runtime environment for JavaScript Apps




  Background information in MSDN



Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   9
Structure of a JavaScript App
             Reference to WinJS



Folder for CSS-Dateien



  Folder for images



 Folder for JavaScript
         files



     HTML files




             Application Manifest
  Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   10
Structure of a JavaScript App




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   11
Demo

• Controls and Data Binding




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   12
ListView, a WinJS Control
<!-- add a WinJS control in HTML -->
<div class="itemlist" data-win-control="WinJS.UI.ListView" […]></div>



// find control in DOM tree
var lv = document.body.querySelector(".itemlist");

// fill WinJS list (=data source for ListView)
var items = new WinJS.Binding.List();
for (var i = 1000; i < 1500; i++) {
    items.push("Hello World!");
}

WinJS.UI.processAll().then(function() {
    lv.winControl.itemDataSource = items.dataSource;
}




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript         13
Demo

• Templates and Data Binding




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   14
ListView, a WinJS Control
<div class="splitpage">
     <div class="itemtemplate" data-win-control="WinJS.Binding.Template">
          <div><img src="#" data-win-bind="src: ImageUri; alt: Title" style="width: 100px" /></div>
          <div class="item-info"><h3 class="item-title win-type-ellipsis" data-win-bind="textContent: Title"></h3></div>
     </div>
     <header aria-label="Header content" role="banner"><h1>Garden Blog</h1></header>
     <section class="itemlistsection" aria-label="List section">
          <div class="itemlist" aria-label="List of this group's items" data-win-control="WinJS.UI.ListView"
                data-win-options="{ selectionMode: 'single', tapBehavior: 'directSelect' }">
          </div>
     </section>
     <section class="articlesection" aria-atomic="true" aria-label="Item detail" aria-live="assertive">
          <header class="header">
                <div class="text"><h2 data-win-bind="textContent: Title"></h2></div>
                <div>
                      <img class="article-image" src="#" data-win-bind="src: ImageUri; alt: Title"
                           style="width: 150px; max-height: 150px" />
                </div>
          </header>
          <article class="article-content" data-win-bind="innerHTML: Text"></article>
     </section>
</div>




           Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript                                 15
ListView, a WinJS Control
function onselectionchanged(eventObject) {
   var listView = document.body.querySelector(".itemlist").winControl;
   // By default, the selection is restriced to a single item.
   listView.selection.getItems().then(function (items) {
       if (items.length > 0 && items[0]) {
          var details = document.querySelector(".articlesection");
          WinJS.Binding.processAll(details, items[0].data);
          details.scrollTop = 0;
       }
   })
}
                     Root node for data                     Data Context for data
                          binding                                 binding




     Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript    16
ListView, a WinJS Control
     WinJS.UI.setOptions(lv.winControl, {
         itemTemplate: document.body.querySelector(".itemtemplate"),
         onselectionchanged: onselectionchanged.bind(this),
         itemDataSource: items.dataSource,
         layout: new WinJS.UI.ListLayout()
     });
     lv.winControl.selection.set(0);




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   17
Demo

• Working with REST Services




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   18
REST Service in Fiddler




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   19
WinJS.xhr
function refreshBlogList() {
     WinJS.xhr({ url: "http://localhost:2220/ServiceBlog.svc/Blog/" }).done(function (feedResponse) {
          // convert feed to list of bindable objects
          var feed = JSON.parse(feedResponse.responseText);
          var items = new WinJS.Binding.List(feed);

          // set properties of list view (including data source for binding)
          var lv = document.body.querySelector(".itemlist");
          WinJS.UI.setOptions(lv.winControl, {
               itemTemplate: document.body.querySelector(".itemtemplate"),
               onselectionchanged: onselectionchanged.bind(this),
               itemDataSource: items.dataSource,
               layout: new WinJS.UI.ListLayout()
          });

          // automatically select first item
          lv.winControl.selection.set(0);
    });
}




     Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript                       20
WinJS.xhr
     app.onactivated = function (eventObject) {
        // lookup list view in DOM
        var lv = document.body.querySelector(".itemlist");

           WinJS.UI.processAll().then(function () {
               refreshBlogList();
           });
     }




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   21
Demo

• AppBar, XHR and Azure




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   22
Azure Blob Storage
                                                                                       SQL Azure
                                                                                        (Blog Content
                                                                                        ohne Bilder)
                                            HTTP GET



                                                                  Webrole
                                                                   (REST Service)
                                     JSON (Blog Entries)



 Metro-Style App                  HTTP GET




                                            Blobs (Bild)


                                                                  Azure Blob Storage
                                                                   (Bilder)


                                                                                          Windows Azure
Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript                              23
Azure Blob Storage
                                                                                        SQL Azure
                                                                                         (Blog Content
                                                                                         ohne Bilder)
                                            HTTP GET



                                                                  Webrole
                                                                   (REST Service)
                                     Shared Access
                                     Signature
                                                                      Generate Shared Access Signature (SAS)

 Metro-Style App                        HTTP POST (Bild)




                                                                  Azure Blob Storage
                                                                   (Bilder)


                                                                                            Windows Azure
Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript                                24
Azure Shared Access Signatures




                                                              Link with signature




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript                     25
INSERT with REST Service




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   26
Adding an AppBar
<div id="appbar" data-win-control="WinJS.UI.AppBar">
    <button data-win-control="WinJS.UI.AppBarCommand"
        data-win-options="{id:'cmd', label:'Create Entry', icon:'placeholder'}">
    </button>
    <button data-win-control="WinJS.UI.AppBarCommand"
        data-win-options="{id:'refresh', label:'Refresh', icon:'placeholder'}">
    </button>
</div>

// add button handler for appbar button
var cmdButton = document.getElementById("cmd");
cmdButton.onclick = onPostBlogEntryClick;
var refreshButton = document.getElementById("refresh");
refreshButton.onclick = refreshBlogList;




 Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript         27
Using WinRT to Access the Webcam
function onPostBlogEntryClick() {
   // let user take a picture. Note that we use WinRT classes here.
   var capture = Windows.Media.Capture;
   var cameraCaptureUI = new capture.CameraCaptureUI();

cameraCaptureUI.captureFileAsync(capture.CameraCaptureUIMode.photo).then(
       function (capturedItem) {
           if (capturedItem) {
              […]
           }
       });
}




    Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   28
Using WinRT to Access the Webcam
if (capturedItem) {
      var rootDiv = document.body.querySelector(".itemlist");
      var busy = getBusyOverlay(rootDiv, { color: 'gray', opacity: 0.25 }, { type: 'oval', color: '#FFFFFF' });

     WinJS.xhr({ url: "http://localhost:2220/ServiceBlog.svc/Blog/GetSasForImage/" + imageName })
     .done(function (result) {
           var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader();
           uploader.method = "PUT";
           uploader.setSourceFile(capturedItem);
           var uri = new Windows.Foundation.Uri(JSON.parse(result.responseText));
           var upload = uploader.createUpload(uri);
           upload.startAsync().done(function (result) {
                 WinJS.xhr({ url: "http://localhost:2220/ServiceBlog.svc/Blog/AddBlog", data: JSON.stringify(newEntry),
                       type: "POST", headers: { "Content-Type": "text/JSON" } }).done(function () {
                       busy.remove();
                       refreshBlogList();
                 });
           },
           function (err) {
                 busy.remove();
           });
     });
}




       Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript                                            29
Demo

• Share Contract




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript   30
Implement the Share Contract
     var dtm = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
     dtm.addEventListener("datarequested", function (e) {
             // capture request member
             var request = e.request;

            // get selected item from list view
            var lv = document.body.querySelector(".itemlist").winControl;
            lv.selection.getItems().then(function (items) {
                    if (items.length > 0) {
                            var item = items[0].data;

                            // set request title and description
                            request.data.properties.title = item.Title;
                            request.data.properties.description = "Garden Blog";

                            // set text content
                            var recipe = item.Text;
                            request.data.setText(recipe);

                            // set image content
                            // note that we use deferral-API here.
                            // (only do this if your operation is quite fast; 200ms time limit or so)
                            var uri = new Windows.Foundation.Uri(item.ImageUri);
                            var reference = Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(uri);
                            request.data.properties.thumbnail = reference;
                            var deferral = request.getDeferral();
                            request.data.setBitmap(reference);
                            deferral.complete();
                    }
            });
     });




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript                                                       31
Summary

What you have seen…                                   Use your existing knowlege
• Structure of a Windows                              about HTML and
  Store App with HTML +                               JavaScript for Windows
  JavaScript                                          Store Apps
• Introduction into WinJS
                                                      Further readings:
• Accessing Windows 8 API                             • http://dev.windows.com
  (WinRT) from JavaScript                             • http://design.windows.com




Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript                     32
Vielen Dank!

Rainer Stropek
 software architects gmbh
is the leading time tracking solution for knowledge
workers. Graphical time tracking calendar, automatic tracking of
your work using signal trackers, high level of extensibility and
customizability, full support to work offline, and SaaS
deployment model make it the optimal choice especially in the
IT consulting business.

Try                 for free and without any risk. You can get your
trial account at http://www.timecockpit.com. After the trial
period you can use                  for only 0,20€ per user and
month without a minimal subscription time and without a
minimal number of users.

Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript       34
ist die führende Projektzeiterfassung für
Knowledge Worker. Grafischer Zeitbuchungskalender,
automatische Tätigkeitsaufzeichnung über Signal Tracker,
umfassende Erweiterbarkeit und Anpassbarkeit, volle
Offlinefähigkeit und einfachste Verwendung durch SaaS machen
es zur Optimalen Lösung auch speziell im IT-Umfeld.

Probieren Sie              kostenlos und ohne Risko einfach
aus. Einen Testzugang erhalten Sie unter http://www.timecockpit.com.
Danach nutzen Sie               um nur 0,20€ pro Benutzer und
Tag ohne Mindestdauer und ohne Mindestbenutzeranzahl.



Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript        35

Mais conteúdo relacionado

Último

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Último (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

Destaque

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destaque (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Programming windows store apps with JavaScript and WinRT

  • 1. Programming Windows Store Apps with JavaScript and WinRT Rainer Stropek software architects gmbh
  • 2. Introduction • software architects gmbh • Rainer Stropek • Developer, Speaker, Trainer • MVP for Windows Azure • rainer@timecockpit.com • @rstropek http://www.timecockpit.com Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 2
  • 3. WinRT System Architecture Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 3
  • 4. WinRT System Architecture Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 4
  • 5. Windows Store Apps in JavaScript? Goals… Prerequisites… • Reuse existing knowledge • Use all the technologies you from the web for developing know from IE 10: HTML5 + Windows applications CSS3 + JavaScript • HTML + JavaScript are 1st • Full access to platform API class citizens for developing (WinRT) Windows Store Apps • "Fast and Fluid" also with • Hardware Acceleration, HTML + JavaScript Plugin-Free, etc. Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 5
  • 6. Goals of This Session • Build a Windows Store App from scratch using HTML + JavaScript • Introduce the WinJS Library • Access API of Windows 8 (WinRT) from JavaScript • One integrated demo used throughout the entire session Non-Goals of the Session: • General HTML/CSS/JavaScript introduction • Training about WinJS, WinRT or Windows Store Apps Tip: Download slides and check hidden slides for code snippets Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 6
  • 7. Important Notice • For demo purposes the sample has been simplified compared to a real-world Windows Store app • In practise you have to remember additional requirements in order to get your app into the Windows Store, e.g.: • Handle different screen resolutions and view modes (e.g. portrait/landscape, snapped, etc.; read more) • Support navigation patterns (e.g. links, back/forward, etc.; read more) • App Lifecycle (e.g. launch, activation, suspend, etc.; read more) Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 7
  • 8. JavaScript Module Pattern (function ( ) { // create variable // var name = "Andi und Rainer"; // create method // var sayHello = function ( ) { // alert(name); // }; })( ); // calling this method. It is plain old JavaScript, also for Windows Store Apps! Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 8
  • 9. Demo • Structure of a JavaScript Windows Store App • Runtime environment for JavaScript Apps Background information in MSDN Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 9
  • 10. Structure of a JavaScript App Reference to WinJS Folder for CSS-Dateien Folder for images Folder for JavaScript files HTML files Application Manifest Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 10
  • 11. Structure of a JavaScript App Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 11
  • 12. Demo • Controls and Data Binding Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 12
  • 13. ListView, a WinJS Control <!-- add a WinJS control in HTML --> <div class="itemlist" data-win-control="WinJS.UI.ListView" […]></div> // find control in DOM tree var lv = document.body.querySelector(".itemlist"); // fill WinJS list (=data source for ListView) var items = new WinJS.Binding.List(); for (var i = 1000; i < 1500; i++) { items.push("Hello World!"); } WinJS.UI.processAll().then(function() { lv.winControl.itemDataSource = items.dataSource; } Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 13
  • 14. Demo • Templates and Data Binding Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 14
  • 15. ListView, a WinJS Control <div class="splitpage"> <div class="itemtemplate" data-win-control="WinJS.Binding.Template"> <div><img src="#" data-win-bind="src: ImageUri; alt: Title" style="width: 100px" /></div> <div class="item-info"><h3 class="item-title win-type-ellipsis" data-win-bind="textContent: Title"></h3></div> </div> <header aria-label="Header content" role="banner"><h1>Garden Blog</h1></header> <section class="itemlistsection" aria-label="List section"> <div class="itemlist" aria-label="List of this group's items" data-win-control="WinJS.UI.ListView" data-win-options="{ selectionMode: 'single', tapBehavior: 'directSelect' }"> </div> </section> <section class="articlesection" aria-atomic="true" aria-label="Item detail" aria-live="assertive"> <header class="header"> <div class="text"><h2 data-win-bind="textContent: Title"></h2></div> <div> <img class="article-image" src="#" data-win-bind="src: ImageUri; alt: Title" style="width: 150px; max-height: 150px" /> </div> </header> <article class="article-content" data-win-bind="innerHTML: Text"></article> </section> </div> Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 15
  • 16. ListView, a WinJS Control function onselectionchanged(eventObject) { var listView = document.body.querySelector(".itemlist").winControl; // By default, the selection is restriced to a single item. listView.selection.getItems().then(function (items) { if (items.length > 0 && items[0]) { var details = document.querySelector(".articlesection"); WinJS.Binding.processAll(details, items[0].data); details.scrollTop = 0; } }) } Root node for data Data Context for data binding binding Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 16
  • 17. ListView, a WinJS Control WinJS.UI.setOptions(lv.winControl, { itemTemplate: document.body.querySelector(".itemtemplate"), onselectionchanged: onselectionchanged.bind(this), itemDataSource: items.dataSource, layout: new WinJS.UI.ListLayout() }); lv.winControl.selection.set(0); Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 17
  • 18. Demo • Working with REST Services Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 18
  • 19. REST Service in Fiddler Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 19
  • 20. WinJS.xhr function refreshBlogList() { WinJS.xhr({ url: "http://localhost:2220/ServiceBlog.svc/Blog/" }).done(function (feedResponse) { // convert feed to list of bindable objects var feed = JSON.parse(feedResponse.responseText); var items = new WinJS.Binding.List(feed); // set properties of list view (including data source for binding) var lv = document.body.querySelector(".itemlist"); WinJS.UI.setOptions(lv.winControl, { itemTemplate: document.body.querySelector(".itemtemplate"), onselectionchanged: onselectionchanged.bind(this), itemDataSource: items.dataSource, layout: new WinJS.UI.ListLayout() }); // automatically select first item lv.winControl.selection.set(0); }); } Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 20
  • 21. WinJS.xhr app.onactivated = function (eventObject) { // lookup list view in DOM var lv = document.body.querySelector(".itemlist"); WinJS.UI.processAll().then(function () { refreshBlogList(); }); } Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 21
  • 22. Demo • AppBar, XHR and Azure Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 22
  • 23. Azure Blob Storage SQL Azure (Blog Content ohne Bilder) HTTP GET Webrole (REST Service) JSON (Blog Entries) Metro-Style App HTTP GET Blobs (Bild) Azure Blob Storage (Bilder) Windows Azure Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 23
  • 24. Azure Blob Storage SQL Azure (Blog Content ohne Bilder) HTTP GET Webrole (REST Service) Shared Access Signature Generate Shared Access Signature (SAS) Metro-Style App HTTP POST (Bild) Azure Blob Storage (Bilder) Windows Azure Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 24
  • 25. Azure Shared Access Signatures Link with signature Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 25
  • 26. INSERT with REST Service Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 26
  • 27. Adding an AppBar <div id="appbar" data-win-control="WinJS.UI.AppBar"> <button data-win-control="WinJS.UI.AppBarCommand" data-win-options="{id:'cmd', label:'Create Entry', icon:'placeholder'}"> </button> <button data-win-control="WinJS.UI.AppBarCommand" data-win-options="{id:'refresh', label:'Refresh', icon:'placeholder'}"> </button> </div> // add button handler for appbar button var cmdButton = document.getElementById("cmd"); cmdButton.onclick = onPostBlogEntryClick; var refreshButton = document.getElementById("refresh"); refreshButton.onclick = refreshBlogList; Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 27
  • 28. Using WinRT to Access the Webcam function onPostBlogEntryClick() { // let user take a picture. Note that we use WinRT classes here. var capture = Windows.Media.Capture; var cameraCaptureUI = new capture.CameraCaptureUI(); cameraCaptureUI.captureFileAsync(capture.CameraCaptureUIMode.photo).then( function (capturedItem) { if (capturedItem) { […] } }); } Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 28
  • 29. Using WinRT to Access the Webcam if (capturedItem) { var rootDiv = document.body.querySelector(".itemlist"); var busy = getBusyOverlay(rootDiv, { color: 'gray', opacity: 0.25 }, { type: 'oval', color: '#FFFFFF' }); WinJS.xhr({ url: "http://localhost:2220/ServiceBlog.svc/Blog/GetSasForImage/" + imageName }) .done(function (result) { var uploader = new Windows.Networking.BackgroundTransfer.BackgroundUploader(); uploader.method = "PUT"; uploader.setSourceFile(capturedItem); var uri = new Windows.Foundation.Uri(JSON.parse(result.responseText)); var upload = uploader.createUpload(uri); upload.startAsync().done(function (result) { WinJS.xhr({ url: "http://localhost:2220/ServiceBlog.svc/Blog/AddBlog", data: JSON.stringify(newEntry), type: "POST", headers: { "Content-Type": "text/JSON" } }).done(function () { busy.remove(); refreshBlogList(); }); }, function (err) { busy.remove(); }); }); } Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 29
  • 30. Demo • Share Contract Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 30
  • 31. Implement the Share Contract var dtm = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView(); dtm.addEventListener("datarequested", function (e) { // capture request member var request = e.request; // get selected item from list view var lv = document.body.querySelector(".itemlist").winControl; lv.selection.getItems().then(function (items) { if (items.length > 0) { var item = items[0].data; // set request title and description request.data.properties.title = item.Title; request.data.properties.description = "Garden Blog"; // set text content var recipe = item.Text; request.data.setText(recipe); // set image content // note that we use deferral-API here. // (only do this if your operation is quite fast; 200ms time limit or so) var uri = new Windows.Foundation.Uri(item.ImageUri); var reference = Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(uri); request.data.properties.thumbnail = reference; var deferral = request.getDeferral(); request.data.setBitmap(reference); deferral.complete(); } }); }); Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 31
  • 32. Summary What you have seen… Use your existing knowlege • Structure of a Windows about HTML and Store App with HTML + JavaScript for Windows JavaScript Store Apps • Introduction into WinJS Further readings: • Accessing Windows 8 API • http://dev.windows.com (WinRT) from JavaScript • http://design.windows.com Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 32
  • 33. Vielen Dank! Rainer Stropek software architects gmbh
  • 34. is the leading time tracking solution for knowledge workers. Graphical time tracking calendar, automatic tracking of your work using signal trackers, high level of extensibility and customizability, full support to work offline, and SaaS deployment model make it the optimal choice especially in the IT consulting business. Try for free and without any risk. You can get your trial account at http://www.timecockpit.com. After the trial period you can use for only 0,20€ per user and month without a minimal subscription time and without a minimal number of users. Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 34
  • 35. ist die führende Projektzeiterfassung für Knowledge Worker. Grafischer Zeitbuchungskalender, automatische Tätigkeitsaufzeichnung über Signal Tracker, umfassende Erweiterbarkeit und Anpassbarkeit, volle Offlinefähigkeit und einfachste Verwendung durch SaaS machen es zur Optimalen Lösung auch speziell im IT-Umfeld. Probieren Sie kostenlos und ohne Risko einfach aus. Einen Testzugang erhalten Sie unter http://www.timecockpit.com. Danach nutzen Sie um nur 0,20€ pro Benutzer und Tag ohne Mindestdauer und ohne Mindestbenutzeranzahl. Herbstcampus 2012 – Windows Store Apps with HTML and JavaScript 35

Notas do Editor

  1. Rainer
  2. Rainer
  3. Rainer
  4. Andi
  5. AndiDauer der Demo: 5 MinutenInhalt der Demo:File/New/ProjectJavaScript Blank ApplicationWalkthrough OrdnerstrukturErklärung &quot;Project Reference&quot; auf WinJS statt Einbindung als &quot;minimized&quot; JS-fileRuntimeApp startenProcess Monitor Hostingprozess zeigen
  6. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.
  7. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.
  8. AndiDauer der Demo: 5 MinutenInhalt der Demo:File/New/ProjectJavaScript Blank ApplicationWalkthrough OrdnerstrukturErklärung &quot;Project Reference&quot; auf WinJS statt Einbindung als &quot;minimized&quot; JS-fileRuntimeApp startenProcess Monitor Hostingprozess zeigen
  9. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.
  10. AndiDauer der Demo: 5 MinutenInhalt der Demo:File/New/ProjectJavaScript Blank ApplicationWalkthrough OrdnerstrukturErklärung &quot;Project Reference&quot; auf WinJS statt Einbindung als &quot;minimized&quot; JS-fileRuntimeApp startenProcess Monitor Hostingprozess zeigen
  11. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.
  12. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.
  13. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.
  14. AndiDauer der Demo: 5 MinutenInhalt der Demo:File/New/ProjectJavaScript Blank ApplicationWalkthrough OrdnerstrukturErklärung &quot;Project Reference&quot; auf WinJS statt Einbindung als &quot;minimized&quot; JS-fileRuntimeApp startenProcess Monitor Hostingprozess zeigen
  15. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.
  16. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.
  17. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.
  18. AndiDauer der Demo: 5 MinutenInhalt der Demo:File/New/ProjectJavaScript Blank ApplicationWalkthrough OrdnerstrukturErklärung &quot;Project Reference&quot; auf WinJS statt Einbindung als &quot;minimized&quot; JS-fileRuntimeApp startenProcess Monitor Hostingprozess zeigen
  19. Rainer
  20. Rainer
  21. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.
  22. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.Request Header:Content-Type: text/JSONRequest Body:{&quot;Title&quot;: &quot;Hi BigDay&quot;, &quot;Text&quot;: &quot;Hello World!&quot;, &quot;ImageUri&quot;: &quot;http:\\/\\/upload.wikimedia.org\\/wikipedia\\/commons\\/d\\/d3\\/Cucumis_sativus0.jpg&quot;}
  23. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.
  24. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.
  25. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.
  26. AndiDauer der Demo: 5 MinutenInhalt der Demo:File/New/ProjectJavaScript Blank ApplicationWalkthrough OrdnerstrukturErklärung &quot;Project Reference&quot; auf WinJS statt Einbindung als &quot;minimized&quot; JS-fileRuntimeApp startenProcess Monitor Hostingprozess zeigen
  27. Absichtlich versteckte Slide; zur Nachlese für die Teilnehmer.