Firefox OS workshop, Colombia

66
Firefox OS & the Open Web

Transcript of Firefox OS workshop, Colombia

Page 1: Firefox OS workshop, Colombia

Firefox OS & the Open Web

Page 2: Firefox OS workshop, Colombia

09:30 Welcome

09:40 Introductions

09:50 Firefox OS overview

10:20 Pushing apps

10:30 Start hacking

12:00 Lunch

13:00 Hacking

17:00 Demos

18:00 Mingle

20:00 Dinner

Agenda

Page 3: Firefox OS workshop, Colombia

Using HTML5, CSS and JavaScript together with a number of APIs to build apps and customize the UI.

Firefox OS

Page 4: Firefox OS workshop, Colombia

Open Web Apps

Page 5: Firefox OS workshop, Colombia

Develop Web App using HTML5, CSS, & Javascript1.

Create an app manifest file2.

Publish/install the app3.

Page 6: Firefox OS workshop, Colombia

{ "version": "1.0", "name": "MozillaBall", "description": "Exciting Open Web development action!", "icons": { "16": "/img/icon-16.png", "48": "/img/icon-48.png", "128": "/img/icon-128.png" }, "developer": { "name": "Mozilla Labs", "url": "http://mozillalabs.com" }, "installs_allowed_from": ["*"], "appcache_path": "/cache.manifest", "locales": { "es": { "description": "¡Acción abierta emocionante del desarrollo del Web!", "developer": { "url": "http://es.mozillalabs.com/" } }, "it": { "description": "Azione aperta emozionante di sviluppo di fotoricettore!", "developer": { "url": "http://it.mozillalabs.com/" } } }, "default_locale": "en"}

Page 7: Firefox OS workshop, Colombia

MANIFEST CHECKERhttp://appmanifest.org/

Page 8: Firefox OS workshop, Colombia

Serve with Content-type/MIME type:

application/x-web-app-manifest+json

Page 12: Firefox OS workshop, Colombia

Packaged vs. Hosted Apps

Page 13: Firefox OS workshop, Colombia

WebAPIs

Page 15: Firefox OS workshop, Colombia

Security Levels

Page 16: Firefox OS workshop, Colombia

Web Content

Regular web content

Installed Web App

A regular web app

Privileged Web App

More access, more responsibility

Certified Web App

Device-critical applications

Page 18: Firefox OS workshop, Colombia

"permissions": { "contacts": { "description": "Required for autocompletion in the share screen", "access": "readcreate" }, "alarms": { "description": "Required to schedule notifications" }}

Page 20: Firefox OS workshop, Colombia

Vibration API (W3C)

Screen Orientation

Geolocation API

Mouse Lock API (W3C)

Open WebApps

Network Information API (W3C)

Battery Status API (W3C)

Alarm API

Web Activities

Push Notifications API

WebFM API

WebPayment

IndexedDB (W3C)

Ambient light sensor

Proximity sensor

Notification

REGULAR APIS

Page 21: Firefox OS workshop, Colombia

BATTERY STATUS API

Page 22: Firefox OS workshop, Colombia

