Adding HTML5 to your Android applications. Martin Gunnarsson & Pär Sikö



Similar documents
Introduction to PhoneGap

JavaFX Mashups. Martin Gunnarsson, Pär Sikö, Jayway. fredag 26 oktober 12

Step One Check for Internet Connection

Mini Project Report ONLINE SHOPPING SYSTEM

the intro for RPG programmers Making mobile app development easier... of KrengelTech by Aaron Bartell

Embedding a Data View dynamic report into an existing web-page

WebView addjavascriptinterface Remote Code Execution 23/09/2013

Intell-a-Keeper Reporting System Technical Programming Guide. Tracking your Bookings without going Nuts!

CMSC434 TUTORIAL #3 HTML CSS JavaScript Jquery Ajax + Google AppEngine Mobile WebApp HTML5

How to develop your own app

Visualizing a Neo4j Graph Database with KeyLines

Website Login Integration

CSE476 Mobile Application Development. Yard. Doç. Dr. Tacha Serif Department of Computer Engineering Yeditepe University

Cisco Adaptive Security Appliance (ASA) Web VPN Portal Customization: Solution Brief

MASTERTAG DEVELOPER GUIDE

Performance Testing for Ajax Applications

A Case Study of an Android* Client App Using Cloud-Based Alert Service

Setting up an Apache Server in Conjunction with the SAP Sybase OData Server

Attacks on WebView in the Android System

Slide.Show Quick Start Guide

WIRIS quizzes web services Getting started with PHP and Java

XSS Lightsabre techniques. using Hackvertor

Developing Android Apps for BlackBerry 10. JAM854 Mike Zhou- Developer Evangelist, APAC Nov 30, 2012

Finding XSS in Real World

Android Environment SDK

Developing Android Apps for BlackBerry 10. JAM 354 Matthew Whiteman - Product Manager February 6, 2013

Using Extensions or Cordova Plugins in your RhoMobile Application Darryn

HTTPS hg clone plugin library SSH hg clone plugin library

Mobile Application Development

Xamarin.Forms. Hands On

The purpose of jquery is to make it much easier to use JavaScript on your website.

Visualizing an OrientDB Graph Database with KeyLines

Advertiser Campaign SDK Your How-to Guide

Login with Amazon Getting Started Guide for Android. Version 2.0

Login with Amazon. Getting Started Guide for Websites. Version 1.0

An Android-based Instant Message Application

Magento 1.4 Theming Cookbook

Web Development 1 A4 Project Description Web Architecture

Web Server Lite. Web Server Software User s Manual

Collections.sort(population); // Método de ordenamiento

Android Framework. How to use and extend it

Android Environment SDK

jquery Programming Cookbook jquery Programming Cookbook

PLAYER DEVELOPER GUIDE

Mocean Android SDK Developer Guide

How to code, test, and validate a web page

Android Studio Application Development

Dashboard Skin Tutorial. For ETS2 HTML5 Mobile Dashboard v3.0.2

IBM Tealeaf CX Mobile Android Logging Framework Version 9 Release 0.1 December 4, IBM Tealeaf CX Mobile Android Logging Framework Guide

Security starts in the head(er)

Last week we talked about creating your own tags: div tags and span tags. A div tag goes around other tags, e.g.,:

How to build your first Android Application in Windows

Timeline for Microsoft Dynamics CRM

Portability Study of Android and ios

App Development for Smart Devices. Lec #4: Services and Broadcast Receivers Try It Out

JQUERY - EFFECTS. Showing and Hiding elements. Syntax. Example

Introduction to NaviGenie SDK Client API for Android

Building Rich Internet Applications with PHP and Zend Framework

Sensors & Motion Sensors in Android platform. Minh H Dang CS286 Spring 2013

Lecture 1 Introduction to Android

MAGENTO THEME SHOE STORE

AdFalcon Android SDK Developer's Guide. AdFalcon Mobile Ad Network Product of Noqoush Mobile Media Group

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

Obsoleted chapter from The Busy Coder's Guide to Advanced Android Development

Chapter 2 Getting Started

