Designing Apps Using The WebView Control

Similar documents
Android The WebKit Browser

Advanced. Android. Development. The Busy Coder's Guide to. Version 1.6 Updated for Android 2.2! Mark L. Murphy COMMONSWARE

1. Location Services. 1.1 GPS Location. 1. Create the Android application with the following attributes. Application Name: MyLocation

Press project on the left toolbar if it doesn t show an overview of the app yet.

Tłumaczenie i adaptacja materiałów: dr Tomasz Xięski. Na podstawie prezentacji udostępnionych przez Victor Matos, Cleveland State University.

Android. YÉÇàá. Victor Matos Cleveland State University

Upcoming Assignments Quiz today Web Ad due Monday, February 22 Lab 5 due Wednesday, February 24 Alpha Version due Friday, February 26

8/30/15 MOBILE COMPUTING. CSE 40814/60814 Fall How many of you. have implemented a command-line user interface?

Mobile Programming Lecture 9. Bound Services, Location, Sensors, IntentFilter

LifeStreet Media Android Publisher SDK Integration Guide

Android Data Storage

Hybrid Apps Combining HTML5 + JAVASCRIPT + ANDROID

Vienos veiklos būsena. Theory

CS 234/334 Lab 1: Android Jump Start

register/unregister for Intent to be activated if device is within a specific distance of of given lat/long

Mobila applikationer och trådlösa nät

Android Security Lab WS 2013/14 Lab 2: Android Permission System

Learn about Android Content Providers and SQLite

Embedded Systems Programming - PA8001

App Development for Smart Devices. Lec #18: Advanced Topics

Real-Time Embedded Systems

Android Using Menus. Victor Matos Cleveland State University

App Development for Smart Devices. Lec #7: Audio, Video & Telephony Try It Out

Android Help. Section 8. Eric Xiao

Android Apps Development for Mobile Game Lesson 5

Computer Science E-76 Building Mobile Applications

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

Android Workshop: Model View Controller ( MVC):

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters

Figure 2.10 demonstrates the creation of a new project named Chapter2 using the wizard.

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

Saving application preferences

DEPARTMENT OF COMPUTER SCIENCE THE UNIVERSITY OF HONG KONG. CSIS0801 Final Year Project. WhozzUp - A Novel Big Data App for HK (Individual Report)

Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen

Basic UI elements: Android Buttons (Basics) Marco Ronchetti Università degli Studi di Trento

COMP4521 EMBEDDED SYSTEMS SOFTWARE

Loca%on Support in Android. COMP 355 (Muppala) Location Services and Maps 1

Android Programming วรเศรษฐ ส วรรณ ก.

Android Basics. - Bhaumik Shukla Android Application STEALTH FLASH

Agenda. The Android GUI Framework Introduction Anatomy A real word example Life cycle Findings

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Android for Java Developers Dr. Markus Schmall, Jochen Hiller

Android Beginners Workshop

A Tour of Android. and some of it s APIs. Bryan Noll

Xin Pan. CSCI Fall

Manifest.xml. Activity.java

LECTURE NOTES OF APPLICATION ACTIVITIES

Notification mechanism

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

Mensch-Maschine-Interaktion 2 Übung 12

Thread. A Thread is a concurrent unit of execution. The thread has its own call stack for methods being invoked, their arguments and local variables.

Practical 1.ListView example

UNDERSTANDING ACTIVITIES

android:orientation="horizontal" android:layout_margintop="30dp"> <Button android:text="button2"

This lecture. The BrowserIntent Example (cont d)

Getting Started ArcGIS Runtime SDK for Android. Andy

External Services. CSE 5236: Mobile Application Development Course Coordinator: Dr. Rajiv Ramnath Instructor: Adam C. Champion

Android Using Menus. Victor Matos Cleveland State University

Solving an Android Threading Problem

Mobila applikationer och trådlösa nät, HI1033, HT2012

Simple Currency Converter

Android Services. Victor Matos Cleveland State University. Services

App Development for Smart Devices. Lec #9: Advanced Topics

Introduction To Android

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

Intents. Your first app assignment

Database Development In Android Applications

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Android Development Tutorial. Yi Huang

Applications. Marco Ronchetti Università degli Studi di Trento

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

Developed and taught by well-known Contact author and developer. At public for details venues or onsite at your location.

