List of Listings

Chapter 1. Introducing Android

Listing 1.1. A basic Activity in an Android application

Listing 1.2. A simple example of an Android Service

Listing 1.3. A sample BroadcastReceiver

Listing 1.4. AndroidManifest.xml

Listing 1.5. AndroidManifest.xml file for a basic Android application

Listing 1.6. AndroidManifest.xml for the Where Do You Live application

Listing 1.7. Implementing the Android Activity in AWhereDoYouLive.java

Listing 1.8. R.java contains the R class, which has UI element identifiers

Listing 1.9. Main.xml defines the UI elements for our sample application

Listing 1.10. strings.xml

Chapter 2. Android’s development environment

Listing 2.1. main.xml contains UI elements

Listing 2.2. ChapterTwo.java implements the tip calculator logic

Chapter 3. User interfaces

Listing 3.1. The first half of the ReviewCriteria Activity class

Listing 3.2. The second half of the ReviewCriteria Activity class

Listing 3.3. First half of the ReviewList Activity class, showing a ListView

Listing 3.4. The second half of the ReviewList Activity class

Listing 3.5. The ReviewAdapter and inner ReviewListView classes

Listing 3.6. First portion of ReviewDetail showing multiple uses of the R class

Listing 3.7. XML layout resource file for review_detail.xml

Listing 3.8. Externalized strings for the RestaurantFinder application, strings.xml

Listing 3.9. Values resource defining reusable styles, styles.xml

Listing 3.10. Arrays.xml used for defining cuisines and ratings

Listing 3.11. Example of an animation defined in an XML resource, scaler.xml

Listing 3.12. The RestaurantFinder AndroidManifest.xml file

Chapter 4. Intents and Services

Listing 4.1. Second section of ReviewDetail, demonstrating Intent invocation

Listing 4.2. Manifest declaration of ReviewList Activity with <intent-filter>

Listing 4.3. The Android manifest file for the WeatherReporter application

Listing 4.4. onStart method of the ReportViewDetail Activity

Listing 4.5. The WeatherAlertServiceReceiver BroadcastReceiver class

Listing 4.6. WeatherAlertService class, used to register locations and send alerts

Listing 4.7. IWeatherReporter.aidl remote IDL file

Listing 4.8. Implementing a weather service that publishes a remotable object

Listing 4.9. Exporting a service for other applications to access

Listing 4.10. Binding to a Service within an Activity

Chapter 5. Storing and retrieving data

Listing 5.1. Storing SharedPreferences using different modes

Listing 5.2. Getting SharedPreferences data stored in the same application

Listing 5.3. Getting SharedPreferences data stored in a different application

Listing 5.4. Creating a file in Android from an Activity

Listing 5.5. Accessing an existing file in Android from an Activity

Listing 5.6. Accessing a noncompiled raw file from res/raw

Listing 5.7. A custom XML file included in res/xml

Listing 5.8. Accessing a compiled XML resource from res/xml

Listing 5.9. Using standard java.io.File techniques with an SD card

Listing 5.10. Portion of the DBHelper class showing the DBOpenHelper inner class

Listing 5.11. Portion of the DBHelper class showing convenience methods

Listing 5.12. WidgetProvider constants, including columns and URI

Listing 5.13. The first portion of the WidgetProvider ContentProvider

Listing 5.14. The second portion of the WidgetProvider ContentProvider

Listing 5.15. WidgetProvider AndroidManifest.xml file

Chapter 6. Networking and web services

Listing 6.1. The onStart method of the NetworkExplorer main Activity

Listing 6.2. A simple echo server for demonstrating socket usage

Listing 6.3. An Android client invoking a raw socket server resource, the echo server

Listing 6.4. The SimpleGet Activity showing java.net.UrlConnection

Listing 6.5. Apache HttpClient with Android Handler and Apache ResponseHandler

Listing 6.6. Using Apache HttpClient via a custom HttpRequestHelper

Listing 6.7. The first part of the HttpRequestHelper class

Listing 6.8. The second part of the HttpRequestHelper class

Listing 6.9. The final part of the HttpRequestHelper class

Listing 6.10. The Delicious HTTPS POX API with authentication from an Activity

Listing 6.11. Using the Google Contacts AtomPub API with authentication

Chapter 7. Telephony

Listing 7.1. Obtaining a TelephonyManager reference and using it to retrieve data

Listing 7.2. Attaching a PhoneStateListener via the TelephonyManager

