You are previewing Android 5 Programming by Example.
O'Reilly logo
Android 5 Programming by Example

Book Description

Turn your ideas into elegant and powerful mobile applications using the latest Android Studio for the Android Lollipop platform

In Detail

Android is a mobile operating system that runs on a staggering number of smart phones and tablets. Android offers developers the ability to build rich and innovative applications written using the Java programming language.

Beginning with detailed instructions on how to install and configure the Android SDK, Studio, and Virtual Device Manager, the book moves on to creating a simple, but working, "Hello World" app that can be run on a real device or emulator.

The book then moves on to layouts and the visual design of Lollipop apps. A new app is begun to demonstrate this and expanded as we move further, and, once material design has been introduced, the book moves on to the Java coding aspect and how to write code that responds to user interactions via callback methods such as touchscreen gesture listeners. No book on Lollipop APIs would be complete without explaining how the new Android TV, Wear, and Auto SDK tools work and how they can be utilized to either create new apps or convert those originally written for other platforms.

The book concludes by demonstrating how to package and deploy your finished app on the Google Play store

What You Will Learn

  • Set up an effective development environment to create Android apps from scratch

  • Control the layout structure and design and edit code to control screen events

  • Respond to user interaction using Java and XML with your app

  • Keep your users up to date with Android's new notification framework

  • Implement Google APIs such as maps and other Google Services

  • Create apps for televisions, cars, and wearables and build home-screen app widgets

  • Add audio and video playback to your apps using the AudioManager and MediaPlayer classes

  • Program the two new Lollipop widgets, CardView and RecyclerView

  • Compile your apps, distribute them on the Google Play store, and build in a variety of ways to monetize them

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

    Table of Contents

    1. Android 5 Programming by Example
      1. Table of Contents
      2. Android 5 Programming by Example
      3. Credits
      4. About the Author
      5. About the Reviewers
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Setting Up the Development Environment
        1. What is Android 5?
          1. Lollipop from a user's perspective
          2. Lollipop from a developer's perspective
            1. Material Design
            2. Other devices
              1. TV
              2. Wear
              3. Auto
        2. Installing and configuring the development environment
          1. Installing the SDK
          2. Managing the SDK tools
        3. Creating a "Hello World" app
          1. Testing the app on a physical device
        4. Setting up a virtual device
          1. Monitoring devices
        5. Summary
      9. 2. Building a UI
        1. Applying a Material Design theme
        2. Adding animated widgets
          1. Designing an XML layout
          2. Controlling the widget behavior with Java
        3. Creating alternative layouts
        4. Summary
      10. 3. Activities and Fragments
        1. Adding a CardView widget
        2. Adding images and text to the layout
        3. Creating a second Activity
        4. Applying Fragments
          1. Adding static Fragments
        5. Adding menus and toolbars
          1. Adding menu items to the menu XML files
          2. Configuring the toolbar
        6. Summary
      11. 4. Managing RecyclerViews and Their Data
        1. Creating a RecyclerView
          1. Adding a CardView with layout
          2. Adding a LayoutManager
          3. Adding a dataset
        2. Creating an Adapter
        3. Responding to the RecyclerView selections
          1. Creating the OnClickListener
          2. Adding the new Activity
            1. Creating the portrait layout
            2. Creating the landscape layout
            3. Connecting Views to web pages
        4. Summary
      12. 5. Detecting Touchscreen Gestures
        1. Adding a GestureDetector to a view
          1. Adding the gallery data
          2. Adding the GestureDetector
          3. Viewing gesture activity with DDMS
          4. Implementing a SimpleOnGestureListener
        2. Adding a GestureDetector to an Activity
          1. Designing the splash screen layout
          2. Editing the Manifest
          3. Adding the GestureDetector
        3. Summary
      13. 6. Notifications and the Action Bar
        1. Constructing a ViewPager
          1. Creating the layout
          2. Adding a ViewPager and FragmentPagerAdapter
        2. Adding tabs and dates
        3. Programming notifications
          1. Adding a standard notification and icon
          2. Expanding a notification
          3. Issuing heads-up and lock screen notifications
        4. Summary
      14. 7. Maps, Locations, and Google Services
        1. Building a location-aware app with Google Maps
          1. Acquiring an API Key
          2. Acquiring the last known location
          3. Requesting location updates
          4. Moving around and animating a Google Map
        2. Summary
      15. 8. Apps for TVs, Cars, and Wearables
        1. Android Wear
          1. Constructing and connecting to a wearable AVD
            1. Connecting a wearable AVD with another emulator
          2. Creating a wearable project
          3. Designing a UI for wearables
            1. Designing the layout
            2. Adding cards
            3. Customizing cards
          4. Accessing sensor data
        2. Android TV
        3. Android Auto
        4. Summary
      16. 9. Camera, Video, and Multimedia
        1. Capturing images
          1. Refactoring code
          2. Previewing the camera output
          3. Saving the camera output
        2. Capturing and playing video
          1. Playing video from memory and the Internet
          2. Exploring the camera2 APIs
        3. Recording and playing audio
        4. Summary
      17. 10. Publishing and Marketing
        1. Making apps backward-compatible
          1. Adding the v7 support libraries
        2. Applying Material Design to older platforms
        3. Publishing apps
        4. Generating a signed APK
          1. Registering as a developer
          2. Publishing an app on the Google Play Store
        5. Distributing by e-mail and websites
          1. Promoting and monetizing apps
          2. Promoting an app
          3. Monetizing an app
        6. In-app billing
          1. Including an advertisement
        7. Summary
      18. Index