26
Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from android sdk

Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Embed Size (px)

Citation preview

Page 1: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Bruce Scharlau, University of Aberdeen, 2010

Android UI, and Networking

Mobile Computing

Based on android-sdk_2.2

Unless otherwise stated, images are from android sdk

Page 2: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Proxy issues while in eduroamMay need page as intermediary for accessing

other services with emulator in Java ME or Android

Bruce Scharlau, University of Aberdeen, 2010

PHP/JSP page

Desired web service

web form can be configured to use proxy

Page 3: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Can do most networking on Android

Bluetooth only on 2.0 onwards – look at that later.

Bruce Scharlau, University of Aberdeen, 2010

Page 4: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Bruce Scharlau, University of Aberdeen, 2010

Android has many components

Page 5: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

All layouts are hierarchical

Bruce Scharlau, University of Aberdeen, 2010

Page 6: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

All screens

are derived

from view

Bruce Scharlau, University of Aberdeen, 2010Source: unlocking android, p 71

Page 7: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Hierarchical views can include similar groups

Bruce Scharlau, University of Aberdeen, 2010

Page 8: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Children do as told in Android

Bruce Scharlau, University of Aberdeen, 2010

TextView is child of parent viewgroup and fills, or wraps content

Page 9: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

There are many types of controls in Android

Bruce Scharlau, University of Aberdeen, 2010

Page 10: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Lists can be handled via adapters and filled from xml file of values

Bruce Scharlau, University of Aberdeen, 2010

Page 11: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Table layout allows for just that with data

Bruce Scharlau, University of Aberdeen, 2010

Page 12: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Use the hierarchy viewer tool to optimize and debug interface

Bruce Scharlau, University of Aberdeen, 2010

http://developer.android.com/guide/developing/tools/hierarchy-viewer.html

Page 13: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Views are tied to activities (screens) in Android

Bruce Scharlau, University of Aberdeen, 2010

Source: unlocking android, p 60

One class per activity, and screen, which may be done as xml file

Page 14: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

One layout per activity (class)

Bruce Scharlau, University of Aberdeen, 2010

main.xml goes with AuctionStart

list.xml goes with ListItems

hit_server.xml goes with HitServer

Page 15: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Xml layout file details components

Bruce Scharlau, University of Aberdeen, 2010

Hierarchy of views as noted earlier

Page 16: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Xml layout inflated in onCreate

Bruce Scharlau, University of Aberdeen, 2010

Set value of inflated objectSet value of inflated object

INCOMPLETE CODEINCOMPLETE CODE

New view items and attached to xml valuesNew view items and attached to xml values

Page 17: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Bruce Scharlau, University of Aberdeen, 2010

Android emulator runs as ‘localhost’, ie ‘loopback’

Emulator is at 127.0.0.1 so need to call service at IP address of service to test network apps on developer machine

http://developer.android.com/guide/developing/tools/emulator.html

Page 18: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Bruce Scharlau, University of Aberdeen, 2010

Activity is one thing you can do

From fundamentals page in sdk

Page 19: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Apps move through states during lifecycle

Bruce Scharlau, University of Aberdeen, 2010Source: unlocking android, p 68

onPause is last state to preserve state and cleanup before app possibly destroyed

Page 20: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Handler class provides access to running thread for main UI

Bruce Scharlau, University of Aberdeen, 2010

Handler has Looper which contains MessageQueue that can be called and return objects to UI thread

Page 21: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Handler puts thread response into UI thread

Bruce Scharlau, University of Aberdeen, 2010Source: unlocking android, p 180

Page 22: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Method returns string from network

Bruce Scharlau, University of Aberdeen, 2010

Log output for debugging, etc

Simple method to call URL and return value

Page 23: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Might need helper calls to network

Bruce Scharlau, University of Aberdeen, 2010

Put heavy lifting work in HTTPRequestHelper so accessible to other classes

Handler waits for message and then returns

Page 24: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Parse xml response and populate Java bean instance

Bruce Scharlau, University of Aberdeen, 2010

Page 25: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Add permissions to manifest for connection and network

Bruce Scharlau, University of Aberdeen, 2010

Page 26: Bruce Scharlau, University of Aberdeen, 2010 Android UI, and Networking Mobile Computing Based on android-sdk_2.2 Unless otherwise stated, images are from

Summary

• Need to provide permissions for network in manifest

• Create tree of xml views for UI

• Can re-use xml views for different displays

Bruce Scharlau, University of Aberdeen, 2010