Listing 7.3. Using Intent actions to dial and call using the built-in dialer application

Listing 7.4. Working with the PhoneNumberUtils class

Listing 7.5. Using in-place Editable View formatting via PhoneNumberUtils

Listing 7.6. Catching and aborting an outgoing call

Listing 7.7. Using SmsManager to send SMS messages

Listing 7.8. Creating an SMS-related BroadcastReceiver

Chapter 8. Notifications and alarms

Listing 8.1. AndroidManifest.xml for SMSNotifyExample

Listing 8.2. SMS Activity for the SMSNotifyExample class

Listing 8.3. A sample SMSNotifyExample

Listing 8.4. A sample SMSNotifyActivity

Listing 8.5. Updated SMSNotifyExample.java

Listing 8.6. AndroidManifest.xml

Listing 8.7. AlarmReceiver.java

Listing 8.8. SimpleAlarm.java

Listing 8.9. SetAlarm.java

Chapter 9. Graphics and animation

Listing 9.1. Listing 9.1 simlepshape.java

Listing 9.2. simplerectangle.xml

Listing 9.3. xmllayout.xml

Listing 9.4. XMLDraw.java

Listing 9.5. xmldrawable.xml

Listing 9.6. Shape1.xml

Listing 9.7. Shape2.xml

Listing 9.8. Shape3.xml

Listing 9.9. line.xml

Listing 9.10. Simple_animation.xml

Listing 9.11. main.xml

Listing 9.12. xmlanimation.java

Listing 9.13. BounceActivity.java

Listing 9.14. BounceView.java

Listing 9.15. OpenGLSquare.java

Listing 9.16. OpenGLSquare.java

Listing 9.17. OpenGLCubeActivity.java

Listing 9.18. OpenGLCubeActivity.java

Listing 9.19. OpenGLCubeActivity.java

Chapter 10. Multimedia

Listing 10.1. main.xml for MediaPlayer Example

Listing 10.2. MediaPlayerActivity.java

Listing 10.3. main.xml—UI for Simple Video Player

Listing 10.4. SimpleVideo.java

Listing 10.5. CameraExample.java

Listing 10.6. CameraExample.java continued

Listing 10.7. ImageCaptureCallback.java

Listing 10.8. SoundRecordingdemo.java

Listing 10.9. AndroidManifest.xml

Listing 10.10. maim.xml

Listing 10.11. VideoCam.java

Chapter 11. Location, location, location

Listing 11.1. A sample GPX file

Listing 11.2. A sample KML file

Listing 11.3. Start of MapViewActivity

Listing 11.4. A manifest file showing COARSE and FINE location-related permissions

Listing 11.5. Creation of LocationListener implementations in MapViewActivity

Listing 11.6. A MapView layout file including the Google Maps API key

Listing 11.7. Portions of code that demonstrate working with maps

Listing 11.8. The OverlayItem subclass BuoyOverlayItem

Listing 11.9. The BuoyItemizedOverlay class

Listing 11.10. The Handler Wind and Waves uses to add overlays to the MapView

Listing 11.11. A Geocoder example

Chapter 12. Putting Android to work in a field service application

Listing 12.1. The field service application’s AndroidManifest.xml file

Listing 12.2. splash.xml, defining the layout of the application’s splash screen

Listing 12.3. Splash.java, which implements the splash screen functionality

Listing 12.4. Prefs class

Listing 12.5. FieldService.java, which implements the FieldService Activity

Listing 12.6. showsettings.xml, which contains UI elements for the settings screen

Listing 12.7. ShowSettings.java, which implements code behind the settings screen

Listing 12.8. XML document containing data for the field service application

Listing 12.9. JobEntry.java

Listing 12.10. JobList.java

Listing 12.11. JobListHandler.java

Listing 12.12. RefreshJobs.java

Listing 12.13. managejobs.xml

Listing 12.14. ManageJobs.java, which implements the ManageJobs Activity

Listing 12.15. ShowJob.java

Listing 12.16. CloseJob.java—GUI setup

Listing 12.17. CloseJob.java—closejobView class

Listing 12.18. CloseJob.java—DoCloseJob class

Listing 12.19. Data definition for tbl_jobs

Listing 12.20. getjoblist.php

Listing 12.21. closejob.php

Chapter 13. Building Android applications in C

Listing 13.1. Hello.c

Listing 13.2. Build script for Hello Android, buildhello.bat

Listing 13.3. pullandroid.bat

