Apache Co Cordova In Ac Action Hazem Saleh A bout me More than - - PowerPoint PPT Presentation

apache co cordova in ac action
SMART_READER_LITE
LIVE PREVIEW

Apache Co Cordova In Ac Action Hazem Saleh A bout me More than - - PowerPoint PPT Presentation

Apache Co Cordova In Ac Action Hazem Saleh A bout me More than ten years of experience in experience Java enterprise and mobile solutions. Apache Committer. Author of four technical books. DeveloperWorks Contributing author. Technical


slide-1
SLIDE 1

Apache Co Cordova In Ac Action

Hazem Saleh

slide-2
SLIDE 2

About me

experience ¡

More than ten years of experience in Java enterprise and mobile solutions. Apache Committer. Author of four technical books. DeveloperWorks Contributing author. Technical Speaker (JavaOne, ApacheCon,

Geecon,JavaLand …etc)

Advisory Software Engineer in IBM.

slide-3
SLIDE 3

Agenda

Apache ¡Cordova ¡Introduc1on ¡ Configura1ons ¡ Cordova ¡Command ¡Line ¡ Cordova ¡APIs ¡Overview ¡ Memo ¡Applica1on ¡Demo ¡ Hello ¡World ¡Demo ¡ jQuery ¡Mobile ¡Integra1on ¡Tips ¡

slide-4
SLIDE 4

Apache Cordova Intsoductjon

PlaEorm ¡ HTML ¡ CSS ¡ JS ¡

slide-5
SLIDE 5

Apache Cordova Intsoductjon

Device native functions examples:

¡

slide-6
SLIDE 6

Apache Cordova Intsoductjon

Hybrid ¡Applica-on ¡ (Cordova) ¡ ¡ Na-ve ¡Applica-on ¡ ¡ Can ¡be ¡uploaded ¡to ¡App ¡ Store ¡ Yes ¡ yes ¡ Technology ¡ HTML ¡+ ¡CSS ¡+ ¡JavaScript ¡ Na1ve ¡plaEorm ¡ Programming ¡Language ¡ Cross-­‑mobiles ¡support ¡ Yes ¡ No ¡ Development ¡Speed ¡ Faster ¡ Slower ¡ Uses ¡Device ¡Na1ve ¡ Features ¡ Yes ¡ yes ¡

Hybrid vs Native Application

slide-7
SLIDE 7

Apache Cordova Intsoductjon

Cordova is supported on the following platforms:

slide-8
SLIDE 8

Apache Cordova Intsoductjon

Challenges of the current mobile apps development:

Many platforms and devices. Different skills needed. Different problem types. Huge Development and Testing Effort to have a single application on these platforms.

For ¡Android: ¡Java ¡skills ¡needed. ¡ ¡For ¡iOS: ¡Objec1ve-­‑C ¡(or ¡SWIFT) ¡ skills ¡needed. ¡ ¡ For ¡Windows: ¡C# ¡skills ¡needed. ¡

slide-9
SLIDE 9

Apache Cordova Intsoductjon

Who can use Cordova?

If you are a web developer and wants to develop a mobile application that can be deployed on the different app store portals. If you are a mobile native developer and wants to develop a single application on the different mobile platforms without having to re-implement the application code on every platform.

slide-10
SLIDE 10

Agenda

Apache ¡Cordova ¡Introduc1on ¡ Configura1ons ¡ Cordova ¡Command ¡Line ¡ Cordova ¡APIs ¡Overview ¡ Memo ¡Applica1on ¡Demo ¡ Hello ¡World ¡Demo ¡ jQuery ¡Mobile ¡Integra1on ¡Tips ¡

slide-11
SLIDE 11

Configuratjon

1 2 3

Prerequisites:

Node JS. Target SDK.

From command line:

> sudo npm install -g cordova

To know the installed version of Cordova:

> cordova -v GIT

slide-12
SLIDE 12

Agenda

