Html5 and beyond   the next generation of mobile web applications - Touch Tour Chennai
Upcoming SlideShare
Loading in...5
×
 

Html5 and beyond the next generation of mobile web applications - Touch Tour Chennai

on

  • 1,827 views

 

Statistics

Views

Total Views
1,827
Views on SlideShare
1,827
Embed Views
0

Actions

Likes
0
Downloads
12
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Html5 and beyond   the next generation of mobile web applications - Touch Tour Chennai Html5 and beyond the next generation of mobile web applications - Touch Tour Chennai Presentation Transcript

  • HTML5 and beyond: Thenext generation of mobileweb applications By Shwetank Dixit, Opera Software
  • about meWeb Evangelist, Opera DeveloperRelations TeamMember, W3C Mobile Web for SocialDevelopment GroupMember, W3C Web EducationCommunity Grouptwitter.com/shwetankemail: shwetankd@opera.com
  • The most important thingto know about the mobileweb...
  • Just one Web
  • Smartphone browsers != Webkit
  • Furthermore, which webkitare you talking about? READ PPK’S ARTICLE TITLED “THERE IS NO WEBKIT ON MOBILE”
  • It’s ok if the same sitelooks different in differentdevicesAs long as they are optimized for it.
  • It’s ok if the same sitelooks different in differentdevicesAs long as they are optimized for it.AND THINK WHETHER IT IS REALLY WORTH IT
  • But if you do have adifferent mobile site...ALWAYS provide a link to switch back to thedesktop version.
  • W3C Mobile Web BestPractices guidelinesRTFG
  • Offline webappswith html5
  • Offline Apps: Storing thefiles need to run offline
  • CACHE MANIFEST #this is a comment. style.css script.js index.htmcontents of the manifest file.
  • <html manifest=”demo.manifest”>Linking the manifest file to the html page.
  • CACHE MANIFEST #this is a comment. style.css script.js index.htm NETWORK: dynamicpage.phpThe NETWORK: section header bypasses the cache
  • CACHE MANIFEST #this is a comment. style.css script.js index.htm FALLBACK: original.jpg backup.jpgIf a file can’t load, then the FALLBACK: section headerspecifies which files to load as a backup in their place
  • ALWAYS KEEPING AN UPDATED CACHE ��
  • Offline Apps: Storing thedata for offline use
  • Storage: Web Storage
  • The problem with cookiesUnreliableNo programmatic APIs to manipulate itNot structuredMost of important of all ...Small file size, so very limited data can bestored.
  • Web StorageSession Storage and Local Storage
  • localStorage.setItem(yourkey,yourvalue); // Store the valuevar item = localStorage.getItem(yourkey); // Retrieve the value and assignit to a variableExample of using Web Storage to store andretrieve values in the browser’s local storageWith this, even if you close the browser and re-open the page again, the values shouldstill load properly.
  • You can store images (andmore) with localStorage ....BUT DON”T.
  • Automatically save enteredform info locallyin case page crashes or closes, person canresume from where he left off
  • STORE USER DATA OFFLINE PERIODICALLY��
  • Or...You could save only when you detect a newkeystroke (or a minimum number of them)
  • GotchaTwo tabs updating the same value
  • Storage eventsKnow if some other page has changed thevalue or not
  • GET NEW VALUE IF ITS BEEN CHANGED IN PARALLEL TAB���
  • GotchaUsing a free hosting service - Don’t use localstorage with it if they store users accountson different directories.e.g, freehosting.com/user1and freehosting.com/user2
  • Other storageoptions- IndexedDB (Limited browser support currently)- WebSQL (Standard in impasse. Limited desktop browsersupport but nice mobile browser support.)
  • Further readingRun your web apps offline with HTML5 Application Cache: http://dev.opera.com/articles/view/offline-applications-html5-appcache/Web Storage: easier, more powerful client-side data storage: http://dev.opera.com/articles/view/web-storage/Taking your web apps offline: A tale of Web Storage, Application Cache and WebSQL:http://dev.opera.com/articles/view/taking-your-web-apps-offline-web-storage-appcache-websql/
  • SVG - Scalable VectorGraphics
  • FormsHTML5 incorporates web forms 2, whichmakes forms fun again!
  • Lets see an example!
  • <input name="age" type="number" min="18" max="25"><input name="email" type="email" required><input name="url" type="uri" list="mylist"><datalist id="mylist">`<option label="google" value="http://google.com"><option label="yahoo" value="http://yahoo.com"><option label="personal" value="http://shwetankdixit.com"></datalist><input name="dob" type="date"><input id="slider" name="a" type="range" mix="1" max="10" value="0"> </input><output name="result" value="5" onforminput="value=a.value" >0</output>Some of the code in the example page
  • Media queries
  • �Provide different styles to differentresolutions using media queries
  • Traditionally, mobile browsers provide a‘zoomed out’ view, and then you can tap in
  • Viewport meta tagAllows you to set the zooming level
  • Scaling constraints<meta name="viewport"content="width=device-width,maximum-scale=2, minimum-scale=0.5">
  • Disable user scaling<meta name="viewport"content="width=device-width,user-scalable=no">
  • In Opera, you can use CSSto control viewportFor example...@-o-viewport { width: device-width; max-zoom: 2; min-zoom: 0.5;}
  • GeolocationFind yourself
  • “These are my thoughts ina well published format”-The early web
  • “Here is what we can alldo together”- “Web 2.0”
  • “This is what I’m thinking”- Facebook, twitter and other social tools
  • “This is where I’m at”- The next step
  • Think of the possibilitiesAugmented realityGeofencinglocation aware advertising...more
  • //Check if browser supports W3C Geolocation APIif (navigator.geolocation) { navigator.geolocation.getCurrentPosition(successFunction, errorFunction);} else { alert(Geolocation not supported.);}Sample code for running geolocation, ifavailable
  • function successFunction(position) { var lat = position.coords.latitude; var long = position.coords.longitude; alert(Your latitude is :+lat+ and longitude is +long);}Determining the position
  • function errorFunction(position){ if (pos.PositionError == 1){ alert(It seems you have decided not to share yourlocation); } if (pos.PositionError == 2){ alert(The location could not be determined by thebrowser. Try to reload the page to try again); }Handling errorsSEE FULL LIST OF ERRORS ON THE SPEC
  • watchPosition()Same as getCurrentPosition() but fireswhenever there is a change in location.Sometimes its better to use this than theformer.
  • AccuracyScarily accurate in some places,amusingly inaccurate in others.DO NOT rely on it.Provide fallbacks, and ways to enter locationinfo manually (like zipcode)
  • The Geolocation SpecMay be up for a bit of a change in the future
  • Further readingHow to use the W3C Geolocation API: http://dev.opera.com/articles/view/how-to-use-the-w3c-geolocation-api/Use the Geolocation API in Webapps: http://goo.gl/EBVYt
  • A sneak peak
  • Device OrientationAccess to gyroscope, accelerometer info etc
  • Access gyroscope infowindow.addEventListener("deviceorientation", function(event) { // process event.alpha, event.beta andevent.gamma }, true);
  • Access accelerometer infowindow.addEventListener("devicemotion",function(event) { // Process event.acceleration }, true);
  • Another sneak peak
  • Check for accessif (navigator.getUserMedia){ navigator.getUserMedia(video, v_success,v_error); }else{ not_supported(); }
  • Check for accessvar video_element = document.querySelector(video);......function v_success(stream){ video_element.src = stream;}
  • Use camera + <video> +<canvas> for new tricksvar button = document.querySelector(#button);button.addEventListener(click,snapshot, false);......function snapshot(){ var c = document.querySelector(canvas); var ctx = c.getContext(2d); var cw = c.clientWidth; var ch = c.clientHeight; ctx.drawImage(video_element, 0, 0, cw, ch); }
  • Keep in mindWebRTC spec (containing getUserMedia) isstill in flux. Not a mature standard yet.
  • Download the OperaMobile labs build withdevice orientation andgetUserMedia supportDownload from here: http://my.opera.com/core/blog/2011/03/23/webcam-orientation-preview
  • Read up onDev.opera.com
  • Cheers!More questions? Ask me now or contact meat:shwetankd@opera.comor, twitter.com/shwetank