Slide 1

Slide 1 text

Building HTML5 Tablet Apps for iOS and Android MINNEWEBCON 2012 @skirchmeier @mikebollinger

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

HTML5 apps kinda suck. The elephant in the room:

Slide 4

Slide 4 text

Native vs. HTML5

Slide 5

Slide 5 text

Native -- Expensive to develop HTML5 + Cheaper to develop -- One platform at a time + Snappy + Refined (true native feel) + Full featured -- Limited features -- Unrefined -- Slower + All platforms at a time

Slide 6

Slide 6 text

Reasons

Slide 7

Slide 7 text

Money 1

Slide 8

Slide 8 text

Time 2

Slide 9

Slide 9 text

Audience 3

Slide 10

Slide 10 text

Control 4

Slide 11

Slide 11 text

Money 1 Time 2 Audience 3 Control 4

Slide 12

Slide 12 text

5 Design Patterns T A B L E T S   H A V E   F L E X I B L E  

Slide 13

Slide 13 text

Money 1 Time 2 Audience 3 Control 4 Flexible Design Patterns 5

Slide 14

Slide 14 text

Change the game.

Slide 15

Slide 15 text

Examples

Slide 16

Slide 16 text

Best Buy http://bby-uv.appspot.com/ Financial Times http://app.ft.com Proof http://proofwhisky.com

Slide 17

Slide 17 text

Best Buy http://bby-uv.appspot.com/ Financial Times http://app.ft.com Proof http://proofwhisky.com iOS Only >! iOS Only >!

Slide 18

Slide 18 text

Frameworks

Slide 19

Slide 19 text

jQuery Mobile jQTouch Sencha Touch

Slide 20

Slide 20 text

Native Wrappers

Slide 21

Slide 21 text

PhoneGap Titanium

Slide 22

Slide 22 text

Our Custom App

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

http://livefront.com/explore

Slide 25

Slide 25 text

How do we build this?

Slide 26

Slide 26 text

Step 1: Travel the world

Slide 27

Slide 27 text

Step 2: HTML (sorry)

Slide 28

Slide 28 text

...
...
...

Slide 29

Slide 29 text

...
...
...

Slide 30

Slide 30 text

...
...
...

Slide 31

Slide 31 text

...
...
...

Slide 32

Slide 32 text

...
...
...

Slide 33

Slide 33 text

...
...
...

Slide 34

Slide 34 text

...
...
...

Slide 35

Slide 35 text

Slide 36

Slide 36 text

Slide 37

Slide 37 text

Slide 38

Slide 38 text

Slide 39

Slide 39 text

...
...
...

Slide 40

Slide 40 text

Techniques

Slide 41

Slide 41 text

Transitions Touch Events Hardware (GPS) Work Offline Sizing Distribution

Slide 42

Slide 42 text

Transitions Touch Events Hardware (GPS) Work Offline Sizing Distribution

Slide 43

Slide 43 text

Transitions Two ways to animate: 1. jQuery (.animate) 2. CSS (-webkit-transform)  

Slide 44

Slide 44 text

Transitions Two ways to animate: 1. jQuery (.animate) 2. CSS (-webkit-transform)  

Slide 45

Slide 45 text

Transitions What can we do with CSS?

Slide 46

Slide 46 text

Transitions -webkit-transform translate scale skew rotate -webkit-animation

Slide 47

Slide 47 text

Transitions -webkit-transform translate scale skew rotate -webkit-animation

Slide 48

Slide 48 text

Transitions ...
...
...

Slide 49

Slide 49 text

Transitions -webkit-transform: translate3d(100%, 0, 0); div#splash div#content

Slide 50

Slide 50 text

Transitions -webkit-transform: translate3d(100%, 0, 0); div#splash div#content -webkit-transition: all 600ms ease-in-out; -webkit-transform: translate3d(0, 0, 0);  

Slide 51

Slide 51 text

Transitions Touch Events Hardware (GPS) Work Offline Sizing Distribution

Slide 52

Slide 52 text

Touch Events How touch events work

Slide 53

Slide 53 text

Touch Events Touch Multi-Touch Gesture iOS P P P Android 2.3 P Android 3 P P Android 4 P P

Slide 54

Slide 54 text

Touch Events Touch Multi-Touch Gesture iOS P P P Android 2.3 P Android 3 P P Android 4 P P

Slide 55

Slide 55 text

Touch Events touchstart touchmove touchend touchcancel

Slide 56

Slide 56 text

Touch Events slides.bind(touchstart, function (e) { if (touchId !== null) { e.stopPropagation(); e.preventDefault(); } else { var touch = e.originalEvent.touches[0]; touchId = touch.identifier; touchStart(touch.clientX); } });

Slide 57

Slide 57 text