Android App Development. Rameel Sethi

Sample HP OO Web Application

Dynamic Web Pages With The Embedded Web Server. The Digi-Geek s AJAX Workbook

Android Development. 吳 俊 興 國 立 高 雄 大 學 資 訊 工 程 學 系

Abusing HTML5. DEF CON 19 Ming Chow Lecturer, Department of Computer Science TuCs University Medford, MA

AJAX and JSON Lessons Learned. Jim Riecken, Senior Software Engineer, Blackboard Inc.

Hello World. by Elliot Khazon

Working with Indicee Elements

Programming Autodesk PLM 360 Using REST. Doug Redmond Software Engineer, Autodesk

RESTful web applications with Apache Sling

Interspire Website Publisher Developer Documentation. Template Customization Guide

BASICS OF WEB DESIGN CHAPTER 2 HTML BASICS KEY CONCEPTS COPYRIGHT 2013 TERRY ANN MORRIS, ED.D

Mobile App Sensor Documentation (English Version)

Client-side Web Engineering From HTML to AJAX

2- Forms and JavaScript Course: Developing web- based applica<ons

Network Traffic based Application Identification Demonstrator (Net AI) GUI. Kenny Nguyen

Guide to Integrate ADSelfService Plus with Outlook Web App

WebSocket Server. To understand the Wakanda Server side WebSocket support, it is important to identify the different parts and how they interact:

Consuming a Web Service(SOAP and RESTful) in Java. Cheat Sheet For Consuming Services in Java

SiteWit JavaScript v3 Documentation

Transcription:

Adding HTML5 to your Android applications Martin Gunnarsson & Pär Sikö

Martin Gunnarsson Mobility expert, Axis Communications Øredev Program Committee member JavaOne Rock Star Beer aficionado @gunnarsson

Pär Sikö I m the poor guy who has to live with all the stupid stuff that Martin does

Objective

Demo

What we need to learn Loading a web page Under the hood Communication Android Javascript Javascript Android Modifying web content Debugging Error handling

Loading a web page

Loading a web page public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); WebView webview = new WebView(this); webview.loadurl("http://www.example.com"); } setcontentview(webview);

WTF?

Enable internet connection <uses-permission android:name="android.permission.internet" />

Loading a web page public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); WebView webview = new WebView(this); webview.loadurl("file:///android_asset/page.html"); } setcontentview(webview);

Loading a web page public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); WebView webview = new WebView(this); String text = "<html><body><b>i wish I was surfing in Hawaii</b></body></html>"; webview.loaddata(text, "text/html", null); } setcontentview(webview);

Under the hood

The web view WebView

The web view WebView WebSettings

The web view WebViewClient WebView WebSettings

The web view WebViewClient WebChromeClient WebView WebSettings

WebView public void goback(); public String geturl(); WebView public String gettitle(); public void loadurl(string url); public void reload();...

WebSettings WebSettings settings = webview.getsettings(); // Disable plugins settings.setpluginstate(pluginstate.off); WebView WebSettings // Configure cache settings.setappcacheenabled(true); settings.setappcachemaxsize(1000 * 1000 * 1); // Handle zoom controls settings.setdefaultzoom(zoomdensity.far); settings.setbuiltinzoomcontrols(true); settings.setdisplayzoomcontrols(true);

WebViewClient WebViewClient WebView public void onloadresource(...) public void onreceivederror(...) public void onpagefinished(...) public boolean shouldoverrideurlloading(...)...

WebChromeClient WebChromeClient WebView public boolean onjsalert(...); public void onprogresschanged(...); public void getvisitedhistory(...);...

The web view WebViewClient WebChromeClient WebView WebSettings

Communication Android Javascript

Executing Javascript Android WebView webview = new WebView(this); webview.getsettings().setjavascriptenabled(true); webview.loadurl("javascript:somefunction()");

Executing Javascript HTML <h1 id="head">headline</h1> Android WebView webview = new WebView(this); webview.getsettings().setjavascriptenabled(true); webview.loadurl("javascript:document.getelementbyid('head').innerhtml='hello!';");

