cs5530 mobile/wireless systems android ui · 2017-03-09 · running android code cs5530 6 ref....
Post on 25-May-2020
4 Views
Preview:
TRANSCRIPT
Ref.CN5E,NT@UW,WUSTLCS5530
CS5530Mobile/WirelessSystems
AndroidUI
YanyanZhuangDepartmentofComputerSciencehttp://www.cs.uccs.edu/~yzhuang
UC.ColoradoSprings
catannounce.txt_
Ref.CN5E,NT@UW,WUSTL2CS5530
• Assignment2willbepostedsoono Dueaftermidterm
• IwillbeawaynextMondayo Dr.Chow’sguestlecture
• Midtermdateo March20
Android…
Ref.CN5E,NT@UW,WUSTL3CS5530
• Androido A mobileoperatingsystem developedby Googleo Basedon Linuxkernel anddesignedprimarilyfor smartphones and tablets
• IDEo Androidstudiohttps://developer.android.com/studio/index.html
• AndroidAPIo Javaastheprogramminglanguage
Android…
Ref.CN5E,NT@UW,WUSTL4CS5530
• AfastevolvingOS:Dashboards} https://developer.android.com/about/dashboards/index.html
Android…
Ref.CN5E,NT@UW,WUSTL5CS5530
• SpecifyMinimumandTargetAPILevelso AndroidManifest.xml
<manifestxmlns:android="http://schemas.android.com/apk/res/android"...><uses-sdk android:minSdkVersion="4"android:targetSdkVersion="15"/>...
</manifest>
• CheckSystemVersionatRuntimeif(Build.VERSION.SDK_INT >=Build.VERSION_CODES.HONEYCOMB){
…...
}
RunningAndroidCode
Ref.CN5E,NT@UW,WUSTL6CS5530
• Runcodeonsimulator
• Runcodeonarealdeviceo Nolicenseneeded
o OnAndroid4.2andnewer, Developeroptions ishiddenbydefault
o NeedtoenabledeveloperoptionandUSBdebugging(Galaxyexample):thisisallyouneedtodo} GotoSettings>More>AboutDevice,scrolldowntoBuildNumber
} Tapitrepeatedly(7times)
} SeetheDeveloperoptionsmenuunderSettings>checkUSBdebugging
Android DebugBridge(ADB)
Ref.CN5E,NT@UW,WUSTL7CS5530
• AndroidDebugBridge(adb)o Command-linetooltoyoucommunicatewithadeviceo Installing/debuggingapps,andaUnixshell
• Aclient-serverprogramwiththreecomponentso Aclient runsondevelopmentmachine
} Invokeaclientbyissuing`adb`
o Adaemon (adbd)runscommandsonadevice} Runsasabackgroundprocessondevice
o Aservermanagescommunicationbetweenclientanddaemon} Runsasabackgroundprocessondevelopmentmachine
Android DebugBridge(ADB)
Ref.CN5E,NT@UW,WUSTL8CS5530
• Toinstalladb (MacOSexample)o Installhomebrew
} ruby-e"$(curl-fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install)"
o Installadb} brewinstallandroid-platform-tools
o Startadb} $adb devices
Listofdevicesattached
07f105740c8cad3fdevice
} $adb shell
AndroidAppStructure
Ref.CN5E,NT@UW,WUSTL9CS5530
• Projectfileso Bydefault,AndroidStudiodisplaysfilesinAndroid view
o manifests} AndroidManifest.xml file
o java} Javasourcecode,separatedbypackagenames
o res} Allnon-coderesources
¨ XMLlayouts,UIstrings,images
AndroidAppStructure
Ref.CN5E,NT@UW,WUSTL10CS5530
• Projectfileso Projectview
} Actualfilestructureoftheproject¨ IncludingallfileshiddenfromAndroidview
o Looksfairlycomplexnow
CreateanAndroidProject
Ref.CN5E,NT@UW,WUSTL11CS5530
• StartanewAndroidStudioproject,orFileà NewProjecto ApplicationName:"MyFirstApp"o CompanyDomain:"example.com"
• TargetAndroidDevices:keepthedefaultvalueso Wewillgetbacktothislater
• AddanActivitytoMobile:select EmptyActivity• CustomizetheActivity:keepdefaultvaluesà Finisho TakesalongtimetoFinish…
CreateanAndroidProject
Ref.CN5E,NT@UW,WUSTL12CS5530
• InAndroidviewo app>java>com.example.myfirstapp >MainActivity.java
} Mainactivity(entrypointforyourapp)} Whenbuildandrunanapp,systemlaunchesaninstanceofthis Activityandloads
itslayout
o app>res>layout>activity_main.xml} Definesthelayoutfortheactivity'sUI
o app>manifests>AndroidManifest.xml} Describesthecharacteristicsoftheappanddefineseachofitscomponents
o Gradle Scripts>build.gradle} 2 fileswiththisname:onefortheprojectandoneforthe"app"module} Mostlyworkwithmodule's build.gradle filetoconfigurehowtheGradle tools
compileandbuildyourapp
Running theApp
Ref.CN5E,NT@UW,WUSTL13CS5530
• Onarealdeviceo WindowsmayneedUSBdriverforthedevice
} https://developer.android.com/studio/run/oem-usb.html
o EnableUSBdebugging(earlier)
• Onasimulatoro Createan AndroidVirtualDevice (AVD)definition
} Tools>Android>AVDManager
} CreateVirtualDevice>SelectHardware
} SystemImage > Download (oneoftherecommendedsystemimages)¨ Takesalongtimeagain
BuildingSimpleUserInterface
Ref.CN5E,NT@UW,WUSTL14CS5530
• UIisbuiltw/ahierarchyoflayouts(ViewGroup objects)&widgets(Viewobjects)o Layoutsareinvisiblecontainersthatcontrolhowitschildviewsarepositioned
o WidgetsareUIcomponentslikebuttonsandtextboxes
BuildingSimpleUserInterface
Ref.CN5E,NT@UW,WUSTL15CS5530
• BuildingUIo XML
o LayoutEditor
BuildingSimpleUserInterface
Ref.CN5E,NT@UW,WUSTL16CS5530
• ComponentTree windowo Showsthelayout'shierarchyofviews
• ConstraintLayouto A layoutthatdefinesthepositionforeachviewbasedonconstraintstosiblingviewsandtheparentlayout
BuildingSimpleUserInterface
Ref.CN5E,NT@UW,WUSTL17CS5530
• ChangeUIstringso res>values>strings.xml
StartActivity
Ref.CN5E,NT@UW,WUSTL18CS5530
• Addamethodin MainActivity.java that'scalledbythebuttono Intent
} Anobjectthatprovidesruntimebindingbetweenseparatecomponents,suchastwoactivities
} The Intent representsanapp’s"intenttodosomething"
o putExtra()} An Intent cancarrydatatypesaskey-valuepairscalled extras
o startActivity()
AddupNavigation
Ref.CN5E,NT@UW,WUSTL19CS5530
• Navigationreturntothelogicalparentscreeninapphierarchyo DeclarewhichactivityisthelogicalparentinAndroidManifest.xml
<activityandroid:name=".DisplayMessageActivity"android:parentActivityName=".MainActivity">
<!-- Themeta-datatagisrequiredifyousupportAPIlevel15andlower--><meta-dataandroid:name="android.support.PARENT_ACTIVITY"android:value=".MainActivity"/>
</activity>
top related