Touch Events slides.bind(touchstart, function (e) { if (touchId !== null) { e.stopPropagation(); e.preventDefault(); } else { var touch = e.originalEvent.touches[0]; touchId = touch.identifier; touchStart(touch.clientX); } });

Slide 58

Slide 58 text

Touch Events slides.bind(touchstart, function (e) { if (touchId !== null) { e.stopPropagation(); e.preventDefault(); } else { var touch = e.originalEvent.touches[0]; touchId = touch.identifier; touchStart(touch.clientX); } });

Slide 59

Slide 59 text

Touch Events slides.bind(touchstart, function (e) { if (touchId !== null) { e.stopPropagation(); e.preventDefault(); } else { var touch = e.originalEvent.touches[0]; touchId = touch.identifier; touchStart(touch.clientX); } });

Slide 60

Slide 60 text

Touch Events slides.bind(touchmove, function (e) { var touch = e.originalEvent.touches[0]; if (touch.identifier == touchId) { touchMove(touch.clientX); } });

Slide 61

Slide 61 text

Touch Events slides.bind(touchend, function (e) { var touch = e.originalEvent.changedTouches[0]; if (touch.identifier == touchId) { touchEnd(touch.clientX); } });

Slide 62

Slide 62 text

Touch Events function touchEnd(x) { ... if (Math.abs(deltaX) > threshold) { swipe(direction); } else if (Math.abs(deltaX) > Config.slideshowSwipeDistanceThreshold && touchDuration < Config.slideshowSwipeDurationThreshold) { swipe(direction); } else { snapBack(); } }

Slide 63

Slide 63 text

Touch Events function touchEnd(x) { ... if (Math.abs(deltaX) > threshold) { swipe(direction); } else if (Math.abs(deltaX) > Config.slideshowSwipeDistanceThreshold && touchDuration < Config.slideshowSwipeDurationThreshold) { swipe(direction); } else { snapBack(); } }

Slide 64

Slide 64 text

Touch Events function touchEnd(x) { ... if (Math.abs(deltaX) > threshold) { swipe(direction); } else if (Math.abs(deltaX) > Config.slideshowSwipeDistanceThreshold && touchDuration < Config.slideshowSwipeDurationThreshold) { swipe(direction); } else { snapBack(); } }

Slide 65

Slide 65 text

Touch Events function touchEnd(x) { ... if (Math.abs(deltaX) > threshold) { swipe(direction); } else if (Math.abs(deltaX) > Config.slideshowSwipeDistanceThreshold && touchDuration < Config.slideshowSwipeDurationThreshold) { swipe(direction); } else { snapBack(); } }

Slide 66

Slide 66 text

Touch Events function touchEnd(x) { ... if (Math.abs(deltaX) > threshold) { swipe(direction); } else if (Math.abs(deltaX) > Config.slideshowSwipeDistanceThreshold && touchDuration < Config.slideshowSwipeDurationThreshold) { swipe(direction); } else { snapBack(); } }

Slide 67

Slide 67 text

Touch Events

Slide 68

Slide 68 text

Touch Events

Slide 69

Slide 69 text

Touch Events div.slide div.slide div.slide div#slides-container

Slide 70

Slide 70 text

Touch Events div.slide div.slide div.slide div#slides-container

Slide 71

Slide 71 text

Touch Events Gotcha #1: Android browser

Slide 72

Slide 72 text

Touch Events Gotcha #1: Android browser

Slide 73

Slide 73 text

Touch Events Gotcha #1: Android browser vs. background-image

Slide 74

Slide 74 text

Touch Events Gotcha #2: Mobile Safari Bounce $(document).bind('touchmove’, function(event){ event.preventDefault(); });

Slide 75

Slide 75 text

Touch Events Gotcha #3: Testing on Desktop var hasTouch = 'ontouchstart' in document.documentElement; var touchstart = hasTouch ? 'touchstart' : 'mousedown'; var touchmove = hasTouch ? 'touchmove' : 'mousemove'; var touchend = hasTouch ? 'touchend' : 'mouseup';

Slide 76

Slide 76 text

Touch Events Gotcha #4: Click Events are Slow Click Event vs. Touch Event

Slide 77

Slide 77 text

Transitions Touch Events Hardware (GPS) Work Offline Sizing Distribution

Slide 78

Slide 78 text

Hardware (GPS) JS - iOS JS - Android PhoneGap Accelerometer P P Compass P P Gyroscope P P Camera P Contacts P Local Storage P P P Geolocation P P P Notifications P

Slide 79

Slide 79 text

Hardware (GPS) JS - iOS JS - Android PhoneGap Accelerometer P P Compass P P Gyroscope P P Camera P Contacts P Local Storage P P P Geolocation P P P Notifications P

Slide 80

Slide 80 text

Hardware (GPS)

Slide 81

Slide 81 text

