70
#SDC13 The Tizen Web Platform, where web apps feels right at home Kenneth Christiansen / Alexis Menard Web Platform Architects Intel Corporation

SDC13 - Unleashing Your Inner Web App Developer Using Tizen

  • View
    454

  • Download
    0

Embed Size (px)

DESCRIPTION

In the session, the Tizen Web Application model (aka Web Runtime) will be introduced along with the major features. We will walk through the major steps for creating a simple application accessing hardware capabilities. Furthermore, we will look at good practices for adapting responsive design, allowing the application to target future Tizen devices, using different resolutions, screen sizes and interaction models.

Citation preview

Page 1: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

#SDC13

The Tizen Web Platform, where web apps feels right at home

Kenneth Christiansen / Alexis Menard Web Platform Architects Intel Corporation

Page 2: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Part 1: The runtime model

In this section, the Tizen Web Application model (aka Web Runtime) will be introduced

along with its major features.

Part 2: Creating an application

We will walk through the major steps for creating a simple application accessing

hardware capabilities

Part 3: Responsive design and good practices

Furthermore, we will look at good practices for adapting responsive design, allowing

the application to target future Tizen devices, using different resolutions, screen sizes

and interaction models

Agenda

Page 3: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Part 1 The runtime model

Page 4: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Tizen is new OS, backed by industry leaders

It is open and the focus is on web apps

It targets multiple devices, not just mobile phones

In many ways, it is ahead of its time with the focus on web and the extensions to the web platform.

What is Tizen

Page 5: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Brilliant support for latest HTML5 specs

Great performance, good implementations, emerging standards:

• Vibrate

• Battery

• Screen lock

Not to forget device API’s currently being standardized in the W3C

What is Tizen

Page 6: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Q: What is a web application?

Why HTML5 and the web platform:

• Integration with existing cloud services

• Most flexible layout engine

• Reuse existing code and knowledge

• Cross platform “promise”

• Immediate update and distribution control (hosted apps)

• Responsive design

Why betting on the web

Page 7: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Downsides

• Timely access to new OS innovations

• Offline support

• Access to native capabilities

• Control over the application (life cycle, launching, etc)

• Store support

• Interaction with the interface (viewport, orientation lock, touch control,…)

Tizen brings the promises of HTML5 and aims at closing the gaps to native

Why betting on the web

Page 8: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Tizen brings its own additional API’s

• These are optional (you should code as such) and only available on Tizen

• General purpose API’s are being standardized in the W3C together with

Mozilla, Intel, Samsung a.o.

Timely access to new OS innovations

Page 9: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Packaged applications

• Bundle HTML, CSS, other resources incl. manifest

• Prepared for offline support

• Based on the W3C Widgets specs

• Localization support

• Query manifest from applications

• Permission control

Offline support

Page 10: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

The additional Tizen API’s allows you to access a variety of things

• Bluetooth, Contacts, Callhistory, NFC, Local Filesystem, etc.

• Capabilities are controlled by permissions control similar to that of

Android apps

Access to native capabilities

Page 11: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

A variety of API’s available

• Deal with discharging battery or control display (Power API)

• Query manifest (widget.description, widget.version, etc.)

• Launch application and receive result (App Control API)

• Schedule tasks: Launch app at a given time (Alarm API)

Control over the application

// when the alarm is triggered the app is launched if not already running var alarm = new tizen.AlarmAbsolute(new Data(2013, 10, 4, 8, 0)); tizen.alarm.add(alarm, “org.tizen.browser”);

Tizen.application.getCurrentApplication();

Page 12: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Great touch and mobile support

• Touch interaction and touch events (web facing)

• Screen Orientation Lock

• Fullscreen support – per element

• Viewport meta tag

Interaction with the user interface

Page 13: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Packaged apps can be distributed via the Tizen Store: http://seller.tizenstore.com

Store support

Page 14: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Part 2 Creating an application

Page 15: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

We will walk through the

major steps for creating a

simple application accessing

hardware capabilities

Creating a simple NFC application

Page 17: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

How to get started

Page 18: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

config.xml

Used when packaging and installing the application, contains attributes such as

ID, name, content (primary HTML file to load), and icon.

index.html

Contains the User Interface: afew labels, a text input to enter the text that is

going to be stored on the tags, and a button to start writing

main.js

Will contain the logic of the application; deals with the NFC chip and with

updating the user interface

Creating the NfcSimple Application

Page 19: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

All TizenJS APIs are nested under the tizen object e.g.

tizen.time, tizen.power, etc.

Most of the APIs are driven by exceptions and event listeners when

asynchronous.

Creating the NfcSimple Application

Page 20: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Tizen uses the wgt format to package the application.

It’s essentially a zipped file with all your images, and html/css/js files in it.

The wgt package is sent over to the phone and installed using the web