Listing 13.4. Build script for dynamically linked Android application

Listing 13.5. Add an exit() call

Listing 13.6. Disassembly of ping

Listing 13.7. crt.S

Listing 13.8. daytime.c

Listing 13.9. Interacting with a SQLite database

Listing 13.10. Daytime application build script

Listing 13.11. UI elements of DaytimeClient.java

Listing 13.12. Requester class implementation

Chapter 14. Bluetooth and sensors

Listing 14.1. Initiating a connection to a BluetoothDevice

Listing 14.2. Monitoring the Bluetooth connection

Listing 14.3. The handleConnected method

Listing 14.4. Our slimmed-down version of onSensorChanged

Listing 14.5. Sensor registration code

Listing 14.6. The onSensorChanged method, which interprets orientation

Listing 14.7. The updateMotors method

Listing 14.8. The MoveMotor method

Chapter 15. Integration

Listing 15.1. Constants for LinkedIn

Listing 15.2. Externalized strings for LinkedIn

Listing 15.3. Selecting a contact from the native contacts app

Listing 15.4. Retrieving email information for a selected contact

Listing 15.5. Adding a contact using the native contacts app

Listing 15.6. Looking up a contact by name and then editing it

Listing 15.7. Updating contact information using a ContentResolver

Listing 15.8. Helper class for storing LinkedIn connections

Listing 15.9. contacts.xml

Listing 15.10. Login activity initialization and authentication

Listing 15.11. Login activity’s multiple stages of logging in

Listing 15.12. Login activity responding to completed login attempt

Listing 15.13. Authenticating against the LinkedIn account

Listing 15.14. Adding support for handling auth token

Listing 15.15. Defining the authentication service

Listing 15.16. authenticator.xml

Listing 15.17. Synchronizing LinkedIn connections to contacts

Listing 15.18. Defining the synchronization service

Listing 15.19. syncadapter.xml

Listing 15.20. AndroidManifest.xml for LinkedIn

Chapter 16. Android web development

Listing 16.1. Sample HTML page

Listing 16.2. Adding the viewport meta tag

Listing 16.3. Interrogating the user agent

Listing 16.4. Sample link statements

Listing 16.5. User interface elements of the SQL sample page in db.html

Listing 16.6. Code that opens the database and creates the table

Listing 16.7. Processing returned rows from a query

Listing 16.8. Data handling functions

Listing 16.9. Setting up a browser control

Listing 16.10. JavaScript interface code implementation

Listing 16.11. index.html

Listing 16.12. A no-op class

Listing 16.13. Managing the search term

Listing 16.14. UAWebViewClient.java

Listing 16.15. UAChrome.java

Chapter 17. AppWidgets

Listing 17.1. SiteMonitorModel class

Listing 17.2. SiteMonitorWidgetImpl, which implements AppWidget functionality

Listing 17.3. Dealing with AppWidgets that won’t die off

Listing 17.4. Setting up a PendingIntent to handle user interactions

Listing 17.5. Updating the widget with RemoteViews in SiteMonitorWidgetImpl

Listing 17.6. AppWidget metadata file defining widget characteristics

Listing 17.7. Setting up the configuration Activity to manage a widget instance

Listing 17.8. Handling button clicks in the configuration Activity

Listing 17.9. Checking for a cancel

Listing 17.10. SiteMonitorBootstrap.java

Listing 17.11. SiteMonitorService class

Listing 17.12. Iterating through each of the sites and request updates

Listing 17.13. AndroidManifest.xml

Chapter 18. Localization

Listing 18.1. Getting current locale at runtime

Listing 18.2. Default strings.xml file

Listing 18.3. Showsettings.xml, which references string constants

Listing 18.4. Menu creation code prior to localization

Listing 18.5. Subset of the string table

Listing 18.6. Retrieving localized strings from the string table

Listing 18.7. Formatting localized strings

Chapter 19. Android Native Development Kit

Listing 19.1. Sample JNI function signature

Listing 19.2. Calling a JNI function

Listing 19.3. ua2efindedges.c

Listing 19.4. converttogray function implementation

Listing 19.5. detectedges routine

Listing 19.6. Android.mk

Listing 19.7. Layout file

Listing 19.8. UA2EFindEdgesApp.java

Listing 19.9. UA2EFindEdges.java

Listing 19.10. Finding the edges

Appendix B. Publishing applications

Listing B.1. .android folder showing keystores

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset