Android for Programmers: An App-Driven Approach Deitel Developer Series
Paul Deitel
Harvey Deitel
Abbey Deitel
Deitel & Associates, Inc.
Michael Morgano
Imerj
Upper Saddle River, NJ Boston Indianapolis San Francisco
New York Toronto Montreal London Munich Paris Madrid
Capetown Sydney Tokyo Singapore Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus, and branding interests. For more information, please contact:
U. S. Corporate and Government Sales
(800) 382-3419
For sales outside the U. S., please contact:
International Sales
Visit us on the Web: informit.com/ph
Library of Congress Cataloging-in-Publication Data
On file
2012 Pearson Education, Inc.
Portions of the cover are modifications based on work created and shared by Google (http://code.google.com/policies.html) and used according to terms described in the Creative Commons 3.0 Attribution License (http://creativecommons.org/licenses/by/3.0/).
All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to (201) 236-3290.
ISBN-13: 978-0-13-212136-1
ISBN-10: 0-13-212136-0
Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, Indiana.
First printing, October 2011
Trademarks
DEITEL, the double-thumbs-up bug and DIVE INTO are registered trademarks of Deitel and Associates, Inc.
Java is a registered trademark of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Microsoft, Internet Explorer and the Windows logo are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.
Google is a trademark of Google, Inc.
Throughout this book, trademarks are used. Rather than put a trademark symbol in every occurrence of a trademarked name, we state that we are using the names in an editorial fashion only and to the benefit of the trademark owner, with no intention of infringement of the trademark.
In memory of Daniel McCracken. Computer science has lost one of its greatest educators.
Paul, Harvey, Abbey and Michael
Contents
Dive-Into Eclipse and the ADT Plugin
Building an Android App with Java
SharedPreferences
, Button
s, Nested Layouts, Intent
s, AlertDialog
s, Inflating XML Layouts and the Manifest File
Assets, AssetManager
, Tweened Animations, Handler
, Menus and Logging Error Messages
Listening for Touches and Gestures, Manual Frame-By-Frame Animation, Graphics, Sound, Threading, SurfaceView
and SurfaceHolder
Property Animation, ViewPropertyAnimator
, AnimatorListener
, Thread-Safe Collections, Default SharedPreferences
for an Activity
Two-Dimensional Graphics, SensorManager
, Multitouch Events and Toast
s
ListActivity
, AdapterView
s, Adapter
s, Multiple Activities, SQLite, GUI Styles, Menu Resources and MenuInflater
Google Maps API, GPS, LocationManager
, MapActivity
, MapView
and Overlay
Gallery and Media Library Access, Built-In Content Providers, MediaPlayer
, Image Transitions, Custom ListActivity
Layouts and the View-Holder Pattern
Serializing Data, Taking Pictures with the Camera and Playing Video in a VideoView
Web Services, JSON, Fragment
, ListFragment
, DialogFragment
, ActionBar
, Tabbed Navigation, App Widgets, Broadcast Intent
s and BroadcastReceiver
s
Chapters on the Web
See the Online Chapters section of the Preface for information on downloading these chapters.
15 PHABs Pizza App
Text-to-Speech, Speech-to-Text and Telephony
16 Voice Recorder App
Audio Recording and Playback
17 Enhanced Address Book App
Bluetooth
18 3D Art App
OpenGL ES 3D Rendering
19 HTML5 Favorite Twitter Searches App
Bonus Chapter: HTML5, CSS3 and JavaScript for Experienced Web Developers
Preface
Welcome to the dynamic world of Android smartphone and tablet app development with the Android Software Development Kit (SDK) 2.3.x and 3.x, the Java programming language and the Eclipse integrated development environment (IDE).
This book presents leading-edge mobile computing technologies for professional software developers. At the heart of the book is our app-driven approach. We present concepts in the context of 17 complete working Android apps16 developed in the native Android environment and one developed in HTML5 for the portable world of the webrather than using code snippets..
Sales of Android devices and app downloads have been growing exponentially. The first-generation Android phones were released in October 2008. A study by comScore showed that by July 2011, Android had 41.8% of the U.S. smartphone market share, compared to 27% for Apples iPhone and 21.7% for Blackberry. Billions of apps have been downloaded from Android Market. More than 500,000 Android devices are being activated daily. The opportunities for Android app developers are enormous.
The demand for mobile devices is increasing as more people rely on smartphones and tablets to stay connected and be productive while away from their personal computers. According to comScore, 234 million Americans used mobile devices in a three-month period ending in July 2011. Of those subscribers, 40.6% used apps.
Fierce competition among popular mobile platforms (Android, BlackBerry, iPhone, Palm, Symbian, Windows Phone 7 and others) and among mobile carriers is leading to rapid innovation and falling prices. Competition among the dozens of Android device manufacturers is driving hardware and software innovation within the Android community. There are now over 300 different Android devices.
Next page