Introduction to PhoneGap

Similar documents
the intro for RPG programmers Making mobile app development easier... of KrengelTech by Aaron Bartell

Developing Native JavaScript Mobile Apps Using Apache Cordova. Hazem Saleh

Enabling Cordova (aka PhoneGap) on Tizen. René Pourtier / Luc Yriarte

place/business fetch details, removefromfavorite () function, 189 search button handler bind, B BlackBerry build environment

Cross-Platform Tools

Mobile Application Development

Retool your HTML/JavaScript to go Mobile

Adding HTML5 to your Android applications. Martin Gunnarsson & Pär Sikö

Android Environment SDK

Android Development. 吳 俊 興 國 立 高 雄 大 學 資 訊 工 程 學 系

Developing multidevice-apps using Apache Cordova and HTML5. Guadalajara Java User Group Guillermo Muñoz Java Developer

Introduction: The Xcode templates are not available in Cordova or above, so we'll use the previous version, for this recipe.

BASIC COMPONENTS. There are 3 basic components in every Apache Cordova project:

Making Web Application using Tizen Web UI Framework. Koeun Choi

Building native mobile apps for Digital Factory

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

PhoneGap Build Starter

Visualizing a Neo4j Graph Database with KeyLines

Bridging the Gap: from a Web App to a Mobile Device App

Building Mobile Applications Creating ios applications with jquery Mobile, PhoneGap, and Drupal 7

Advertiser Campaign SDK Your How-to Guide

SYST35300 Hybrid Mobile Application Development

Operational Decision Manager Worklight Integration

directory to "d:\myproject\android". Hereafter, I shall denote the android installed directory as

Website Login Integration

IBM Tealeaf CX Mobile Android Logging Framework Version 9 Release 0.1 December 4, IBM Tealeaf CX Mobile Android Logging Framework Guide

PLAYER DEVELOPER GUIDE

Android Environment SDK

max firt.mobi martes 26 de julio de 11

Visualizing an OrientDB Graph Database with KeyLines

Develop a Native App (ios and Android) for a Drupal Website without Learning Objective-C or Java. Drupaldelphia 2014 By Joe Roberts

MASTERTAG DEVELOPER GUIDE

APEX World 2013 APEX & Christian Rokitta. OGh APEX World 9 April 2013

Hello World. by Elliot Khazon

About this Release. Introduction. Prerequisites. Installation. Using the Web SDK Packager

ios SDK possibilities & limitations

Client-side Web Engineering From HTML to AJAX

Copyright by Object Computing, Inc. (OCI). All rights reserved. AngularJS Testing

... Introduction Acknowledgments... 19

How to build your first Android Application in Windows

Building Web Applications with HTML5, CSS3, and Javascript: An Introduction to HTML5

Developer Guide: Hybrid Apps. SAP Mobile Platform 2.3

Web Development CSE2WD Final Examination June (a) Which organisation is primarily responsible for HTML, CSS and DOM standards?

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

c. Write a JavaScript statement to print out as an alert box the value of the third Radio button (whether or not selected) in the second form.

Slide.Show Quick Start Guide

Cross-Platform Phone Apps & Sites with jquery Mobile

Web Development 1 A4 Project Description Web Architecture

Login with Amazon Getting Started Guide for Android. Version 2.0

Sitecore Dashboard User Guide

Introduction to NaviGenie SDK Client API for Android

How To Use Titanium Studio

BUILDING MOBILE WEB APPS WITH PHONEGAP. Matt Zukowski

The Bootstrapper's Guide to the Mobile Web by Deltina Hay. Mobile App Strategy Worksheet. I. Target Market, App Category, Platforms

Intell-a-Keeper Reporting System Technical Programming Guide. Tracking your Bookings without going Nuts!