Apache ¡Cordova ¡Introduc1on ¡ Configura1ons ¡ Cordova ¡Command ¡Line ¡ Cordova ¡APIs ¡Overview ¡ Memo ¡Applica1on ¡Demo ¡ Hello ¡World ¡Demo ¡ jQuery ¡Mobile ¡Integra1on ¡Tips ¡

slide-13
SLIDE 13

Cordova Command Line

To create an application:

> ¡cordova ¡create ¡<<app_dir>> ¡<<project_id>> ¡<<app_1tle>> ¡

To add a platform (from the app folder):

> ¡cordova ¡plaEorm ¡add ¡<<plaEorm_name>> ¡

To build Cordova project:

> ¡cordova ¡build ¡

To deploy the app on emulator:

> ¡cordova ¡emulate ¡<<plaEorm_name>> ¡

slide-14
SLIDE 14

Agenda

Apache ¡Cordova ¡Introduc1on ¡ Configura1ons ¡ Cordova ¡Command ¡Line ¡ Cordova ¡APIs ¡Overview ¡ Memo ¡Applica1on ¡Demo ¡ Hello ¡World ¡Demo ¡ jQuery ¡Mobile ¡Integra1on ¡Tips ¡

slide-15
SLIDE 15

HEL ELLO WOL WOLRL RLD DEM EMO

slide-16
SLIDE 16

Agenda

Apache ¡Cordova ¡Introduc1on ¡ Configura1ons ¡ Cordova ¡Command ¡Line ¡ Cordova ¡APIs ¡Overview ¡ Memo ¡Applica1on ¡Demo ¡ Hello ¡World ¡Demo ¡ jQuery ¡Mobile ¡Integra1on ¡Tips ¡

slide-17
SLIDE 17

Cordova APIs Overview

Native device functions are represented as plugins that can be added and removed using the command line. Adding camera plugin example:

> ¡cordova ¡plugin ¡add ¡hZps://git-­‑wip-­‑us.apache.org/repos/ asf/cordova-­‑plugin-­‑camera.git ¡

Removing Camera plugin example:

> ¡cordova ¡plugin ¡rm ¡org.apache.cordova.core.camera ¡

slide-18
SLIDE 18

Cordova APIs Overview

Device

An object that holds information about the device hardware and software. Device information is mainly about: Ø Device name. Ø Device Platform. Ø Device Platform version. Ø Device model. “deviceready” event is an indicator that Cordova finishes loading and Cordova APIs are ready to be called.

slide-19
SLIDE 19

Cordova APIs Overview

Camera

An object that provides an access to the device camera. It can be used for: Ø Capturing a photo using the device’s Camera. Ø Picking a photo from the device’s gallery.

navigator.camera.getPicture(onSuccess, ¡onFail, ¡{ ¡quality: ¡50, ¡ ¡ ¡ ¡ ¡des1na1onType: ¡Camera.Des1na1onType.DATA_URL ¡ }); ¡ func1on ¡onSuccess(imageData) ¡{ ¡ ¡ ¡ ¡ ¡var ¡image ¡= ¡document.getElementById('myImage'); ¡ ¡ ¡ ¡ ¡image.src ¡= ¡"data:image/jpeg;base64," ¡+ ¡imageData; ¡ } ¡ func1on ¡onFail(message) ¡{ ¡ ¡ ¡ ¡ ¡alert('Failed ¡because: ¡' ¡+ ¡message); ¡ } ¡

slide-20
SLIDE 20

Cordova APIs Overview

Media

An object that allows recording and playing back audio files on the device.

var ¡my_media ¡= ¡new ¡Media("someFile.mp3", ¡onSuccess, ¡

  • nError); ¡

