html for the mobile web, firefox os

57
HTML for the Mobile Web All Things Open Firefox OS 2014-10-22 Frédéric Harper Sr. Technical Evangelist @ Mozilla @fharper | outofcomfortzone.net Creative Commons: https://ic.kr/p/5HzQsy

Upload: all-things-open

Post on 14-Jul-2015

263 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: HTML for the Mobile Web, Firefox OS

HTML for the Mobile Web

All Things Open

Firefox OS

2014-10-22

Frédéric Harper

Sr. Technical Evangelist @ Mozilla

@fharper | outofcomfortzone.net

Crea

tive

Com

mon

s: h

ttps

://fl

ic.k

r/p/

5HzQ

sy

Page 2: HTML for the Mobile Web, Firefox OS

Creative Commons: http://j.mp/1hCZYIe

Page 3: HTML for the Mobile Web, Firefox OS

Creative Commons: http://j.mp/1ljZuJC

Page 4: HTML for the Mobile Web, Firefox OS
Page 5: HTML for the Mobile Web, Firefox OS
Page 6: HTML for the Mobile Web, Firefox OS

38 billion devices connected in 2020

ABI Research - 2013-05-09 - http://j.mp/38billion

Page 7: HTML for the Mobile Web, Firefox OS

Creative Commons: http://j.mp/1gP4X4K

Page 8: HTML for the Mobile Web, Firefox OS
Page 9: HTML for the Mobile Web, Firefox OS

What you deserve

Page 10: HTML for the Mobile Web, Firefox OS
Page 11: HTML for the Mobile Web, Firefox OS

Built with the Web

Using HTML5, CSS3 and JavaScript

with a number of APIs

to build apps.

Page 12: HTML for the Mobile Web, Firefox OS

It’s open source

Page 13: HTML for the Mobile Web, Firefox OS

Some facts

•  Available in more than 24 countries

•  Primarly aimed at emerging & low

end markets

Page 14: HTML for the Mobile Web, Firefox OS

Some of the devices

Page 15: HTML for the Mobile Web, Firefox OS
Page 16: HTML for the Mobile Web, Firefox OS
Page 17: HTML for the Mobile Web, Firefox OS
Page 18: HTML for the Mobile Web, Firefox OS
Page 19: HTML for the Mobile Web, Firefox OS
Page 20: HTML for the Mobile Web, Firefox OS

A Firefox OS app?

§  Creating a hosted or packaged app

§  Using §  Vanilla HTML5

§  Librairies…

§  Regular API

§  Privileged API

§  Certified API

Page 21: HTML for the Mobile Web, Firefox OS

