You are previewing Android Apps for Absolute Beginners.
O'Reilly logo
Android Apps for Absolute Beginners

Book Description

Anybody can start building multimedia apps for the Android platform, and this book will show you how! Now updated to include both Android 4.4 and the new Android 5.0, Android Apps for Absolute Beginners, Third Edition takes you through the process of getting your first Android apps up and running using plain English and practical examples.

This book cuts through the fog of jargon and mystery that surrounds Android apps development, and gives you simple, step-by-step instructions to get you started.

  • Teaches Android application development in language anyone can understand, giving you the best possible start in Android development
  • Provides simple, step-by-step examples that make learning easy, allowing you to pick up the concepts without fuss
  • Offers clear code descriptions and layout so that you can get your apps running as soon as possible
  • This book covers both Android 4.4 (KitKat) and Android 5.0, but is also backwards compatible to cover the previous Android releases since Android 1.5.

    Table of Contents

    1. Cover
    2. Title
    3. Copyright
    4. Dedication
    5. Contents at a Glance
    6. Contents
    7. About the Author
    8. About the Technical Reviewer
    9. Acknowledgments
    10. Introduction
    11. Chapter 1: Setting Up Your Android App Development System
      1. The History of the Android OS: Impressive Growth
      2. Advantage Android: How Can Android Benefit Me?
      3. The Scope of This Book
        1. What is Covered in This Book
        2. What is Not Covered in This Book
      4. Assembling Your Android Development Workstation
        1. Android Development Workstation: Hardware Foundation
        2. Android Development Workstation: Software Foundation
        3. Java SE 6: Download and Install a Foundation for Android
        4. Android ADT Bundle: Find and Download Android’s IDE
        5. Install the Android ADT Bundle: Extract Android ADT IDE
        6. Digital Image Compositing Software: the GIMP
        7. 3D Modeling, Rendering, and Animation: Blender 3D
        8. UI Design and Wireframing Software: Pencil Project
        9. Digital Audio Editing and Engineering: Audacity
        10. Professional Digital Video Editing: EditShare Lightworks
        11. A Complete Business Software Suite: Apache OpenOffice
        12. Other Open Source Software
      5. Summary
    12. Chapter 2: Configuring Your Android App Development System
      1. Updating Eclipse ADT: Check For Updates!
      2. Configuring Eclipse: Android SDK Manager Repository
      3. Android Virtual Devices: Creating the AVD
        1. Creating AVDs: Android Virtual Device Manager
        2. Creating an AVD from a Pre-configured Device Definition
        3. Creating an AVD from Scratch: Pine SmartWatch
      4. What Will Be Covered in this Book
        1. Introduction to Android Application Development Platform
        2. How Android Simplifies Design: Designing Apps Using XML
        3. Android Application Framework: Java Programming Primer
        4. Screen Real Estate: View and Activity Classes
        5. Interactivity: Using Android Intent and Event Handling
        6. UI Design: Adding User Controls to Your Apps
        7. Graphics Design: Add Visuals to Your Apps
        8. Animation: Adding Motion Graphics to Your Apps
        9. Digital Video: Captive or Streaming Video for an Application
        10. Digital Audio: Adding Audio Media to Your Apps
        11. Services: Adding Background Processing to Apps
        12. Content Providers: Accessing Stored Data Inside of Your App
        13. Android Wearables: Creating a Smartwatch Application
        14. Android Appliances: Creating an Android Appliance App
        15. The Future of Android: 64-bit Android 5.0
      5. Summary
    13. Chapter 3: An Introduction to the Android Application Development Platform
      1. How the Android Platform is Structured: Java, XML, and New Media on Top of Linux
        1. Details Regarding Android’s Platform Structure
        2. Compiled App: Runtime Executable Java Bytecode
      2. Android Runtimes: Dalvik VM
      3. Android Runtimes: The Android RunTime VM
      4. Creating Your First Android Application
        1. Using Eclipse ADT to Create a New Android App
        2. Navigating Around an Android Project
      5. Android Resources: Asset Project Folders
        1. Android Drawable: Assets that Draw to a Screen
        2. Android Layout: Assets that Lay Out a UI Design
        3. Android Menu: Assets that Define Menu Options
        4. Android Values: Assets Defining App Constants
        5. Android Anim: Assets Defining Tween Animation
        6. Android Animator: Asset for Property Animation
        7. Android Raw: Pre-Optimized Video & Audio Files
        8. Android XML: Arbitrary XML and Configurations
      6. Creating a Custom App Launch Icon
        1. Creating a Launch Icon for Each Screen Density
        2. Creating Transparency: Edit the Image in GIMP
        3. Creating Resolution Density App Launch Icons
        4. Saving Your GIMP Composite: Native .XCF Format
        5. Repeat the Work Process for the Lower Density Assets
      7. Summary
    14. Chapter 4: Introduction to XML: Defining an Android App, Its Design, and Constants
      1. Extensible Markup Language: XML Overview
        1. XML Naming Schema: Tag & Parameter Repository
        2. XML Syntax: Containers, Brackets, and Nesting
        3. XML Referencing: Chain XML Constructs Together
        4. XML Constants: Editing Constants Using XML
        5. XML Dimensions: Editing Dimensions Using XML
        6. XML Styles: Editing Styles or Themes Using XML
        7. Running Your HelloUniverse App: Using Your AVD
        8. Changing the App’s Theme using XML: HOLO Dark
        9. Changing the App’s Theme using XML: HOLO Light
        10. XML Menus: Designing Menus for Android Apps
        11. XML Manifest: Configuring the Android Manifest
        12. XML Application Structure: A Bird’s Eye View
        13. Using the Eclipse Graphical Layout XML Editor
        14. Using Eclipse’s Graphical Manifest XML Editors
      2. XML Inflation: How XML Works with Java
      3. XML’s Role: Revisiting How Android Works
      4. Summary
    15. Chapter 5: Introduction to Java: Objects, Methods, Classes, and Interfaces
      1. The Three Versions, or Editions, of Java
      2. The Foundation of OOP: The Java Object
      3. OOP Terminology: Variables, Methods, Constants
      4. Java Constructs: Create Your Own Objects
        1. The Java Class: Java Code Structure Container
        2. The Java Method: Java Code Function Definition
        3. Constructor Methods: The Java Object Blueprint
        4. Instantiating Objects: The Java “new” Keyword
        5. Extend an Object’s Structure: Java Inheritance
        6. The Interface: Defining a Class Usage Pattern
        7. Logical Collection of Classes: Using a Package
        8. The API
      5. Modifiers: Data Type, Access, Inheritance
        1. Java Access Modifiers: Four Levels of Access
        2. Non-Access Modifiers: Static, Final & Abstract
      6. Creating Your HelloUniverse Class: Galaxy
        1. Defining a Galaxy Class: Variables and Methods
        2. Coding the Galaxy Class: Variable Declarations
      7. Coding Galaxy Objects: Constructor Method
        1. Creating Galaxy Functions: Coding Your Methods
        2. Creating a Java Class in Eclipse:
        3. Coding Your Class with Eclipse ADT
      8. Summary
    16. Chapter 6: Android Screen Design: Writing to the Display Using Activity and View
      1. How Activity, View, and ViewGroup Relate
      2. The ViewGroup Class: A Subclass of View
      3. Customizing Your UI Design: Galaxy Screen
        1. Eclipse Clean Project: Sanitizing Your Project
        2. Using the Galaxy Class: Creating a Galaxy Object
        3. Using LinearLayout: Creating Linear UI Designs
        4. Using Digital Imagery: Adding a Galaxy Background
        5. Creating UI Contrast: The TextView Color Parameter
        6. Nested LinearLayout Containers: Creating a More Complex UI
        7. Interfacing with UI Elements: The ID Parameter
        8. Creating Modular Code: createDefaultGalaxy()
      4. Updating the UI in Java: Using UI Objects
      5. A UI Instantiation Method: createUiTextViews()
        1. Creating the transferDataValues() Method
        2. Testing and Debugging your Application
        3. Using the LogCat
      6. Summary
    17. Chapter 7: Making Apps Interactive: Intents, Event Handling, and Menus
      1. The Menu Class and Interface: Android Menus
        1. Designing Menus in XML Using <menu> and <item>
        2. AVD Is Not Starting App: Using the Eclipse AVD Manager
      2. Inflating the Menu: onCreateOptionsMenu()
        1. The MenuItem Class: onOptionsItemSelected()
        2. The Java Switch Statement: Choosing a MenuItem
        3. Using Intent Objects: The Android Intent Class
        4. Instantiate an Intent Object: An App’s Context
        5. Explaining Context: The Android Context Class
        6. Creating Your Second Activity: The EditGalaxy Class
        7. Starting an Activity: Using the .startActivity() Method
        8. Coding the onCreate() Method: Using setContentView()
      3. Creating an EditGalaxy UI: Using a RelativeLayout
        1. Using Editable Text Fields: The EditText Widget
        2. Using Buttons in UI Designs: The Button Widget
        3. Aligning Widgets Using RelativeLayout Parameters
        4. Using the Eclipse Graphical Layout Editor (GLE)
        5. Giving an EditText Field a Hint for Your Users
        6. Aligning Several UI Elements Using RelativeLayout Parameters
        7. Adding EditGalaxy to Your App: Editing Your AndroidManifest
      4. Finishing Up the RelativeLayout UI Design
        1. Using Baseline Alignment: The layout_alignBaseline Parameter
        2. Adding a Graphics Asset to the RelativeLayout Container
      5. Event Handling: Using Event Listeners
        1. Creating an Event Listener: .onClickListener()
        2. Creating an Event Listener: .onClickListener()
        3. Making the Galaxy Object Accessible: Using The static Keyword
        4. Transferring EditText Data to the Galaxy Object Using .parse() Methods
      6. Summary
    18. Chapter 8: Android UI Design: Using Advanced ViewGroup Layout Containers
      1. Using the Android GridLayout UI Container
        1. GridLayout Class: Grid-Based UI Layout Designs
        2. Using the rowSpec and columnSpec Parameters
        3. GridLayout Location, Flexibility, and Gravity
        4. The GridLayout.LayoutParams Nested Class: Parameters
        5. The GridLayout.Alignment Nested Class: Alignment Constants
      2. Converting a RelativeLayout UI to a GridLayout
        1. Upgrading Your HelloUniverse App to Android 4.0
        2. GridLayout Parent Parameters: Let’s Experiment!
      3. GridLayout Parameters: Configuring Your Grid
        1. GridLayout Alignment: The UseDefaultMargins Constant
        2. Changing the Widget Order Inside of the GridLayout
      4. Combining GridLayout Cells: Using a Span
        1. Align GridLayout Cells: Using the layout_gravity Parameter
      5. Using the Android SlidingPaneLayout Class
        1. The Android SlidingPaneLayout: Class Specification
      6. Using SlidingPaneLayout: Galaxy Selector
        1. Creating a SlidingPaneLayout: Revising the XML
        2. Set Pane Size: layout_width and layout_weight
      7. Summary
    19. Chapter 9: Android Graphic Design: Making Your UI Designs Visual
      1. Imaging Concepts, Formats, and Techniques
        1. The Foundation of Digital Images: The “Pixel”
        2. The Shape of a Digital Image: The Aspect Ratio
        3. Coloring Your Digital Images: RGB Color Theory
        4. Image Compositing Transparency: Alpha Channels
        5. Algorithmic Image Compositing: Blending Modes
        6. Masking Digital Imagery: Using Alpha Channels
        7. Smoothing Edges: The Concept of Anti-Aliasing
        8. Optimizing Digital Images: Compress and Dither
        9. Using Indexed Color Imagery: Dithering Pixels
        10. Android Image Formats: Lossless Versus Lossy
      2. Creating Android NinePatchDrawable Assets
        1. Installing Your Android Draw 9-patch Software
        2. Opening the Source Digital Image in Draw 9-patch
        3. Exploring Your New Draw 9-patch Editing Software
        4. Defining Your NinePatchDrawable Scalable Areas
        5. Defining Your NinePatchDrawable Padding Areas
        6. Saving Your NinePatchDrawable Asset in Android
      3. The ImageButton Class: Multi-state Buttons
        1. The States: Normal, Pressed, Focused, Hovered
      4. Creating Multi-State Imagery: Using GIMP
        1. Using GIMP for Compositing: Importing a Layer
        2. Creating an Alpha Channel: Fuzzy Select Tool
        3. Creating a Composite Layer Using the Clipboard
        4. Creating Five Resolution Density Button Versions
        5. Creating Your Other Three ImageButton States
      5. Creating Your ImageButton’s XML Structure
        1. Referencing Multi-State XML via activity_main
      6. Adding a NinePatch to a SlidingPaneLayout
      7. Summary
    20. Chapter 10: Android Animation: Making Your UI Designs Move
      1. Frame Animation Concepts and Techniques
        1. Frame Animation: Cels, Frames, and Terminology
        2. Frame Animation Formats: PNG, GIF, JPEG & WebP
        3. Optimizing Frames: Color Depth and Frame Count
        4. Animation Resolution: Pixels Add to File Size!
      2. The Android AnimationDrawable Class
      3. Creating Frame Animation Using XML Markup
        1. The <animation-list> Tag: Your Frame Container
        2. The <item> Tag: How to Add in Animation Frames
      4. Creating Frame Animation in MainActivity
        1. Creating an anim_milkyway.xml File and Markup
        2. Wiring-Up Your Animation: Referencing Your XML
        3. Resizing Source Imagery: Using Padding Values
        4. Testing Your SlidingPane in a Galaxy Nexus AVD
      5. Tween Animation Concepts and Techniques
        1. Procedural Concepts: Rotate, Scale, Translate
        2. Procedural Data Values: Ranges and Pivot Point
        3. Procedural Compositing: Alpha Blending
        4. Procedural Timing: Using Duration and Offsets
        5. Procedural Loops: RepeatCount and RepeatMode
        6. The Animation Class: Android Tween Animation
      6. Creating Tween Animation Using XML Markup
        1. Create an /anim Folder: Tween Animation Assets
        2. Rotate Transform: The Configuration Parameters
        3. SetUp an ImageView: Assigning an ID Parameter
        4. Java Coding: Tying Your UI Together Using Java
        5. Making Your UI Interactive: Add Event Handling
        6. Using .setBackground(): Upgrade App to SDK V16
      7. Hybrid Animation: Using Frames with Tween
        1. Setting up Your Hybrid Animation via Java Code
        2. Completing the Galaxy UI Design: Using .setText()
      8. Procedural Animation or Frame Animation?
      9. The Animator Class: Parameter Animation
      10. Summary
    21. Chapter 11: Digital Video: Streaming Video, MediaPlayer, and MediaController classes
      1. The FrameLayout Class: Framing DV Content
        1. FrameLayout.LayoutParams Nested Class: Gravity
        2. Creating a Frame Layout Using XML Mark-Up
      2. Create a Activity Subclass
      3. Creating Your activity_play XML UI Design
      4. The VideoView Class: A VideoPlayer Widget
        1. A VideoView Lifecycle: Eight Video Playback Stages
        2. Creating a VideoView Widget in the FrameLayout
      5. The Uri Class: Referencing the Video Data
        1. The Uri.parse() Method: Loading Your VideoView
      6. Digital Video Concepts: Bitrates & Codecs
        1. Digital Video in Android: MPEG4 H.264 and WebM
        2. Digital Video Compression: Bitrate and Streams
        3. Digital Video Optimization: Codec and Settings
      7. Creating Digital Video Content: Terragen3
        1. Creating an Uncompressed AVI File: VirtualDub
        2. Applying Video Compression: Sorenson Squeeze 9
      8. Starting A Video Playback: Using .start()
        1. Positioning a Video Asset Using layout_gravity
        2. Scaling Video Non-Uniformly to Fit the Screen
      9. Android MediaPlayer: VideoPlayback Engine
        1. Loop Digital Video: Using .OnPrepareListener()
        2. Streaming Digital Video: Using HTTP URL in URI
        3. Add a Video Transport UI Using MediaController
      10. Summary
    22. Chapter 12: Digital Audio: Providing Aural Feedback for UI Designs Using SoundPool
      1. Audacity 2: Creating Digital Audio Assets
        1. Audacity Plug-Ins: Adding Codecs and Features
        2. Free Digital Audio: Locate HelloUniverse Audio
        3. Digital Audio Optimization: Concepts & Formats
        4. Setting Sample Rate and Resolution in Audacity
        5. Exporting Uncompressed PCM Baseline WAV Format
        6. Exporting via Lossless FLAC: FLAC audio files
        7. Exporting Lossy Ogg Vorbis: OGG audio files
        8. Exporting Lossy MPEG3 Format: MP3 audio files
        9. Exporting Lossy MPEG4 Format: M4A audio files
        10. Exporting Narrow Band Format: AMR audio files
      2. Android SoundPool: Audio Engine & Methods
        1. Adding a SoundPool Engine to the HelloUniverse
        2. Creating a .triggerSample() Method: SoundPool .play()
        3. Adding SoundPool to Your UI: Calling .triggerSample()
      3. Summary
    23. Chapter 13: Android Service Class and Threads: Background Processing
      1. Android Service Classes: Characteristics
        1. Controlling Your Service: Privacy and Priority
        2. Processes and Thread: Foundational Information
        3. Spawning a Process: The android:process XML Parameter
        4. The Process Lifecycle: Keeping a Process Alive
        5. Thread Caveats: Don’t Interfere with UI Thread
        6. Should Your Android App Use Services or Threads?
      2. Creating a Service Subclass: AmbientService
        1. Using a Service to Carry Out a Task
        2. Configuring AndroidManifest to Add a <service>
      3. Starting a Service: Using .startService()
        1. Setting Up Your UI Design Using XML and Java
        2. Testing the PlayVideo Class with the Nexus One
      4. Summary
    24. Chapter 14: Android Content Providers: Providing Data to Applications
      1. An Overview of Android Content Providers
      2. Database Fundamentals: Concepts and Terms
      3. SQLite: The Open Source Database Engine
      4. Android Built-in Content Providers
        1. Android 1.5 Contacts Database Contact Provider
        2. Deprecated Database Structures: Software Upgrades
        3. The Android MediaStore Content Providers
        4. The Android CalendarContract Content Providers
      5. Referencing a Content Provider: Content URI
      6. Creating the Activity:
        1. Adding the ContactGalaxy Class to the Manifest
        2. Adding a Contact Galaxy Ruler Item to the Menu
        3. Adding a Menu Intent in the MainActivity Class
        4. Creating Your Galaxy Emperor Contact Database
      7. Adding Permissions in the AndroidManifest
      8. TableLayout: Creating Tabular UI Designs
        1. Creating Your TableLayout UI for ContactGalaxy
      9. ContactGalaxy Class: Accessing Your Database
        1. Using the Android ContentResolver Class
      10. Writing to a Database: addGalaxyViceroy()
      11. Summary
    25. Chapter 15: Developing for Android Wearable Devices
      1. True Wearables versus Android Peripherals
      2. Development Strategy: Android, Wear SDK, or Plug-In
      3. Smartwatch Optimization Fundamentals: Display and CPU
      4. Creating Your EarthTime.APK Android App
      5. EarthTime UI Design: Styling an AnalogClock
        1. Adding the Background Image of Planet Earth
        2. EarthTime Code: Class
        3. Attaching the Pine to the Workstation USB Port
        4. Creating Your EarthTime Application Icons
      6. Adding Interactivity to the EarthTime App
        1. Adding Four ImageView UI Icons to a UI Design
        2. Enhancing the App: Adding Background Images
        3. EarthTime Interactive: Adding Event Handling
      7. Summary
    26. Chapter 16: The Future of Android: The 64-Bit Android 5.0 OS
      1. What’s New in Android 5: New OS Features
        1. Android 5.0 Platform: 64-Bit Linux and Java 7
        2. Android 5 Runtime: ART Will Become the Default
        3. Enhanced 3D Support: OpenGL, Z-Layers, and Shadows
        4. The Camera 2 API: UHD with High Dynamic Range
        5. Project Volta: Control Power Use Optimization
        6. Enhanced Notifications: Notify via Lockscreen
        7. USB Audio Port: Connect Audiophile Equipment
        8. Android 5 Support: New CPU Hardware and Search
        9. Google Play 5.0: New Server-Side 5.0 Services
      2. Material Design: Multi-Platform UI Design
      3. Developing 64-Bit Android: The Android 5 IDE
      4. Removing Java 6: Prepare a System for Android 5
      5. Java 7 SE: The Foundation for Android Studio 5
      6. Android Studio 5: IntelliJ Android SDK Bundle
      7. Downloading and Installing Android Studio
        1. Exploring Android Studio 5: Configuring an IDE
      8. Creating Your First Android 5 Project
        1. Exploring Your Android 5.0 App in IntelliJ
      9. Updating the Android Studio IntelliJ IDEA
      10. Android TV: Setting Up Android 5 Apps for iTV
      11. Porting the EarthTime App to Android TV
      12. Summary
    27. Appendix A: Audio Concepts, Terminology, and Codecs
      1. Analog Audio and Digital Audio: History, Concepts, and Theory
        1. Foundation of Analog Audio: Sound Waves of Air
        2. Digital Audio: Samples, Resolution, and Frequency
        3. Digital Audio Attributes: HD, Stream, and Bit Rate
        4. Android Digital Audio: Digital Audio Formats
        5. Digital Audio Optimization: Device Compatible
      2. Audio Sequencing: Concepts and Principles
        1. Digital Audio Synthesis: Concepts and Principles
        2. Raw Audio Data Optimization: Memory Footprint
        3. Digital Audio Synthesis and Sequencing Caveats
    28. Index