Wallace Jackson
4th ed.
Wallace Jackson
Lompoc, California, USA
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/9781484222676 . For more detailed information, please visit www.apress.com/source-code .
ISBN 978-1-4842-2267-6
e-ISBN 978-1-4842-2268-3
DOI 10.1007/978-1-4842-2268-3
Library of Congress Control Number: 2017934892
© Wallace Jackson 2017
Copyright credit in author's nameThis work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.
Printed on acid-free paper
This Android Apps for Absolute Beginners book is dedicated to everyone in the open source community who is working so diligently to make professional application development software and media content development tools freely available to multimedia application developers to utilize to achieve creative dreams and financial goals. Last, but not least, I dedicate this book to my father, Parker Jackson, my family, my life-long friends, and content production ranch neighbors, for their constant help, assistance, and those stimulating, late night BBQs.
The Android OS is currently the most popular operating system in the world. The Android OS runs on everything from smartwatches to HD or UHD smartphones to touchscreen tablets to e-book readers to game consoles to smartglasses to smartwatches to auto dashboards to new ultra-high definition interactive television sets (or iTV sets). If you want your apps to run everywhere, Android is the optimal solution.
There are even more types of consumer electronics devices, such as those found in the automotive, home appliance, security, robotics, drones, photography, industrial, and home automation markets, which are adopting the open source Android OS as their platform as time goes on. This book will show you how to develop applications for these new device-type verticals as they emerge into the market.
Since there are literally billions of Android consumer electronics devices owned by billions of people all over the world, it stands to reason that developing great Android applications for all these people might be an extremely lucrative undertaking, assuming that you have the right concept and design.
This book will help you go a long way toward learning how to develop Android applications that will run across the plethora of Android-compatible consumer electronics devices; and across all popular versions of the Android OS, including 32-bit Android 4.4 OS and the 64-bit Android 5, 6, and 7 OSes.
Developing an Android application that works well across all of these types of consumer electronics devices requires a very specific work process if you are an Absolute Beginner, involving leveraging all the Android Studio helper features, which I cover during this book. I had to write Android Apps for Absolute Beginners, Fourth Edition , from scratch because most of Android Studio 2.3’s new features are targeted at Absolute Beginners. This book is intended for readers who are Absolute Beginners to Android development. Of course you must be technically savvy, but this book is for readers who are not yet familiar with computer programming concepts and techniques.
The book will be more advanced than previous editions of Android Apps for Absolute Beginners. The first edition of this book was a mere 300 pages, as Android 1.5 was the first version to appear on Android hardware devices (smartphones), and a second edition of this book was 33% longer, at 400 pages. I’ve expanded this version of the book even more.
I designed this book to be a more comprehensive overview of the Android application development work process than most beginning Android application development books, because, at this point, there is really no way to sugarcoat the Android application development process. The new Android Studio IDE is however attempting to help beginners code and design applications using some helper features and drag-and-drop visual design editors that we will cover in detail in the book.
To become the leading Android 7 application developer that you seek to become, you will have to understand, as well as master, XML markup, user interface design, Java 8 programming, as well as new media content creation. Once you have done this, hopefully by the end of this book, you will be able to create the vanguard user experience required to create popular, best-selling Android 7 apps.
Android apps used to be developed for 32-bit Android 1.x through 4.x using Eclipse ADT’s IDE. Starting with 64-bit Android 5, Eclipse ADT IDE was replaced with Android Studio. Android applications are not developed via Android Studio alone (currently at version 2.3), but are also developed in conjunction with several key genres (2D, SVG, i3D, audio, video, imaging, SFX, etc.) of new media content development software packages.
For this reason, this book covers a wide variety of popular open source software packages, including GIMP 2.8.18, Planetside Terragen 4, Sorenson Squeeze Pro 11, and Audacity 2.1. These professional new media content production tools should be utilized in conjunction with developing your Android 7 applications. This book will show you exactly how to accomplish this, as well as how to download, install, update, configure, and actually use a number of the popular open source software packages.
This comprehensive Android 4/7 application development work process will allow you to experience exactly how the use of all of these multimedia content development software packages needs to fit into your overall Android application development work process. This 100% comprehensive "soup to nuts" multimedia-centric Android app development approach sets this 32-bit Android 4.4 and 64-bit Android 5/6/7 book title distinctly apart from all of the other Android application development titles that are currently on the market. This book covers an Android development process at a broad level while at the same time showing the Absolute Beginner Android application developer how to use an Android Studio handholding approach, by leveraging Android Studio’s ability to code bootstrap application projects allowing you to simply add your application specifics, use pop-up Java and XML code helper dialogs, use code completion, utilize a new Visual Design Editor, and implement backward compatibility features.
Chapter 1 starts at the absolute ground level, explaining what Android is, where it came from, what it is used for, where it is going, what its benefits include, what is covered in this book, as well as what is not covered in this book, as well as what some of the new features in Android 7.1.1 (called Nougat) include.
Chapter 2 covers how to assemble your Android Studio 2.3 application development workstation from scratch. This starts by covering hardware requirements and considerations, and then downloading and installing the current Java SE 8 JDK and Android Studio 2.3, along with more than half a dozen powerful open source content development applications, including Fusion, Audacity, Inkscape, Blender, GIMP, Lightscape, Open Office, and more.
Chapter 3 gives you an overview of how the Android Studio IDE, Java 8, XML, multimedia assets, and Android hardware devices are used together to create Android applications. You will be exploring the Android Studio 2.3 IDE, and learn how to have Android Studio create an application Java code and XML markup infrastructure for you to use to create your Android 7.1.1 application with. You will examine an Android Project structure and hierarchy, to see how everything comes together, and will learn about the project resource folder hierarchy and new media formats and genres that are supported in Android, of which there are many. You will learn about Android Drawables, Animation, and Menu capabilities, and how to pre-define data, constants, user interface design, and multimedia assets for your applications by using XML markup. You will learn how to update your Android Studio 2.3 IDE, so you can keep your Android development workstation current, as new versions are released.
Chapter 4 teaches you all about the XML markup language, including how to use the new Android Studio Visual Design Editor to generate entire XML markup code listings that define complex user interface design. We will dissect what XML parent and child tags are used for in UI layout containers and how to create functional UI elements in a UI design using widgets. You will also look at how XML can be used to define your application constants (fixed settings, UI designs, themes, and assets that will not change during your application’s usage). We will do all of this while expanding on the Hello World application that you created in Chapter 3 , by adding 2D graphics and a user interface design to make the application more professional, and show you how to add appeal to your bootstrap Android 7.1.1 app.
Chapter 5 serves as a Java 8 primer for those not yet exposed to Java 8, and as a review for those who have been exposed to Java 8 before. You learn all about the Java 8 SE programming language, including packages, classes, methods, constants, variables, interfaces, modifiers, keywords, versions, objects, and OOP concepts and techniques. All of this is additionally demonstrated using a sample Java code project and its structures. Thus, the first third of this Android 7.1.1 book is foundational material, which explains how the Android 7 OS works together as a whole, as well as how each of these components works in and of itself. You will build on this learning material throughout the remainder of the book.
Chapters 6 explores user interface design concepts, techniques, and workflows for Android Studio 2.3 – specifically your Visual Design Editor usage, and the Android View , ViewGroup , and Activity classes, which user interface design code, UI layout containers, and UI elements (called widgets) come from. You learn how View and ViewGroup subclasses are used to create UI layout containers filled with UI widgets, and how an Activity screen hosts and displays these, and all about the Activity class life cycle, and how these organize the application Java 8 code into logical phases (create, start, pause, resume, stop, destroy). You create a user interface design from scratch, for the project you created in Chapters 3 and 4 , including graphics ( Drawable objects) assets, UI design elements, and Android 7 OS themes.
Chapter 7 takes your static application, and makes it interactive, by using Android 7 Intent objects and coding Java event handling and event listening constructs for user interface elements defined using XML. This is where the book starts to get more complicated, both conceptually, with real-time event queue processing and application component communication using Intent objects, as well as Java 8 code-wise, with deeply nested event processing structures, explicit Intent objects, and implicit Intent Filter concepts. You will learn about the Android Intent class and objects and about what operating system events do to allow applications to know what is going on in the operating environment and what users are doing with the hardware and with user interface designs (covered during Chapter 6 ).
Chapter 8 examines Pure Android UI design patterns. These are guidelines for making your Android applications look and feel like they belong on the popular Android platform. This chapter covers the new Material Design paradigm, introduced in 64-bit Android 5, and advanced concepts such as i3D UI design, real-time automated shadowing, and animated user interface design concepts. We cover different types of hardware devices that run Android OS, and the different types of Android APIs, such as the core API for smartphones and tablets; the Wear 2.0 API, for smartwatches; the Glass API, for smartglasses; the Auto API, for automobile dashboards; and the Android TV API, for iTV Sets. I show you how to have Android Studio create one of these design paradigms, the sliding drawer UI design, for you, and how to examine the XML and Java code to understand how it works under the hood. We then test and configure this application using an AVD emulator and an Android manifest XML definition file.
Chapters 9 delves into the concepts and work process of Digital Imaging for Android, including how to create NinePatch drawables; how to use GIMP 2.8.18 to create image assets; Android Drawable classes; supported digital image formats; and digital image concepts such as pixels, resolution, alpha channels, aspect ratio, color depth, dithering, compositing, blending modes, anti-aliasing, and similar concepts that are supported across Android’s advanced digital image compositing, rendering, and Porter-Duff blending and transfer (compositing) algorithms. I show you how to have Android Studio 2.3 create a navigation drawer UI design pattern for you, and how to create multi-state image buttons.
Chapter 10 brings your application into the fourth dimension using 2D animation engines in Android such as the frame (bitmap) AnimationDrawable class and the tween (vector) Animation class. This chapter outlines the necessary animation concepts, data formats, and classes, and shows you how to create frame (or bitmap) animation, tween (vector, or procedural) animation, and a hybrid (frame and procedural combined) animation. We also add these animation assets to the NavDrawerPattern project that you created in Chapter 9 , to show how different animation approaches will work inside of one of the five different pure Android design patterns you’ll create during the course of this book.
Chapter 11 shows you how to stream Digital Video content to your Android application by using the Uri , MediaPlayer , and MediaController classes. This chapter goes into detail regarding digital video concepts, formats, and data footprint optimization, and also shows you how to create a 3D digital video asset from scratch, using Planetside Software’s Terragen 4 and Sorenson Squeeze Desktop Pro 11. You’ll code a DigitalVideoMedia project using yet another Android design pattern ( FullscreenActivity ) and address how to code a captive (part of the APK) video, and a streaming (from an external server) video asset.
Chapter 12 gets your Android hardware device’s speakers involved by adding digital audio assets to your application, using the powerful Android SoundPool class. This chapter goes into detail regarding digital audio concepts, formats, and data footprint optimization, and also shows you how to optimize a digital audio asset from scratch, using open source Audacity 2.1.2. You’ll code a fourth, DigitalAudioSequencer project, using yet another pure Android design pattern ( ScrollingActivity ) and you’ll code a children’s educational application that teaches kids the sounds that different animals make.
Chapter 13 offloads processing-intensive tasks to Android OS for background processing. You’ll learn about advanced operating system processing concepts like threads, processes, and services, which are used to perform background processing using the Android Service or Thread class. We’ll add this capability to the DigitalAudioSequencer application you created in Chapter 12 so it can play ambient background audio as a Service process, using the Android MediaPlayer operated by the Service class.
Chapter 14 looks into the Android SQLite database management system, as well as Android ContentProvider , ContentResolver, and ContentValues classes. You will learn about RDBMS database theory and how to use Android content providers to access databases.
Whereas the first five chapters of the book are foundational information, in the final five chapters of this book, you will learn about some of the more advanced development topics that normally would not be included in an Absolute Beginner title. I included these so that the important topics regarding leading-edge Android application development are all in this one, single, unified book. The included advanced topics include 2D animation, digital video, digital audio, threads, processes, and SQLite databases.
This book attempts to be the most comprehensive Absolute Beginners book for Android application development out there, by covering most, if not all of, the significant Android Studio 2.3 application development assistance features, and those core Android classes that will always need to be used to create leading-edge, 32-bit Android 4.4.4, or 64-bit Android 5.0 through 7.1.1, software applications.
It is the intention of this book to take you from being an “Absolute Beginner” in Android application development, to having a comprehensive, solid, intermediate knowledge of both 32-bit Android 4.4 and 64-bit Android 7.1.1 application development.
You should be advised that this book contains a significant amount of technical knowledge and work processes that may take more than one read-through to assimilate into your application development knowledge base (your current Android knowledge “quiver of arrows,” so to speak). This vast journey developing backwardly compatible applications for 32-bit Android 4.0 (API Level 15) through the 64-bit Android 7.1.1 (API Level 25, and later versions) will be well worth your time, however; rest assured.
I would like to acknowledge all my fantastic editors and the support staff at Apress who worked long hours and toiled so very hard on this book to make it the ultimate Absolute Beginner Android title.
Matthew Moodie , for his work as the Lead Editor on the book, and for his experience and guidance in the process of making this book one of the great Android Absolute Beginner development titles.
Mark Powers , for his work as the Coordinating Editor on the book, and for his constant diligence in making sure I hit or surpassed my deadlines.
Chaim Krause , for his work as the Technical Reviewer on the book, and for making sure I didn’t make any programming mistakes. Java code with mistakes does not run properly, if at all, unless they are very lucky mistakes, which is quite rare in computer programming these days.
Frank Serafine , my close friend, the world’s finest and most respected sound designer, and popular rock musician, for contributing the background audio sample used in this book. This audio sample is from his stellar (no pun intended) work on some of the world’s most popular science fiction as well as action adventure movies and television shows, including but not limited to Star Trek and Hunt for Red October .
Finally, I’d like to acknowledge Oracle for acquiring Sun Microsystems, and for continuing to enhance Java so that it remains the premiere open source programming language; and Google , for making Android the premiere open source operating system, and for acquiring ON2’s VP8 and VP9 video codecs (WebM) and making these available to multimedia producers on the Android OS and HTML5 platforms, allowing open source video encoding performance similar to HEVC (H.265).
Wallace Jackson has been writing for leading multimedia publications about his work process for interactive new media content development since the advent of Multimedia Producer Magazine nearly two decades ago, when he wrote about advanced computer processor architecture for a special issue centerfold (removable “mini-issue” insert) distributed at the SIGGRAPH trade show. Since then, Wallace has written for a significant number of other popular publications about his work in interactive 3D and new media advertising campaign design, including 3D Artist Magazine , Desktop Publishers Journal , Cross Media Magazine , AV Video and Multimedia Producer Magazine, Digital Signage Magazine, and Kiosk Magazine .
Wallace Jackson has authored more than half a dozen Android Development book titles for Apress, including several titles in the popular Pro Android series. This particular Android Apps for Absolute Beginners title has been rewritten entirely from scratch four times, and this fourth edition is one of the most thorough and comprehensive Absolute Beginner Android titles to be found in the market.
Wallace is currently the CEO of Mind Taffy Design , a new media content production and digital campaign design and development agency located in North Santa Barbara County, halfway between clientele in Silicon Valley to the north and in Hollywood, “The OC,” and San Diego to the south. Mind Taffy also produces interactive 3D content for major brands around the world from their content production studio on Point Concepcion Peninsula in the California Central Coast area. Mind Taffy Design has created open source technology (HTML5, Java, and Android) and digital new media content deliverables for more than a quarter century (since 1991) for a large number of the top-branded manufacturers in the world, including Sony, Samsung, IBM, Epson, Nokia, TEAC, Sun, SGI, Dell, Compaq, ViewSonic, Western Digital, CTX International, KDS USA, KFC, ADI, and Mitsubishi.
Wallace received his undergraduate degree in Business Economics from the University of California at Los Angeles (UCLA) and his graduate degree in MIS Design and Implementation from the University of Southern California (USC). His postgraduate degree from USC is in Marketing Strategy. He also completed the USC Graduate Entrepreneurship Program at USC’s popular Marshall School of Business MBA program. You can connect with Wallace at: http://www.linkedin.com/wallacejackson and follow him on Twitter @wallacejackson if you like, or visit the iTVset.com or iTVclock.com websites to see his i3D HD and UHD work.
Chaim Krause presently lives in Leavenworth, Kansas, where the U.S. Army employs him as a Simulation Specialist. In his spare time he likes to play PC games and occasionally develops his own. He has recently taken up the sport of golf to spend more time with his significant other, Ivana. Although he holds a BA in Political Science from the University of Chicago, Chaim is an autodidact when it comes to computers, programming, and electronics. He wrote his first computer game in BASIC on a Tandy Model I Level I and stored the program on a cassette tape. Amateur radio introduced him to electronics while the Arduino and the Raspberry Pi provided a medium to combine computing, programming, and electronics into one hobby.
34.231.180.210