my_media.play(); ¡ ¡ func1on ¡onSuccess() ¡{ ¡ ¡ ¡ ¡ ¡console.log("playAudio():Audio ¡Success"); ¡ } ¡ func1on ¡onError(error) ¡{ ¡ ¡ ¡ ¡ ¡alert('code: ¡' ¡ ¡ ¡ ¡+ ¡error.code ¡ ¡ ¡ ¡+ ¡'\n' ¡+ ¡'message: ¡' ¡+ ¡ error.message ¡+ ¡'\n'); ¡ } ¡

slide-21
SLIDE 21

Cordova APIs Overview

Notification

An object that displays visual, audible, and tactile notification.

// ¡Show ¡a ¡na1ve ¡looking ¡alert ¡ navigator.no1fica1on.alert( ¡ ¡ ¡ ¡ ¡'Cordova ¡is ¡great!', ¡ ¡// ¡message ¡ ¡ ¡ ¡ ¡'Cordova', ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡// ¡1tle ¡ ¡ ¡ ¡ ¡'Ok' ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡// ¡buZonName ¡ ); ¡ // ¡Beep ¡four ¡1mes ¡ navigator.no1fica1on.beep(4); ¡ // ¡Vibrate ¡for ¡3 ¡seconds ¡ navigator.no1fica1on.vibrate(3000); ¡

slide-22
SLIDE 22

Cordova APIs Overview

Storage

Provides an access to the W3C Web Storage interface:

window.localStorage.setItem("key", ¡"value"); ¡ ¡ var ¡value ¡= ¡window.localStorage.getItem("key"); ¡ ¡ window.localStorage.removeItem("key"); ¡ window.localStorage.clear(); ¡ ¡

  • Local Storage (window.localStorage).
  • Session Storage (window.sessionStorage).
slide-23
SLIDE 23

Cordova APIs Overview

Storage

Provides an access to the device Web SQL Database (Full featured database). Cordova supports IndexedDB for WP8 and Blackberry 10.

func1on ¡populateDB(tx) ¡{ ¡ ¡ ¡ ¡ ¡tx.executeSql('DROP ¡TABLE ¡IF ¡EXISTS ¡DEMO'); ¡ ¡ ¡ ¡ ¡tx.executeSql('CREATE ¡TABLE ¡IF ¡NOT ¡EXISTS ¡DEMO ¡(id ¡unique, ¡data)'); ¡ ¡ ¡ ¡ ¡tx.executeSql('INSERT ¡INTO ¡DEMO ¡(id, ¡data) ¡VALUES ¡(1, ¡"First ¡row")'); ¡ ¡ ¡ ¡ ¡tx.executeSql('INSERT ¡INTO ¡DEMO ¡(id, ¡data) ¡VALUES ¡(2, ¡"Second ¡row")'); ¡ } ¡ func1on ¡errorCB(err) ¡{ ¡ ¡ ¡ ¡ ¡alert("Error ¡processing ¡SQL: ¡" ¡+ ¡err.code); ¡ } ¡ func1on ¡successCB() ¡{ ¡ ¡ ¡ ¡ ¡alert("success!"); ¡ } ¡ var ¡db ¡= ¡window.openDatabase("Demos", ¡"1.0", ¡"Cordova ¡Demo", ¡200000); ¡ db.transac1on(populateDB, ¡errorCB, ¡successCB); ¡

slide-24
SLIDE 24

Cordova APIs Overview

Accelerometer (Capture device motion) Compass (Get the device direction) Connection (Get the device connection) Contacts (Access to device contacts database). File (Access to device File system based on W3C File API) Globalization (Access to user locale information) Events (Handle Apache Cordova life cycle events). Geolocation (Know your mobile location. API is W3C based)

More APIs:

slide-25
SLIDE 25

Agenda

Apache ¡Cordova ¡Introduc1on ¡ Configura1ons ¡ Cordova ¡Command ¡Line ¡ Cordova ¡APIs ¡Overview ¡ Memo ¡Applica1on ¡Demo ¡ Hello ¡World ¡Demo ¡ jQuery ¡Mobile ¡Integra1on ¡Tips ¡

slide-26
SLIDE 26

