Getting started with Firefox OS and Open Web Apps
14:30 Introduction
15:30 Get set up
15:45 Start first app
16:30 Break
16:45 Hacking
Agenda:
Using HTML5, CSS and
JavaScript together with a
number of APIs to build
apps and customize the UI.
Firefox OS
Foxconn
Open Web Apps
HTML5 + manifest file (JSON)
Steps to Take
Develop Web App using
HTML5, CSS, & Javascript1.
Create an app manifest file2.
Publish/install the app3.
1.Develop Web App using
HTML5, CSS & JavaScript
Reuse any existing web site/app or develop from scratch
with open web standards.
Utilize HTML5 features such as localStora...
2.Create an app manifest file
Create a file with a .webapp extension
{
"version": "1",
"name": "Firefox OS Boilerplate App",
"launch_path": "/index.html",
"description": "Boilerplate Firefox ...
MANIFEST CHECKER
http://appmanifest.org/
Serve with Content-type/MIME type:
application/x-web-app-manifest+json
Apache - in mime.types:
application/x-web-app-manifest+json webapp
Apache - in .htaccess:
AddType application/x-web-app-ma...
IIS:
In IIS Manager, right-click the local
computer, and click Properties.
Click the MIME Types button.
Click New.
In the ...
curl -I http://mozillalabs.com/manifest.webapp
3.Publish/install the app
Firefox Marketplace
https://marketplace.firefox.com/
https://marketplace.firefox.com/developers/
Installing/hosting the app
var request = navigator.mozApps.install(
"http://robnyman.github.com/Firefox-OS-Boilerplate-App/manifest.webapp",
{
user_i...
Build excellent interfaces!
Packaged & hosted apps
WebAPIs
Security Levels
Web Content
Regular web content
Installed Web App
A regular web app
Privileged Web App
More access, more responsibility
Ce...
https://wiki.mozilla.org/
WebAPI#Planned_for_initial_release_of_B2G_.28aka_Basecamp.29
"permissions": {
"contacts": {
"description": "Required for autocompletion in the share screen",
"access": "readcreate"
},...
PERMISSIONS
Vibration API (W3C)
Screen Orientation
Geolocation API
Mouse Lock API (W3C)
Open WebApps
Network Information API (W3C)
Bat...
BATTERY STATUS
API
var battery = navigator.battery;
if (battery) {
var batteryLevel = Math.round(battery.level * 100) + "%",
charging = (batt...
NOTIFICATION
var notification = navigator.mozNotification;
notification.createNotification(
"See this",
"This is a notification",
iconU...
SCREEN
ORIENTATION API
// Portrait mode:
screen.mozLockOrientation("portrait");
/*
Possible values:
"landscape"
"portrait"
"landscape-primary"
"l...
VIBRATION API
// Vibrate for one second
navigator.vibrate(1000);
// Vibration pattern [vibrationTime, pause,…]
navigator.vibrate([200, 1...
WEB PAYMENTS
var pay = navigator.mozPay(paymentToken);
pay.onsuccess = function (event) {
// Weee! Money!
};
mozmarket.receipts.Prompter({
storeURL: "https://marketplace.mozilla.org/app/myapp",
supportHTML: '<a href="mailto:me@exam...
NETWORK
INFORMATION API
var connection = window.navigator.mozConnection,
online = connection.bandwidth > 0,
metered = connection.metered;
ALARM API
var alarmId1,
request = navigator.mozAlarms.add(
new Date("May 15, 2012 16:20:00"),
"honorTimezone",
{
mydata: "my event"
...
var request = navigator.mozAlarms.getAll();
request.onsuccess = function (event) {
console.log(JSON.stringify(event.target...
navigator.mozSetMessageHandler(
"alarm",
function (message) {
// Note: message has to be set in the manifest file
console....
DEVICEPROXIMITY
window.addEventListener("deviceproximity", function (event) {
// Current device proximity, in centimeters
console.log(even...
AMBIENT LIGHT
EVENTS
window.addEventListener("devicelight", function (event) {
// The lux values for "dim" typically begin below 50,
// and the...
PAGE VISIBILITY
document.addEventListener("visibilitychange", function () {
if (document.hidden) {
console.log("App is hidden");
}
else {
...
Device Storage API
Browser API
TCP Socket API
Contacts API
systemXHR
PRIVILEGED APIS
DEVICE STORAGE
API
var deviceStorage = navigator.getDeviceStorage("videos");
var storage = navigator.getDeviceStorage("videos"),
cursor = storage.enumerate();
cursor.onerror = function() {
console.er...
CONTACTS API
var contact = new mozContact();
contact.init({name: "Tom"});
var request = navigator.mozContacts.save(contact);
request.on...
WebTelephony
WebSMS
Idle API
Settings API
Power Management API
Mobile Connection API
WiFi Information API
WebBluetooth
Per...
WEBTELEPHONY
// Telephony object
var tel = navigator.mozTelephony;
// Check if the phone is muted (read/write property)
console.log(tel...
// Place a call
var cal = tel.dial(“123456789”);
// Receiving a call
tel.onincoming = function (event) {
var incomingCall = event.call;
// Get the number of the incoming c...
WEBSMS
// SMS object
var sms = navigator.mozSMS;
// Send a message
sms.send("123456789", "Hello world!");
// Recieve a message
sms.onreceived = function (event) {
// Read message
console.log(event.message);
};
WEB ACTIVITIES
Interacting with the camera
var activity = new MozActivity({
name: "view",
data: {
type: "image/png",
url: ...
}
});
activity.onsuccess = function () ...
{
"activities": {
"share": {
"filters": {
"type": ["image/png", "image/gif"]
}
"href": "sharing.html",
"disposition": "win...
var register = navigator.mozRegisterActivityHandler({
name: "view",
disposition: "inline",
filters: {
type: "image/png"
}
...
navigator.mozSetMessageHandler("activity", function (a) {
var img = getImageObject();
img.src = a.source.url;
// Call a.po...
Future APIs
Resource lock API
UDP Datagram Socket API
Peer to Peer API
WebNFC
WebUSB
HTTP-cache API
Calendar API
Spellcheck API
LogAPI...
Web Apps from Mozilla
Dialer
Contacts
Settings
SMS
Web browser
Gallery
Video Player
Music Player
E-mail (POP, IMAP)
Calendar
Alarm Clock
Camera
...
Web Components & Mozilla Brick
http://mozilla.github.io/brick/
<x-flipbox>
<div>I'm the front face.</div>
<div>And I'm the back face.</div>
</x-flipbox>
// assume that toggleButton and flipBox are already
// defined as their respective DOM elements
toggleButton.addEventListe...
appbar
calendar
datepicker
deck
flipbox
iconbutton
layout
slidebox
slider
tabbar
toggle
togglegroup
tooltip
Get started
https://addons.mozilla.org/firefox/addon/firefox-os-
simulator/
FIREFOX OS
BOILERPLATE APP
https://github.com/robnyman/Firefox-OS-Boilerplate-App
Trying things out
Robert Nyman
robertnyman.com
robert@mozilla.com
Mozilla
@robertnyman
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
Firefox OS workshop, JSFoo, India
Upcoming SlideShare
Loading in...5
×

Firefox OS workshop, JSFoo, India

1,671

Published on

Published in: Technology, Design
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,671
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
64
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Firefox OS workshop, JSFoo, India

  1. 1. Getting started with Firefox OS and Open Web Apps
  2. 2. 14:30 Introduction 15:30 Get set up 15:45 Start first app 16:30 Break 16:45 Hacking Agenda:
  3. 3. Using HTML5, CSS and JavaScript together with a number of APIs to build apps and customize the UI. Firefox OS
  4. 4. Foxconn
  5. 5. Open Web Apps
  6. 6. HTML5 + manifest file (JSON)
  7. 7. Steps to Take
  8. 8. Develop Web App using HTML5, CSS, & Javascript1. Create an app manifest file2. Publish/install the app3.
  9. 9. 1.Develop Web App using HTML5, CSS & JavaScript
  10. 10. Reuse any existing web site/app or develop from scratch with open web standards. Utilize HTML5 features such as localStorage, offline manifest, IndexedDB and access Web APIs for more options. Responsive web design for adapting to varying resolutions and screen orientation.
  11. 11. 2.Create an app manifest file
  12. 12. Create a file with a .webapp extension
  13. 13. { "version": "1", "name": "Firefox OS Boilerplate App", "launch_path": "/index.html", "description": "Boilerplate Firefox OS app", "icons": { "16": "/images/logo16.png", "32": "/images/logo32.png", "48": "/images/logo48.png", "64": "/images/logo64.png", "128": "/images/logo128.png" }, "developer": { "name": "Robert Nyman", "url": "http://robertnyman.com" }, "installs_allowed_from": ["*"], "default_locale": "en" }
  14. 14. MANIFEST CHECKER http://appmanifest.org/
  15. 15. Serve with Content-type/MIME type: application/x-web-app-manifest+json
  16. 16. Apache - in mime.types: application/x-web-app-manifest+json webapp Apache - in .htaccess: AddType application/x-web-app-manifest+json webapp NGinx - in mime.types: types { text/html html htm shtml; text/css css; text/xml xml; application/x-web-app-manifest+json webapp; }
  17. 17. IIS: In IIS Manager, right-click the local computer, and click Properties. Click the MIME Types button. Click New. In the Extension box, type the file name extension. In the MIME type box, type a description that exactly matches the file type defined on the computer. Click OK.
  18. 18. curl -I http://mozillalabs.com/manifest.webapp
  19. 19. 3.Publish/install the app
  20. 20. Firefox Marketplace
  21. 21. https://marketplace.firefox.com/
  22. 22. https://marketplace.firefox.com/developers/
  23. 23. Installing/hosting the app
  24. 24. var request = navigator.mozApps.install( "http://robnyman.github.com/Firefox-OS-Boilerplate-App/manifest.webapp", { user_id: "some_user" } ); request.onsuccess = function() { // Success! Notification, launch page etc } request.onerror = function() { // Failed. this.error.name has details }
  25. 25. Build excellent interfaces!
  26. 26. Packaged & hosted apps
  27. 27. WebAPIs
  28. 28. Security Levels
  29. 29. 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
  30. 30. https://wiki.mozilla.org/ WebAPI#Planned_for_initial_release_of_B2G_.28aka_Basecamp.29
  31. 31. "permissions": { "contacts": { "description": "Required for autocompletion in the share screen", "access": "readcreate" }, "alarms": { "description": "Required to schedule notifications" } }
  32. 32. PERMISSIONS
  33. 33. 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
  34. 34. BATTERY STATUS API
  35. 35. 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); }
  36. 36. NOTIFICATION
  37. 37. var notification = navigator.mozNotification; notification.createNotification( "See this", "This is a notification", iconURL );
  38. 38. SCREEN ORIENTATION API
  39. 39. // Portrait mode: screen.mozLockOrientation("portrait"); /* Possible values: "landscape" "portrait" "landscape-primary" "landscape-secondary" "portrait-primary" "portrait-secondary" */
  40. 40. VIBRATION API
  41. 41. // Vibrate for one second navigator.vibrate(1000); // Vibration pattern [vibrationTime, pause,…] navigator.vibrate([200, 100, 200, 100]); // Vibrate for 5 seconds navigator.vibrate(5000); // Turn off vibration navigator.vibrate(0);
  42. 42. WEB PAYMENTS
  43. 43. var pay = navigator.mozPay(paymentToken); pay.onsuccess = function (event) { // Weee! Money! };
  44. 44. mozmarket.receipts.Prompter({ storeURL: "https://marketplace.mozilla.org/app/myapp", supportHTML: '<a href="mailto:me@example.com">email me@example.com</a>', verify: true });
  45. 45. NETWORK INFORMATION API
  46. 46. var connection = window.navigator.mozConnection, online = connection.bandwidth > 0, metered = connection.metered;
  47. 47. ALARM API
  48. 48. var alarmId1, request = navigator.mozAlarms.add( new Date("May 15, 2012 16:20:00"), "honorTimezone", { mydata: "my event" } ); request.onsuccess = function (event) { alarmId1 = event.target.result; }; request.onerror = function (event) { console.log(event.target.error.name); };
  49. 49. var request = navigator.mozAlarms.getAll(); request.onsuccess = function (event) { console.log(JSON.stringify(event.target.result)); }; request.onerror = function (event) { console.log(event.target.error.name); };
  50. 50. navigator.mozSetMessageHandler( "alarm", function (message) { // Note: message has to be set in the manifest file console.log("Alarm fired: " + JSON.stringify(message)); } );
  51. 51. DEVICEPROXIMITY
  52. 52. 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); });
  53. 53. AMBIENT LIGHT EVENTS
  54. 54. 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); });
  55. 55. PAGE VISIBILITY
  56. 56. document.addEventListener("visibilitychange", function () { if (document.hidden) { console.log("App is hidden"); } else { console.log("App has focus"); } });
  57. 57. Device Storage API Browser API TCP Socket API Contacts API systemXHR PRIVILEGED APIS
  58. 58. DEVICE STORAGE API
  59. 59. var deviceStorage = navigator.getDeviceStorage("videos");
  60. 60. 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; } };
  61. 61. CONTACTS API
  62. 62. 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") };
  63. 63. WebTelephony WebSMS Idle API Settings API Power Management API Mobile Connection API WiFi Information API WebBluetooth Permissions API Network Stats API Camera API Time/Clock API Attention screen Voicemail CERTIFIED APIS
  64. 64. WEBTELEPHONY
  65. 65. // Telephony object var tel = navigator.mozTelephony; // Check if the phone is muted (read/write property) console.log(tel.muted); // Check if the speaker is enabled (read/write property) console.log(tel.speakerEnabled);
  66. 66. // Place a call var cal = tel.dial(“123456789”);
  67. 67. // Receiving a call tel.onincoming = function (event) { var incomingCall = event.call; // Get the number of the incoming call console.log(incomingCall.number); // Answer the call incomingCall.answer(); }; // Disconnect a call call.hangUp(); // Iterating over calls, and taking action depending on their changed status tel.oncallschanged = function (event) { tel.calls.forEach(function (call) { // Log the state of each call console.log(call.state); }); };
  68. 68. WEBSMS
  69. 69. // SMS object var sms = navigator.mozSMS; // Send a message sms.send("123456789", "Hello world!");
  70. 70. // Recieve a message sms.onreceived = function (event) { // Read message console.log(event.message); };
  71. 71. WEB ACTIVITIES
  72. 72. Interacting with the camera
  73. 73. 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!"); };
  74. 74. { "activities": { "share": { "filters": { "type": ["image/png", "image/gif"] } "href": "sharing.html", "disposition": "window" } } }
  75. 75. var register = navigator.mozRegisterActivityHandler({ name: "view", disposition: "inline", filters: { type: "image/png" } }); register.onerror = function () { console.log("Failed to register activity"); }
  76. 76. 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 });
  77. 77. Future APIs
  78. 78. 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
  79. 79. Web Apps from Mozilla
  80. 80. 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
  81. 81. Web Components & Mozilla Brick
  82. 82. http://mozilla.github.io/brick/
  83. 83. <x-flipbox> <div>I'm the front face.</div> <div>And I'm the back face.</div> </x-flipbox>
  84. 84. // assume that toggleButton and flipBox are already // defined as their respective DOM elements toggleButton.addEventListener("click", function(){ flipBox.toggle(); });
  85. 85. appbar calendar datepicker deck flipbox iconbutton layout slidebox slider tabbar toggle togglegroup tooltip
  86. 86. Get started
  87. 87. https://addons.mozilla.org/firefox/addon/firefox-os- simulator/
  88. 88. FIREFOX OS BOILERPLATE APP https://github.com/robnyman/Firefox-OS-Boilerplate-App
  89. 89. Trying things out
  90. 90. Robert Nyman robertnyman.com robert@mozilla.com Mozilla @robertnyman
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×