SlideShare a Scribd company logo
1 of 53
Download to read offline
About PhoneGap
                   Starting with PhoneGap
                      Example application




                Introduction to PhoneGap
            Web development for mobile platforms


      Manuel Rego Casasnovas <rego@igalia.com>



          Master on Free Software / August 2012




Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                          Starting with PhoneGap
                             Example application


Outline

  1   About PhoneGap

  2   Starting with PhoneGap
        Development environment
        First PhoneGap application
        PhoneGap API overview
        Building PhoneGap

  3   Example application
        Example
        Exercise


       Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                       Starting with PhoneGap   About PhoneGap
                          Example application


What is PhoneGap?



    Mobile web development framework
    Based on JavaScript, HTML5 and CSS3
    Open source: Apache 2.0 License
    Supported platforms: iPhone, Android, Windows Phone,
    BlackBerry, Symbian, webOS and Bada (comming soon)
    Homepage:          http://phonegap.com/




    Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                        Starting with PhoneGap   About PhoneGap
                           Example application


History


     Started by Nitobi Software
     Peopleā€™s Choice Award at Oā€™Reilly Mediaā€™s 2009 Web 2.0
     Conference
     Adobe acquired Nitobi on October 2011
     PhoneGap was contributed to the Apache Software
     Foundation
            First it was called Apache Callback
            Renamed to Apache Cordova
            URL: http://incubator.apache.org/cordova/




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                        Starting with PhoneGap   About PhoneGap
                           Example application


Features
     JavaScript API to access different parts of the device:
            Accelerometer
            Camera
            Capture
            Compass
            Connection
            Contacts
            Device
            Events
            File
            Geolocation
            Media
            Notiļ¬cations (alert, sound, vibration)
            Storage
     Documentation:            http://docs.phonegap.com/

     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                       Starting with PhoneGap   About PhoneGap
                          Example application


Advantages



    Multi-platform
    Well-known technologies: HTML + JavaScript + CSS
    Vast amount of JavaScript libraries/frameworks available:
           General purpose: jQuery, Prototype, . . .
           Mobile: jQuery Mobile, Enyo, . . .
           ...
    Conclusion: More and more web is everywhere




    Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                               About PhoneGap
                                                 First PhoneGap application
                        Starting with PhoneGap
                                                 PhoneGap API overview
                           Example application
                                                 Building PhoneGap


Eclipse



     Download Eclipse Classic
     http://www.eclipse.org/downloads/
     Uncompress Eclipse
     # cd /opt/
     # tar -xzvf 
         /home/user/Downloads/eclipse-SDK-4.2-linux-gtk-x86_64.tar.gz
     # cd /usr/local/bin/
     # ln -s /opt/eclipse/eclipse
     Run Eclipse
     $ eclipse




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                               About PhoneGap
                                                 First PhoneGap application
                        Starting with PhoneGap
                                                 PhoneGap API overview
                           Example application
                                                 Building PhoneGap