How To Write A File Station In Android.Com (For Free) On A Microsoft Macbook Or Ipad (For A Limited Time) On An Ubuntu 8.1 (For Ubuntu) On Your Computer Or Ipa (For

Mocean Android SDK Developer Guide

Adobe Summit 2015 Lab 712: Building Mobile Apps: A PhoneGap Enterprise Introduction for Developers

Getting Started: Creating a Simple App

@ME (About) Marcelo Cyreno. Skype: marcelocyreno Linkedin: marcelocyreno Mail:

Login with Amazon. Getting Started Guide for Websites. Version 1.0

Introduction to Tizen SDK Alpha. Taiho Choi Samsung Electronics

Dave Haseman, Ross. Hightower. Mobile Development for SAP* ^>. Galileo Press. Bonn. Boston

Outline. 1.! Development Platforms for Multimedia Programming!

Cross-Platform Mobile Geolocation Applications Based on PhoneGap

Developing and deploying mobile apps

Chapter 2 Getting Started

Pay with Amazon Integration Guide

l What is Android? l Getting Started l The Emulator l Hello World l ADB l Text to Speech l Other APIs (camera, bitmap, etc)

ANGULAR JS SOFTWARE ENGINEERING FOR WEB SERVICES HASAN FAIZAL K APRIL,2014

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

Script Handbook for Interactive Scientific Website Building

Website Planning Checklist

2. Click the download button for your operating system (Windows, Mac, or Linux).

CiviMobile & CiviSync Mobile. Peter McAndrew Rohit Thakral

Design of Information Technology in Enhancing the Quality of M- Learning-Based Learning at Diponegoro University

Bazaarvoice for Magento Extension Implementation Guide v6.3.4

ANDROID APP DEVELOPMENT: AN INTRODUCTION CSCI /19/14 HANNAH MILLER

How to Create an Android Application using Eclipse on Windows 7

Tutorial: Android Object API Application Development. SAP Mobile Platform 2.3 SP02

Web-based Hybrid Mobile Apps: State of the Practice and Research Opportunities

Web Design Basics. Cindy Royal, Ph.D. Associate Professor Texas State University

How To Develop A Mobile App With Phonegap

Lecture 1 Introduction to Android

To Study and Design a Cross-Platform Mobile Application for Student Information System using PhoneGap Framework

IOIO for Android Beginners Guide Introduction

Tizen Web Runtime Update. Ming Jin Samsung Electronics

Chapter 22 How to send and access other web sites

BUILD A MOBILE APP WITH HTML5 AND JAVASCRIPT

Xuan (The STACK Box) Application Development. Xuan (The STACK Box) Application Development

Transcription:

Web development for mobile platforms Master on Free Software / August 2012

Outline About PhoneGap 1 About PhoneGap 2 Development environment First PhoneGap application PhoneGap API overview Building PhoneGap 3

About PhoneGap 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/

About PhoneGap 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/

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

About PhoneGap 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

Eclipse About PhoneGap Development environment First PhoneGap application PhoneGap API overview Building PhoneGap 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

Android SDK and ADT Plugin Development environment First PhoneGap application PhoneGap API overview Building PhoneGap 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

Development environment First PhoneGap application PhoneGap API overview 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 files 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

Development environment First PhoneGap application PhoneGap API overview 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");

Configure permissions Development environment First PhoneGap application PhoneGap API overview Building PhoneGap 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" />

Basic UI About PhoneGap Development environment First PhoneGap application PhoneGap API overview Building PhoneGap Create a new file index.html inside assets/www/ with the following content <!DOCTYPE HTML> <html> <head> <title>phonegap </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

Check that PhoneGap is ready Development environment First PhoneGap application PhoneGap API overview Building PhoneGap Add JavaScript waiting for PoneGap to be loaded <script type="text/javascript"> document.addeventlistener("deviceready", ondeviceready, false); function ondeviceready() { alert("phonegap loaded"); </script>

Screenshot About PhoneGap Development environment First PhoneGap application PhoneGap API overview Building PhoneGap

Notification I About PhoneGap Development environment First PhoneGap application PhoneGap API overview Building PhoneGap Alert function showalert() { navigator.notification.alert( "Testing notification.alert", afteralert, "Alert title", "Button" ); function afteralert() { // Do something

Notification II About PhoneGap Development environment First PhoneGap application PhoneGap API overview Building PhoneGap Confirm 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)

Notification III About PhoneGap Development environment First PhoneGap application PhoneGap API overview Building PhoneGap Beep navigator.notification.beep(1); Vibrate navigator.notification.vibrate(2000);

Connection About PhoneGap Development environment First PhoneGap application PhoneGap API overview Building PhoneGap 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]);

Device About PhoneGap Development environment First PhoneGap application PhoneGap API overview Building PhoneGap 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);

Camera About PhoneGap Development environment First PhoneGap application PhoneGap API overview Building PhoneGap 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);

Other About PhoneGap Development environment First PhoneGap application PhoneGap API overview Building PhoneGap Accelerometer Capture Compass Contacts Events File Geolocation Media Storage Documentation: http://docs.phonegap.com/

Building for other platforms Development environment First PhoneGap application PhoneGap API overview Building PhoneGap 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

PhoneGap Build About PhoneGap Development environment First PhoneGap application PhoneGap API overview Building PhoneGap Special files: index.html: App main page config.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/

Feed Reader About PhoneGap 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)

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>

Basic page template II Page <div data-role="page" id="main"> </div> <div data-role="header"> <h1>rss/atom Reader</h1> </div> <div data-role="content"> TODO </div>

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>

Basic page template IV

Read feed I About PhoneGap Include JavaScript for jfeed <script type="text/javascript" charset="utf-8" src="jquery.jfeed.pack.js"></script>

Read feed II About PhoneGap 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); );

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

Fill the list with the posts I Change HTML <div data-role="content"> <ul data-role="listview" id="posts"> </ul> </div>

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>");

Fill the list with the posts III

Fix list rendering I About PhoneGap 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"); );

Fix list rendering II About PhoneGap

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);

Improving list of posts II

Add option to configure 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

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>

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>

New page for options III

Save feed URL About PhoneGap 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) { [...] );

Reload posts lists I About PhoneGap 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"); );

Reload posts lists II About PhoneGap Call refreshposts() from savefeedurl() function savefeedurl() { var url = $("#url").val(); window.localstorage.setitem("feedurl", url); refreshposts();

Add feed title I About PhoneGap 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");

Add feed title II About PhoneGap

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" ); );

Manage errors reading feed II Add new function gotooptions() function gotooptions() { $.mobile.changepage("#options");

Manage errors reading feed III

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);

Check Internet connection II

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