• No results found

Android Framework. How to use and extend it

N/A
N/A
Protected

Academic year: 2021

Share "Android Framework. How to use and extend it"

Copied!
24
0
0

Loading.... (view fulltext now)

Full text

(1)

Android Framework

(2)

Alberto Panizzo 2

Lecture 3: UI and Resources

• Android UI

• Resources = {XML, Raw data}

○ Strings, Drawables, Layouts, Sound files ..

• UI definition: Layout example • Elements of advanced UI

• Use Android prebuilt resources

• How to enhance application Portability:

○ Localization

(3)

Alberto Panizzo 3

Lab 2: Developer's tools

SDK related: android, emulator • THE developer's tool adb

• Debugging: logcat, ddms, traceview

• Graphical: draw9patch, hierarchyviewer, layoutopt

(4)

Alberto Panizzo 4

android

• If you have already installed the Android SDK, you are also familiar with the android graphical tool:

○ Manage installed “packages”, components of the

Android SDK

○ Manage Android Virtual Devices

• The shell command allow you also to manage Android

Projects:

$ android create project -n <name> -t <targetID> -k <package_name> \ -a <default_activity_name> -p <root_path>

$ android list targets

$ android update project [-n <name>] -p <root_path> \ [-l <library_path>] [-t <targetID>]

(5)

Alberto Panizzo 5

emulator

• Execute an Android Virtual Device inside qemu • The only reqired parameter is: -avd <name>

• Few interesting options:

What is happening?

-show-kernel display kernel messages

-shell enable root shell on current terminal -prop <name>=<value> set system property on boot

Execute custom images:

-sysdir <dir> search for system disk images in <dir>

-system <file> read initial system image from <file>

-datadir <dir> write user data into <dir>

-kernel <file> use specific emulated kernel

-ramdisk <file> ramdisk image (default <system>/ramdisk.img) Peripheral connection:

-radio <device> redirect radio modem interface to char device -gps <device> redirect NMEA GPS to character device

(6)

Alberto Panizzo 6

Lab 2: Developer's tools

• SDK related: android, emulatorTHE developer's tool adbadb

• Debugging: logcat, ddms, traceview

(7)

Alberto Panizzo 7

adb

• Android Debug Bridge implements a custom protocol to communicate with the device (emulator/real device) and achieve several functionalities

$ adb [-d|-e|-s <serialNumber>] <command> • List devices

$ adb devices

List of devices attached emulator-5554 device 343256F8A32400EC device -e -d -s $ adb kill-server $ adb devices

(8)

Alberto Panizzo 8

adb

• File management:

$ adb push <local> <remote> $ adb pull <remote> [<local>]

• Package management:

$ adb shell [command]

• Run an interactive shell or execute a command:

$ adb install [-r] [-s] <file> # -r reinstall -s on sd-card $ adb uninstall [-k] <package_name> # -k keep data

$ adb logcat

• Shortcut to logcat:

$ adb connect [host[:port]] # If no host is specified it take # $ADBHOST otherwise localhost

(9)

Alberto Panizzo 9

Lab 2: Developer's tools

• SDK related: android, emulator • THE developer's tool adb

Debugging: logcat, ddms, traceview

• Graphical: draw9patch, hierarchyviewer, layoutopt

(10)

Alberto Panizzo 10

Logging

Java interface to write into the system log buffer:

[2]

import android.util.Log;

public class AnActivity extends Activity {

Private static String TAG = "MyTag";

public void f() {

Log.e(TAG, "Error"); Log.w(TAG, "Warning"); Log.i(TAG, "Info"); Log.d(TAG, "Debug");

Log.v(TAG, "VerboseDebug"); }

(11)

Alberto Panizzo 11

logcat

Tool running on the device which shows the system logs $ adb shell logcat [options] [filterspecs]

$ adb logcat [options] [filterspecs] Results:

$ adb logcat

I/DEBUG ( 31): debuggerd: Jun 30 2010 13:59:20 D/qemud ( 38): entering main loop

I/Vold ( 29): Vold 2.1 (the revenge) firing up I/Netd ( 30): Netd 1.0 starting

W/Vold ( 29): No UMS switch available

D/qemud ( 38): fdhandler_accept_event: accepting on fd 10 D/qemud ( 38): created client 0xe078 listening on fd 8

D/qemud ( 38): client_fd_receive: attempting registration for service 'boot-properties'

D/qemud ( 38): client_fd_receive: -> received channel id 1

D/qemud ( 38): client_registration: registration succeeded for client 1 ...

(12)

Alberto Panizzo 12

logcat

Results:

<level>/<Tag> (<pid>): Message

level: E/W/I/D/V (Error/Warning/Info/Debug/Verbose) tag: Component specific log tag

pid: Process ID hosting the component message: Log message

Useful options:

-c Clear the log cache

-d Dump the log cache and exit

-b Select the buffer: 'main'(def), 'events', 'radio' You can use filterspecs or egrep:

(13)

Alberto Panizzo 13

ddms

(14)

Alberto Panizzo 14

ddms

• Key features:

○ Embeds logcat output (colored/full functional) ○ Device Screenshots/File manager

Device → Screen capture..

○ Easy interface to dump system info

Device → Dump*

○ On-demand start/stop profiling on certain processes ○ Embeds in Eclipse through the ADT plugin

(15)

Alberto Panizzo 15

(16)

Alberto Panizzo 16

Lab 2: Developer's tools

• SDK related: android, emulator • THE developer's tool adb

• Debugging: logcat, ddms, traceview

(17)

Alberto Panizzo 17

draw9patch

(18)

Alberto Panizzo 18

hierarchyviewer

• Analyse the layout hierarchy of the current activity running on the emulator (eng or userdebug build)

(19)

Alberto Panizzo 19

hierarchyviewer

(20)

Alberto Panizzo 20

layoutopt

$ layoutopt samples/ samples/compound.xml

   7:23 The root-level <FrameLayout/> can be replaced with <merge/>    11:21 This LinearLayout layout or its FrameLayout parent is useless samples/simple.xml

   7:7 The root-level <FrameLayout/> can be replaced with <merge/> samples/too_deep.xml

   -1:-1 This layout has too many nested layouts: 13 levels, it should have <= 10!    20:81 This LinearLayout layout or its LinearLayout parent is useless

   24:79 This LinearLayout layout or its LinearLayout parent is useless    28:77 This LinearLayout layout or its LinearLayout parent is useless    32:75 This LinearLayout layout or its LinearLayout parent is useless    36:73 This LinearLayout layout or its LinearLayout parent is useless samples/too_many.xml

   7:413 The root-level <FrameLayout/> can be replaced with <merge/>

   -1:-1 This layout has too many views: 81 views, it should have <= 80! samples/useless.xml

   7:19 The root-level <FrameLayout/> can be replaced with <merge/>    11:17 This LinearLayout layout or its FrameLayout parent is useless

(21)

Alberto Panizzo 21

Notes on past exercise

Clean the code

○ Remove all useless things

○ Do not show me that you copied some examples..

Coding style

○ Indent with spaces or tabs? Be consistent

○ Comment the code to make me understand that you

have understood

○ Localize as much as possible (at least all XML)

Be sure it's working

(22)

Alberto Panizzo 22

Notes on past exercise

The solution was to create a BroadcastReceiver and

register it (within the AndroidManifest.xml) to receive the action:

android.intent.action.BOOT_COMPLETED Because this action is sent as broadcast.

Within the onReceive() the chosen Activity will be started using startActivity() with the correct intent.

The application must acquire the following permission: android.permission.RECEIVE_BOOT_COMPLETED

(23)

Alberto Panizzo 23

Exercise

Develop an Android application which match the shown layout.

This application must be able to switch the picture shown among all the

available pictures set using the arrows.

Download all the resources needed from the course website:

(24)

Alberto Panizzo 24

Links of interest

[1] http://developer.android.com/guide/developing/tools/index.html [2] http://developer.android.com/guide/developing/debugging/debugging-log.html [3] http://developer.android.com/guide/developing/debugging/debugging-tracing.html [4] http://developer.android.com/guide/developing/debugging/debugging-ui.html

References

Related documents

“ the seven words of our LORD on

The effects of the hydrography on zooplankton dis- tributions can easily be seen: zooplankton biomass was high where cold surface water was present nearshore, over the wide Heceta

The functionally relevant, non-kissing tRNA sequences selected to bind AM1A (Group II) had binding affinities and sequence specificity rivaling that seen in the wild-type tRNA

To address these questions, the following goals were set: (a) to reproduce field explosions pertaining to primary blast injury as accurate as possible in a controlled

Switching your payroll and all the processes along with it from one provider to the next: it’s the one thing people in the payroll world tend to fear the most.. If you’ve

s-process p-process Mass known Half-life known

+CBEDGF HJIKFLI ?© MKNGNGOP MJQMJR S0ODTF VUXWU... ¥¦ü!ޘ§XàKã9ðïòñfáXubÝá˜ê^áno¿ñ1ÝpiUñbâ6Þ ê‚ñbâ ðÜ$øeë3Bëm%Þx

Security-Assessment.com discovered that it is possible to leverage Cross Site Request Forgery (XSRF) attacks with the potential of leaking cookie, basic and