Android Apps for Absolute Beginners_ Get Started with Building Your Very Own Android Apps (2nd ed.) [Jackson 2012-12-03](2).pdf

(28653 KB) Pobierz
Get started with building your
very own Android apps
for
Absolute Beginners
SECOND EDITION
Wallace Jackson
Android Apps
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
Contents at a Glance
About the Author �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½xiii
About the Technical Reviewer �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xv
Acknowledgments �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xvii
Introduction �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½
xix
Chapter 1: Preliminary Information: Before We Get Started �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½1
Chapter 2: What’s Next? Our Road Ahead�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½13
Chapter 3: Setting Up Your Android Development Environment �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½21
Chapter 4: Introducing the Android Software Development Platform �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½53
Chapter 5: Android Framework Overview �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½99
Chapter 6: Screen Layout Design: Views and Layouts �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½125
Chapter 7: UI Design: Buttons, Menus, and Dialogs�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½163
Chapter 8: An Introduction to Graphics Resources in Android �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½209
Chapter 9: Adding Interactivity: Handling UI Events �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½235
Chapter 10: Understanding Content Providers �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½277
Chapter 11: Understanding Intents and Intent Filters �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½305
Chapter 12: Advanced Android Topics �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½351
Index �½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½�½369
iii
Introduction
Over the last three years, Google’s Android operating system (OS) has gone from a virtually unknown
open source solution to the current mobile OS market leader among all mobile handsets, with over
one-half of the market share and still climbing. Android has even started to dominate the tablet OS
marketplace, and is also the foundation for the popular iTV OS known as GoogleTV as well as for
e-book e-readers from Sony, Amazon (Kindle), and Barnes and Noble (Nook). There seems to be no
end in sight for Android’s rocketing success, which is great news for the owners of this book.
I’ve heard a great many people say, “I have a really phenomenal idea for a smartphone and
tablet application! Can you program it for me!?” Rather than sit back and code all of these cool
applications for everyone, I thought it might be a smarter idea to write a book about how an absolute
beginner could code an Android application using open source tools that cost nothing to download
and that are free for commercial use, and then leverage that new found knowledge to reach their
dream of making their application idea a revenue-generating reality.
Thanks to open source tools and formats and Google’s Android development environment,
Oracle’s Java programming language, Linus Torvalds’ Linux operating system, the Eclipse code
editing software, and to this book of course, vaporizing a software product out of thin air and at no
production cost other than your PC and “sweat equity,” is now a complete reality.
The Target: The Programming Neophyte
As you may have inferred from the title, this book assumes that you have never programmed before
in any programming language. It is written for someone who has never written a single line of code,
and who is thus unfamiliar with object-oriented programming (OOP) languages such as Oracle’s Java
and markup languages such as XML. Both of these open source languages are used extensively in
creating Android applications and will be taught thoroughly in this book.
There are a lot of Java and Android books out there, but all of those books assume that you have
programmed before and know all the OOP and programming lingo. I wanted to write a book that
takes readers from knowing absolutely nothing about programming; not even knowing about how to
install a software development kit (SDK) or an integrated development environment (IDE), all of the
way from Ground Zero to being able to program useful Android applications using Java and XML
and new media assets such as images, audio, and animation.
xix
xx
Introduction
The Weapon: Android—An Innovative Internet 2�½0
Coding Environment
Android is my Internet 2.0 development weapon of choice because it allows me to develop highly
advanced applications for the primary Internet 2.0 devices, including the primary four consumer
electronics product “verticals” where revenue potential is by far the greatest:
n
n
n
n
Smartphones
Tablets
e-book e-readers
iTVs or interactive television sets
The other reason I place my bets on Android is because it is open source and uses open source
technologies and is therefore free from royalties and politics. It includes advanced new media
“engines” (tools) such as OpenGL, ON2 VP8 (WebM and WebP), Java, XML, CSS, HTML5, PNG,
and JPEG. I do not have to submit my Android application to any company and ask for permission
to publish it, as long as it is not harmful in any way to others. For this reason, and due to the free for
commercial use nature of open source software, there is little external risk involved in developing an
application for the Android Platform.
How This Book Is Organized
Because this is a book for absolute beginners, we start at the very beginning—showing where to
download, and how to install, the various Android, Java, and Eclipse environments. We also show
how to configure these environments, and how to set them up for application development and
testing. We even show how and where to download the other leading-edge new media tools (GIMP,
for instance) that you will use in conjunction with the primary Android development tools.
We essentially show you exactly how to put together a complete and professional-level Android New
Media Content Production Workstation, and at zero cost to yourself to boot. This in itself is no easy
task, and must be done correctly, as these professional tools provide the foundation for all of our
Android development, debugging, and testing for the remainder of the book.
Next we provide you with an overview of where Android came from, why, how, and when Google
acquired it, and how it is uniquely structured among software development platforms. We introduce
XML, Java, OOP, and Android concepts soon after that, as well as covering how Android manages
its screen layout. We then move these concepts into use in later chapters in the second half of the
book; these chapters explain the most important concepts in Android, in their most logical order, as
they pertain to your applications development.
In that second half of the book, we start getting into developing a user interface (UI), as that is the
front-end or interface for your end-users to your Android application. Soon after that we cover
how your UI talks to your application via events processing. To spice up your application’s visual
appearance, we’ll get into graphics, animation, and audio, and then into even more advanced topics
after that, such as databases and communications.
Zgłoś jeśli naruszono regulamin