IPN-ESCOM Application Development for Mobile Devices. Extraordinary. A Web service, invoking the SOAP protocol, in an Android application.

A Crash Course to Android Mobile Platform

Starting Another Activity Preferences

Action Bar. (c) 2010 Haim Michael. All Rights Reserv ed.

GATAV 5. Animations Using a Game Loop

CS 4330/5390: Mobile Application Development Exam 1

Object-Oriented Databases Object-Relational Mappings and Frameworks. Alexandre de Spindler Department of Computer Science

Project 3 CIS 408 Internet Computing

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

Linkify Documentation

CS 528 Mobile and Ubiquitous Computing Lecture 3: Android UI, WebView, Android Activity Lifecycle Emmanuel Agu

10.1 Introduction. Higher Level Processing. Word Recogniton Model. Text Output. Voice Signals. Spoken Words. Syntax, Semantics, Pragmatics

CS 4518 Mobile and Ubiquitous Computing Lecture 4: WebView (Part 2) Emmanuel Agu

Android Application Model I. CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr.

Android Specifics. Jonathan Diehl (Informatik 10) Hendrik Thüs (Informatik 9)

Terms: MediaPlayer, VideoView, MediaController,

Preview from Notesale.co.uk Page 6 of 337

Software Practice 3 Before we start Today s lecture Today s Task Team organization

Advanced Android Development

ELET4133: Embedded Systems. Topic 15 Sensors

Have a development environment in 256 or 255 Be familiar with the application lifecycle

App Development for Smart Devices. Lec #8: Android Sensors

Mobile Application Development - Android

Tutorials. Android. Programming. Version 2.9. Mark L. Murphy. for Android 2.2 COMMONSWARE

Internet of Things Sensors - Part 1 Location Services

Android Application Model I

EMBEDDED SYSTEMS PROGRAMMING Application Basics

HTML 5 and CSS 3, Illustrated Complete. Unit L: Programming Web Pages with JavaScript

Transcription:

28 Designing Apps Using The Control Victor Matos Cleveland State University Notes are based on: Android Developers http://developer.android.com/index.html The Busy Coder's Guide to Advanced Android Development by Mark L. Murphy. Ed. CommonsWare.

28. Android - An interesting class of Android applications could be created by combining JavaScripted HTML pages and the control. The widget is typically used by the WebKit browser engine to display pages accessed from the Internet. However, you could also display local HTML pages on a. The Android application interacts with the through user created objects which are passed back and forth between the and the Android Activities. 2

28. Android - Architecture: HTML & Javascript pages + Android Activities Javascript uses custom object UI designed using HTML 3

28. Android - What is New? The addjavascriptinterface() method on allows you to pass a Java object from Android activities to the, exposing its methods. The various getters/setters methods defined in the object allow data exchange between the HTML-UI and Android activities. In addition Javascript events (clicking buttons, making selections, filling boxes, etc) could be used to react to the user requests and correspondingly pass data from the UI to the Android classes. 4

28. Android - Example: How is the HTML-Android exchange done? In this example the current coordinates (latitude, longitude) of the device will be displayed on the screen. Assume: 1. The application s UI consists of a called browser, also in the Assets folder the developer has introduced a Javascripted web-page called geoweb2.html. 2. The Android application has defined a custom object called locater with get/set methods exposing the *lat, lon] values. 5

28. Android - Example: How is the HTML-Android exchange done? (continuation) The following statements are held in the Android main activity browser.getsettings().setjavascriptenabled(true); browser.addjavascriptinterface(new Locater(), "locater"); browser.loadurl("file:///android_asset/geoweb2.html"); 1. The first allows the use of Javascript on the 2. The second statement passes the object type and name. 3. The last stat. loads the local HTML page on the. 6