Hardware (GPS) function displayCurrentLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( function (position) { var lat = position.coords.latitude; var lng = position.coords.longitude; ... // Display lat/lng } ); } };

Slide 82

Slide 82 text

Transitions Touch Events Hardware (GPS) Work Offline Sizing Distribution

Slide 83

Slide 83 text

Work Offline Local Storage

Slide 84

Slide 84 text

Work Offline Gotcha: 5mb

Slide 85

Slide 85 text

Work Offline var hasLocalStorage = (function () { try { localStorage.setItem('test', 'test'); localStorage.removeItem('test'); return true; } catch(e) { return false; } })();

Slide 86

Slide 86 text

Work Offline var localStoragePhotoData = null; if (hasLocalStorage) { localStoragePhotoData = localStorage.getItem(key); } if (localStoragePhotoData === null) { if (hasLocalStorage) { // Save photo data to localStorage. var photoDataString = JSON.stringify(PhotoData); localStorage.setItem(key); ... } } else { // Use photo data cached in localStorage. var photoDataObject = JSON.parse(localStoragePhotoData); ... }

Slide 87

Slide 87 text

Work Offline var localStoragePhotoData = null; if (hasLocalStorage) { localStoragePhotoData = localStorage.getItem(key); } if (localStoragePhotoData === null) { if (hasLocalStorage) { // Save photo data to localStorage. var photoDataString = JSON.stringify(PhotoData); localStorage.setItem(key); ... } } else { // Use photo data cached in localStorage. var photoDataObject = JSON.parse(localStoragePhotoData); ... }

Slide 88

Slide 88 text

Work Offline var localStoragePhotoData = null; if (hasLocalStorage) { localStoragePhotoData = localStorage.getItem(key); } if (localStoragePhotoData === null) { if (hasLocalStorage) { // Save photo data to localStorage. var photoDataString = JSON.stringify(PhotoData); localStorage.setItem(key); ... } } else { // Use photo data cached in localStorage. var photoDataObject = JSON.parse(localStoragePhotoData); ... }

Slide 89

Slide 89 text

Work Offline var localStoragePhotoData = null; if (hasLocalStorage) { localStoragePhotoData = localStorage.getItem(key); } if (localStoragePhotoData === null) { if (hasLocalStorage) { // Save photo data to localStorage. var photoDataString = JSON.stringify(PhotoData); localStorage.setItem(key); ... } } else { // Use photo data cached in localStorage. var photoDataObject = JSON.parse(localStoragePhotoData); ... }

Slide 90

Slide 90 text

Transitions Touch Events Hardware (GPS) Work Offline Sizing Distribution

Slide 91

Slide 91 text

Sizing Support different screens Handle rotation Hide browser chrome Disable zoom Disable other browser features

Slide 92

Slide 92 text

Sizing Support different screens Easier in HTML than native % based layouts background-size: cover; Absolute positioning is often necessary

Slide 93

Slide 93 text

Sizing Handle rotation $(window).resize(doSomething);

Slide 94

Slide 94 text

Sizing Handle rotation $(window).resize(reposition);

Slide 95

Slide 95 text

Sizing Handle rotation Gotcha: You get notification after rotation is complete

Slide 96

Slide 96 text

Sizing Hide browser chrome

Slide 97

Slide 97 text

Sizing Disable zoom

Slide 98

Slide 98 text

Sizing Disable other browser features /* turn off default press states */ -webkit-tap-highlight-color: transparent; /* disable save image on long press */ -webkit-touch-callout: none; /* disable selection copy/paste */ -webkit-user-select: none; /* disable dragging images */ -webkit-user-drag: none;

Slide 99

Slide 99 text

Transitions Touch Events Hardware (GPS) Work Offline Sizing Distribution

Slide 100

Slide 100 text

Distribution

Slide 101

Slide 101 text

Distribution Two ways to distribute: 1. Web only Reminder to bookmark 2. App gallery Custom native wrapper Framework like PhoneGap  

Slide 102

Slide 102 text

Distribution Two ways to distribute: 1. Web only Reminder to bookmark 2. App gallery Custom native wrapper Framework like PhoneGap  

Slide 103

Slide 103 text

Distribution https://github.com/cubiq/ add-to-homescreen

Slide 104

Slide 104 text

Distribution

Slide 105

Slide 105 text

Distribution

Slide 106

Slide 106 text

Distribution Home Screen Icon

Slide 107

Slide 107 text

Distribution 144 x 144

Slide 108

Slide 108 text

Distribution

Slide 109

Slide 109 text

Transitions Touch Events Hardware (GPS) Work Offline Sizing Distribution

Slide 110

Slide 110 text

Go explore.

Slide 111

Slide 111 text

Thanks! MINNEWEBCON 2012 @skirchmeier @mikebollinger

Slide 112

Slide 112 text

APP: http://livefront.com/explore SOURCE CODE: http://github.com/livefront/ minnewebcon2012-explore SLIDES: http://livefront.com/explore/slides.pdf