CoreMob Camera App:
Real Life HTML5 Use Cases for Mobile

Tomomi Imura, @girlie_mac

Real Life HTML5 Use Cases for Mobile

CoreMob Camera App

Sabdy the cat using a mobile phone

Hello

my name is

Tomomi

@girlie_mac
HTTP Status Cats

Mobile (vs. Sessile)

Hillary Clinton texting

Luc Viatour | www.Lucnix.be • & • caitbiology.wikispaces.com

Communicating

Hillary Clinton texting

AP PHOTO / Kevin Lamarque

Reading

Tokyo bus

http://www.flickr.com/photos/mi-ki/2454554920/

Playing

A bird playing Angry Birds

http://www.flickr.com/photos/potyike/4599545293/

Taking
Pictures

A man taking his own picture

http://www.flickr.com/photos/insane_capture/8113802393/

Locating

Google pin

http://www.flickr.com/photos/hezicohen/4648981682/

Paying

Suica mobile payment

http://www.flickr.com/photos/u-suke/100870738/

More...

iphonelife.com

HTML5

http://lemarquis.deviantart.com/art/HTML5-Wallpaper-243682854

Core Mobile Web Platform CG

W3C CG logo

Goal:

To accelerate the adoption of the Mobile Web as a compelling platform for the development of modern mobile Web applications

Last year, W3C announced an industry-wide initiative, called Core Mobile Web Platform Community Group (CoreMob CG, for short), to help improve the mobile web. The goal of the CoreMob is to accelerate the adoption of the Mobile Web as a compelling platform for the development of modern mobile Web applications. In order to achieve this mission, the CG brings developers, equipment manufacturers, browser vendors, operators and other relevant members of the industry together. The companies includes - Nokia, Samsung, AT&T, Verizon, Vodafone, Orange, Telefónica, KDDI, Softbank Qualcomm, Intel, Texas Instruments, Mozilla, Opera, Microsoft and Facebook and more.

http://coremob.github.com/coremob-2012/

Core Mobile Web Platform CG

W3C CG logo
  1. Agree on core features developers can depend on
  2. Compile related conformance test suites
  3. Provide use cases, scenarios, and other input to drive successful mobile deployment
and we get together to: 1. Agree on core features developers can depend on. These will be defined by reference to a variety of other specifications from the W3C and other standards bodies. 2. Compile related conformance test suites. 3. Provide to W3C (and non-W3C) groups use cases, scenarios, and other input to drive successful mobile deployment.

http://coremob.github.com/coremob-2012/

Coremob
Camera

Coremob Camera app on Android

Project Goals

  1. Showcase the capabilities of the Web platform
  2. Educate Web developers
  3. Help improve browsers

Watch the Video: http://sdrv.ms/UF55gM

HTML Media Capture

Coremob Camera app

Taking a photo with using a native camera

		
<input type="file" accept="image/*" 
                           capture="camera">
// New spec
<input type="file" accept="image/*" capture>
		
		
18
15bl
3
10
6*
10*
10*

File API

Returning the photo as a file object

		var input = document.querySelector('input[type=file]'); 
camera.addEventListener('change', function() {
    var localFile = input.files[0];
    var reader = new FileReader();
    reader.readAsDataURL(localFile);
    reader.onload = function(e){
        preview.src = e.target.result;
    }
}, false);
		
		

Canvas

Coremob Camera app

Applying filters to the photo

		
var c = document.createElement('canvas');
var ctx = this.c.getContext('2d');
ctx.drawImage(imgObj, 0, 0);
var imgData = ctx.getImageData(x, y, w, h); 
//...Pixel manipulation ...
ctx.putImageData(imgData, 0, 0); 
		
		
7
9

Canvas Pixel Manipulation

canvas diagram

Canvas Pixel Manipulation

// Grayscale using CIE 1931 luminance
var d = imgData.data;
for (var i = 0; i < d.length; i += 4) {
    var r = d[i];
    var g = d[i + 1];
	var b = d[i + 2];
	var avg = 0.2126*r + 0.7152*g + 0.0722*b;
	d[i] = d[i + 1] = d[i + 2] = avg;
}
		
		

canvas.toBlob

Converting the filtered photo (canvas) to blob


if (canvas.toBlob) {
    var blob = canvas.toBlob(function(blob){
        // async callback
    }, 'image/jpeg');
}
		
18

Blob URLs

Displaying Blob

<img src="blob:958c1b50-09a0-2543-8528-8697ae387667">

var URL = window.URL || window.webkitURL*;
var imgURL = URL.createObjectURL(blob);
		
18*
23
15bl
4*
6*
10*
10

IndexedDB

Coremob Camera app

Storing the photos locally

		
if(window.indexedDB) {
   var req = indexedDB.open('coremobCamera'); 
   req.onsuccess = function(e) {
      // async
   }
} 
		
		

IndexedDB

Chrome 18 and BlackBerry requires the webkit prefix.

		
var indexedDB = window.indexedDB || window.webkitIndexedDB;

		
		

"Basic" Async iDB Support

18*
25
15bl
10*
16
10

IndexedDB:
Spotty Browser Support

XMLHttpRequest Level 2

Coremob Camera app

Sending a photo


var formData = new FormData();
formData.append('photo', blob); 
		
3
5
10
12
15bl

XMLHttpRequest Level 2

Sending a photo


var xhr = new XMLHttpRequest();        
xhr.open('POST', '/gallery'); 
xhr.upload.addEventListener('progress', handleProgress, false);
xhr.addEventListener('load', handleFinish, false);
xhr.addEventListener('error', handleError, false);
xhr.addEventListener('abort', handleAbort, false);
xhr.send(formData);
		

XMLHttpRequest Level 2

Coremob Camera app

Sending a photo


function handleProgress(e) { 
  if (e.lengthComputable) {
     el.textContent = 
     (e.loaded / e.total * 100) >>> 0 + '%';
  } 
}
		

CORS:
Cross Origin Resource Sharing

Access-Control-Allow-Origin: http://some-domain.org

//Apache .htaccess
<IfModule mod_headers.c>
  Header set Access-Control-Allow-Origin "*"
</IfModule>
		
12
15bl

Touch Events v.1

Coremob Camera app

Photo Gallery Carousel


el.addEventListener('touchstart', 
                    startHandler, false);
el.addEventListener('touchmove'...);
el.addEventListener('touchend'...);
		

You probably want to include mouse events too (mousedown, mousemove, and mouseup).

Pointer Events

Micorsoft Pointer event diagram

For any input devices: touch, mouse, pen...


if (navigator.pointerEnabled) {
    el.addEventListener('pointerdown', 
                         startHandler, false);
    el.addEventListener('pointermove', ...);
    el.addEventListener('pointerup', ...);
}
		

Pointer Events

Only IE10 supports so far...


if (navigator.msPointerEnabled) {
    el.addEventListener('MSPointerDown', startHandler, false);
    el.addEventListener('MSPointerMove', moveHandler, false);
    el.addEventListener('MSPointerUp', endHandler, false);
}
		
10

** Experimental Chromium build (26.0.1409.0) - no vendor prefix

More...

PhoneGap

Windows Phone 8

HTML5 + Native

Filling the gap of missing HTML5 features


coremob.github.io/camera/vanilla/index.html
goo.gl/My8mf

Thank you!

Tomomi Imura

Fork me on Github