Flipping images Card Back Front

Flipping images

Flipping images <div id="card_1" class="card"> <img id="1_front" class="front" /> <img id="1_back" class="back" /> </div> HTML

Flipping images <div id="card_1" class="card"> <img id="1_front" class="front" /> <img id="1_back" class="back" /> </div>.card { -webkit-transition: -webkit-transform 2s; -webkit-transform-style: preserve-3d; } HTML CSS.card > img { -webkit-backface-visibility: hidden; }.card > img.back { -webkit-transform: rotatex(180deg); }

Flipping images function changeimage(source, index, degrees) { var card = document.getelementbyid('card_' + index); var side = (degrees % 360 == 0)? '_front' : '_back'; var image = document.getelementbyid(index + side); Javascript } image.src = source; card.style.webkittransform = "rotatex(" + degrees + "deg)";

Flipping images function changeimage(source, index, degrees) { var card = document.getelementbyid('card_' + index); var side = (degrees % 360 == 0)? '_front' : '_back'; var image = document.getelementbyid(index + side); Javascript } image.src = source; card.style.webkittransform = "rotatex(" + degrees + "deg)"; Android webview.loadurl("javascript:changeimage(url, 2, 180)");

Communication Javascript Android

Javascript Android Android JavaScript

Javascript Android Android JavaScript

Javascript Android Android JavaScript

Javascript Android Android JavaScript

Javascript Android Android JavaScript

Javascript Android Android JavaScript

Javascript Android class Callback { Android } public void openimage(string url) { Intent showimage = new Intent(); showimage.setclass(context, ImageActivity.class); startactivity(showimage); }

Javascript Android class Callback { Android } public void openimage(string url) { Intent showimage = new Intent(); showimage.setclass(context, ImageActivity.class); startactivity(showimage); } webview.addjavascriptinterface(new Callback(), "android"); Android

Opening images function openimage(index) { var card = document.getelementbyid('card_' + index); android.openimage(card.currentimage.src); } Javascript

Opening images function openimage(index) { var card = document.getelementbyid('card_' + index); android.openimage(card.currentimage.src); } Javascript <div id="card_1" class="card" onclick="openimage(1)" > <img id="1_front" class="front" /> <img id="1_back" class="back" /> </div> HTML

Modifying web content

JSON

Modifying web content String line; StringBuilder builder = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); while ((line = reader.readline())!= null) { builder.append(line); } JSONObject jsobj = new JSONObject(builder.toString()); JSONObject item = jsobj.getjsonobject("entry");... Android

Modifying web content <html> <head>...</head> <body> HTML <h1 id="headline"></h1> <p id="snippet"></p> <a id="link" href="">read more</a> </body> </html>

Modifying web content String headline = item.getstring("title"); webview.loadurl("javascript: document.getelementbyid('headline').innerhtml = '" + title + "'"); Android

Debugging

Debugging Javascript

Debugging console.error('oh noes!'); Javascript

Debugging console.error('oh noes!'); Javascript 11-13 16:24:14.147: E/Web Console(23749): Oh noes! at file:///android_asset/file.html:5

Debugging console.error('oh noes!'); Javascript 11-13 16:24:14.147: E/Web Console(23749): Oh noes! at file:///android_asset/file.html:5 // WebChromeClient Android @Override public boolean onconsolemessage(consolemessage message) { // Handle message }

Weinre

Weinre

Weinre

Demo

Error handling

Error handling

Error handling

Error handling

Error handling // WebViewClient Android @Override public boolean shouldoverrideurlloading(webview view, String url) { // Check if URL is the one we expect } return true;

Error handling // WebViewClient Android @Override public boolean shouldoverrideurlloading(webview view, String url) { // Check if URL is the one we expect } return true; @Override public void onreceivederror(webview view, int code, String desc, String url) { webview.loadurl("file:///android_asset/error_page.html"); } Android

Threading issues UI thread Callback runonuithread

Threading issues Android runonuithread(new Runnable() { @Override public void run() { // Do stuff } });

To sum things up...

Q&A

Thank you!