runtime of Tizen, which will add a shortcut on the launch screen.

The packaged application

Page 21: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

To complete the Web Platform offering, Tizen offers couple of JavaScript APIs you can use to make a richer application

The packaged application

Page 22: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

NfcSimple: Get the default adapter and power it on

// Get the NFC adapter try { adapter = tizen.nfc.getDefaultAdapter(); if (!adapter.powered) { adapter.setPowered( true, // Enable NFC adapter onPowerOn, // Handle success function () { console.log("Power on failed") }); // Handle failure } else { onPowerOn(); } } catch (err) { console.log(err.name + ": " + err.message); }

Page 23: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

NfcSimple: Get notifications when a tag is detected

var onTagDetectedCB = { onattach : function(nfcTag) { nfcLog("NFC Tag's type is " + nfcTag.type); // now that Tag is detected, call read try { if (!nfcTag.isSupportedNDEF) { nfcLog('Tag does not support NDEF'); return; } nfcLog('Tag supports NDEF; reading messages...'); nfcTag.readNDEF(readCB, onError); } catch (err) { console.log(err); } } ... adapter.setTagListener(onTagDetectedCB);

Page 24: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

NfcSimple: Write to the tag

var newMessage = new tizen.NDEFMessage(); newMessage.records[0] = new tizen.NDEFRecordText(message, 'en-US', 'UTF8'); nfcTag.writeNDEF(newMessage, onSuccess, onError);

• NDEF is the NFC Data Exchange Format

• Tizen provides a set of APIs to ease manipulating them for read and write

Page 25: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

NfcSimple: Try it on the phone

Page 26: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

NfcSimple: End result

After deploying to the phone, you should see a result

very similar to what is shown on the right side:

Using standard HTML5, plus a few of the Tizen API’s

it is possible to write really complex and useful

applications.

The Tizen UI Framework (based on jQuery Mobile)

can help you create a Tizen like UI with very little

effort.

Page 27: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Part 3 Responsive design and good practices

Page 28: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

The market today

Different screen sizes/resolutions, densities and even different behavior

Image from the Responsible Web Design – www.abookapart.com/products/responsive-web-design

Page 29: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Post-PC – lots of different devices, happening now

Common solutions

Show desktop pages

Small text (mobile browsers enlarge smartly!)

Lots of annoying pinching and panning

Sniff the user agent

Different content sources

Hard to test property

Breaks when UA string or browser changes

Page 30: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

How is the web structured?

Semantics aka HTML

Styling aka CSS

Behavior aka JavaScript

Page 31: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

How is the web structured?

Semantics aka HTML

Styling aka CSS

Behavior aka JavaScript

We want to be responsive

Page 32: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

How is the web structured?

Semantics aka HTML

Styling aka CSS

Behavior aka JavaScript

We want to be responsive

We want to keep the semantics

but change the rest

Page 33: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Fluid grids (‘dimensions’),

Flexible images and

Media Queries This is the definition of Responsive Web Design

Page 34: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Time for exploration

Page 35: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

How to accomplish something like this?

Page 36: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Fluid dimensions

It’s all about layout

Show, hide, change, reorder

CSS to the rescue!

Page 37: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Fluid dimensions

Lots of real estate One particular design

Page 38: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Fluid dimensions

Less real estate A more compact styling

Page 39: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Fluid dimensions

And it goes on… New layout constructs as Flexible box even

supports reordering cells!

Page 40: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Do not use fixed sizing Say what???

Designers are commonly used to the fixed medium,

and as ‘the control freaks they are ;-)’ they want to

achieve pixel perfection

Page 41: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Insert ‘new mindset’ here

“ “

Use percentages (%), add min-width: …px

To avoid breaking the design

Page 42: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Insert ‘new mindset’ here

But be aware

Some words about sub-pixel layout and

the lack there of.

Page 43: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Sub-pixel layout

With a 6 column grid:

100% ÷ 6 = 16.67%

Page 44: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Sub-pixel layout

With a 1000px viewport that is 166.67

Pixel per column, oh, oh…

Page 45: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Sub-pixel layout

If we round to nearest pixel it won’t fit

on screen

Page 46: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Sub-pixel layout

If we round to nearest pixel it won’t fit

on screen

167x6 = 1002

Page 47: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Sub-pixel layout

Only fixed by sub-pixel layout

Supported by IE and newest WebKit based browsers

Page 48: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Meet the Media Query

Page 49: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

The media query

Media queries allow you to specify a condition for a block of CSS

If that block is met, the block is applied to your HTML

If not, it is completely ignored

They are an awesome fit for real needs!

Page 50: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

The media query

Example

<link rel=“stylesheet” type=“text/css” href=“core.css” media=“screen”> <link rel=“stylesheet” type=“text/css” href=“print.css” media=“print”>

Format

@media screen and (max-weight: 3kg) and (color), (orientation: portrait) { ... }

Page 51: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Size breakpoints

Media queries allow that you to add breakpoints given size

<link rel=“stylesheet” type=“text/css” media=“screen and (max-device-width: 480px*)” href=“shetland.css” /> @media screen and max-width: 480px) { .column { float: none; } }