var battery = navigator.battery;if (battery) { var batteryLevel = Math.round(battery.level * 100) + "%", charging = (battery.charging)? "" : "not ", chargingTime = parseInt(battery.chargingTime / 60, 10, dischargingTime = parseInt(battery.dischargingTime / 60, 10); // Set events battery.addEventListener("levelchange", setStatus, false); battery.addEventListener("chargingchange", setStatus, false); battery.addEventListener("chargingtimechange", setStatus, false); battery.addEventListener("dischargingtimechange", setStatus, false); }

Page 23: Firefox OS workshop, Colombia

NOTIFICATION

Page 24: Firefox OS workshop, Colombia

var notification = navigator.mozNotification;notification.createNotification( "See this", "This is a notification", iconURL);

Page 25: Firefox OS workshop, Colombia

SCREENORIENTATION API

Page 26: Firefox OS workshop, Colombia

// Portrait mode:screen.mozLockOrientation("portrait");

/* Possible values: "landscape" "portrait" "landscape-primary" "landscape-secondary" "portrait-primary" "portrait-secondary"*/

Page 27: Firefox OS workshop, Colombia

VIBRATION API

Page 28: Firefox OS workshop, Colombia

// Vibrate for one secondnavigator.vibrate(1000);

// Vibration pattern [vibrationTime, pause,…]navigator.vibrate([200, 100, 200, 100]);

// Vibrate for 5 secondsnavigator.vibrate(5000);

// Turn off vibrationnavigator.vibrate(0);

Page 29: Firefox OS workshop, Colombia

NETWORK INFORMATION API

Page 30: Firefox OS workshop, Colombia

var connection = window.navigator.mozConnection, online = connection.bandwidth > 0, metered = connection.metered;

Page 31: Firefox OS workshop, Colombia

DEVICEPROXIMITY

Page 32: Firefox OS workshop, Colombia

window.addEventListener("deviceproximity", function (event) { // Current device proximity, in centimeters console.log(event.value); // The maximum sensing distance the sensor is // able to report, in centimeters console.log(event.max); // The minimum sensing distance the sensor is // able to report, in centimeters console.log(event.min);});

Page 33: Firefox OS workshop, Colombia

AMBIENT LIGHT EVENTS

Page 34: Firefox OS workshop, Colombia

window.addEventListener("devicelight", function (event) { // The level of the ambient light in lux console.log(event.value);});

Page 35: Firefox OS workshop, Colombia

window.addEventListener("devicelight", function (event) { // The lux values for "dim" typically begin below 50, // and the values for "bright" begin above 10000 console.log(event.value);});

Page 36: Firefox OS workshop, Colombia

Device Storage API

Browser API

TCP Socket API

Contacts API

systemXHR

PRIVILEGED APIS

Page 37: Firefox OS workshop, Colombia

DEVICE STORAGE API

Page 38: Firefox OS workshop, Colombia

var deviceStorage = navigator.getDeviceStorage("videos");

Page 39: Firefox OS workshop, Colombia

// "external", "shared", or "default".deviceStorage.type;

// Add a file - returns DOMRequest with file namedeviceStorage.add(blob);

// Same as .add, with provided namedeviceStorage.addNamed(blob, name);

// Returns DOMRequest/non-editable File objectdeviceStorage.get(name);

// Returns editable FileHandle objectdeviceStorage.getEditable(name);

// Returns DOMRequest with success or failuredeviceStorage.delete(name);

// Enumerates filesdeviceStorage.enumerate([directory]);

// Enumerates files as FileHandlesdeviceStorage.enumerateEditable([directory]);

Page 40: Firefox OS workshop, Colombia

var storage = navigator.getDeviceStorage("videos"), cursor = storage.enumerate(); cursor.onerror = function() { console.error("Error in DeviceStorage.enumerate()", cursor.error.name);};

cursor.onsuccess = function() { if (!cursor.result) return; var file = cursor.result;

// If this isn't a video, skip it if (file.type.substring(0, 6) !== "video/") { cursor.continue(); return; }

// If it isn't playable, skip it var testplayer = document.createElement("video"); if (!testplayer.canPlayType(file.type)) { cursor.continue(); return; }};

Page 41: Firefox OS workshop, Colombia

CONTACTS API

Page 42: Firefox OS workshop, Colombia

var contact = new mozContact();contact.init({name: "Tom"});

var request = navigator.mozContacts.save(contact);request.onsuccess = function() { console.log("Success");};

request.onerror = function() { console.log("Error")};

Page 43: Firefox OS workshop, Colombia

WEB ACTIVITIES

Page 44: Firefox OS workshop, Colombia
Page 45: Firefox OS workshop, Colombia

var activity = new MozActivity({ name: "view", data: { type: "image/png", url: ... }});

activity.onsuccess = function () { console.log("Showing the image!");};

activity.onerror = function () { console.log("Can't view the image!");};

Page 46: Firefox OS workshop, Colombia

{ "activities": { "share": { "filters": { "type": ["image/png", "image/gif"] } "href": "sharing.html", "disposition": "window" } }}

Page 47: Firefox OS workshop, Colombia

var register = navigator.mozRegisterActivityHandler({ name: "view", disposition: "inline", filters: { type: "image/png" }});

register.onerror = function () { console.log("Failed to register activity");}

Page 48: Firefox OS workshop, Colombia

navigator.mozSetMessageHandler("activity", function (a) { var img = getImageObject(); img.src = a.source.url; // Call a.postResult() or a.postError() if // the activity should return a value});

Page 49: Firefox OS workshop, Colombia
Page 50: Firefox OS workshop, Colombia

Future APIs

Page 51: Firefox OS workshop, Colombia
Page 52: Firefox OS workshop, Colombia

Resource lock API

UDP Datagram Socket API

Peer to Peer API

WebNFC

WebUSB

HTTP-cache API

Calendar API

Spellcheck API

LogAPI

Keyboard/IME API

WebRTC

FileHandle API

Sync API

Page 53: Firefox OS workshop, Colombia

Web Apps from Mozilla

Page 54: Firefox OS workshop, Colombia
Page 55: Firefox OS workshop, Colombia

Dialer

Contacts

Settings

SMS

Web browser

Gallery

Video Player

Music Player

E-mail (POP, IMAP)

Calendar

Alarm Clock

Camera

Notes

First Run Experience

Notifications

Home Screen

Mozilla Marketplace

System Updater

Localization Support

Page 57: Firefox OS workshop, Colombia

Get started

Page 60: Firefox OS workshop, Colombia

Getting help

Page 61: Firefox OS workshop, Colombia
Page 62: Firefox OS workshop, Colombia

https://lists.mozilla.org/listinfo/dev-webapps

irc://irc.mozilla.org/#openwebapps

Page 63: Firefox OS workshop, Colombia

Trying things out

Page 64: Firefox OS workshop, Colombia