Top Banner
By Rohit Ghatol
56

HTML 5

May 12, 2015

Download

Technology

Rohit Ghatol
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: HTML 5

By Rohit Ghatol

Page 2: HTML 5

• Name – Rohit Ghatol• Associations – Founder Pune GTUG and Co Founder

Pune Agile Group. Technical Speaker on various platforms like CSI, Indic Threads, etc. Certified Scrum Master

• Experience – 8 years total, 3 years as a speaker & trainer

• Companies – Synerzip, Google, Persistent, Sigma• Technologies – GWT, Ajax, Android, OpenSocial, GAE,

Cloud computing, J2EE, Google Ajax Apis etc..• Role – Architect and Senior Manager. Agile Practitioner

and Trainer in Synerzip.• Qualification – BE from PICT Pune

Page 3: HTML 5

• History! Why HTML 5?• What is HTML 5?• How to use HTML 5?• Examples• Programming in Java instead of

Javascript

Page 4: HTML 5

User Experience

Time line

1990 ……..2010

HTML

DOMCSS

Ajax

Canvas/SVG

Offline

VideoGeo

Workers

200820042000

Static HTML

Ajax Apps

RIA/Next Gen Apps

HTML 5

6Funeral

Flex/Silver light

Page 5: HTML 5

• Flash, Silver light, JavaFx, and more….• Standards Vs Corporate Babies• Say in the Standards

• In short, Browsers + Standards = Better Results

Page 6: HTML 5

Offline CacheX

DatabaseMain Thread

More Threads

N

S

EW

Geo LocationCanvas & SVG

Video

Page 7: HTML 5

<!DOCTYPE html><html><body><svg width="200" height="200"><rectx="0" y="0"width="100" height="100"fill="blue" stroke="red"stroke-width="5px"rx="8" ry="8"id="myRect" class="chart" /></svg></body></html>

Page 8: HTML 5

var svgRect = document.getElementById(“myRect”);

svgRect.onClick=function(){alert(“Clicked Rect”);};

It’s the same!

Page 9: HTML 5

• Browsers only sees a HTML as SVG if its content type is “image/svg+xml"

• E.g in JSP one would need to add this to it<%@ page contentType="image/svg+xml" %>

Page 10: HTML 5

• Yes, the same classic question again?• No, IE 8 does not have support for SVG!

• Optionso Use SVGWeb, a javascript library that uses

flash to enable SVG support on IE browser

Page 11: HTML 5

• http://www.w3schools.com/svg/tryit.asp?filename=animatemotion_2&type=svg

• http://upload.wikimedia.org/wikipedia/commons/6/63/A_large_blank_world_map_with_oceans_marked_in_blue.svg

Page 12: HTML 5

<canvas id="myCanvas" width="150" height="150"></canvas> <script type="text/javascript"> var canvas = document.getElementById('myCanvas');var ctx = canvas.getContext('2d');ctx.fillStyle = "rgb(200,0,0)";ctx.fillRect (10, 10, 55, 50);ctx.fillStyle = "rgba(0, 0, 200, 0.5)";ctx.fillRect (30, 30, 55, 50); </script>

Page 13: HTML 5

<!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="150" height="150"></canvas> <script type="text/javascript"> var canvas = document.getElementById('myCanvas');var ctx = canvas.getContext('2d');ctx.fillStyle = "rgb(200,0,0)";ctx.fillRect (10, 10, 55, 50);ctx.fillStyle = "rgba(0, 0, 200, 0.5)";ctx.fillRect (30, 30, 55, 50); </script> </body> </html>

Page 14: HTML 5

SVG

• Based on Tree of UI Objects

• Interactively via mouse• Easy as Tag based• Medium Animation• Overall an High level API

Canvas

• Based on Pixels• Difficult object selection• Based on JS APIs• Better Animation• Overall a Low Level API

Page 15: HTML 5

• First Person Gifter• Population Demo

Page 16: HTML 5

FireFox Safari FireFox Opera IE

Canvas/SVG Yes Yes Yes Yes SvgWeb and Explorer Canvas

Page 17: HTML 5

Current Video Support

Install Plug-ins