* Be aware of viewport adaptation

Page 52: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Size breakpoints – Adobe Edge Reflow

Adobe provides a nice tools for doing this

Page 53: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Sizing to the viewport

Page 54: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

The new viewport related vh/vw units

Viewport width, viewport height units per 100

Want to make sure an element fits inside 1/3 of the viewport?

No need to measure with JavaScript, just use the new units

.element { width: 33vw; } img { max-height: 95vh; }

Page 55: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Image resolution and bandwidth savings

Page 56: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Retina, hi-res, etc.

CSS pixels

Device pixels

height: 2px

width: 2px

height: 2px

width: 2px

De-facto standard Retina

x4

Device units vs. density independent pixels aka CSS units

Page 57: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Media queries and future ideas

Use media queries today

#image { background: url(image.png); } @media (-webkit-min-device-pixel-ratio: 2) { #image { background :url([email protected]); } }

Near future

@media (min-resolution: 2dppx) { // or (min-resolution: 192dpi) #image { background :url([email protected]); } }

Page 58: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Media queries and future ideas

#image { background: url(image.png); } @media (-webkit-min-device-pixel-ratio: 2) { #image { background :url([email protected]); } }

Mat Marques suggested the <picture> element

<picture ...> <source media=“(min-resolution: 2dppx)” source=“[email protected]”> <source ...> <img src=“image.png”> </picture>

Apple suggested

<image src=“image.png” srcset=“image.png 1x, [email protected] 2x”>

Page 59: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Viewport adaptation

Page 60: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Viewport adaptation

The CSS viewport is not always the actual 1.0 scale browser view

Keep in mind that the browser view is in CSS units (not device ones)

But then how can a mobile browser fit a whole desktop page?

And not break the layout?

They lie! Most mobile browsers do not layout pages at their true Browser view

Page 61: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Viewport adaptation

Mobile browsers often lays out at 980px or similar

Then they fit the contents to the view, resulting in != 1.0 scale

This is useless for web apps which should use 1 CSS px as 1 UI px.

Page 62: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

The viewport meta-tag

The meta tag takes care of that

<meta name=“viewport” contents=“width=device-width, initial-scale=2”>

Very flexible, somewhat ‘quirky’ and hard to understand

<meta name=“viewport” contents=“width=device-width”>

If device-width above is 320 (iPhone default) it will be scaled differently

in portrait than in landscape. Adding ‘maximum-scale=1’ make it “overflow” to 480 in

landscape, as it wasn’t allowed to scale.

Page 63: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

CSS Device Adaptation spec

CSS version of the meta tag, easier to use

@viewport { width: device-width; } @media screen and (width: 397px) { @viewport { width: 500px; } }

Supported already by IE 10 (partial), IE10 mobile, Opera and trunk Webkit

Page 64: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Advanced media queries

Page 65: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

How to adapt behavior implemented in JavaScript

Query or listen

mql = window.styleMedia.matchMedium(“(max-width: 480px)”); if (mql.matches) { alert(“Gotta have a pizza tonight!”); } // Lets subscribe to changes! mql.addListener(function(result) { alert(result.matches); })

Page 66: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Rounding up Best approach

Page 67: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Rounding up

Responsive design is There today!

And most works with any modern browser Retina support, vw/hw units, dppx is new, but should be universally supported

a year from now

Page 68: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Best approach

Mobile first, consider bandwidth constraints

Add additional UI components for larger target screens, keeping

the former in mind

Less subpages

Cut the crap, promote what matters

Less is more!

Page 69: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

Thank You!

Page 70: SDC13 - Unleashing Your Inner Web App Developer Using Tizen

License Notices

Except where noted, sample source code written by Samsung Electronics Co. Ltd and provided to you is licensed as described below. Copyright © 2010-2013, Samsung Electronics Co. Ltd. All rights reserved except as otherwise explicitly indicated. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other

materials provided with the distribution. Neither the name of the Samsung Electronics Co. Ltd nor the names of its contributors may be used to endorse or promote products derived from this software

without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED

TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Other source code displayed in this presentation may be offered under other licenses. Apache 2.0 Copyright © 2010, Android Open Source Project. All rights reserved unless otherwise explicitly indicated. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Creative Commons 3.0 Attribution License Portions of this presentation are reproduced from work created and shared by Google (http://code.google.com/policies.html) and used according to terms described in the Creative Commons 3.0 Attribution License (http://creativecommons.org/licenses/by/3.0/).