ANDROID DEVELOPMENT KELLY MCBEAN. DEVELOPMENT ENVIRONMENT OVERVIEW Eclipse Standard IDE for...
-
Upload
lydia-capers -
Category
Documents
-
view
217 -
download
1
Transcript of ANDROID DEVELOPMENT KELLY MCBEAN. DEVELOPMENT ENVIRONMENT OVERVIEW Eclipse Standard IDE for...
ANDROID DEVELOPMENT
KELLY MCBEAN
DEVELOPMENT ENVIRONMENTOVERVIEW
EclipseStandard IDE for Developing Android
Applications
Install:1. Java (JDK) – Since Eclipse Runs on top of Java2. Eclipse Standard3. Using Eclipse “Install Software”
1. Developer Tools (Plugins)2. Android SDK3. Android APIs
TESTING FOR JAVA
http://java.com
If you get the Congratulations message, skip to Installing Eclipse…else continue with the Java Install
INSTALLING JAVA
Install Documentation:
http://developer.android.com/sdk/installing.html
Java Platform (JDK)
http://www.oracle.com/technetwork/java/javase/downloads/index.html
INSTALLING JAVA
Install latest version * for appropriate OS
* At this time 7u25 is the latest
INSTALLING ECLIPSE
Downloads:http://www.eclipse.org/downloads
Install:1. Save file to a temp folder2. Open Zip file and copy the eclipse to root
(c:\)3. Run eclipse from c:\eclipse\eclipse.exe4. Accept the default workspace
INSTALLING PLUG-IN
From Inside Eclipse:Menu: Help > Install New Software…
Work with: http://dl.google/android/eclipse
After Accepting License Agreement Eclipse will reboot and continue with installing SDK
INSTALLING SDK
Note the Target Location
Accept All
And Wait…
INSTALLING API
The Android APIs are the Android platforms (i.e. 2.2, 4.1, etc.)
By Default, only One API is installed
To check on Installed Android APIs:Windows > PreferencesAndroid Tab
Optional: Menu: Windows > Android SDK Manager
Choose Additional APIs to Install
VIRTUAL DEVICES (AVD)
The AVD is an emulator instance that enables you to model an actual device
APIs are available to emulate many of the most popular Android devices
While tethering a device through a USB connection is possible, AVDs are invaluable for testing applications
CREATING A VIRTUAL DEVICE
The AVD is an emulator instance that enables you to model an actual device
You will need one for each API you want to test…
Menu: Windows > AVD Manager
UPDATE ENVIRONMENT PATH
My Computer. Properties. Advanced
Add “C:\android-sdks\tools; C:\android-sdks\platform-tools” to …
Environment . System . Path
Optional?
ECLIPSE DEVELOPMENT ENVIRONMENT FOR ANDROID
The Eclipse Development Environment should be ready to go…
CREATING ANDROID APPLICATION
Application Name is shown in Play Store
Project Name must be unique within Android Workspace
Package Name is a Unique Identifier for the Application
ANDROID PLATFORM DISTRIBUTION
ANATOMY OF AN ANDROID APPLICATION
src – Contains the Java source files for the project
gen – Contains the R.java file, a compiler-generated file that references all the project resources
res – All the project resources. Also contains subfolders to support devices with different size screen resolutions and densities
values – Contains string constants for the application
AndroidManifest – The manifest for the Android application includes the Intents for the Activities and any permissions needed by the application
ACTIVITIES AND INTENTS
An Activity is a window that contains the user interface
An application can have zero or more activities
In Android, you navigate between Activities through what is known as an intent
Intents enable different activities from different applications to work together
DIALOG WINDOWS
o Dialog windows are used to display information and sometimes to get confirmation from the user
o Common Dialog Windows consist of:o Toast
o A message that pops up on the bottom of the user screen for a short period of time
o Alert Dialog Windowo Displays choices to the user and waits
for a responseo Progress Dialog Window
o Useful for displaying the progress of a process
TOAST DIALOG
A toast provides simple feedback in a small popup
Toasts take 3 parameters1) Application Context2) Text Message3) Duration
OR
ALERT DIALOG
Alert Dialog gets a confirmation from the user
Code to handle the following eventsPositive: Typically “OK”Negative: Typically “Cancel”MultiChoice: When the user selects
from a list
PROGRESS DIALOG
INTENTS
o In Android, you navigate between activities through what is known as an intent
o Results can be returned from an Intento Data can also be passed using Intent Objecto Built-in applications can be called using Intents
o Web Browsero Phone Dialero Contactso Mapo Etc.
WEB BROWSER & PHONE INTENT
NOTIFICATIONS
A notification is a message displayed to the user outside of the applications UI
To see the details of the notification, the user opens the notification drawer
This is the old way of calling notifications but still works…
NOTIFICATIONS
o Activity to receive the notification is just a single TextView
BREAK
RECAP
Installing and Configuring the IDE Java (JDK) Eclipse
Plug-Ins SDKs APIs
The UI screen for Android Applications are called Activities
Intents are used to link Activities There are built-In Intents (Browser, Contacts,
Etc.)
Dialog Windows Toasts Alerts Progress
Notifications
USER INTERFACE (ACTIVITIES)
• An Activity is a window that contains the user interface (Views and ViewGroups)
o Views consist ofo TextViews (labels)o TextEdits (text boxs)o Radio Buttonso Check Boxeso Date Pickerso Time Pickerso Etc.
USER INTERFACE (ACTIVITIES)
ViewGroups are layouts used to arrange Views into proper location on the screen
o Android supports the following ViewGroups• Linear Layouts• Absolute Layout• Table Layout• Relative Layout• Frame Layout• Scroll View
o ViewGroups can be nested
VIEWGROUPS (LINEAR LAYOUT)
o The Linear Layout Stacks Views on top of each other
o Orientation can be Vertical (default) or Horizontal
View
View
View
View
Linear Layout
ViewView
Linear Layout
VIEWGROUPS (LINEAR LAYOUT)
VIEWGROUPS (RELATIVE LAYOUT)
o The Relative Layout arranges Views in relation to the parent or other Views
Relative Layout
View
View
View
View
View
View
View
VIEWGROUPS (RELATIVE LAYOUT)
VIEWGROUPS (SCROLLVIEW)
o The ScrollView enables users to scroll through a list of Views that occupy more space than the physical display
o The ScrollView can only have one child, typically a Linear Layout
ScrollView
Linear Layout
View
View
View
View
View
VIEWGROUPS (SCROLLVIEW)
ANCHORING VIEWS
CUSTOM ORIENTATIONS SCREENS
o A preferable alternate to anchoring is to create custom screens based on orientation
o To support Landscape mode, create a new folder in the res folder named layout-land
o Layouts contained in the layout folder defines the UI for portrait mode
o Layouts contained in the layout-land folder defines the UI for landscape mode
CUSTOM LANDSCAPE UI
PERSISTING STATE INFORMATION
o Changing screen orientation destroys the Activity and re-creates it
o Current state of the Activity is losto When an Activity is killed, it’ll fire the
onPause and onSaveInstanceState eventso You can implement the onPause event to
save state information to database, internal or external storage
Oro Implement the onSaveInstanceState event
and save the state using Bundle objecto After the activity is re-recreated retrieve
and reset the state in the onRestoreInstanceState event
PERSISTING STATE INFORMATION
Flow:o Orientation
Changeso Activity is Killedo Activity is re-
createdo State information
“McBean” is lost
ACTIVITY LIFE CYCLE
o These are the major events triggered during the life cycle of an Activity
Additionallyo onRestoreInstanceSt
ate occurs after onStart
o onSaveInstanceState occurs after onPause
PERSISTING STATE INFORMATION
REGISTERING EVENTS FOR VIEWS
o Views can fire events when user interacts with them
o The appropriate events need to be explicitly registered
o Events can be registered using an inner class or an anonymous class
REGISTERING EVENTS FOR VIEWS
o Using the AnchorView as an example
o The buttons are linked to the UI buttons using findViewById
o The setOnClickListener gives the buttons “ears” to listen for the click event to be triggered by the user
o btn1…btn4 call an anonymous class btnListener
o Btn5 calls an inner class
BASIC VIEWS
Views commonly used are:
TextView – Display InformationEditText – Allows user to key in Information
CheckBox – Turn on and off
RadioButtons – Select one in a list
ToggleButton – Turn on and off
SIMPLE LIST VIEW
o The ListView displays a long list of items in an Activity
o No UI Layout Requiredo Presentation is dictated by
the second parameter of the setListAdapter
CUSTOM LIST VIEW
o Colleges array was moved to strings.xml file and now called as a resource
SPINNER VIEW
Similar to the ListView except is used when other Views will be displayed on the UI