Page 18: HTML 5

Current Video Support

<video src="http://www.w3schools.com/html5/movie.ogg" controls >Your browser does not support the video element.

</video>

Page 19: HTML 5

<button id="play“ onClick="playMovie()"> Play </button>

<script>

function playMovie(){var player = document.getElementsByTagName("video")[0];player.play();}

</script>

Page 20: HTML 5

FireFox Safari FireFox Opera IE

Canvas/SVG Yes Yes Yes Yes SvgWeb and Explorer Canvas

Video Yes Yes Yes Yes Not Yet

Page 21: HTML 5

• Geo helps Local Business• Geo helps Social Networking• Geo helps Ads• Geo helps Photo/Video tagging• And more…..• All Future Netbooks and Phone probably

will have Geo Awareness

Page 22: HTML 5

navigator.geolocation.getCurrentPosition(function(position) {var lat = position.coords.latitude;var lon = position.coords.longitude;var acc = position.coords.accurary;// Show position on Google Maps});

Page 23: HTML 5
Page 24: HTML 5

<!DOCTYPE html><html><head><script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=abcdefg" type="text/javascript"></script>// See next page for script which goes here</head><body onLoad="initialize()"><h1>Geo Demo</h1><b>Your location is <div id="loc">Loading...</div></b><hr><div id="map_canvas" style="border:1px solid black;width: 500px; height: 300px"></div></body></html>

Page 25: HTML 5

<script type="text/javascript">function initialize() {if (GBrowserIsCompatible()) {var map = new GMap2(document.getElementById("map_canvas"));navigator.geolocation.getCurrentPosition(function(position) {var lat = position.coords.latitude;var lon = position.coords.longitude;document.getElementById("loc").innerHTML=lat+","+lon;map.setCenter(new GLatLng(lat, lon), 13);var point = new GLatLng(lat,lon);map.addOverlay(new GMarker(point));});}}</script>

Page 26: HTML 5

FireFox Safari Safari Opera IE

Canvas/SVG Yes Yes Yes Yes SvgWeb and Explorer Canvas

Video Yes Yes Yes Yes Not Yet

Geo Yes IPhone Not Yet

Page 27: HTML 5

• Lets see these one by one

Page 28: HTML 5

• Loading of web apps when browser is offline

• Storage of cache of the web app resources

• Tracking and Aware of cache changes

Page 29: HTML 5

• Enable offline cache

<html manifest="todo.manifest"></html>

Page 30: HTML 5

CACHE MANIFEST# version 1

CACHE:todo-list-3.htmlcss/todo-list.cssimages/todo.jpgscript/todo-list.js

Page 31: HTML 5

<script type="text/javascript"> function online(event) {

var status = document.getElementById('statusDiv'); status.className = navigator.onLine ? 'online' :

'offline'; status.innerHTML = navigator.onLine ? 'online' :

'offline'; } addEvent(window, 'online', online); addEvent(window, 'offline', online); </script>

Page 32: HTML 5

• For example, you get the DOMApplicationCache object as follows:

cache = window.applicationCache;

• You can check the status of the application cache as follows:if (window.applicationCache.status == window.applicationCache.UPDATEREADY)...

• If the application cache is in the UPDATEREADY state, then you can update it by sending it the update() message as follows:

window.applicationCache.update();

• If the update is successful, swap the old and new caches as follows:

window.applicationCache.swapCache();

Page 33: HTML 5

• For example, you get the DOMApplicationCache object as follows:

cache = window.applicationCache;

• You can listen to cache updates  register for the updateready event to be notified when the application cache is ready to be updated:

cache.addEventListener('updateready', cacheUpdatereadyListener, false);

• Also, register for the error event to take some action if the update process fails

cache.addEventListener('error', cacheErrorListener, false);

Page 34: HTML 5

• For more details visit – • http://www.whatwg.org/specs/web-apps/c

urrent-work/multipage/offline.html#offline

Page 35: HTML 5

Opening a database Connection

if (window.openDatabase) { db = openDatabase("NoteTest", "1.0", "HTML5 Database API

example", 200000);}

Page 36: HTML 5

function loaded(){db.transaction(function(tx) {tx.executeSql("SELECT COUNT(*) FROM Tasks", [], function(tx,result) {count=result.rows.item(0)["COUNT(*)"];alert(“Total rows is “+count);}, function(tx, error) {tx.executeSql("CREATE TABLE Tasks (id REAL UNIQUE, task TEXT)", [], function(result) { alert(“created tables”);});});});}

Page 37: HTML 5

Running everything as a transactionsdb.transaction(<<func(tx)>>,<<func(tx,error>>);

1.First function is used to execute an sql• Second function is a call back when

transaction error occures

Page 38: HTML 5

Running everything as a transactionstx.executeSql(<<sql>>,<<args>>,<<func(tx,result)>>);1.First argument is an sql• Second argument is paramters to sql• Callback when sql query returns

• tx – SQL transaction• result – SQL Result Set

Page 39: HTML 5

function loadTasks(){db.transaction(function(tx) {tx.executeSql("SELECT id, task FROM Tasks", [], function(tx, result) {for (var i = 0; i < result.rows.length; ++i) {var row = result.rows.item(i);innerHTML=innerHTML+row.task+"<br>";}todoListElem.innerHTML=innerHTML;}, function(tx, error) {alert('Failed to retrieve tasks from database - ' + error.message);});});}

Page 40: HTML 5

function saveTask(){var textBox=document.getElementById("task")var taskText=textBox.value;textBox.value="";db.transaction(function (tx) {tx.executeSql("INSERT INTO Tasks (id, task) VALUES (?, ?)", [count++,taskText ]);});loadTasks();}

Page 41: HTML 5

function clearAllTask(){db.transaction(function (tx) {tx.executeSql("Delete From Tasks");});loadTasks();}

Page 42: HTML 5

FireFox Safari Safari Opera IE

Canvas/SVG Yes Yes Yes Yes SvgWeb and Explorer Canvas

Video Yes Yes Yes Yes Not Yet

Geo Yes IPhone Not Yet

Offline/Database

Yes Yes Not Yet

Page 43: HTML 5

• History!• Browsers are single threaded, except ajax

callbacks

Page 44: HTML 5

• JavaScript has become 100 times more fast

> 100x

Page 45: HTML 5

• ThenOne Tortoise

Single Threaded Browser

Page 46: HTML 5

• NowMany Rabbits

Multi Threaded Browser

Page 47: HTML 5

• Too many to be true, Pinch me I am dreaming

<script>var worker = new Worker('worker.js');worker.onmessage = function (event) {console.log('Results: ' + event.data);};</script>

Page 48: HTML 5

function findPrimes() {// ... prime algorithm herepostMessage(nextPrime);}findPrimes();

Page 49: HTML 5

Heavy Progressing

Slow Throughput, I may want to do this processing in a different thread

Year 2010, Dual/Quad Core Processors,Browsers can’t do multithreading

Priceless!

Page 50: HTML 5

Worker sends messages

Worker sends messages

Browser can now use the actual CPU Power of the machine, to do wonders!

Page 51: HTML 5

Myth!

Page 52: HTML 5

• Needs to understand o JavaScript language in deptho Closureso Memory leakso Browser Quirkso Cross Browser compatibilityo CSS knowledgeo DOM handlingo List continues……………………….

Page 53: HTML 5

JavaScript

• Go ahead with hiring or training JS developers

• Try it for 6 months• Let your projects fail• Burn your fingers• Now try option two

Java based

• Use something like GWT, no use GWT

• Use HTML 5 Libraries, or create some your self

• Let your developers code in Java, be productive

• Let GWT give you the most optimized js ever possible

• After 6 months Thank me!

Page 54: HTML 5

• Day 3 your java developers are productive• No. of 3rd party support for html 5 and

widgets available (even of IE, can you believe it!)

• You can quickly create wrapper on underlying javascript apis for HTML 5 and abstract you developers from it

Page 55: HTML 5

• What topics you want?• We vote now and fix this!• Some Options

o GWTo GAE (java)o Google Ajax API (including Maps)o Androido Wave (done twice actually)

Page 56: HTML 5

Thank you!