28. Android - Example: How does the HTML page uses the object? (continuation) The HTML page could manage the locater object through its accessors such as in the following lines: document.getelementbyid("lat").innerhtml=locater.getlatitude(); locater.setaddress ( document.getelementbyid( address").innerhtml ); Locater.doSomething(); Where lat (and address ) are HTML placeholders defined using <span id="lat"> (unknown) </span> 7

28. Android - Example: How does the HTML page uses the object? (continuation) Consider the JavaScript expression: document.getelementbyid("lat").innerhtml The innerhtml property is used along with getelementbyid within your JavaScript code to refer to an HTML element and change its contents. innerhtml allows you to change the page's content without refreshing the page (this makes your website feel quicker and more responsive to user input). The innerhtml property is not actually part of the official DOM specification, despite this, it is supported in all major browsers including Android s WebKit. 8

28. Android - Complete Example: Get Location Show on a Local main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > < android:id="@+id/browser" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout> Add to the Manifest <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_fine_location" /> 9

28. Android - Complete Example: Get Location Show on a Local assets: geoweb2.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <title>android GeoWebOne Demo</title> <script language="javascript"> function whereami() { document.getelementbyid("lat").innerhtml=locater.getlatitude(); document.getelementbyid("lon").innerhtml=locater.getlongitude(); var spy = "Spy data coming from HTML\n" + document.getelementbyid("lat").innerhtml + "\n" + document.getelementbyid("lon").innerhtml; locater.setvalue(spy); function whereami2() { var spy = "Spy data coming from HTML\n" + document.getelementbyid("lat").innerhtml + "\n" + document.getelementbyid("lon").innerhtml; locater.htmlpassing2android(spy); </script> </head> <body> </body> </html> <p>you are at</p> <table border="1" cellspacing="1" cellpadding="1"> <tr> <td bgcolor="#ffffcc">latitude</td> <td><span id="lat">(unknown)</span></td> </tr> <tr> <td bgcolor="#ffffcc">longitude</td> <td><span id="lon">(unknown)</span></td> </tr> </table> <p><a onclick="whereami()"><u>click to Update Location</u></a></p> <p> <input type="button" onclick= "whereami2()" value="spying"> 10

28. Android - Complete Example: Get Location Show on a Local package ucr.geowebtwo; // code based on M. Murphy - CommonsWare, V. Matos import android.app.activity; import android.content.context; import android.os.bundle; import android.location.location; import android.location.locationlistener; import android.location.locationmanager; import android.webkit.; import android.widget.toast; public class GeoWebTwo extends Activity { private String PROVIDER = "gps"; private browser; private LocationManager mylocationmanager = null; Locater locater = new Locater(); @Override public void oncreate(bundle icicle) { super.oncreate(icicle); setcontentview(r.layout.main); browser = () findviewbyid(r.id.browser); // request GPS location services mylocationmanager = (LocationManager) getsystemservice(context.location_service); // enable JavaScript, pass user's object, load page browser.getsettings().setjavascriptenabled(true); browser.addjavascriptinterface(locater, "locater"); browser.loadurl("file:///android_asset/geoweb2.html"); 11

28. Android - Complete Example: Get Location Show on a Local @Override public void onresume() { super.onresume(); mylocationmanager.requestlocationupdates( PROVIDER, 3000, 10,onLocationChange); @Override public void onpause() { super.onpause(); mylocationmanager.removeupdates(onlocationchange); // ---------------------------------------------------------------------- LocationListener onlocationchange = new LocationListener() { // passing the actual values of lat & lon. Waiting for the function // whereami(...) to drop the arguments into HTML placeholders public void onlocationchanged(location location) { StringBuilder buf = new StringBuilder("javascript:whereami("); buf.append(string.valueof(location.getlatitude())); buf.append(","); buf.append(string.valueof(location.getlongitude())); buf.append(")"); browser.loadurl(buf.tostring()); public void onproviderdisabled(string provider) { // required for interface, not used 12

28. Android - Complete Example: Get Location Show on a Local public void onproviderenabled(string provider) { // required for interface, not used public void onstatuschanged(string provider, int status, Bundle extras) { // required for interface, not used ; 13

28. Android - Complete Example: Get Location Show on a Local // /////////////////////////////////////////////////////////////// public class Locater { public String spy = ""; public double getlatitude() { Location loc = mylocationmanager.getlastknownlocation(provider); if (loc == null) { return (0); return (loc.getlatitude()); public double getlongitude() { Location loc = mylocationmanager.getlastknownlocation(provider); if (loc == null) { return (0); return (loc.getlongitude()); public void htmlpassing2android(string datafromhtml) { // changes to the HTML place-holders lat & lon can be seen here. // There is an HTML button that when clicked calls this Android method. spy = datafromhtml; Toast.makeText(getApplicationContext(), spy, 1).show(); // Locater // GeoWebTwo Last 14

28. Android - Questions Zipped code: 15