787
INDEX
Numbers
3D views, Surface Views, 4703G network, 6, 2024G network, 6, 202
A
AAPT (Android Asset Packaging Tool), 48AccelerateDecelerateInterpolator,
448accelerometers, 491
change detection, 492–493linear acceleration, 491x-axis acceleration, 492y-axis acceleration, 492z-axis acceleration, 492
accessibilityevents, broadcasting, 148–149navigation, non-touch screen, 436textual description, 436Views, 148–149
AccessibilityEvents, 148accuracy in Location Providers, 517–518Action Bar
actions, 370specifying, 380–381
Activities and, 360background, customizing, 363–364disabling, 361Earthquake Monitor, 370–376enabling, 360–361icon, 362–363menu bar and, 377
navigation and, 364–370drop-down lists, 368–370icon navigation, 365–366tabs, 366–368views, 370
split mode, 364title text, 362–363
Action Providers, menu system, 383action tag, 184ActionProvider class, 383active lifetime of an Activity, 93–94active processes, 82Activities, 54
Action Bar and, 360actions, anonymous, 193App Widget confi guration Activities,
580–582contact data, 187–193creating, skeleton code, 86Dialogs and, 400–401displaying, 166Earthquake Monitor, settings,
223–231ForceMeter, 494Fragments and, 114
adding, 120–125attaching/detaching, 119references, 126
instance state, lifecycle handlers and, 242–243
Intents, resolving, 168–169launch Intent, 186–187launching
Intents and, 166–174native applications, 172–174
bindex.indd 787bindex.indd 787 4/2/2012 2:05:41 PM4/2/2012 2:05:41 PM
COPYRIG
HTED M
ATERIAL
788
Activity class – analytics
lifecycleActivity stacks, 88state changes, 89–91state event handlers, 90–91states, 88–89
lifetimesactive, 92–93full lifetime, 92visible lifetime, 92
Live Folder Activity, 608–610map-based, 536–537
creating, 538–540Map Activity, 536Map View, 536Where Am I and, 542–546
passing responsibility, 187Preference Activities, 231, 232
Earthquake Monitor, 238–242PreferencesActivity, 226registering as Intent handler, 184–185request codes, 169results, returning, 169–172searches, 292–293
default provider, 293–296SearchView widget, 297
Services, binding, 336–338startActivity method, 166–167starting explicitly, 167states, Shared Preferences and, 242sub-Activities
launching, 169–170results, 171–172
UI assignment, 87, 97–988UI design, 96WeatherStation, 508–511WhereAmI, 520
Activity class, 54creating, 86ExpandableListActivity subclass, 93ListActivity subclass, 93MapActivity subclass, 93
Activity Intents, 172–174Activity Manager, 17activity tag, 61–62
adaptersArray Adapter, customzing, 156–158native
ArrayAdapters, 156SimpleCursorAdapter, 156
SimpleCursorAdapter, 162–163Views, binding data to, 158–163
ADB (Android Debug Bridge), 48, 51ADT (Android Developer Tools), 23
Android Project Wizard, 24Android Virtual Device manager, 24automation, 24DDMS (Dalvik Debug Monitoring
Service), 24debugging, 24emulator, 24forms-based editors, 24installation, 24–26updates, 27
ADT Wizard, 65advertising-supported applications, 780AIDL (Android Interface Defi nition
Language), 338binding, 764–765classes, parcelable, 759–762data types supported, 759IPC (inter-process communication),
759service defi nition, 762
exposing, 764implementing, 762–764
Alarms, 351–352creating, 352–353repeating, 353–354
network refreshes, 354–357Widget refreshing, 579–580
Alert Dialogs, confi guring, 396–397
AlertDialog class, 396Alpha animations, 71AlphaAnimation, 443altitude calculation, 507Amazon Web Services, 217analytics, 783–785. See also Google Analytics
bindex.indd 788bindex.indd 788 4/2/2012 2:05:42 PM4/2/2012 2:05:42 PM
789
Android – applications
Androidadoption drivers, 12as mobile handset, 3components, 4dependent parts, 4–5development
barriers to entry, 11reasons for, 11–13
features unique to platform, 12–13
OHA (Open Handset Alliance), 4open-source software stack, 4original handset, 10–11Rubin, Andy, on, 4
Android Beam, 13message creation, 697–699message receipt, 699–670payload, assigning, 699
Android Developer Consoleerror reports, 778–779statistics, 778uploading applications, 776–777
Android Developer website, 426Android Developers Widget Design
Guidelines, 567Android New Project Wizard,
28–30Android SDK. See SDK (software
development kit)Android Training website, 434AndroidManifest.xml, 55–56Animation class, 443AnimationDrawable class, 446AnimationListener, 444AnimationResources, 75animations
Alpha, 71AlphaAnimation, 443attributes, 71folder, 65Fragment transactions, 125Frame animations, 442frame-by-frame, 72–73,
445–446
Interpolated Property animation, 442
Layout Animations, 444–445layouts, 444–445listeners, 449property animations, 70–71,
446–449Rotate, 71RotateAnimation, 443Scale, 71ScaleAnimation, 443Translate, 71TranslateAnimation, 443Tweened View animation, 442view animations, 71–72View Groups, 444–445
anti-aliasing, 456–457anonymous actions, 193
as menu items, 195–196AOSP (Android Open Source
Project), 5maps package, 538
APIs (application programming interfaces), 6Bluetooth communications, 673Google, 22–23Maps API key, 537–538SDK inclusion, 14
App Widget confi guration Activity, 580–582
App Widgets, 566–569Application class
extending, 83–84overriding lifecycle events, 84–85skeleton, 84using, 83
application layers, 3, 16application tag, 61application-specifi c folders, 246–247applications
Activities, 54advertising-supported, 780anonymous actions, 193
as menu items, 195–196background, 37
bindex.indd 789bindex.indd 789 4/2/2012 2:05:42 PM4/2/2012 2:05:42 PM
790
AppWidgets – background
backward compatibility, 765building, 766–769
Broadcast Receivers, 55components, 54–55
reuse, 6Content Providers, 54data, saving, 222debugging, 33distribution
Google Play Store, 774–776strategies, 780–783
equality among, 13error repots, 778–779examples, to-do list, 107–114feedback, 778fi les
cache, 248private, 247–248
foreground, 36–37free, In-App Billing and, 780full screen, 392–394Google, 5Intents, 54intermittent, 37internationalization, 782–783launch strategies, 781lifecycle, 81marketing, 780–781monetizing, 779–780native, 5–6
Intents, 172–174Notifi cations, 55paid, 779pre-installed, 4priority, 82processes, 82promotion, 780–781publishing, 776–778running, 33Services, 54signing
Export Android Application wizard, 772–774
upgrades, 773
statistics, 778storage, external versus internal, 55–56UI state, saved, 222upgrades, 773usage patterns, 783–784Widgets, 55
AppWidgets, 566Array Adapter, customizing, 156–158ArrayAdapter, 156
To-Do List application, 158–162arrow keys, 436asynchronous tasks, 345–349AsyncTask, 345–347audio, 58
effects, 645focus, 635–637formats supported, 622playback initialization, 624–625raw, 640–643
Audio Manageraudio focus, 635–637registeredMediaButtonEventReceiver
method, 634Audio Record, recording with, 640–641Audio Track, 640
effects, 645playing audio, 642–643
authorities tag, 262AVD (Android Virtual Device), 20, 47,
48–49AVD Manager, 14creating, 30emulators, skins, 435manager, 24resolution, custom, 435screen size, custom, 435
azimuth, device orientation and, 498
B
back stack, Fragment Manager, 124–125background
Action Bar, 363–364applications, 37
bindex.indd 790bindex.indd 790 4/2/2012 2:05:42 PM4/2/2012 2:05:42 PM
791
backward compatibility – camera
data transfersgetBackgroundDataSetting, 680user preferences support,
679–681processes, 83services, 6, 7, 12threads, 345–351
backward compatibility, 765building applications with, 766–769Preference Screens and, 237
barometer sensor, 506–507battery
Bluetooth and, 667changes, listening for, 197–198downloads and, 219–220Location Providers and, 527Wake Locks, 757
beginTransaction method, 122binding data
runtime, implicit Intents, 167–168to Views, adapters and, 158–163
Bluetooth, 7, 58battery life and, 667communications, APIs, 673description, 666device discoverability, 669–671
isDiscovering method, 671–672remote devices, 671–673
enabling, 668RFCOMM, 673–674
Bluetooth Adapterdiscoverability and, 669–671getState method, 667management, 666–669
Bluetooth Server Socket, listener, 674–675
Bluetooth Socketclient connection, 676–677data transmission, 677–678
BluetoothAdapter class, 666BluetoothServerSocket class,
673–674BluetoothSocket class, 673–674Broadcast Receivers. See ReceiversBrowser, 316
bundles, battery and, 220Button control, 132
C
C/C++, 2C2DM (Cloud to Device Messaging),
9–10messages
receiving, 749–750sending to devices, 748–749
overview, 743registration, 744
device registration, 744–747restrictions, 743–744
Calendar, 316entries
displaying events, 328editing events, 327–328modifying directly, 329new events, 327
queries, 325–326Call Log, 316callbacks, Cursor Loaders, 278–279camera, 58
auto focus, 650–651distance to focused objects,
648–649EXIF (Exchangeable Image File Format),
655–656face detection, 653–654facial features, 653–654focus area, 650–651hardware, 59images
format, 650parameters, 649–650size, 650
JPEG quality, 650metering area, 650–651picture taking, Intents, 646–647preview, 651–653preview frame rate, 650properties, 648–649settings, 649–650
bindex.indd 791bindex.indd 791 4/2/2012 2:05:43 PM4/2/2012 2:05:43 PM
792
Camera Parameters – code
taking pictures, 654–655thumbnail quality, 650
Camera Parameters, 648–649Canvas
advanced drawing, 450–466best practices for drawing, 457–458color, translucency, 452Overlays, 547–548Paint class, 451–456painter’s algorithm, 143Shaders, 452–453
Color Filters, 455gradient shaders, 453–454Mask Filters, 454–455Paint, 454Path Effects, 455–456tile modes, 454Transfer Mode, 456
Canvas class, 143–144capacity limits, design and, 38–39category tag, 184CDD (Compatibility Defi nition Document), 4CDMA networks, cell location changes, 710cell location changes, 710CharacterPickerDialog, 397check boxes, 381CheckBox control, 132CheckBoxPreference control, 234Chronometer control, 132classes
ActionProvider, 383Activity, 54, 86AlertDialog, 396Animation, 443AnimationDrawable, 446Application, 83AsyncTask, 345–347BluetoothAdapter, 666BluetoothServerSocket, 673–674BluetoothSocket, 673–674Canvas, 143–144ClipData, 479–480CompassView, 150–155ContentValues, 253–354Criteria, 517–518
Cursor, 253–354Dialog, 395–396Drawables, 143–144EarthquakeWidget, 583Environment, 247ExifInterface, 655–656Fragment, 115–116Geocoder, 532IntentFilter, 179–180layout classes, 98LocationManager, 517–518MarketBillingService,
755–756ObjectAnimator, 447–449Paint, 143–144,
451–456PendingIntent, 182–183, 531PreferenceActivity,
236–237PreferenceFragment, 235RecognizerIntent, 439Resources, 74–75Sensor, 482Service, 331Shader, 452–453SharedPreferences,
222–223SQLiteOpenHelper, 255–257SurfaceView, 141, 467–470Toast, 401–405ToDoContentProvider, 283ToDoListItemView, 136–138UriMatcher, 263–264ViewGroup, 97
click listener, in menus, 382client Sockets, creating, 692–693Clip Data object, 480Clipboard Manager
ClipData class, 479–480pasting data, 480
ClipData class, 479–480cloud computing, 217.
See also C2DMcoarse permissions, 514code, resources in, 74–75
bindex.indd 792bindex.indd 792 4/2/2012 2:05:43 PM4/2/2012 2:05:43 PM
793
Collection View Widgets – Content Providers
Collection View Widgets, 587–589binding to Content Providers,
596–598Earthquake Widget, 598–605interactivity among items, 595–596layouts, creating, 589–590Live Folders and, 605populating, Remote Views Service,
594–595refreshing, 598Remote Views Factory, 591–593Remote Views Service, 591
color, 67folder, 65Paint class, 452translucency, 452
Color Drawables, 431Color Filters, Shaders, 455color tag, 67communication, inter-process, 13Compass View, 149–155
device orientation and, 502–505onDraw method, 458–466
CompassView class, 150–155compatibleWidthLimitDp tag, 60composite Drawables, transformative
DrawablesLayer Drawables, 477–478Level List Drawables, 478State List Drawables, 478
compound controls, 138–141condensed titles in menus, 381connection reuse, 220ConnectionInfoListener, 691connectivity. See also Connectivity Manager;
Wi-Fi Managerchanges, listening for, 198–199Mobile Internet, 202Wi-Fi, 202
Connectivity Manageraccessing, 679determining connectivity, 681–682monitoring connectivity, 682Wi-Fi connectivity and, 683
ConnectivityManager, 679
constants, SQLite databases, public, 254Contacts Contract, 316, 318–319
details, 319–323direct editing, 324–325
Intents and, 323–324contacts, ContactPicker Activity,
187–192container views, Fragment layouts, 121Content Providers, 8, 17, 54
adding content, 280Browser, 316Calendar, 316
entries, 327–328modifying entries directly, 329queries, 325–326
Call Log, 316Collection View Widgets, binding,
596–598Contacts Contract, 316, 318–325database, creating, 264deleting content, 281Earthquake Monitor, 301–316fi les
access, 282–283storage, 268–270
implementation, skeleton, 270–273Live Folders and, 606–607Media Store, 316, 317–318overview, 252provider tag, 62queries
Content Resolver, 274–277Cursor Loader, 277–280implementing, 264–266
registering, 262searches
metadata, 291–292Quick Search Box, 291Search bar, 291Search View, 291suggestions, 298–301
To-Do List application, 283–290transactions, 266–268updating content, 281–282URI address, publishing, 263–264
bindex.indd 793bindex.indd 793 4/2/2012 2:05:43 PM4/2/2012 2:05:43 PM
794
Content Resolver – DDMS
Content Resolver, 274adding content, 280Content Providers, queries, 274–277deleting content, 281updating content, 281–282
Content Values, 253–354ContentValues class, 253–354Context Menus, 387
creating, 388–389selections, 389Views, 388–389
controllers, directional, 436controls, 97
Button, 132CheckBox, 132CheckBoxPreference, 234Chronometer, 132compound, 138–141
layouts and, 141custom, 155EditTextPreferences, 234EditView, 132ImageButton, 132interactive, 470–476ListPreferences, 234ListView, 132MultiSelectListPreferences, 234onDraw method, 143–144preferences, 234QuickContactBadge, 132RadioButton, 132RingtonePreferences, 234sizing, 144–146Spinner, 132TextView, 132ToggleButton, 132touch screen, 471VideoView, 132ViewFlipper, 132ViewPager, 133
copy protection, License Verifi cation Library and, 750–753
core libraries, 15costs, development and, 41–42Criteria class, 517–518
current location, privacy, 519Cursor
columns, 259values, extracting, 259–260
Cursor class, 253–354Cursor Loader
callbacks, 278–279Content Providers, queries, 277–280initializing, 280restarting, 280
custom controls, 155
D
D-pads, 436Dalvik Debug Monitoring Service, 48, 50Dalvik VM, 4, 16–17
bytecode, 19Linux kernel and, 14run time, 15
datashared, 13shared stores, 6, 8–9
data stream, opening, 203data tag, 184data transfer, 7
backgroundgetBackgroundDataSetting, 680user preferences support,
679–681peers, 692–693Wi-Fi Direct, framework initialization,
686–688databases. See also Content Providers
Content Values, 253–354opening
openOrCreateDatabase method, 257
SQLite Open Helper, 256SQLite, 252, 253To-Do List application, 283–290
DatePickerDialog, 397DDMS (Dalvik Debug Monitoring Service),
20, 48, 50
bindex.indd 794bindex.indd 794 4/2/2012 2:05:43 PM4/2/2012 2:05:43 PM
795
debugging – downloads
debugging, 33ADT and, 24Dalvik Debug Monitoring Service, 48, 50Debug Confi gurations, 110Default Debug Keystore, 537MD5 fi ngerprint, 537–538
Default Debug Keystore, 537delete method, 261–262density-independent pixels, 68, 426–427deprecated orientation sensor, 501–502design
Android Developers Widget Design Guidelines, 567
challenges, 20Android specifi cs, 43–47costs, 41–42hardware-imposed, 38–42speed, 40–41user environment, 42–43
databases, SQLite, 257UI, 96–97Widgets, 567–568
developmentAndroid
barriers to entry, 11reasons for, 11–13specifi cs, 43–47
design challenges, 20hardware-imposed, 38–42
platform, 4reasons for, 11user environment, 42–43
deviceGForceMeter project, 494–497movement, 489orientation, 489
azimuth, 498Compass View and, 502–505deprecated orientation sensor, 501–
502detecting, 492–493gyroscope, 505–506magnetometer, 498–500natural, 490–491pitch, 497–498
roll, 498standard reference frame,
497–498remapping, 500–501
state changes, 197–199dialer application, replacing, 703–704Dialog class, 395–396Dialogs, 394–395
Activity event handlers, 400–401Alert Dialogs, confi guring, 396–397AlertDialog class, 396CharacterPickerDialog, 397creating, 395–396DatePickerDialog, 397Dialog Fragments, 398–400Earthquake Monitor, 418–423input, 397–398ProgressDialog, 397TimePickerDialog, 397
dimen tag, 67–68dimensions, 67–68directional controllers, 436distribution, Google Play Store, 21,
774–776dmtracedump, 48Dock mode, 78docking changes, 199documentation, SDK, 14Download Manager, 210–211
cancelling downloads, 214completed downloads, 215downloading fi les, 211–212locations, 213–214Notifi cations, 212–213paused downloads, 216–217querying, 215–217removing downloads, 214
downloadsbettery drain and, 219–220cancelling, 214completed, 215fi les, 211–212location, 213–214Notifi cations, 212–213paused, 216–217
bindex.indd 795bindex.indd 795 4/2/2012 2:05:43 PM4/2/2012 2:05:43 PM
796
Draw9patch – ExpandableListActivity class
removing, 214repeated, 220
Draw9patch, 48Drawable resources, 427
Color Drawables, 431composite Drawables
Layer Drawables, 477–478Level List Drawables, 479State List Drawables, 478transformative Drawables,
476–477Gradient Drawables, 432–434NinePatch images, 434Shape Drawables, 431–432
drawables, 68–69Drawables class, 143–144Drawables folder, 65drawing
best practices, 457–458Canvas, advanced, 450–466
drop-down lists, navigation with Action Bar, 368–370
Dx, 48dynamic layouts, populating, 123–124
E
Earthquake Monitor, 205–210Action Bar, 370–376Activities, settings, 223–231AIDL interface defi nition, 762Dialogs, 418–423Earthquake Update Service, 357–358
repeating alarms, 355–357Live Folder, 610–613maps, 558–563Menu Items, 390–392Notifi cations, 418–423Preference Activities, 238–242search results in QSB, 615searchable earthquake Content Provider,
301–316Services, 338–343
Earthquake Widget, 582–587Collection View Widgets, 598–605
EarthquakeListFragment, 205EarthquakeUpdateService, 339EarthquakeWidget class, 583Eclipse, 19
ADT plug-in, 23Eclipse Java Development Tools, 23Indigo, 23WST (Web Standard Tools), 23
EDGE network, 6, 202EditTextPreference control, 234EditView control, 132effects, media, EffectFactory, 661effi ciency in development, 38–39embedded devices, developing for, 38–47Emergency Responder SMS example,
720–729automating, 729–737
empty processes, 83Emulator, 24, 47, 50
AVDs, skins, 435LBSs, testing, 516Location Providers
GPS, 516updating locations, 515–516
SMS messages, 719Environment class, 247environmental sensors, barometer,
506–507error reports, 778–779events
accessibility, broadcasting, 148–149broadcasting, Intents and, 177–181Motion Event, 471–472onActivityCreated, 127onAttach, 127onCreateView, 127onDetach, 127
evolution of mobile phone, 2–3EXIF (Exchangeable Image File Format),
655–656ExifInterface class, 655–656ExpandableListActivity class, 93
bindex.indd 796bindex.indd 796 4/2/2012 2:05:43 PM4/2/2012 2:05:43 PM
797
Export Android Application wizard – Frame animation
Export Android Application wizard, 772–774
external storage, 55–56, 246
F
fi le resources, static fi les as, 245fi le-management tools, 246fi les
applicationcache, 248private, 247–248
Content Providers and, 268–270, 282–283
databases and, SQLite, 257downloading, 211–212folders, application-specifi c, 246–247public, 248–249static, as resources, 245
fi ltersIntent fi lters
implicit Intents and, 183–193intent resolution, 185–186plug-ins, 193–196
Match Filter, 176Transform Filter, 176
findFragmentById method, 122–123fi ne permissions, 514fl ashing light Notifi cation, 409folders. See also Live Folders
application-specifi c, 246–247res, 77resources, 65
fonts, size, 80ForceMeter Activity, 494foreground
applications, 36–37dispatch system, 695–696Services, 343–345
forward geocoding, 532, 534–535Fragment class, 115–116Fragment Manager, 17
Activities, adding to Fragments, 120–125
adding Fragments, 122back stack and, 124–125Dialog Fragment, 399findFragmentById method,
122–123Fragment Transactions, 121–122getFragmentManager method, 120layouts, dynamic, populating,
123–124removing Fragments, 122replacing Fragments, 122transactions, animating, 125
Fragments, 96. See also Fragment ManagerActivities and, 114
attaching/detaching, 119references, 126
creating, 115–116, 119destroying, 119Dialog Fragments, 398–400DialogFragment subclass, 128event callback interfaces, 126event handlers, 116–118hiding, 124instance state, lifecycle handlers and,
243–245layouts, container views and, 121lifecycle, 116–118
events, 119ListFragment subclass, 128Map Views, 540–541Menu Items, 383–384navigation and, 366NewItemFragment, 128–129Preference Fragments, 232skeleton code, 115states, 119–120to-do list application, 128–132UIs
creating, 119design, 96destroying, 119lack of, 126–128
WebViewFragment subclass, 128Frame animation, 442
bindex.indd 797bindex.indd 797 4/2/2012 2:05:44 PM4/2/2012 2:05:44 PM
798
frame-by-frame animation – GridLayout class
frame-by-frame animation, 72–73, 445–446
FrameLayout class, 98framework, 14, 15, 16free applications, In-App Billing and, 780full lifetime of an Activity, 92full screen applications, 392–394
G
Geocoder, 532forward geocoding, 532, 534–535Geocoder class, 532reverse geocoding, 532, 533–534Where Am I, 535–536
getActivity method, 126getAntibanding camera parameter, 650getAutoWhiteBalanceLook camera
parameter, 649getBackgroundDataSetting method, 679–
680getBestProvider method, 518getCacheDir method, 248getColorEffect camera parameter, 649getColumnIndexOrThrow function, 254getColumnIndexOrThrow method, 259getColumnName function, 254getColumnNames function, 254getCount function, 254getDefaultSensor method, 484getExternalCacheDir method, 248getExternalFilesDir method, 247getExternalStoragePublicDirectory
method, 248–249getFlashMode camera parameter, 650getFocusMode camera parameter, 650getFragmentManager method, 120getIntent method, 186–187getLastKnownLocation method, 516, 519getPosition function, 254getProviders method, 517getReadableDatabase method, 256getResources method, 74–75getSceneMode camera parameter, 649
getSensorList method, 484getSharedPreferences method,
222–223getString method, 76getSystemService method, 482, 705getType method, 264–266getWhiteBalance camera parameter, 649getWritableDatabase method, 256GForceMeter project, 494–497Gmail client, 5Google
APIs, 22–23applications
Gmail client, 5Google Maps, 5Google Talk, 5YouTube, 5
Google Analytics, 784–786Google APIs, Internet resources, 201Google App Engine, 217–219Google Maps, 5, 7, 12Google Play Store
client, 5DDA (Developer Distribution
Agreement), 774–776developer account creation, 775–776distributing applications, 774–776distributing to, 21promotion in, 781–782
Google Services APIs, 217Google Talk, 5GPRS network, 202GPS, 7, 513
Location Provider, 516Gradient Drawables, 432–434gradient shaders, 453–454graphics, 6
hardware-acceleration, 466–467libraries, 9NinePatch images, 434scalable assets, 431–434stretchable, 434
gravity sensors. See accelerometersGrid Layout, 102–103GridLayout class, 99
bindex.indd 798bindex.indd 798 4/2/2012 2:05:44 PM4/2/2012 2:05:44 PM
799
GSM network – Intent Receivers
GSM network, 6cell location changes, 710
gyroscope sensor, 505–506
H
hardwareaccelerated graphics, 6access, 6–7availability issues, 765–766camera, 59multimedia, 6optional features, 58resources, 77–79sensors (See sensors)specifying as required, 766telephony support, 701–702uses-feature tag, 58
hardware-acceleration in graphics, 466–467
hardware-imposed design considerations, 38–42
headers, Preference Fragments, 234–235heightMeasureSpec method stub, 145Hello World project, 33–35
layout, 69–70Hierarchy Viewer, 48, 51–52home screen. See also screens
Live Wallpaper, 565QSB (Quick Search Box), 565Widgets, 565
App Widgets, 566, 567–582Honeycomb MR2, attributes, 58Hprof-conv, 48HTML5 WebKit, browser, 6
I
IAB. See In-App Billingicon navigation, 365–366icons
Action Bar, 362–363menu system, 377, 382
ImageButton control, 132images
EXIF (Exchangeable Image File Format), 655–656
formats supported, 622NinePatch, 434stretchable, 434
implicit Intentsfi lters, 183–193late runtime binding, 167–168
In-App Billingbilling requests, 756free applications, 780library installation, 754MarketBillingService class,
755–756overview, 753–754public key, 754–755purchasable items, 754–755purchase requests, responses,
756–757restrictions, 754transactions, initiating, 755–756
include tag, 104incoming phone calls
Intent Receivers and, 712–713Phone State Listener, 709
inputdevices, 57, 436
keyboard type, 78trackballs, 476
Dialogs, 397–398events, Views, 147–148voice, 440–441
insert method, 260–261insistent Notifi cations, 415–416installationLocation attribute, 55–56instance state
Activities, lifecycle handlers and, 242–243
Fragments, lifecycle handlers, 243–245instrumentation tag, 61Intent Receivers
third-party, 194–195Widgets, 570–572
bindex.indd 799bindex.indd 799 4/2/2012 2:05:44 PM4/2/2012 2:05:44 PM
800
Intent Service – launch confi gurations
Intent ServiceEarthquake Update Service and, 357–358implementing, 348
IntentFilter class, 179–180Intents, 8, 17, 54
Activitieslaunch Intent, 186–187launching, 166–174native applications, 172–174resolving to, 168–169results, 169–172
battery changes, 197–198broadcast, native, listening for, 196–197broadcasting
events, 177–181ordered, 180–181sticky, 181
connectivity changes, 198–199Contacts Contract and, 323–324docking changes, 199fi lters
implicit Intents and, 183–193intent resolution, 185–186plug-ins, 193–196
implicit, late runtime binding, 167–168
importing system preferences, 234–235
menus, 382MMS messages, sending, 713–714permissions, enforcing, 742picture taking, 646–647SMS messages, sending, 713–714uses, 166video recording and, 656–657Widget refresh and, 578–579
interactive controls, 470–476intermittent applications, 37internal storage, 55–56Internet data stream, opening, 203Internet resources
bandwidth and, 202battery and, 202caching and, 202connecting to, 202–203
Google APIs, 201native features and, 202WebView, 201
Internet servicesAmazon Web Services, 217Google App Engine, 217Google Services APIs, 217Yahoo! Pipes, 217
Interpolated Property animation, 442IPC (inter-process communication),
759message passing, 6
isDiscovering method, 671–672ItemizedOverlays, 554–556
J
Jarsigner command-line tool, 772Java, IDE (integrated development
environment), 19Java ME, 3JDK (Java development kit), 19JVM (Java virtual machine),
MIDLets, 2–3
K
keyboardavailability, 78exposed, 80hidden, 80input type, 78type change, 80
KeyEvent parameter, 475Keytool command-line tool, 772KML (Keyhole Markup Language), 515–516
L
languages, 77resources, 77–79user changes settings, 79
largestWidthLimitDp tag, 60launch confi gurations, 30–33
bindex.indd 800bindex.indd 800 4/2/2012 2:05:44 PM4/2/2012 2:05:44 PM
801
Layer Drawables – Linkify
Layer Drawables, 477–478Layout Animations, 444–445layout classes, 98
FrameLayout, 98GridLayout, 99LinearLayout, 98RelativeLayout, 98
Layout Managers, 98LayoutAnimationController, 444LayoutOpt, 48, 51–52LayoutParameters, 100layouts, 69–70, 97.
animating, 444–445Collection View Widgets, 589–590compound controls and, 141compound Views, 138–140defi ning, 99–100dynamic, populating, 123–124Fragments, container views and, 121Grid Layout, 102–103Hello World, 69–70implementing, 100Linear Layout, 100–101, 428Lint tool, 106optimizing for screen types, 428–429Preference Screens, 232redundant, 103–104Relative Layout, 101–102, 428resources, 76
directory names, 79scalable, 428UIs, device independent, 100–103View Stubs, 105–106Widgets, 567
size, 567–568supported, 568–569visual styling, 568
XML, 99–100layouts folder, 65LBS (location-based services), 6, 58, 513
current locationprivacy, 519refreshing, 522–525
Emulator andLocation Providers, 515–516
testing, 516last location, 519Location Manager, 514Location Providers, 514
accuracy, 517–518availability, 528–530getLastKnownLocation method,
519Passive Location Provider, 525status monitoring, 528–530Where Am I, 519–520
My Location Overlay, 553–554requestLocationUpdates method, 526update best practices, 527–530updateWithNewLocation method, 521
Level List Drawables, 478libraries, 16, 18
Bluetooth, 6core, 15graphics, 9media, 6NFC hardware, 6shared, uses-library tag, 62software stack, 15
License Verifi cation Librarychecks, 752–753installation, 750–751policy confi guration, 751–752public key, 751
lifecycle handlers, instance state andActivities, 242–243Fragments, 243–245
lifecyclesapplication, 81Fragments, 116–118
events, 119Linear Layout, 100–101, 428LinearLayout class, 98Linkify
addLinks method, 174link strings, custom, 175–176Match Filter, 176native link types, 174–175RegEx pattern matching and, 174Transform Filter, 176
bindex.indd 801bindex.indd 801 4/2/2012 2:05:44 PM4/2/2012 2:05:44 PM
802
Lint tool – map-based Activities
Lint tool, 106Linux kernel, 4, 16
Dalvik VM, 14security and, 740software stack, 15
LiPS (Linux Phone Standards Forum), 3ListActivity class, 93ListPreference control, 234ListView control, 132Live Folder Activity, 608–610Live Folders, 605–606
Collection View Widgets and, 605Content Provider, 606–607Earthquake project, 610–613
Live Wallpaper, 6, 9, 13, 37, 565creating, 616resource defi nition, 616–617Wallpaper Service, 617–618Wallpaper Service engine, 618–619
Loaders, 349Local Broadcast Manager
Intents, transmitting, 182Receivers, registering, 182sendBroadcastSync method, 182
localization, 6Location Listener, 522–523Location Manager, 514
accessing, 514current location
Broadcast Receiver, 524Pending Intent, 523–524refreshing, 522–525
Location Providers, 514accuracy, 517–518availability and, 527
monitoring, 528–530battery life and, 527capabilities, determining, 518–519Emulator and
GPS, 516updating locations, 515–516
fi nding, 517criteria, 517–518
getBestProvider method, 518
getLastKnownLocation method, 519getProviders method, 518Passive Location Provider, 525startup time and, 527status monitoring, 528–530update rate and, 527Where Am I, 519–520
tracking location in, 525–526location-based services. See LBSLocationManager class, 517–518logcat, 48LTE network, 6, 202
M
magnetometer, device orientation and, 498–500
Manifest Editor, 63–64manifest node, 56–63manifest Receivers, 178
managing at run time, 199–200manifest tag, sub-node tags, 56–57Map Activity, 536
Where Am I and, 542–546Map Controller, Map Views and, 541–542map taps, 548–549Map View, 536
confi guration, 541Earthquake Monitor, 558–563Fragments, 540–541Map Controller and, 541–542map tiles download, 538Overlays
adding/removing, 549creating, 546–547map taps, 548–549My Location Overlay, 553–554
pinning Views to, 556–557uses, 541
map-based Activities, 536–537creating, 538–540Map Activity, 536Map View, 536
bindex.indd 802bindex.indd 802 4/2/2012 2:05:44 PM4/2/2012 2:05:44 PM
803
MapActivity class – menus
MapActivity class, 93Maps, 7, 513Maps API key, 537–538MarketBillingService class,
755–756Mask Filters, Shaders, 454–455Match Filter, 176MCC/MNC (Mobile Country Code and
Mobile Network Code), 77MD5 fi ngerprint, debugging and,
537–538measureHeight method stub, 145measureWidth method stub, 145media
adding to Media Store, 662–663effects, EffectFactory, 661–662libraries, 6streaming
network protocols, 623video preview, 660
Media PlayerBassBoost class, 645Broadcast Receivers and,
632–634effects, 645EnvironmentalReverb class, 645Equalizer class, 645Media Controller, 629–631MediaPlayer instance, 623output, 631playback control, 629–631
pausing at output change, 637responding to, 632–634
PresetReverb class, 645setMediaController method,
629–630setVolumeControlStream method,
632state machine, 623streaming media, INTERNET permission,
623Virtualizer class, 645volume controls, 631–632Wake Locks, 631
Media Recorderconfi guration, 658–660setCamera method, 658time-lapse, 661video recording, 657–661
controlling, 660–661Media Scanner, adding media to Media Store,
662–663Media Store, 316, 317–318
adding media, 662–663MediaPlayer instance, 623MediaScannerConnection, 662MediaScannerConnectionClient, 662memory, optimized, 10Menu Item
adding, 379–380check boxes, 381click listener, 382condensed titles, 381Earthquake Monitor, 390–392Fragments, 383–384icons, 382Intents, 382radio buttons, 381selections, 386–387shortcut keys, 381updating, dynamically, 385–386
menu systemAction Bar actions, 377Action Providers, 383Context Menus, 387
creating, 388–389selections, 389
expanded menu, 378hierarchies, XML and, 384–385icon menu, 377overfl ow menu, 378Popup Menus, 389–390selections, 386–387submenus, 378–379
creating, 387Views, 382–383
menus, 73anonymous actions, 195–196
bindex.indd 803bindex.indd 803 4/2/2012 2:05:44 PM4/2/2012 2:05:44 PM
804
merge tag – methods
creating, 379–380folder, 65
merge tag, 104messaging, C2DM (Cloud to Device
Messaging), 9–10methods
beginTransaction, 122delete, 261–262findFragmentById, 122–123getActivity, 126getBackgroundDataSetting, 679–680getCacheDir, 248getColumnIndexOrThrow, 259getDefaultSensor, 484getExternalCacheDir, 248getExternalFilesDir, 247getExternalStoragePublicDirectory,
248–249getFragmentManager, 120getIntent, 186–187getLastKnownLocation, 516, 519getProviders, 517getReadableDatabase, 256getResources, 74–75getSharedPreferences, 222–223getString, 76getSystemService, 705getType, 264–266getWritableDatabase, 256insert, 260–261isDiscovering, 671–672onAccuracyChanged, 486onConfigurationChanged, 85onContextItemSelected, 389onCreate, 34, 84onDraw, 142, 143–144onLowMemory, 85onMeasure, 142, 144–146OnNavigationListener, 369–370onReceive, 178onSensorChanged, 486onStartCommand, 333–335onTrackBallEvent, 476onTrimMemory, 85
openFileInput, 247–248openFileOutput, 247–248openInputStream, 282–283openOrCreateDatabase, 257openOutputStream, 282–283openRawResources, 245overriding, 84–85query, 215–217, 257–258, 264–266refreshEarthquakes, 340–343registeredMediaButtonEvent
Receiver, 634registerRemoteControlClient, 638remapCoordinateSystem, 500–501requestLocationUpdates, 522, 526sendAccessbilityEvent, 148sendBroadcastSync, 182sendOrderedBroadcast, 180–181sendStickyBroadcast, 181setCamera, 658setCancelable, 397setContentView, 87, 97–98setDisplayUseLogoEnabled,
362–363setInexactRepeating, 353setLanguage, 438setLayoutParams, 100setListNavigationCallbacks,
369–370setMeasuredDimension, 145setMediaController, 629–630setNavigationMode, 366–367setNotificationVisibility, 213setRepeating, 353setResult, 170setRetainInstance, 127setShowAsActionFlags, 380–381setTransition, 125setTransportControlFlags, 639setVideoPath, 625setVideoURI, 625setVolumeControlStream, 632speak, 438startActivity, 166–167, 234startActivityForResult, 169
bindex.indd 804bindex.indd 804 4/2/2012 2:05:45 PM4/2/2012 2:05:45 PM
805
microphone – On Shared Preferences Change Listeners
startForeground, 343–345updateWithNewLocation, 521
microphone, 58MIDlets, 2–3MkSDCard, 48MMS (multimedia messaging service), 713–
714mobile development, reasons for, 11mobile devices, developing for, 38–47mobile handset, Android as, 3Mobile Internet, 202mobile phone evolution, 2–3monetizing applications, 779–780Monkey, 48, 52Monkey Runner, 48, 52Motion Event, 471–472
movement tracking, 473–474movement tracking on touch screen, 473–474moveToFirst function, 253moveToNext function, 253movetoPosition function, 254moveToPrevious function, 253multimedia, hardware, 6MultiSelectListPreference control, 234My Location Overlay, 553–554
N
native adaptersArrayAdapter, 156SimpleCursorAdapter, 156
native applications, 5–6native broadcast Intents, 196–197native dialer application, replacing, 703–704navigation
Action Bar, 364–365drop-down lists, 368–370icon navigation, 365–366tabs, 366–368views, 370
Fragments and, 366icon, 365–366non-touch screen, 436
navigation key availability, 78NDEF message creation, 698–699Ndef Records, 697NDK (native development kit), 16Network Connectivity Service, Connectivity
Manager and, 679network protocols, streaming media, 623network-based location detection, 6NewItemFragment, 128–129NFC (near-fi eld communications)
NFC Beam, 7support, 58tags
payload extraction, 694reading, 693–694
Night mode, 78NinePatch images, 434Notifi cation Builder, 410Notifi cation Manager, 7, 17, 405–406Notifi cation Tray UI, 410–415NotificationManager, 406Notifi cations, 7, 55, 405
canceling, 417creating, 407–410defaults, 408downloads, 212–213Earthquake Monitor, 418–423fl ashing lights, 409insistent, 415–416ongoing, 415–416sounds, 408status bar and, 407–410ticker text, 414–415triggering, 416updating, 416–417vibrating phone, 409
NPE (null pointer error), 568
O
ObjectAnimator class, 447–449OHA (Open Handset Alliance), 4, 10OMA (Open Mobile Alliance), 3On Shared Preferences Change Listeners, 238
bindex.indd 805bindex.indd 805 4/2/2012 2:05:45 PM4/2/2012 2:05:45 PM
806
onActivityCreated event – paid applications
onActivityCreated event, 127onActivityResult event handler, 169, 171onAttach event, 127onConfigurationChanged method, 85onConnectionInfoAvailable handler, 691onContextItemSelected method, 389onCreate method, 34, 84onCreateDialog handler, 398–399, 400onCreateLoader handler, 278onCreateOptionsMenu, 379–380onCreateView event, 127onCreateView handler, 399onDetach event, 127onDraw method, 142
Compass View, 458–466controls, 143–144
ongoing Notifi cations, 415–416onKeyDown handler, 470OnKeyListener, 475onKeyUp handler, 471onLoaderReset handler, 278onLoadFinished handler, 278onLowMemory method, 85onMeasure method, 142, 144–146OnNavigationListener method, 369–370onReceive method, 178onSaveInstanceState handler, 242–243onSensorChanged method, 486onStartCommand method, 333–335onTap event handler, 548–549onTouchEvent handler, 470OnTouchListener, 474–475onTrackballEvent handler, 471onTrackBallEvent method, 476onTrimMemory method, 85Open Mobile Alliance (OMA), 3open philosophy, 5open platform, 4–5open-source libraries
OpenGL, 4SQLite, 4WebKit, 4
open-source philosophy, 13openFileInput method, 247–248
openFileOutput method, 247–248OpenGL, 4openInputStream method, 282–283openOrCreateDatabase method, 257openOutputStream method, 282–283openRawResources method, 245optimized memory, 10optional hardware features, 58ordered Intents, broadcasting,
180–181orientation
device, 489azimuth, 498Compass View and, 502–505deprecated orientation sensor, 501–
502gyroscope, 505–506magnetometer, 498–500natural, 490–491pitch, 497–498roll, 498standard reference frame,
497–498remapping, 500–501
rotation, 80Overlays, 513
adding/removing, 549Canvas drawing, 547–548creating, 546–547ItemizedOverlays, 554–556map taps, 548–549maps and, 546–553My Location Overlay, 553–554Projections, 547Where Am I and, 549–553
overriding methods, Application class, 84–85
P
Package ManagerActivity launching, 168–169telephony support and, 702
paid applications, 779
bindex.indd 806bindex.indd 806 4/2/2012 2:05:45 PM4/2/2012 2:05:45 PM
807
Paint – process management
Paintanti-aliasing, 456–457Color Filters, 455Mask Filters, 454–455Path Effects, 455–456Shaders, 454Transfer Mode, 456
Paint class, 143–144, 451–456Passive Location Provider, 525Path Effect, 455–456Pending Intent, 523–524
proximity alerts, 530–532PendingIntent class, 182–183, 531permission tag, 60–61permissions, 740–741
coarse, 514declaring, 741enforcing, 742fi ne, 514Intents, enforcing, 742permission tag, 60–61uses-permissions tag, 60
phone callsincoming
Intent Receivers and, 712–713Phone State Listener, 709
initiating, 703system telephony stack, 704
MCC+MNC (Mobile Country Code and Mobile Network Code), 706
Phone State Listener, 708–709cell location changes, 710data connectivity, monitoring,
711–712data transfer, status changes, 711–712event handlers, 708incoming phone calls, 709onCallStateChanged method, 709service changes, tracking, 710–711unregistering, 708
PhoneStateListener, 708picture taking, Intents, 646–647pitch, device orientation and, 497–498pixels
density, resource qualifi ers, 427density-independent, 68, 426–427scale-independent, 68screen pixel density, 78
platforms, 20open, 4–5release nodes, 22Symbian, 2version, 79
plug-ins, Intent fi lters, 193–196Popup Menus, 389–390POST requests, C2DM messages,
748–749pre-installed applications, 4Preference Activities, 231, 232
Earthquake Monitor, 238–242Preference Fragments, 232
headers and, 235–236Preference Headers, 232Preference Screens, 231
backward compatibility and, 237controls, 234layout, 232
XML defi nition, 232–235system preferences, importing with
Intents, 234–235PreferenceActivity class, 236–237PreferenceCategory class, 233–234PreferenceFragment class, 235preferences
controls, native, 234importing using Intents, 234–235shared, 222, 238
Change Listener, 232creating, 222–223On Shared Preferences Change
Listeners, 238retrieving, 223saving, 222–223
PreferencesActivity class, 226prefetching, battery and, 220priority of applications, 82private application fi les, 247–248process management, 10
bindex.indd 807bindex.indd 807 4/2/2012 2:05:45 PM4/2/2012 2:05:45 PM
808
processes – remote devices
processes, 82–83ProgressDialog, 397ProGuard, 48Projections, 547promotion, 781
Google Play Store, 781–782property animations, 70–71, 446–449
sets, 449provider tag, 262proximity alerts, Pending Intents, 530–532public fi les, 248–249publishing applications, 776–778
Q
QSB (Quick Search Box), 301, 565Earthquake Monitor, search results, 615search results, 614–615
queriesCalendar, 325–326Content Providers
Content Resolver, 274–277Cursor Loader, 277–280implementing, 264–266
databases, SQLite, 257–258Download Manager, 215–217
query method, 215–217, 257–258, 264–266
Quick Search Box. See QSBQuickContactBadge control, 132
R
radio buttons, 381RadioButton control, 132raw audio, 640–643raw resources folder, 65RDBMS (relational database management
system), 253receiver tag, 62Receivers, 55
current location, 524
implementing, 178–179listening for broadcasts, 178–180manifest Receivers, 178
managing at run time, 199–200
media playback, 632–634proximity alerts, 531–532receiver tag, 62registering
application manifest, 180in code, 179–180
Recognizer Intent, 439constants, 440
RecognizerIntent class, 439redundant layouts, 103–105references
Activities, 126resources, in resources, 75–76styles in current theme, 76–77
referral tracking, 783–784Google Analytics, 786
refreshEarthquakes method, 340–343
RegEx pattern matchingLinkify and, 174Match Filter, 176
regions, 77registeredMediaButtonEventReceiver
method, 634registerRemoteControlClient method,
638Relative Layout, 101–102, 428RelativeLayout class, 98remapCoordinateSystem method,
500–501Remote Control Client, 637
registering, 638–639registerRemoteControlClient
method, 638remote devices
Bluetooth discovery, 671–673selecting for communications,
675–676
bindex.indd 808bindex.indd 808 4/2/2012 2:05:45 PM4/2/2012 2:05:45 PM
809
Remote Views – screens
Remote ViewsApp Widget Manager, 572–574
interactivity, 575–577Collection View Widgets, 591
populating, 594–595Remote Views Factory, Collection View
Widgets, 591–593repeated downloads, 220repeating Alarms, network refreshes, 354–
357request codes, launching Activities, 169requestLocationUpdates method, 522, 526requiresSmallestWidthDp tag, 60res folder, 77resolution
graphics, scalable assets, 431–434independence, 426–427pixels, density-independent,
426–427testing, 435
Resource Manager, 17resources
animationsframe-by-frame, 72–73property animations, 70–71view animations, 72
customizing, 77–78drawables, 68–69dynamic changes, 80folders, 65hardware, 77–79in code, 74–75Internet (See Internet resources)languages, 77–79layouts, 69–70, 76
directory names, 79menus, 73references, styles in current theme, 76–77referencing within resources, 75–76simple values, 65–66
colors, 67dimensions, 67–68strings, 66–67
styles, 68system resources, 76themes, 68
Resources class, 74–75results from Activities, 169–172reverse geocoding, 532, 533–534RFCOMM, Bluetooth and, 673–674RingtonePreference control, 234roll, device orientation and, 498Rotate animations, 71RotateAnimation, 443Rubin, Andy, on Android, 4Run Confi gurations, 110run time, 4
core libraries, 15Dalvik VM, 15
runtime binding, implicit Intents, 167–168
runtime confi guration changes, 79–80
S
S60 application layer, 3SaaS (software as a service), 217scalable layouts, 428Scale animations, 71scale-independent pixels, 68ScaleAnimation, 443screens. See also home screen
aspect ratio, 78design for, 39–40height, available, 78layout change, 80orientation, 78pixel density, 78Preference Screens, 231
backward compatibility and, 237layout, 232–235
resolution, independence, 426–427size, 78, 80, 96
optimizing, 427–430scalable layouts, 428
bindex.indd 809bindex.indd 809 4/2/2012 2:05:46 PM4/2/2012 2:05:46 PM
810
SDK – Sensors
supporting, 427–430testing, 435
supports-screens tag, 59–60ttouch screens, type, 78width supported, 60
available, 77–78smallest, 77
SDK (software development kit)Android APIs, 14AVD (Android Virtual Device) Manager,
14development tools, 14
AAPT (Android Asset Packaging Tool), 48
ADB (Android Debug Bridge), 48AVD (Android Virtual Device), 47DDMS (Dalvik Debug Monitoring
Service), 48dmtracedump, 48Draw9patch, 48Dx, 48Emulator (See Emulator)Hierarchy Viewer, 48, 51–52Hprof-conv, 48LayoutOpt, 48, 51–52logcat, 48MkSDCard, 48Monkey, 48, 51–52Monkey Runner, 48, 51–52ProGuard, 48SDK managers, 47SQLite3, 48Traceview, 48
documentation, 14downloading, 21–23features, 6installation, 21–23online support, 15sample code, 14starter package, 19
SDK Manager, 20, 49–50
searchesActivities, 292–293
default provider, 293–296application results in system search, 6Content Providers
metadata, 291–292Quick Search Box, 291Search bar, 291Search View, 291suggestions, 298–301
QSB (Quick Search Box), 301, 614–615
results, displaying, 294–296SearchView widget, 297speech recognition, 441
SearchView widget, 297security
Linux kernel-level security, 740permissions, 740–741
declaring, 741enforcing, 742Intents, 742
self-terminating Services, 336sendAccessbilityEvent method, 148sendBroadcastSync method, 182sendOrderedBroadcast method, 180–181sendStickyBroadcast method, 181Sensor class, 482Sensor Event Listener, implementation, 485–
487Sensor Manager, 481
accelerometer, changes, 492–493getDefaultSensor method, 484getSensorList method, 484getSystemService method, 482listing Sensors, 484onAccuracyChanged method, 486
SensorEventListener, 485–487Sensors, 58
accuracy, 486environmental, barometer, 506–507
bindex.indd 810bindex.indd 810 4/2/2012 2:05:46 PM4/2/2012 2:05:46 PM
811
Server Sockets – Shared Preferences
fi nding, 484–485gyroscope sensor, 505–506monitoring, SensorEventListener,
485–487TYPE_ACCELEROMETER, 482TYPE_AMBIENT_TEMPERATURE, 482TYPE_GRAVITY, 482TYPE_GYROSCOPE, 482–483TYPE_LIGHT, 483TYPE_LINEAR_ACCELERATION, 482TYPE_MAGNETIC_FIELD, 483TYPE_PRESSURE, 483TYPE_PROXIMITY, 483TYPE_RELATIVE_HUMIDITY, 483TYPE_ROTATION_VECTOR, 483values, 487–489virtual, 483–484
Server Sockets, creating, 692Service class, 331
skeleton, 332–333service tag, 62ServiceConnection, 337Services, 54
Activities, binding, 336–338creating, 332–333Earthquake Monitor, 338–343executing, 333–335foreground, 343–345Intent Service, implementing, 348Loaders, 349node, adding to manifest, 333registering as Intent handler, 184–185restart behavior, 333–335self-terminating, 336starting, 335–336stopping, 335–336Vibrator Service, 442Wallpaper Service, 617–618
setAntibanding camera parameter, 650setAutoWhiteBalanceLook camera
parameter, 649
setCamera method, 658setCancelable method, 397setColorEffect camera parameter, 649setContentView method, 87, 97–98setDisplayUseLogoEnabled method, 362–
363setFocusMode camera parameter, 650setInexactRepeating method, 353setLanguage method, 438setLayoutParams method, 100setListNavigationCallbacks method,
369–370setMeasuredDimension method, 145setMediaController method, 629–630setNavigationMode method, 366–367setNotificationVisibility method, 213setRepeating method, 353setResult method, 170setRetainInstance method, 127setSceneMode camera parameter, 649setShowAsActionFlags method,
380–381setTransition method, 125setTransportControlFlags method, 639setVideoPath method, 625setVideoURI method, 625setVolumeControlStream method, 632setWhiteBalance camera parameter, 649Shader class, 452–453
gradient shaders, 453–454Shaders, 452–453
Color Filters, 455Mask Filters, 454–455Paint, 454tile modes, 454
Shape Drawables, 431–432shared libraries, uses-library tag, 62Shared Preferences, 222, 238
Activity state, 242Change Listener, 232creating, 222–223
bindex.indd 811bindex.indd 811 4/2/2012 2:05:46 PM4/2/2012 2:05:46 PM
812
SharedPreferences class – static fi les as resources
On Shared Preferences Change Listeners, 238
retrieving, 223saving, 222–223
SharedPreferences class, 222–223short messaging service. See SMSshortcut keys, 381signing applications, Export Android
Application wizard, 772–774SIM
detecting, 79querying details, 707
simple values, 65–66colors, 67dimensions, 67–68strings, 66–67XML, 65–66
simple values folder, 65SimpleCursorAdapter, 156, 162–163SIP (Session Initiation Protocol), 737sizing, controls, 144–146SKD (software development kit), 5SMS (short messaging service), 701
Emergency Responder, 720–729messages
data, 717, 719emulator and, 719incoming, 717–719Intents and, 713–714maximum size, 717
overview, 713SMS Broadcast Intents, 717–719SMS Manager
message delivery, tracking/confi rming, 715–717
messagesdata messages, 717, 719maximum size, 717
sending messages, 714–715software availability, 765software stack
application framework, 15
application layer, 15libraries, 15Linux kernel, 15run time, 15
Sound Pool, 643–645sounds, Notifi cations, 408speak method, 438speech recognition
initializing, 439Recognizer Intents, 439RecognizerIntent class, 439searches, 441voice input, 440–441
speed, design challenges, 40–41speed synthesis, 437. See also TTS (text-to-
speech)Spinner control, 132split Action Bar, 364SQLite, 4, 7
databasesauto-increment key, 257constants, public, 254design, 257fi le storage, 257null column hack, 261querying, 257–258rows, 260–262SQLiteOpenHelper class, 255–257
introduction, 252, 253SQLite Open Helper, 255–256
opening databases, 256SQLite3, 48SQLiteOpenHelper class, 255–257standard reference frame
device orientation and, 497–498remapping, 500–501
startActivity method, 166–167, 234startActivityForResult method, 169startForeground method, 343–345startup, Location Providers and, 527State List Drawables, 478static fi les as resources, 245
bindex.indd 812bindex.indd 812 4/2/2012 2:05:46 PM4/2/2012 2:05:46 PM
813
sticky Intents – ToDoContentProvider class
sticky Intents, broadcasting, 181storage
external, 55–56, 246internal, 55–56public fi les, 248–249
streaming mediaaudio, playback initialization, 624–625Media Player, INTERNET permission, 623network protocols, 623video
playback initialization, 625playback surface, 626–629preview, 660Video View, 625–626
stretchable images, 434Strict Mode, 769–770strings, 66–67
link strings, 175–176style tag, 68styles, 68styles folder, 65sub-Activities
launching, 169–170results, 171–172
submenus, 378–379creating, 387
support package, 27–28supports-gl-texture tag, 60supports-screens tag, 59–60Surface Holders, 626–629Surface Views, 467–470SurfaceHolder object, 626–629SurfaceView class, 141, 467–470Symbian, 2system resources, 76
T
tasks, asynchronous, 345–349telephony, 58, 702–703
hardware support, 701–702phone call initiation, 704
Telephony Managerdata connection, 707–708data transfer activity, 707–708getSimSerialNumber method,
707getSystemService method, 705Intent Receivers, incoming phone calls,
712–713network details, 706phone device details, 705SIM, querying details, 707
textual descriptions, 436texture, supports-gl-texture tag,
60TextView control, 132themes, 68
styles, referencing, 76–77Thread Policy, 769threads
background, 345–351creating, manually, 349–351GUI, synchronization, 349–351Toasts, 404–405
ticker text in Notifi cations, 414–415
time-lapse video, 661TimePickerDialog, 397To-Do List application, 107–114
ArrayAdapter, 158–162Content Provider, 283–290database, 283–290Fragments, 128–132views, 135–138
Toast class, 401–405Toasts, 401–402
displaying, 402GUI threads, 404–405text alignment, 403Views, 403–404
ToDoContentProvider class, 283
bindex.indd 813bindex.indd 813 4/2/2012 2:05:46 PM4/2/2012 2:05:46 PM
814
ToDoListItemView class – uses-sdk tag
ToDoListItemView class, 136–138ToggleButton control, 132touch screen, 58
KeyEvent parameter, 475movement tracking, 473–474multiple touch events, 471non-touch screen navigation, 436onKeyDown event, 475OnKeyListener, 475onKeyUp event, 475onTouchEvent handler, 471OnTouchListener, 474–475single touch events, 471type, 78
Traceview, 48trackballs, 436, 476Transfer Mode, 456Transform Filter, 176Translate animations, 71TranslateAnimation, 443translucent colors, 452TTS (text-to-speech), 437–439Tweened View animation, 442
applying, 443–444creating, 443uses, 442–443
TYPE_ACCELEROMETER sensor, 482, 492–493
TYPE_AMBIENT_TEMPERATURE sensor, 482
TYPE_GRAVITY sensor, 482TYPE_GYROSCOPE sensor, 482–483TYPE_LIGHT sensor, 483TYPE_LINEAR_ACCELERATION sensor,
482TYPE_MAGNETIC_FIELD sensor, 483TYPE_PRESSURE sensor, 483, 506–507TYPE_PROXIMITY sensor, 483
TYPE_RELATIVE_HUMIDITY sensor, 483TYPE_ROTATION_VECTOR sensor, 483
U
UI (user interface)Activities, assigning, 87, 97–98customization, 5design, 96–97device independent, layouts, 100–103Fragments, 96
creating, 119destroying, 119lack, 126–128
framework, 4Layout Managers, 95mode change, 80navigation type, 78saved state, 222screen sizes, 96Strict Mode, 769–770
UIQ application layer, 3update method, 261updateWithNewLocation method, 521URI addresses, Content Providers, publishing,
263–264UriMatcher class, 263–264usage patterns, 783–784USB, 58user environment, 42–43user experience, Action Bar, 360–370user interface. See UI (user interface)uses-configuration tag, 57uses-feature tag, 58uses-library tag, 62uses-permission tags, 740–741uses-permissions tag, 60uses-sdk tag, 56
bindex.indd 814bindex.indd 814 4/2/2012 2:05:46 PM4/2/2012 2:05:46 PM
815
values – Wake Locks
V
valuesCursor, extracting, 259–260Sensors, 487–489simple values, 65–66
VIBRATE permission, 441vibration, VIBRATE permission, 441Vibrator Service, 442video
formats supported, 622–623Media Recorder and, 657–661
confi guration, 658–660controlling recording, 660–661time-lapse, 661
playback initialization, 625playback surface, 626–629recording, Intents and, 656–657stream, previewing, 660Video View, 625–626
Video View, 625–626VideoView control, 132view animations, 71–72View Groups, 86, 97
animating, 444–445layouts, 97UI design and, 96
View Stub, 105–106ViewFlipper control, 132ViewGroup class, 97
extending, 138–141layouts, 98
ViewPager control, 133Views, 34
accessibility, 148–149binding data to, adapters and, 158–163Compass View, 149–155compound, 138–140Context Menus, 388–389
controls, 97creating, 142–146custom, 141–155input events, 147–148Map Views, 536measurement implementation, 146–147menu system, 382–383minimizing use, 105–106modifying, 133–138pinning to Map View, 556–557Remote Views, App Widget Manager,
572–577size, 100subclasses, 133Toasts, 403–404UI design and, 96user interaction events, 147–148widgets, 97
views, 17container views, Fragment layouts, 121navigation, 370Surface Views, 467–470to-do list application example, 135–138Video View, 625–626
virtual Sensors, 483–484visible lifetime of an Activity, 92visible processes, 83Vm Policy, 769voice input, 440–441VOIP (voice over Internet protocol), 737volume control in Media Player, 631–632
W
Wake Locks, 631battery and, 757calling, 758
bindex.indd 815bindex.indd 815 4/2/2012 2:05:47 PM4/2/2012 2:05:47 PM
816
wallpaper – Widgets
creating, 757–758FULL_WAKE_LOCK, 757PARTIAL_WAKE_LOCK, 758SCREEN_BRIGHT_WAKE_LOCK, 757SCREEN_DIM_WAKE_LOCK, 758
wallpaper, Live Wallpaper, 6, 9, 13, 37, 565creating, 616resource defi nition, 616–617Wallpaper Service engine, 618–619
Wallpaper Service, 617–618Wallpaper Service engine, 618–619WeatherStation Activity, 508–511WeatherStation project, 508–511WebKit, 4WebView, Internet resources, 201Where Am I, 519–520
geocoding and, 535–536Map Activities and, 542–546Overlays, 549–553tracking location, 525–526
WhereAmI Activity, 520Wi-Fi, 7, 58, 202
hardware access, 6network confi gurations, 685–686
Wi-Fi Direct, 13enabling, 688framework initialization,
686–688status change, 688–689
Wi-Fi Manageraccess, 682–683confi gurations, managing, 685connection details, 684hotspots, scanning for, 684–685monitoring connectivity, 683–684
Widgets, 9, 13, 37, 55, 565Android Developers Widget Design
Guidelines, 567App Widget confi guration Activity,
580–582App Widget Manager, Remote Views,
572–577
App Widgetsadding, 566creating, 567–582
Button control, 132CheckBox control, 132Chronometer control, 132Collection View Widgets, 587–589
binding to Content Providers, 596–598
interactivity among items, 595–596
layout creation, 589–590populating, 594–595refreshing, 598Remote Views Factory,
591–593Remote Views Service, 591
design guidelines, 567–568Earthquake Widget, 582–587EditText control, 132home-screen, 6ImageButton control, 132Intent Receivers, 570–572interactivity, 575–577layouts, 567
size, 567–568supported, 568–569visual styling, 568
ListView control, 132QuickConnectBadge control, 132RadioButton control, 132refreshing
Alarms, 579–580Intents, 578–579minimum update rate,
577–578SearchView, 297settings, 569–570Spinner control, 132TextView control, 132ToggleButton control, 132VideoView control, 132
bindex.indd 816bindex.indd 816 4/2/2012 2:05:47 PM4/2/2012 2:05:47 PM
817
width supported – z-axis acceleration
ViewFlipper control, 132ViewPager control, 133Views and, 97, 568–569
width supported, 60availablesmallest, 77
widthHeightSpec method stub, 145WiFi P2P Manager, 687–688
data transfer, peers, 692–693peer connections, 690–692peer discovery, 689–692
WifiManager, 679Windows, installer, 21wizards
ADT Wizard, 65Android New Project Wizard,
28–30Export Android Application,
772–774
X
x-axis acceleration, 492XML (eXtensible Markup Language), 65
Earthquake Monitor, 205–210layouts, 99–100menu hierarchies, 384–385
Object Animator and, 448parsing, 203–205Preference Screen layout, 232–235simple values, 65–66XML Pull Parser, 203–205
XML fi les folder, 65
Y
y-axis acceleration, 492Yahoo! Pipes, 217YouTube, 5
Z
z-axis acceleration, 492
bindex.indd 817bindex.indd 817 4/2/2012 2:05:47 PM4/2/2012 2:05:47 PM
bindex.indd 818bindex.indd 818 4/2/2012 2:05:47 PM4/2/2012 2:05:47 PM
bindex.indd 819bindex.indd 819 4/2/2012 2:05:47 PM4/2/2012 2:05:47 PM