Mbile/Wireless Systems Andrid UI Yanyan Zhuang Department f Cmputer Science http://www.cs.uccs.edu/~yzhuang UC. Clrad Springs
cat annunce.txt_ Assignment 2 will be psted sn Due after midterm I will be away next Mnday Dr. Chw s guest lecture Midterm date March 20 2
Andrid Andrid IDE A mbile perating system develped by Ggle Based n Linux kernel and designed primarily fr smartphnes and tablets Andrid studi https://develper.andrid.cm/studi/index.html Andrid API Java as the prgramming language 3
Andrid A fast evlving OS: Dashbards } https://develper.andrid.cm/abut/dashbards/index.html 4
Andrid Specify Minimum and Target API Levels AndridManifest.xml <manifest xmlns:andrid="http://schemas.andrid.cm/apk/res/andrid"... > <uses-sdk andrid:minsdkversin="4" andrid:targetsdkversin="15" />... </manifest> Check System Versin at Runtime if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {... } 5
Running Andrid Cde Run cde n simulatr Run cde n a real device N license needed On Andrid 4.2 and newer, Develper ptins is hidden by default Need t enable develper ptin and USB debugging (Galaxy example): this is all yu need t d } G t Settings > Mre > Abut Device, scrll dwn t Build Number } Tap it repeatedly (7 times) } See the Develper ptins menu under Settings > check USB debugging 6
Andrid Debug Bridge (ADB) Andrid Debug Bridge (adb) Cmmand-line tl t yu cmmunicate with a device Installing/debugging apps, and a Unix shell A client-server prgram with three cmpnents A client runs n develpment machine } Invke a client by issuing `adb` A daemn (adbd) runs cmmands n a device } Runs as a backgrund prcess n device A server manages cmmunicatin between client and daemn } Runs as a backgrund prcess n develpment machine 7
Andrid Debug Bridge (ADB) T install adb (Mac OS example) Install hmebrew } ruby -e "$(curl -fssl https://raw.githubusercntent.cm/hmebrew/install/master/install)" Install adb } brew install andrid-platfrm-tls Start adb } $ adb devices List f devices attached 07f105740c8cad3f device } $ adb shell 8
Andrid App Structure Prject files By default, Andrid Studi displays files in Andrid view manifests } AndridManifest.xml file java } Java surce cde, separated by package names res } All nn-cde resurces XML layuts, UI strings, images 9
Andrid App Structure Prject files Prject view } Actual file structure f the prject Including all files hidden frm Andrid view Lks fairly cmplex nw 10
Create an Andrid Prject Start a new Andrid Studi prject, r File à New Prject Applicatin Name: "MyFirstApp" Cmpany Dmain: "example.cm" Target Andrid Devices: keep the default values We will get back t this later Add an Activity t Mbile: select Empty Activity Custmize the Activity: keep default values à Finish Takes a lng time t Finish 11
Create an Andrid Prject In Andrid view app > java > cm.example.myfirstapp > MainActivity.java } Main activity (entry pint fr yur app) } When build and run an app, system launches an instance f this Activity and lads its layut app > res > layut > activity_main.xml } Defines the layut fr the activity's UI app > manifests > AndridManifest.xml } Describes the characteristics f the app and defines each f its cmpnents Gradle Scripts > build.gradle } 2 files with this name: ne fr the prject and ne fr the "app" mdule } Mstly wrk with mdule's build.gradle file t cnfigure hw the Gradle tls cmpile and build yur app 12
Running the App On a real device Windws may need USB driver fr the device } https://develper.andrid.cm/studi/run/em-usb.html Enable USB debugging (earlier) On a simulatr Create an Andrid Virtual Device (AVD) definitin } Tls > Andrid > AVD Manager } Create Virtual Device > Select Hardware } System Image > Dwnlad (ne f the recmmended system images) Takes a lng time again 13
Building Simple User Interface UI is built w/ a hierarchy f layuts (ViewGrup bjects) & widgets (View bjects) Layuts are invisible cntainers that cntrl hw its child views are psitined Widgets are UI cmpnents like buttns and text bxes 14
Building Simple User Interface Building UI XML Layut Editr 15
Building Simple User Interface Cmpnent Tree windw Shws the layut's hierarchy f views CnstraintLayut A layut that defines the psitin fr each view based n cnstraints t sibling views and the parent layut 16
Building Simple User Interface Change UI strings res > values > strings.xml 17
Start Activity Add a methd in MainActivity.java that's called by the buttn Intent } An bject that prvides runtime binding between separate cmpnents, such as tw activities } The Intent represents an app s "intent t d smething" putextra() } An Intent can carry data types as key-value pairs called extras startactivity() 18
Add up Navigatin Navigatin return t the lgical parent screen in app hierarchy Declare which activity is the lgical parent in AndridManifest.xml <activity andrid:name=".displaymessageactivity" andrid:parentactivityname=".mainactivity" > <!-- The meta-data tag is required if yu supprt API level 15 and lwer --> <meta-data andrid:name="andrid.supprt.parent_activity" andrid:value=".mainactivity" /> </activity> 19