jQuery Mobile Intfgratjon

jQuery Mobile is: One of the most popular User Interface framework for building Mobile Web applications. Uses HTML5 + CSS3 for layout pages with minimal scripting. Compatible with most of the mobile and tablet browsers.

slide-27
SLIDE 27

jQuery Mobile Intfgratjon

Cordova does not restrict using any specific JavaScript library but using a JavaScript library will save you a lot of time creating your own widgets from scratch. jQuery Mobile is used in the demo application with Cordova to create the Memo utility. There are also many cool frameworks you can use in your Cordova mobile apps such as: Angular ¡JS ¡+ ¡lonic. ¡ Dojo ¡mobile ¡ Sencha ¡Touch. ¡

slide-28
SLIDE 28

jQuery Mobile Intfgratjon

Windows Phone 8 Issues: Fixes:

Trimmed ¡header ¡1tle. ¡ Footer ¡is ¡not ¡aligned ¡to ¡boZom. ¡ Set ¡ui-­‑header ¡and ¡ui-­‑*tle ¡classes’ ¡

  • verflow ¡to ¡visible. ¡

Hide ¡System ¡Tray ¡using ¡app ¡config ¡ (shell:SystemTray.isVisible ¡= ¡“False”). ¡

slide-29
SLIDE 29

jQuery Mobile Intfgratjon

iOS 7 (and 8) Issues: One of the possible workarounds:

Collision ¡between ¡jQM ¡header ¡1tle ¡ and ¡iOS ¡ ¡device ¡status ¡bar. ¡ Hide ¡the ¡status ¡bar ¡by ¡adding ¡and ¡ setng ¡two ¡proper1es ¡in ¡the ¡ app's ¡.plist ¡file: ¡

  • 1. ¡The ¡Status ¡bar ¡is ¡ini1ally ¡hidden ¡

property ¡set ¡to ¡the ¡YES ¡value. ¡

  • 2. ¡The ¡View ¡controller-­‑based ¡status ¡

bar ¡appearance ¡property ¡set ¡to ¡the ¡ NO ¡value ¡

slide-30
SLIDE 30

jQuery Mobile Intfgratjon

In order to boost the performance of jQuery mobile with Cordova, it is recommended to disable transition effects as follows:

$.mobile.defaultDialogTransi-on ¡= ¡'none’; ¡ $.mobile.defaultPageTransi-on ¡ ¡ ¡= ¡'none'; ¡

slide-31
SLIDE 31

jQuery Mobile Intfgratjon

  • Use cordova-jquery-npm module to speed up adding

ready-made jQuery mobile templates to your existing Cordova project. Available templates are:

  • Multiple pages.
  • Persistent Navigation bar for three pages.
  • External Panel Template.
  • All what you need to do is to run cordova-jquery

command from your project root and follow the template creation Wizard.

  • cordova-jquery-npm module is an open source project

that is available in:

  • https://github.com/Open-I-Beam/cordova-jquery-

npm

slide-32
SLIDE 32

Agenda

Apache ¡Cordova ¡Introduc1on ¡ Configura1ons ¡ Cordova ¡Command ¡Line ¡ Cordova ¡APIs ¡Overview ¡ Memo ¡Applica1on ¡Demo ¡ Hello ¡World ¡Demo ¡ jQuery ¡Mobile ¡Integra1on ¡Tips ¡

slide-33
SLIDE 33

GitHub ¡URL: ¡ hZps://github.com/hazems/cordova-­‑mega-­‑app ¡ ¡

MEM EMO APPLICATION

slide-34
SLIDE 34

JavaScript Quiz

<script> var number = 50; var obj = { number: 60, getNum: function () { var number = 70; return this.number; } }; alert(obj.getNum()); alert(obj.getNum.call()); alert(obj.getNum.call({number: 20})); </script>

slide-35
SLIDE 35

Questjons

Twitter: @hazems Blog: http://www.technicaladvices.com Email: hazems@apache.org