HTML5 + manifest (JSON) = Firefox OS app {

"version": “42",

"name": ”My amazing app",

"launch_path": "/index.html",

"description": ”My super amazing app do super amazing things",

"icons": {

"16": "/images/logo16.png”,},

"developer": {

"name": ”Frédéric Harper",

"url": "http://outofcomfortzone.net",

},

"default_locale": "en",

"permissions": {

"geolocation": {

"description": ”Get the long/lat of the user"

}

}

}

Page 22: HTML for the Mobile Web, Firefox OS

DEMO Firefox OS + App Manager + Emberjs todomvc

Page 23: HTML for the Mobile Web, Firefox OS

Web APIs

Page 24: HTML for the Mobile Web, Firefox OS

Web APIs – Regular •  Alarm API •  Ambient light sensor •  Archive API •  Battery Status API •  Geolocation API •  IndexedDB •  Network Information API •  Notifications API

•  Open WebApps •  Proximity sensor •  Push API •  Screen Orientation •  Vibration API •  Web Activities •  WebFM API •  WebPayment

packaged

hosted

Page 25: HTML for the Mobile Web, Firefox OS

Ambient Light Sensor

Page 26: HTML for the Mobile Web, Firefox OS

Ambient Light Sensor

window.addEventListener("devicelight", function (event) {

// The level of the ambient light in lux

// The lux values for "dim" typically begin below 50,

// and the values for "bright" begin above 10000

console.log(event.value);

});

Page 27: HTML for the Mobile Web, Firefox OS

DEMO Boilerplate – Ambient Light Sensor

Page 28: HTML for the Mobile Web, Firefox OS

Battery Status

Page 29: HTML for the Mobile Web, Firefox OS

Battery Status

var battery = navigator.battery;

if (battery) {

var batteryLevel = Math.round(battery.level * 100) + "%",

 

charging = (battery.charging)? “yes" : "no",

chargingTime = parseInt(battery.chargingTime / 60, 10,

dischargingTime = parseInt(battery.dischargingTime / 60, 10);

 

battery.addEventListener("levelchange", setStatus, false);

battery.addEventListener("chargingchange", setStatus, false);

battery.addEventListener("chargingtimechange", setStatus, false);

}

Page 30: HTML for the Mobile Web, Firefox OS

Web APIs – Privileged •  Browser API •  Contacts API •  Device Storage API •  systemXHR •  TCP Socket API

packaged

Page 31: HTML for the Mobile Web, Firefox OS

Browser

Page 32: HTML for the Mobile Web, Firefox OS

Browser

<div>

<span id='location-bar'></span>

<button onclick='go_button_clicked()'>Go</button>

</div>

<div id='load-status'></div>

<div id='security-status'></div>

<img id='favicon'>

<div id='title'></div>

<iframe mozbrowser src=‘yoursite.com' id='browser'></iframe>

Page 33: HTML for the Mobile Web, Firefox OS

Browser

addEventListener('mozbrowserloadstart', function(e) {

//Do stuff

});

/*

Possible values:

"mozbrowserloadstart“ "mozbrowserloadend"

"mozbrowserlocationchange“ "mozbrowsertitlechange"

"mozbrowsericonchange“ "mozbrowsersecuritychange"

"mozbrowsercontextmenu“ "mozbrowsererror"

"mozbrowserkeyevent“ "mozbrowsershowmodalprompt"

"mozbrowseropenwindow“ "mozbrowserclose"

*/

Page 34: HTML for the Mobile Web, Firefox OS

Web APIs – Certified •  Camera API •  Idle API •  Mobile Connection API •  Network Stats API •  Permissions API •  Power Management API •  Settings API •  Time/Clock API

•  Voicemail •  WebBluetooth •  WebSMS •  WebTelephony •  WiFi Information API

OS/OEM

Page 35: HTML for the Mobile Web, Firefox OS

Web Activities

Page 36: HTML for the Mobile Web, Firefox OS

Web Activities •  browse •  configure •  costcontrol •  dial •  Open •  new

•  mail •  websms/sms •  webcontacts/contact

•  pick •  record •  save-bookmark •  share •  view •  update

packaged

hosted

Page 37: HTML for the Mobile Web, Firefox OS

Pick var activity = new MozActivity({

name: "pick",

//Provide the data required

//by the filter of the activity

data: {

type: "image/jpeg"

}

});

Page 38: HTML for the Mobile Web, Firefox OS

Pick activity.onsuccess = function () {

var img = document.createElement("img");

if (this.result.blob.type.indexOf("image") != -1) {

img.src = window.URL.createObjectURL(this.result.blob);

}

};

activity.onerror = function () {

//error

};

Page 39: HTML for the Mobile Web, Firefox OS

Dial var call = new MozActivity({

name: "dial",

data: {

number: "+46777888999"

}

});

Page 40: HTML for the Mobile Web, Firefox OS

Web Activity Received Handler "activities": {

"pick": {

"filters": {

"type": ["image/jpeg", "image/png"]

},

"disposition": "inline",

"returnValue": true,

"href": "/index.html#pick"

}

}

Page 41: HTML for the Mobile Web, Firefox OS

Don’t forget to handle it! navigator.mozSetMessageHandler('activity', function(activityRequest) {

var option = activityRequest.source;

if (activityRequest.source.name === "pick") {

// Do something to handle the activity

if (picture) {

activityRequest.postResult(picture);

}

else {

activityRequest.postError("Unable to provide a picture");

}

}

});

Page 42: HTML for the Mobile Web, Firefox OS

Creative Commons: http://j.mp/1iZHGAW

Page 43: HTML for the Mobile Web, Firefox OS

Creative Commons: https://flic.kr/p/4mJnLg

Page 44: HTML for the Mobile Web, Firefox OS

How to start

Page 45: HTML for the Mobile Web, Firefox OS

Creative Commons: http://j.mp/1iquK8Q

Page 46: HTML for the Mobile Web, Firefox OS

Creative Commons: http://j.mp/Ilm7wx

Page 47: HTML for the Mobile Web, Firefox OS

Phonegap & Cordova

& <3

Page 48: HTML for the Mobile Web, Firefox OS

Plugins implementation

http://mozilla-cordova.github.io/

Page 49: HTML for the Mobile Web, Firefox OS

Simplicity…

Page 50: HTML for the Mobile Web, Firefox OS

Firefox Web Developer Tools

Page 51: HTML for the Mobile Web, Firefox OS
Page 52: HTML for the Mobile Web, Firefox OS
Page 53: HTML for the Mobile Web, Firefox OS

Creative Commons: http://j.mp/1gIdcPF

To infinity, and beyond…

Page 54: HTML for the Mobile Web, Firefox OS

More Web APIs & features

•  Calendar API

•  FileHandle API Sync API

•  Keyboard/IME API WebRTC

•  HTTP-cache API

•  Peer to Peer API

•  Spellcheck API LogAPI

•  Resource lock API

•  UDP Datagram Socket API

•  WebNFC

•  WebUSB

Page 55: HTML for the Mobile Web, Firefox OS

Next time you’ll build a mobile app Think about HTML5 & Firefox OS

Page 56: HTML for the Mobile Web, Firefox OS

Resources Firefox OS Simulator http://j.mp/fxosSimulator Firefox OS App Manager http://j.mp/fxosAppManager Mozilla Developer Network https://developer.mozilla.org

StackOverflow forum http://j.mp/fxosStackOverflow Firefox OS Boilerplate http://j.mp/fxosBoilerplate

Page 57: HTML for the Mobile Web, Firefox OS

Frédéric Harper

[email protected]

@fharper

http://hacks.mozilla.org

http://outofcomfortzone.net