Android SDK and ADT Plugin


     Download Android SDK
     (http://developer.android.com/sdk/index.html)
     $ cd ~
     $ tar -xzvf ~/Downloads/android-sdk_r20.0.1-linux.tgz
     Download and install ADT Plugin in Eclipse
            Add site: Juno -
            http://download.eclipse.org/releases/juno
            Add site: ADT Plugin -
            https://dl-ssl.google.com/android/eclipse/
            Install ADT Plugin
                   Android SDK Manager
                   AVD Manager




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                               About PhoneGap
                                                 First PhoneGap application
                        Starting with PhoneGap
                                                 PhoneGap API overview
                           Example application
                                                 Building PhoneGap


Android project with PhoneGap library I


     Download PhoneGap http://phonegap.com/download
     Create a new Android Application Project in Eclipse
     Create 2 new folders in the root of the project:
            libs/
            assets/www/
     Copy some ļ¬les from donwloaded PhoneGap:
            Copy cordova-2.0.0.js to assets/www/
            Copy cordova-2.0.0.jar to libs/
            Copy xml/ folder to res/
     Add cordova-2.0.0.jar to project Build Path


     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                               About PhoneGap
                                                 First PhoneGap application
                        Starting with PhoneGap
                                                 PhoneGap API overview
                           Example application
                                                 Building PhoneGap


Android project with PhoneGap library II

     Modify MainActivity to extend DroidGap
     package com.igalia.phonegap.example.helloworldphonegap;

     import org.apache.cordova.DroidGap;

     import android.os.Bundle;

     public class MainActivity extends DroidGap {

         @Override
         public void onCreate(Bundle savedInstanceState) {
             super.onCreate(savedInstanceState);
             super.loadUrl("file:///android_asset/www/index.html");
         }

     }




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                               About PhoneGap
                                                 First PhoneGap application
                        Starting with PhoneGap
                                                 PhoneGap API overview
                           Example application
                                                 Building PhoneGap


Conļ¬gure permissions
     Modify AndroidManifest.xml adding the following lines
     between <uses-sdk.../> and <application.../>
     <supports-screens
         android:largeScreens="true"
         android:normalScreens="true"
         android:smallScreens="true"
         android:resizeable="true"
         android:anyDensity="true" />
     <uses-permission android:name="android.permission.VIBRATE" />
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
     <uses-permission android:name="android.permission.
           ACCESS_LOCATION_EXTRA_COMMANDS" />
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.RECEIVE_SMS" />
     <uses-permission android:name="android.permission.RECORD_AUDIO" />
     <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
     <uses-permission android:name="android.permission.READ_CONTACTS" />
     <uses-permission android:name="android.permission.WRITE_CONTACTS" />
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.GET_ACCOUNTS" />
     <uses-permission android:name="android.permission.BROADCAST_STICKY" />


     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                               About PhoneGap
                                                 First PhoneGap application
                        Starting with PhoneGap
                                                 PhoneGap API overview
                           Example application
                                                 Building PhoneGap


Basic UI


     Create a new ļ¬le index.html inside assets/www/ with
     the following content
     <!DOCTYPE HTML>
     <html>
     <head>
         <title>PhoneGap Example</title>
         <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></
               script>
     </head>
     <body>
         <h1>Hello World!</h1>
     </body>
     </html>



     Run as Android Application



     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                               About PhoneGap
                                                 First PhoneGap application
                        Starting with PhoneGap
                                                 PhoneGap API overview
                           Example application
                                                 Building PhoneGap


Check that PhoneGap is ready



     Add JavaScript waiting for PoneGap to be loaded
         <script type="text/javascript">
             document.addEventListener("deviceready", onDeviceReady, false);

             function onDeviceReady() {
                 alert("PhoneGap loaded");
             }
         </script>




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                               About PhoneGap
                                                 First PhoneGap application
                        Starting with PhoneGap
                                                 PhoneGap API overview
                           Example application
                                                 Building PhoneGap


Screenshot




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                                About PhoneGap
                                                  First PhoneGap application
                         Starting with PhoneGap
                                                  PhoneGap API overview
                            Example application
                                                  Building PhoneGap


Notiļ¬cation I



      Alert
      function showAlert() {
          navigator.notification.alert(
                  "Testing notification.alert",
                  afterAlert,
                  "Alert title",
                  "Button"
              );
      }

      function afterAlert() {
          // Do something
      }




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                                About PhoneGap
                                                  First PhoneGap application
                         Starting with PhoneGap
                                                  PhoneGap API overview
                            Example application
                                                  Building PhoneGap


Notiļ¬cation II


      Conļ¬rm
      function showConfirm() {
          navigator.notification.confirm(
                  "Do you like PhoneGap?",
                  onConfirm,
                  "About PhoneGap",
                  "Yes,No"
              );
      }

      function onConfirm(buttonIndex) {
          // Do something depending on the button (index starting in 1)
      }




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                                About PhoneGap
                                                  First PhoneGap application
                         Starting with PhoneGap
                                                  PhoneGap API overview
                            Example application
                                                  Building PhoneGap


Notiļ¬cation III



      Beep
      navigator.notification.beep(1);



      Vibrate
      navigator.notification.vibrate(2000);




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                               About PhoneGap
                                                   First PhoneGap application
                        Starting with PhoneGap
                                                   PhoneGap API overview
                           Example application
                                                   Building PhoneGap


Connection


     Internet connection
     function checkConnection() {
         var networkState = navigator.network.connection.type;

         var states = {};
         states[Connection.UNKNOWN]        =   "Unknown connection";
         states[Connection.ETHERNET]       =   "Ethernet connection";
         states[Connection.WIFI]           =   "WiFi connection";
         states[Connection.CELL_2G]        =   "Cell 2G connection";
         states[Connection.CELL_3G]        =   "Cell 3G connection";
         states[Connection.CELL_4G]        =   "Cell 4G connection";
         states[Connection.NONE]           =   "No network connection";

         alert("Connection type: " + states[networkState]);
     }




     Manuel Rego Casasnovas <rego@igalia.com>      Introduction to PhoneGap
Development environment
                               About PhoneGap
                                                 First PhoneGap application
                        Starting with PhoneGap
                                                 PhoneGap API overview
                           Example application
                                                 Building PhoneGap


Device



     Device information (name, PhoneGap version, platform,
     UUID, version)
     function showDeviceInfo() {
         alert("name: " + device.name + "n" +
                 "cordova: " + device.cordova + "n" +
                 "platform: " + device.platform + "n" +
                 "uuid: " + device.uuid + "n" +
                 "version: " + device.version);
     }




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                              About PhoneGap
                                                First PhoneGap application
                       Starting with PhoneGap
                                                PhoneGap API overview
                          Example application
                                                Building PhoneGap


Camera


    Get picture
    function takePicture() {
        navigator.camera.getPicture(onSuccess, onFail, {
                quality: 50,
                destinationType: Camera.DestinationType.DATA_URL
            });
    }

    function onSuccess(imageData) {
        var image = document.getElementById("myImage");
        image.src = "data:image/jpeg;base64," + imageData;
    }

    function onFail(message) {
        alert("Failed because: " + message);
    }




    Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                                  About PhoneGap
                                                    First PhoneGap application
                           Starting with PhoneGap
                                                    PhoneGap API overview
                              Example application
                                                    Building PhoneGap


Other

        Accelerometer
        Capture
        Compass
        Contacts
        Events
        File
        Geolocation
        Media
        Storage
  Documentation:           http://docs.phonegap.com/


        Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                                About PhoneGap
                                                  First PhoneGap application
                         Starting with PhoneGap
                                                  PhoneGap API overview
                            Example application
                                                  Building PhoneGap


Building for other platforms



      Previous example is using Android as target platform
      About other platforms:
             Look for documentation and build it manually
             Use PhoneGap Build (https://build.phonegap.com/)
                    Free for public apps
                    Platforms: iOS (only if iOS developer), Android, Windows
                    Phone, BlackBerry, webOS and Symbian




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
Development environment
                              About PhoneGap
                                                First PhoneGap application
                       Starting with PhoneGap
                                                PhoneGap API overview
                          Example application
                                                Building PhoneGap


PhoneGap Build



     Special ļ¬les:
           index.html: App main page
           conļ¬g.xml: Basic data about your application (name,
           description, author, icon, permissions, ...) based on the
           W3C widget spec (http://www.w3.org/TR/widgets/)
           *.png: Icon in PNG format
     More info:      https://build.phonegap.com/docs/




    Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                Example
                       Starting with PhoneGap
                                                Exercise
                          Example application


Feed Reader



    Goal: Develop a simple feed reader
    Technologies:
           PhoneGap: HTML + JavaScript + CSS
           jQuery (http://jquery.com/download/)
           jQuery Mobile (http://jquerymobile.com/download/)
           jFeed (jQuery plugin): RSS/Atom feed parser
           (https://github.com/jfhovinne/jFeed/downloads)




    Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Basic page template I




     Include JavaScript and CSS for jQuery Mobile
     <script type="text/javascript" charset="utf-8"
         src="jquery-1.7.2.min.js"></script>
     <script type="text/javascript" charset="utf-8"
         src="jquery.mobile-1.1.1.min.js"></script>

     <link rel="stylesheet" type="text/css"
         href="jquery.mobile-1.1.1.min.css"></link>




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Basic page template II


     Page
     <div data-role="page" id="main">

         <div data-role="header">
             <h1>RSS/Atom Reader</h1>
         </div>

         <div data-role="content">
             TODO
         </div>

     </div>




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Basic page template III



     List
     <div data-role="content">
         <ul data-role="listview">
             <li><a href="#">Post 1</a></li>
             <li><a href="#">Post 2</a></li>
             <li><a href="#">Post 3</a></li>
         </ul>
     </div>




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Basic page template IV




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Read feed I




     Include JavaScript for jFeed
     <script type="text/javascript" charset="utf-8"
         src="jquery.jfeed.pack.js"></script>




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Read feed II


     Change onDeviceReady() function (using Planet
     GNOME as example)
     function onDeviceReady() {
         jQuery.getFeed({
             url: "http://planet.gnome.org/rss20.xml",
             success: function(feed) {
                 for (var i = 0; i < feed.items.length; i++) {
                     var item = feed.items[i];
                     console.log("Item " + i + ": " + item.title);
                 }
             }
         });
     }




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Read feed III
     Log
     07-31 11:37:39.110: I/Web Console(1222):
         Item 0: Richard Hughes: Being an OpenHardwar
         at file:///android_asset/www/index.html:24
     07-31 11:37:39.114: I/Web Console(1222):
         Item 1: Beth Hadley: GUADEC 2012
         at file:///android_asset/www/index.html:24
     07-31 11:37:39.125: I/Web Console(1222):
         Item 2: Eitan Isaacson: GUADEC!
         at file:///android_asset/www/index.html:24
     07-31 11:37:39.125: I/Web Console(1222):
         Item 3: Matilda Bernard: GUADEC
         at file:///android_asset/www/index.html:24

     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                  Example
                         Starting with PhoneGap
                                                  Exercise
                            Example application


Fill the list with the posts I




      Change HTML
      <div data-role="content">
          <ul data-role="listview" id="posts">
          </ul>
      </div>




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                  Example
                         Starting with PhoneGap
                                                  Exercise
                            Example application


Fill the list with the posts II

      Change onDeviceReady() function
      function onDeviceReady(){
          jQuery.getFeed({
              url: "http://planet.gnome.org/rss20.xml",
              success: function(feed) {
                  for (var i = 0; i < feed.items.length; i++) {
                      var item = feed.items[i];
                      appendPost(item);
                  }
              }
          });
      }

      function appendPost(item) {
          $("#posts").append("<li>" + item.title + "</li>");
      }




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                  Example
                         Starting with PhoneGap
                                                  Exercise
                            Example application


Fill the list with the posts III




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                  Example
                         Starting with PhoneGap
                                                  Exercise
                            Example application


Fix list rendering I


      Refresh list using listview("refresh")
      function onDeviceReady() {
          jQuery.getFeed({
              url: "http://planet.gnome.org/rss20.xml",
              success: function(feed) {
                  for (var i = 0; i < feed.items.length; i++) {
                      var item = feed.items[i];
                      appendPost(item);
                  }
                  $("#posts").listview("refresh");
              }
          });
      }




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                  Example
                         Starting with PhoneGap
                                                  Exercise
                            Example application


Fix list rendering II




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                  Example
                         Starting with PhoneGap
                                                  Exercise
                            Example application


Improving list of posts I



      Modify appendPost(item) function
      function appendPost(item) {
          var link = $("<a />").attr("href", item.link);
          $("<h3 />").append(item.title).appendTo(link);
          $("<p />").append(item.updated).appendTo(link);

          var li =    $("<li />").append(link);

          $("#posts").append(li);
      }




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                  Example
                         Starting with PhoneGap
                                                  Exercise
                            Example application


Improving list of posts II




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Add option to conļ¬gure feed



     Tasks TODO:
            Create a new Options page with the form
            Process the form with jQuery and save the URL using
            PhoneGap API for Storage
            Reload the posts list with the new URL
            Add feed title
            Manage possible erros in the URL and request a new one
            again
            Add warning if there is not Internet connection




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


New page for options I




     Add link to Options page
     <div data-role="header">
         <h1>RSS/Atom Reader</h1>
         <a href="#options" class="ui-btn-right"
             data-icon="gear" data-iconpos="notext">Options</a>
     </div>




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


New page for options II
     Add new Options page
     <div data-role="page" id="options">
         <div data-role="header">
             <a data-rel="back" data-role="button"
                 data-icon="back" data-iconpos="notext">Back</a>
             <h1>Options</h1>
         </div>
         <div data-role="content">
             <div data-role="fieldcontain">
                 <label for="url">Feed URL:</label>
                 <input id="url" type="text"></input>
             </div>
             <fieldset class="ui-grid-a">
                 <div class="ui-block-a">
                     <a href="#main" data-role="button"
                         data-icon="delete">Cancel</a>
                 </div>
                 <div class="ui-block-b">
                     <a href="#main" data-role="button"
                         data-icon="check" data-theme="b"
                         onClick="saveFeedURL();">Accept</a>
                 </div>
             </fieldset>
         </div>
     </div>


     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


New page for options III




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Save feed URL

     Save feed URL using Storage API
     function saveFeedURL() {
         var url = $("#url").val();
         window.localStorage.setItem("feedUrl", url);
     }



     Read the stored feed URL
     function onDeviceReady() {
         var url = window.localStorage.getItem("feedUrl");
         $("#url").val(url);

         jQuery.getFeed({
             url: url,
             success: function(feed) {
                 [...]
             }
         });
     }




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                  Example
                         Starting with PhoneGap
                                                  Exercise
                            Example application


Reload posts lists I

      Move to a separate method the code inside
      onDeviceReady()
      function onDeviceReady() {
          refreshPosts();
      }

      function refreshPosts() {
          var url = window.localStorage.getItem("feedUrl");
          $("#url").val(url);

          $("#posts").empty();
          jQuery.getFeed({
              url: url,
              success: function(feed) {
                  for (var i = 0; i < feed.items.length; i++) {
                      var item = feed.items[i];
                      console.log("Item " + i + ": " + item.title);
                      appendPost(item);
                  }
                  $("#posts").listview("refresh");
              }
          });
      }


      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                  Example
                         Starting with PhoneGap
                                                  Exercise
                            Example application


Reload posts lists II



      Call refreshPosts() from saveFeedURL()
      function saveFeedURL() {
          var url = $("#url").val();
          window.localStorage.setItem("feedUrl", url);

          refreshPosts();
      }




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                  Example
                         Starting with PhoneGap
                                                  Exercise
                            Example application


Add feed title I



      Modify success function inside refreshPosts()
      success: function(feed) {
          $("#posts").append($("<li data-role="list-divider" />")
                  .append(feed.title));

          for (var i = 0; i < feed.items.length; i++) {
              var item = feed.items[i];
              console.log("Item " + i + ": " + item.title);
              appendPost(item);
          }
          $("#posts").listview("refresh");
      }




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                  Example
                         Starting with PhoneGap
                                                  Exercise
                            Example application


Add feed title II




      Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Manage errors reading feed I


     Add error function inside refreshPosts()
     jQuery.getFeed({
         url: url,
         success: function(feed) {
             [...]
         },
         error: function(error) {
             var msg = "URL: " + url + "n" +
                 error.status + ": " + error.statusText;
             navigator.notification.alert(
                 msg,
                 goToOptions,
                 "Problems reading feed",
                 "Ok"
             );
         }
     });




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Manage errors reading feed II




     Add new function goToOptions()
     function goToOptions() {
         $.mobile.changePage("#options");
     }




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Manage errors reading feed III




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Check Internet connection I

     Modify onDeviceReady()
     function onDeviceReady() {
         if (isOnline()) {
             refreshPosts();
         } else {
             navigator.notification.alert(
                     "Sorry but it needs Internet to download the posts",
                     null,
                     "Off-line",
                     "Ok"
                  );
         }
     }



     Create new function isOnline()
     function isOnline() {
         var networkState = navigator.network.connection.type;
         return (networkState != Connection.NONE);
     }




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
About PhoneGap
                                                 Example
                        Starting with PhoneGap
                                                 Exercise
                           Example application


Check Internet connection II




     Manuel Rego Casasnovas <rego@igalia.com>    Introduction to PhoneGap
References



References

    PhoneGap
    http://phonegap.com/

    Apache Cordova API Documentation
    http://docs.phonegap.com/

    PhoneGap Wiki
    http://wiki.phonegap.com/

    PhoneGap Build Documentation
    https://build.phonegap.com/docs/

    PhoneGap - Wikipedia, the free encyclopedia
    http://en.wikipedia.org/wiki/PhoneGap



     Manuel Rego Casasnovas <rego@igalia.com>   Introduction to PhoneGap

More Related Content

What's hot

Introduction to PhoneGap
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGapRamesh Nair
Ā 
PhoneGap: a brief history and apologia
PhoneGap: a brief history and apologiaPhoneGap: a brief history and apologia
PhoneGap: a brief history and apologialorinbeer
Ā 
Building Native Mobile Applications with PhoneGap
Building Native Mobile Applications with PhoneGapBuilding Native Mobile Applications with PhoneGap
Building Native Mobile Applications with PhoneGapSimon MacDonald
Ā 
PhoneGap Day US 2013 - Chrome Packaged Apps
PhoneGap Day US 2013 - Chrome Packaged AppsPhoneGap Day US 2013 - Chrome Packaged Apps
PhoneGap Day US 2013 - Chrome Packaged AppsPhoneGap
Ā 
Cordova and PhoneGap Insights
Cordova and PhoneGap InsightsCordova and PhoneGap Insights
Cordova and PhoneGap InsightsMonaca
Ā 
PhoneGap: Building Mobile Applications with HTML/JS
PhoneGap: Building Mobile Applications with HTML/JSPhoneGap: Building Mobile Applications with HTML/JS
PhoneGap: Building Mobile Applications with HTML/JSRyan Stewart
Ā 
From mobile browser to mobile app
From mobile browser to mobile appFrom mobile browser to mobile app
From mobile browser to mobile appRyan Stewart
Ā 
DroidCon 2011: Developing HTML5 and hybrid Android apps using Phonegap
DroidCon 2011: Developing HTML5 and hybrid Android apps using PhonegapDroidCon 2011: Developing HTML5 and hybrid Android apps using Phonegap
DroidCon 2011: Developing HTML5 and hybrid Android apps using PhonegapAyushman Jain
Ā 
Phone gap in android technology
Phone gap in android technologyPhone gap in android technology
Phone gap in android technologyVikrant Thakare
Ā 
Debugging and deploying with phone gap
Debugging and deploying with phone gapDebugging and deploying with phone gap
Debugging and deploying with phone gapRyan Stewart
Ā 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGapRyan Stewart
Ā 
Developing with Phonegap - Adobe Refresh 2012
Developing with Phonegap - Adobe Refresh 2012Developing with Phonegap - Adobe Refresh 2012
Developing with Phonegap - Adobe Refresh 2012Ryan Stewart
Ā 
Getting Acquainted with PhoneGap
Getting Acquainted with PhoneGapGetting Acquainted with PhoneGap
Getting Acquainted with PhoneGapJoseph Labrecque
Ā 
The Phonegap Architecture
The Phonegap ArchitectureThe Phonegap Architecture
The Phonegap ArchitectureFrank Gielen
Ā 
Flutter vs React Native Development in 2020
Flutter vs React Native Development in 2020Flutter vs React Native Development in 2020
Flutter vs React Native Development in 2020Devathon
Ā 
Hybrid App Development with PhoneGap
Hybrid App Development with PhoneGapHybrid App Development with PhoneGap
Hybrid App Development with PhoneGapDotitude
Ā 
Phonegap
PhonegapPhonegap
PhonegapTim Kim
Ā 

What's hot (20)

Introduction to PhoneGap
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGap
Ā 
PhoneGap: a brief history and apologia
PhoneGap: a brief history and apologiaPhoneGap: a brief history and apologia
PhoneGap: a brief history and apologia
Ā 
PhoneGap
PhoneGapPhoneGap
PhoneGap
Ā 
Building Native Mobile Applications with PhoneGap
Building Native Mobile Applications with PhoneGapBuilding Native Mobile Applications with PhoneGap
Building Native Mobile Applications with PhoneGap
Ā 
Phonegap
PhonegapPhonegap
Phonegap
Ā 
PhoneGap Day US 2013 - Chrome Packaged Apps
PhoneGap Day US 2013 - Chrome Packaged AppsPhoneGap Day US 2013 - Chrome Packaged Apps
PhoneGap Day US 2013 - Chrome Packaged Apps
Ā 
Cordova and PhoneGap Insights
Cordova and PhoneGap InsightsCordova and PhoneGap Insights
Cordova and PhoneGap Insights
Ā 
PhoneGap: Building Mobile Applications with HTML/JS
PhoneGap: Building Mobile Applications with HTML/JSPhoneGap: Building Mobile Applications with HTML/JS
PhoneGap: Building Mobile Applications with HTML/JS
Ā 
From mobile browser to mobile app
From mobile browser to mobile appFrom mobile browser to mobile app
From mobile browser to mobile app
Ā 
Phonegap
PhonegapPhonegap
Phonegap
Ā 
DroidCon 2011: Developing HTML5 and hybrid Android apps using Phonegap
DroidCon 2011: Developing HTML5 and hybrid Android apps using PhonegapDroidCon 2011: Developing HTML5 and hybrid Android apps using Phonegap
DroidCon 2011: Developing HTML5 and hybrid Android apps using Phonegap
Ā 
Phone gap in android technology
Phone gap in android technologyPhone gap in android technology
Phone gap in android technology
Ā 
Debugging and deploying with phone gap
Debugging and deploying with phone gapDebugging and deploying with phone gap
Debugging and deploying with phone gap
Ā 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
Ā 
Developing with Phonegap - Adobe Refresh 2012
Developing with Phonegap - Adobe Refresh 2012Developing with Phonegap - Adobe Refresh 2012
Developing with Phonegap - Adobe Refresh 2012
Ā 
Getting Acquainted with PhoneGap
Getting Acquainted with PhoneGapGetting Acquainted with PhoneGap
Getting Acquainted with PhoneGap
Ā 
The Phonegap Architecture
The Phonegap ArchitectureThe Phonegap Architecture
The Phonegap Architecture
Ā 
Flutter vs React Native Development in 2020
Flutter vs React Native Development in 2020Flutter vs React Native Development in 2020
Flutter vs React Native Development in 2020
Ā 
Hybrid App Development with PhoneGap
Hybrid App Development with PhoneGapHybrid App Development with PhoneGap
Hybrid App Development with PhoneGap
Ā 
Phonegap
PhonegapPhonegap
Phonegap
Ā 

Similar to Introduction to PhoneGap

PhoneGap JavaScript API vs Native Components
PhoneGap JavaScript API vs Native ComponentsPhoneGap JavaScript API vs Native Components
PhoneGap JavaScript API vs Native ComponentsTechAhead
Ā 
PhoneGap/PhoneGap Build - Amsterdam Adobe Camp
PhoneGap/PhoneGap Build - Amsterdam Adobe CampPhoneGap/PhoneGap Build - Amsterdam Adobe Camp
PhoneGap/PhoneGap Build - Amsterdam Adobe CampMihai Corlan
Ā 
What is PhoneGap?
What is PhoneGap?What is PhoneGap?
What is PhoneGap?Chirag Parmar
Ā 
PhoneGap
PhoneGapPhoneGap
PhoneGapEmil Varga
Ā 
Georges Chitiga - Introduction to Phonegap - HTML5 & JS to native mobile app
Georges Chitiga - Introduction to Phonegap - HTML5 & JS to native mobile appGeorges Chitiga - Introduction to Phonegap - HTML5 & JS to native mobile app
Georges Chitiga - Introduction to Phonegap - HTML5 & JS to native mobile appCodecamp Romania
Ā 
Getting started with PhoneGap
Getting started with PhoneGapGetting started with PhoneGap
Getting started with PhoneGapMihai Corlan
Ā 
PhoneGap - Now and the Future
PhoneGap - Now and the FuturePhoneGap - Now and the Future
PhoneGap - Now and the FutureTim Kim
Ā 
Choosing the Right Mobile Development Platform (Part 3)
Choosing the Right Mobile Development Platform (Part 3)Choosing the Right Mobile Development Platform (Part 3)
Choosing the Right Mobile Development Platform (Part 3)Chris Griffith
Ā 
An introduction to Apache Cordova
An introduction to Apache CordovaAn introduction to Apache Cordova
An introduction to Apache Cordovavaluebound
Ā 
Developing cross platform mobile applications with phone gap for windows phone
Developing cross platform mobile applications with phone gap for windows phoneDeveloping cross platform mobile applications with phone gap for windows phone
Developing cross platform mobile applications with phone gap for windows phoneColin Eberhardt
Ā 
Android SDK and PhoneGap
Android SDK and PhoneGapAndroid SDK and PhoneGap
Android SDK and PhoneGapDoncho Minkov
Ā 
Introduction to PhoneGap
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGapQuang Minh Dao
Ā 
Intro to PhoneGap and PhoneGap Build
Intro to PhoneGap and PhoneGap BuildIntro to PhoneGap and PhoneGap Build
Intro to PhoneGap and PhoneGap BuildChris Griffith
Ā 
Cross Platform Mobile App Development
Cross Platform Mobile App Development Cross Platform Mobile App Development
Cross Platform Mobile App Development Jakir Hossain
Ā 

Similar to Introduction to PhoneGap (20)

Phonegap
PhonegapPhonegap
Phonegap
Ā 
PhoneGap JavaScript API vs Native Components
PhoneGap JavaScript API vs Native ComponentsPhoneGap JavaScript API vs Native Components
PhoneGap JavaScript API vs Native Components
Ā 
PhoneGap/PhoneGap Build - Amsterdam Adobe Camp
PhoneGap/PhoneGap Build - Amsterdam Adobe CampPhoneGap/PhoneGap Build - Amsterdam Adobe Camp
PhoneGap/PhoneGap Build - Amsterdam Adobe Camp
Ā 
What is PhoneGap?
What is PhoneGap?What is PhoneGap?
What is PhoneGap?
Ā 
PhoneGap
PhoneGapPhoneGap
PhoneGap
Ā 
Phone gap development, testing, and debugging
Phone gap development, testing, and debuggingPhone gap development, testing, and debugging
Phone gap development, testing, and debugging
Ā 
phonegap_101
phonegap_101phonegap_101
phonegap_101
Ā 
Georges Chitiga - Introduction to Phonegap - HTML5 & JS to native mobile app
Georges Chitiga - Introduction to Phonegap - HTML5 & JS to native mobile appGeorges Chitiga - Introduction to Phonegap - HTML5 & JS to native mobile app
Georges Chitiga - Introduction to Phonegap - HTML5 & JS to native mobile app
Ā 
Getting started with PhoneGap
Getting started with PhoneGapGetting started with PhoneGap
Getting started with PhoneGap
Ā 
PhoneGap - Now and the Future
PhoneGap - Now and the FuturePhoneGap - Now and the Future
PhoneGap - Now and the Future
Ā 
Choosing the Right Mobile Development Platform (Part 3)
Choosing the Right Mobile Development Platform (Part 3)Choosing the Right Mobile Development Platform (Part 3)
Choosing the Right Mobile Development Platform (Part 3)
Ā 
An introduction to Apache Cordova
An introduction to Apache CordovaAn introduction to Apache Cordova
An introduction to Apache Cordova
Ā 
Developing cross platform mobile applications with phone gap for windows phone
Developing cross platform mobile applications with phone gap for windows phoneDeveloping cross platform mobile applications with phone gap for windows phone
Developing cross platform mobile applications with phone gap for windows phone
Ā 
Android SDK and PhoneGap
Android SDK and PhoneGapAndroid SDK and PhoneGap
Android SDK and PhoneGap
Ā 
Phone gap development, testing, and debugging
Phone gap development, testing, and debuggingPhone gap development, testing, and debugging
Phone gap development, testing, and debugging
Ā 
Introduction to PhoneGap
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGap
Ā 
Phonegap
PhonegapPhonegap
Phonegap
Ā 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
Ā 
Intro to PhoneGap and PhoneGap Build
Intro to PhoneGap and PhoneGap BuildIntro to PhoneGap and PhoneGap Build
Intro to PhoneGap and PhoneGap Build
Ā 
Cross Platform Mobile App Development
Cross Platform Mobile App Development Cross Platform Mobile App Development
Cross Platform Mobile App Development
Ā 

More from degarden

MICHELIN_-AGILIS-CrossClimate_GB
MICHELIN_-AGILIS-CrossClimate_GBMICHELIN_-AGILIS-CrossClimate_GB
MICHELIN_-AGILIS-CrossClimate_GBdegarden
Ā 
ABC 2021 Guia del vino
ABC 2021 Guia del vinoABC 2021 Guia del vino
ABC 2021 Guia del vinodegarden
Ā 
Audi-A3-Sportback-catalogo-es-1146
Audi-A3-Sportback-catalogo-es-1146Audi-A3-Sportback-catalogo-es-1146
Audi-A3-Sportback-catalogo-es-1146degarden
Ā 
Why btrfs is the Bread and Butter of Filesystems
Why btrfs is the Bread and Butter of FilesystemsWhy btrfs is the Bread and Butter of Filesystems
Why btrfs is the Bread and Butter of Filesystemsdegarden
Ā 
Toshiba X300 salessheet english-web_r2
Toshiba X300 salessheet english-web_r2Toshiba X300 salessheet english-web_r2
Toshiba X300 salessheet english-web_r2degarden
Ā 
Toshiba N300 salessheet english-web_r2
Toshiba N300 salessheet english-web_r2Toshiba N300 salessheet english-web_r2
Toshiba N300 salessheet english-web_r2degarden
Ā 
The 20 maps that will help you understand Spain - The Local
The 20 maps that will help you understand Spain - The LocalThe 20 maps that will help you understand Spain - The Local
The 20 maps that will help you understand Spain - The Localdegarden
Ā 
Toshiba X300 Performance Internal Hard Drive
Toshiba X300 Performance Internal Hard DriveToshiba X300 Performance Internal Hard Drive
Toshiba X300 Performance Internal Hard Drivedegarden
Ā 
Bronces
BroncesBronces
Broncesdegarden
Ā 
Sper Food Safety Thermometer with IR
Sper Food Safety Thermometer with IRSper Food Safety Thermometer with IR
Sper Food Safety Thermometer with IRdegarden
Ā 
Plarad Torque and tension systems
Plarad Torque and tension systemsPlarad Torque and tension systems
Plarad Torque and tension systemsdegarden
Ā 
Plarad Hydraulikaggregate Hydraulic Power Packs
Plarad Hydraulikaggregate Hydraulic Power PacksPlarad Hydraulikaggregate Hydraulic Power Packs
Plarad Hydraulikaggregate Hydraulic Power Packsdegarden
Ā 
Hands-Free Profile 1.7
Hands-Free Profile 1.7Hands-Free Profile 1.7
Hands-Free Profile 1.7degarden
Ā 
Fingerprinting Bluetooth-Low-Energy Devices Based on the Generic Attribute Pr...
Fingerprinting Bluetooth-Low-Energy Devices Based on the Generic Attribute Pr...Fingerprinting Bluetooth-Low-Energy Devices Based on the Generic Attribute Pr...
Fingerprinting Bluetooth-Low-Energy Devices Based on the Generic Attribute Pr...degarden
Ā 
Reverse Engineering BLE Devices Documentation
Reverse Engineering BLE Devices DocumentationReverse Engineering BLE Devices Documentation
Reverse Engineering BLE Devices Documentationdegarden
Ā 
pWeb: A P2P Web Hosting Framework
pWeb: A P2P Web Hosting FrameworkpWeb: A P2P Web Hosting Framework
pWeb: A P2P Web Hosting Frameworkdegarden
Ā 
ĀæQuĆ© esconde tu telĆ©fono? AdquisiciĆ³n forense de dispositivos Android
ĀæQuĆ© esconde tu telĆ©fono? AdquisiciĆ³n forense de dispositivos Android ĀæQuĆ© esconde tu telĆ©fono? AdquisiciĆ³n forense de dispositivos Android
ĀæQuĆ© esconde tu telĆ©fono? AdquisiciĆ³n forense de dispositivos Android degarden
Ā 
Bose NC 700 - User manual English
Bose NC 700 - User manual EnglishBose NC 700 - User manual English
Bose NC 700 - User manual Englishdegarden
Ā 
MICHELIN CrossCLIMATE+
MICHELIN CrossCLIMATE+MICHELIN CrossCLIMATE+
MICHELIN CrossCLIMATE+degarden
Ā 
CatƔlogo-Producto-Familia-A3-PI_MY17_Medidas-Semana-9_2017
CatƔlogo-Producto-Familia-A3-PI_MY17_Medidas-Semana-9_2017CatƔlogo-Producto-Familia-A3-PI_MY17_Medidas-Semana-9_2017
CatƔlogo-Producto-Familia-A3-PI_MY17_Medidas-Semana-9_2017degarden
Ā 

More from degarden (20)

MICHELIN_-AGILIS-CrossClimate_GB
MICHELIN_-AGILIS-CrossClimate_GBMICHELIN_-AGILIS-CrossClimate_GB
MICHELIN_-AGILIS-CrossClimate_GB
Ā 
ABC 2021 Guia del vino
ABC 2021 Guia del vinoABC 2021 Guia del vino
ABC 2021 Guia del vino
Ā 
Audi-A3-Sportback-catalogo-es-1146
Audi-A3-Sportback-catalogo-es-1146Audi-A3-Sportback-catalogo-es-1146
Audi-A3-Sportback-catalogo-es-1146
Ā 
Why btrfs is the Bread and Butter of Filesystems
Why btrfs is the Bread and Butter of FilesystemsWhy btrfs is the Bread and Butter of Filesystems
Why btrfs is the Bread and Butter of Filesystems
Ā 
Toshiba X300 salessheet english-web_r2
Toshiba X300 salessheet english-web_r2Toshiba X300 salessheet english-web_r2
Toshiba X300 salessheet english-web_r2
Ā 
Toshiba N300 salessheet english-web_r2
Toshiba N300 salessheet english-web_r2Toshiba N300 salessheet english-web_r2
Toshiba N300 salessheet english-web_r2
Ā 
The 20 maps that will help you understand Spain - The Local
The 20 maps that will help you understand Spain - The LocalThe 20 maps that will help you understand Spain - The Local
The 20 maps that will help you understand Spain - The Local
Ā 
Toshiba X300 Performance Internal Hard Drive
Toshiba X300 Performance Internal Hard DriveToshiba X300 Performance Internal Hard Drive
Toshiba X300 Performance Internal Hard Drive
Ā 
Bronces
BroncesBronces
Bronces
Ā 
Sper Food Safety Thermometer with IR
Sper Food Safety Thermometer with IRSper Food Safety Thermometer with IR
Sper Food Safety Thermometer with IR
Ā 
Plarad Torque and tension systems
Plarad Torque and tension systemsPlarad Torque and tension systems
Plarad Torque and tension systems
Ā 
Plarad Hydraulikaggregate Hydraulic Power Packs
Plarad Hydraulikaggregate Hydraulic Power PacksPlarad Hydraulikaggregate Hydraulic Power Packs
Plarad Hydraulikaggregate Hydraulic Power Packs
Ā 
Hands-Free Profile 1.7
Hands-Free Profile 1.7Hands-Free Profile 1.7
Hands-Free Profile 1.7
Ā 
Fingerprinting Bluetooth-Low-Energy Devices Based on the Generic Attribute Pr...
Fingerprinting Bluetooth-Low-Energy Devices Based on the Generic Attribute Pr...Fingerprinting Bluetooth-Low-Energy Devices Based on the Generic Attribute Pr...
Fingerprinting Bluetooth-Low-Energy Devices Based on the Generic Attribute Pr...
Ā 
Reverse Engineering BLE Devices Documentation
Reverse Engineering BLE Devices DocumentationReverse Engineering BLE Devices Documentation
Reverse Engineering BLE Devices Documentation
Ā 
pWeb: A P2P Web Hosting Framework
pWeb: A P2P Web Hosting FrameworkpWeb: A P2P Web Hosting Framework
pWeb: A P2P Web Hosting Framework
Ā 
ĀæQuĆ© esconde tu telĆ©fono? AdquisiciĆ³n forense de dispositivos Android
ĀæQuĆ© esconde tu telĆ©fono? AdquisiciĆ³n forense de dispositivos Android ĀæQuĆ© esconde tu telĆ©fono? AdquisiciĆ³n forense de dispositivos Android
ĀæQuĆ© esconde tu telĆ©fono? AdquisiciĆ³n forense de dispositivos Android
Ā 
Bose NC 700 - User manual English
Bose NC 700 - User manual EnglishBose NC 700 - User manual English
Bose NC 700 - User manual English
Ā 
MICHELIN CrossCLIMATE+
MICHELIN CrossCLIMATE+MICHELIN CrossCLIMATE+
MICHELIN CrossCLIMATE+
Ā 
CatƔlogo-Producto-Familia-A3-PI_MY17_Medidas-Semana-9_2017
CatƔlogo-Producto-Familia-A3-PI_MY17_Medidas-Semana-9_2017CatƔlogo-Producto-Familia-A3-PI_MY17_Medidas-Semana-9_2017
CatƔlogo-Producto-Familia-A3-PI_MY17_Medidas-Semana-9_2017
Ā 

Recently uploaded

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
Ā 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
Ā 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
Ā 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
Ā 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
Ā 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
Ā 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
Ā 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
Ā 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
Ā 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
Ā 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
Ā 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
Ā 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
Ā 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
Ā 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
Ā 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
Ā 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
Ā 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
Ā 

Recently uploaded (20)

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
Ā 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
Ā 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
Ā 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
Ā 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
Ā 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
Ā 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
Ā 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
Ā 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
Ā 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
Ā 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
Ā 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Ā 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
Ā 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
Ā 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
Ā 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
Ā 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
Ā 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
Ā 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
Ā 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
Ā 

Introduction to PhoneGap

  • 1. About PhoneGap Starting with PhoneGap Example application Introduction to PhoneGap Web development for mobile platforms Manuel Rego Casasnovas <rego@igalia.com> Master on Free Software / August 2012 Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 2. About PhoneGap Starting with PhoneGap Example application Outline 1 About PhoneGap 2 Starting with PhoneGap Development environment First PhoneGap application PhoneGap API overview Building PhoneGap 3 Example application Example Exercise Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 3. About PhoneGap Starting with PhoneGap About PhoneGap Example application What is PhoneGap? Mobile web development framework Based on JavaScript, HTML5 and CSS3 Open source: Apache 2.0 License Supported platforms: iPhone, Android, Windows Phone, BlackBerry, Symbian, webOS and Bada (comming soon) Homepage: http://phonegap.com/ Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 4. About PhoneGap Starting with PhoneGap About PhoneGap Example application History Started by Nitobi Software Peopleā€™s Choice Award at Oā€™Reilly Mediaā€™s 2009 Web 2.0 Conference Adobe acquired Nitobi on October 2011 PhoneGap was contributed to the Apache Software Foundation First it was called Apache Callback Renamed to Apache Cordova URL: http://incubator.apache.org/cordova/ Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 5. About PhoneGap Starting with PhoneGap About PhoneGap Example application Features JavaScript API to access different parts of the device: Accelerometer Camera Capture Compass Connection Contacts Device Events File Geolocation Media Notiļ¬cations (alert, sound, vibration) Storage Documentation: http://docs.phonegap.com/ Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 6. About PhoneGap Starting with PhoneGap About PhoneGap Example application Advantages Multi-platform Well-known technologies: HTML + JavaScript + CSS Vast amount of JavaScript libraries/frameworks available: General purpose: jQuery, Prototype, . . . Mobile: jQuery Mobile, Enyo, . . . ... Conclusion: More and more web is everywhere Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 7. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Eclipse Download Eclipse Classic http://www.eclipse.org/downloads/ Uncompress Eclipse # cd /opt/ # tar -xzvf /home/user/Downloads/eclipse-SDK-4.2-linux-gtk-x86_64.tar.gz # cd /usr/local/bin/ # ln -s /opt/eclipse/eclipse Run Eclipse $ eclipse Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 8. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Android SDK and ADT Plugin Download Android SDK (http://developer.android.com/sdk/index.html) $ cd ~ $ tar -xzvf ~/Downloads/android-sdk_r20.0.1-linux.tgz Download and install ADT Plugin in Eclipse Add site: Juno - http://download.eclipse.org/releases/juno Add site: ADT Plugin - https://dl-ssl.google.com/android/eclipse/ Install ADT Plugin Android SDK Manager AVD Manager Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 9. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Android project with PhoneGap library I Download PhoneGap http://phonegap.com/download Create a new Android Application Project in Eclipse Create 2 new folders in the root of the project: libs/ assets/www/ Copy some ļ¬les from donwloaded PhoneGap: Copy cordova-2.0.0.js to assets/www/ Copy cordova-2.0.0.jar to libs/ Copy xml/ folder to res/ Add cordova-2.0.0.jar to project Build Path Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 10. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Android project with PhoneGap library II Modify MainActivity to extend DroidGap package com.igalia.phonegap.example.helloworldphonegap; import org.apache.cordova.DroidGap; import android.os.Bundle; public class MainActivity extends DroidGap { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.loadUrl("file:///android_asset/www/index.html"); } } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 11. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Conļ¬gure permissions Modify AndroidManifest.xml adding the following lines between <uses-sdk.../> and <application.../> <supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:resizeable="true" android:anyDensity="true" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission. ACCESS_LOCATION_EXTRA_COMMANDS" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.BROADCAST_STICKY" /> Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 12. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Basic UI Create a new ļ¬le index.html inside assets/www/ with the following content <!DOCTYPE HTML> <html> <head> <title>PhoneGap Example</title> <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></ script> </head> <body> <h1>Hello World!</h1> </body> </html> Run as Android Application Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 13. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Check that PhoneGap is ready Add JavaScript waiting for PoneGap to be loaded <script type="text/javascript"> document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { alert("PhoneGap loaded"); } </script> Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 14. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Screenshot Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 15. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Notiļ¬cation I Alert function showAlert() { navigator.notification.alert( "Testing notification.alert", afterAlert, "Alert title", "Button" ); } function afterAlert() { // Do something } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 16. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Notiļ¬cation II Conļ¬rm function showConfirm() { navigator.notification.confirm( "Do you like PhoneGap?", onConfirm, "About PhoneGap", "Yes,No" ); } function onConfirm(buttonIndex) { // Do something depending on the button (index starting in 1) } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 17. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Notiļ¬cation III Beep navigator.notification.beep(1); Vibrate navigator.notification.vibrate(2000); Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 18. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Connection Internet connection function checkConnection() { var networkState = navigator.network.connection.type; var states = {}; states[Connection.UNKNOWN] = "Unknown connection"; states[Connection.ETHERNET] = "Ethernet connection"; states[Connection.WIFI] = "WiFi connection"; states[Connection.CELL_2G] = "Cell 2G connection"; states[Connection.CELL_3G] = "Cell 3G connection"; states[Connection.CELL_4G] = "Cell 4G connection"; states[Connection.NONE] = "No network connection"; alert("Connection type: " + states[networkState]); } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 19. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Device Device information (name, PhoneGap version, platform, UUID, version) function showDeviceInfo() { alert("name: " + device.name + "n" + "cordova: " + device.cordova + "n" + "platform: " + device.platform + "n" + "uuid: " + device.uuid + "n" + "version: " + device.version); } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 20. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Camera Get picture function takePicture() { navigator.camera.getPicture(onSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.DATA_URL }); } function onSuccess(imageData) { var image = document.getElementById("myImage"); image.src = "data:image/jpeg;base64," + imageData; } function onFail(message) { alert("Failed because: " + message); } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 21. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Other Accelerometer Capture Compass Contacts Events File Geolocation Media Storage Documentation: http://docs.phonegap.com/ Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 22. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap Building for other platforms Previous example is using Android as target platform About other platforms: Look for documentation and build it manually Use PhoneGap Build (https://build.phonegap.com/) Free for public apps Platforms: iOS (only if iOS developer), Android, Windows Phone, BlackBerry, webOS and Symbian Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 23. Development environment About PhoneGap First PhoneGap application Starting with PhoneGap PhoneGap API overview Example application Building PhoneGap PhoneGap Build Special ļ¬les: index.html: App main page conļ¬g.xml: Basic data about your application (name, description, author, icon, permissions, ...) based on the W3C widget spec (http://www.w3.org/TR/widgets/) *.png: Icon in PNG format More info: https://build.phonegap.com/docs/ Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 24. About PhoneGap Example Starting with PhoneGap Exercise Example application Feed Reader Goal: Develop a simple feed reader Technologies: PhoneGap: HTML + JavaScript + CSS jQuery (http://jquery.com/download/) jQuery Mobile (http://jquerymobile.com/download/) jFeed (jQuery plugin): RSS/Atom feed parser (https://github.com/jfhovinne/jFeed/downloads) Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 25. About PhoneGap Example Starting with PhoneGap Exercise Example application Basic page template I Include JavaScript and CSS for jQuery Mobile <script type="text/javascript" charset="utf-8" src="jquery-1.7.2.min.js"></script> <script type="text/javascript" charset="utf-8" src="jquery.mobile-1.1.1.min.js"></script> <link rel="stylesheet" type="text/css" href="jquery.mobile-1.1.1.min.css"></link> Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 26. About PhoneGap Example Starting with PhoneGap Exercise Example application Basic page template II Page <div data-role="page" id="main"> <div data-role="header"> <h1>RSS/Atom Reader</h1> </div> <div data-role="content"> TODO </div> </div> Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 27. About PhoneGap Example Starting with PhoneGap Exercise Example application Basic page template III List <div data-role="content"> <ul data-role="listview"> <li><a href="#">Post 1</a></li> <li><a href="#">Post 2</a></li> <li><a href="#">Post 3</a></li> </ul> </div> Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 28. About PhoneGap Example Starting with PhoneGap Exercise Example application Basic page template IV Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 29. About PhoneGap Example Starting with PhoneGap Exercise Example application Read feed I Include JavaScript for jFeed <script type="text/javascript" charset="utf-8" src="jquery.jfeed.pack.js"></script> Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 30. About PhoneGap Example Starting with PhoneGap Exercise Example application Read feed II Change onDeviceReady() function (using Planet GNOME as example) function onDeviceReady() { jQuery.getFeed({ url: "http://planet.gnome.org/rss20.xml", success: function(feed) { for (var i = 0; i < feed.items.length; i++) { var item = feed.items[i]; console.log("Item " + i + ": " + item.title); } } }); } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 31. About PhoneGap Example Starting with PhoneGap Exercise Example application Read feed III Log 07-31 11:37:39.110: I/Web Console(1222): Item 0: Richard Hughes: Being an OpenHardwar at file:///android_asset/www/index.html:24 07-31 11:37:39.114: I/Web Console(1222): Item 1: Beth Hadley: GUADEC 2012 at file:///android_asset/www/index.html:24 07-31 11:37:39.125: I/Web Console(1222): Item 2: Eitan Isaacson: GUADEC! at file:///android_asset/www/index.html:24 07-31 11:37:39.125: I/Web Console(1222): Item 3: Matilda Bernard: GUADEC at file:///android_asset/www/index.html:24 Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 32. About PhoneGap Example Starting with PhoneGap Exercise Example application Fill the list with the posts I Change HTML <div data-role="content"> <ul data-role="listview" id="posts"> </ul> </div> Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 33. About PhoneGap Example Starting with PhoneGap Exercise Example application Fill the list with the posts II Change onDeviceReady() function function onDeviceReady(){ jQuery.getFeed({ url: "http://planet.gnome.org/rss20.xml", success: function(feed) { for (var i = 0; i < feed.items.length; i++) { var item = feed.items[i]; appendPost(item); } } }); } function appendPost(item) { $("#posts").append("<li>" + item.title + "</li>"); } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 34. About PhoneGap Example Starting with PhoneGap Exercise Example application Fill the list with the posts III Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 35. About PhoneGap Example Starting with PhoneGap Exercise Example application Fix list rendering I Refresh list using listview("refresh") function onDeviceReady() { jQuery.getFeed({ url: "http://planet.gnome.org/rss20.xml", success: function(feed) { for (var i = 0; i < feed.items.length; i++) { var item = feed.items[i]; appendPost(item); } $("#posts").listview("refresh"); } }); } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 36. About PhoneGap Example Starting with PhoneGap Exercise Example application Fix list rendering II Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 37. About PhoneGap Example Starting with PhoneGap Exercise Example application Improving list of posts I Modify appendPost(item) function function appendPost(item) { var link = $("<a />").attr("href", item.link); $("<h3 />").append(item.title).appendTo(link); $("<p />").append(item.updated).appendTo(link); var li = $("<li />").append(link); $("#posts").append(li); } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 38. About PhoneGap Example Starting with PhoneGap Exercise Example application Improving list of posts II Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 39. About PhoneGap Example Starting with PhoneGap Exercise Example application Add option to conļ¬gure feed Tasks TODO: Create a new Options page with the form Process the form with jQuery and save the URL using PhoneGap API for Storage Reload the posts list with the new URL Add feed title Manage possible erros in the URL and request a new one again Add warning if there is not Internet connection Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 40. About PhoneGap Example Starting with PhoneGap Exercise Example application New page for options I Add link to Options page <div data-role="header"> <h1>RSS/Atom Reader</h1> <a href="#options" class="ui-btn-right" data-icon="gear" data-iconpos="notext">Options</a> </div> Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 41. About PhoneGap Example Starting with PhoneGap Exercise Example application New page for options II Add new Options page <div data-role="page" id="options"> <div data-role="header"> <a data-rel="back" data-role="button" data-icon="back" data-iconpos="notext">Back</a> <h1>Options</h1> </div> <div data-role="content"> <div data-role="fieldcontain"> <label for="url">Feed URL:</label> <input id="url" type="text"></input> </div> <fieldset class="ui-grid-a"> <div class="ui-block-a"> <a href="#main" data-role="button" data-icon="delete">Cancel</a> </div> <div class="ui-block-b"> <a href="#main" data-role="button" data-icon="check" data-theme="b" onClick="saveFeedURL();">Accept</a> </div> </fieldset> </div> </div> Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 42. About PhoneGap Example Starting with PhoneGap Exercise Example application New page for options III Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 43. About PhoneGap Example Starting with PhoneGap Exercise Example application Save feed URL Save feed URL using Storage API function saveFeedURL() { var url = $("#url").val(); window.localStorage.setItem("feedUrl", url); } Read the stored feed URL function onDeviceReady() { var url = window.localStorage.getItem("feedUrl"); $("#url").val(url); jQuery.getFeed({ url: url, success: function(feed) { [...] } }); } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 44. About PhoneGap Example Starting with PhoneGap Exercise Example application Reload posts lists I Move to a separate method the code inside onDeviceReady() function onDeviceReady() { refreshPosts(); } function refreshPosts() { var url = window.localStorage.getItem("feedUrl"); $("#url").val(url); $("#posts").empty(); jQuery.getFeed({ url: url, success: function(feed) { for (var i = 0; i < feed.items.length; i++) { var item = feed.items[i]; console.log("Item " + i + ": " + item.title); appendPost(item); } $("#posts").listview("refresh"); } }); } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 45. About PhoneGap Example Starting with PhoneGap Exercise Example application Reload posts lists II Call refreshPosts() from saveFeedURL() function saveFeedURL() { var url = $("#url").val(); window.localStorage.setItem("feedUrl", url); refreshPosts(); } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 46. About PhoneGap Example Starting with PhoneGap Exercise Example application Add feed title I Modify success function inside refreshPosts() success: function(feed) { $("#posts").append($("<li data-role="list-divider" />") .append(feed.title)); for (var i = 0; i < feed.items.length; i++) { var item = feed.items[i]; console.log("Item " + i + ": " + item.title); appendPost(item); } $("#posts").listview("refresh"); } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 47. About PhoneGap Example Starting with PhoneGap Exercise Example application Add feed title II Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 48. About PhoneGap Example Starting with PhoneGap Exercise Example application Manage errors reading feed I Add error function inside refreshPosts() jQuery.getFeed({ url: url, success: function(feed) { [...] }, error: function(error) { var msg = "URL: " + url + "n" + error.status + ": " + error.statusText; navigator.notification.alert( msg, goToOptions, "Problems reading feed", "Ok" ); } }); Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 49. About PhoneGap Example Starting with PhoneGap Exercise Example application Manage errors reading feed II Add new function goToOptions() function goToOptions() { $.mobile.changePage("#options"); } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 50. About PhoneGap Example Starting with PhoneGap Exercise Example application Manage errors reading feed III Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 51. About PhoneGap Example Starting with PhoneGap Exercise Example application Check Internet connection I Modify onDeviceReady() function onDeviceReady() { if (isOnline()) { refreshPosts(); } else { navigator.notification.alert( "Sorry but it needs Internet to download the posts", null, "Off-line", "Ok" ); } } Create new function isOnline() function isOnline() { var networkState = navigator.network.connection.type; return (networkState != Connection.NONE); } Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 52. About PhoneGap Example Starting with PhoneGap Exercise Example application Check Internet connection II Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap
  • 53. References References PhoneGap http://phonegap.com/ Apache Cordova API Documentation http://docs.phonegap.com/ PhoneGap Wiki http://wiki.phonegap.com/ PhoneGap Build Documentation https://build.phonegap.com/docs/ PhoneGap - Wikipedia, the free encyclopedia http://en.wikipedia.org/wiki/PhoneGap Manuel Rego Casasnovas <rego@igalia.com> Introduction to PhoneGap