Android 9 Development Cookbook
eBook - ePub

Android 9 Development Cookbook

Over 100 recipes and solutions to solve the most common problems faced by Android developers, 3rd Edition

  1. 464 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Android 9 Development Cookbook

Over 100 recipes and solutions to solve the most common problems faced by Android developers, 3rd Edition

About this book

Build feature-rich, reliable Android Pie apps with the help of more than 100 proven industry standard recipes and strategies.

Key Features

  • Uncover the latest features in Android 9 Pie to make your applications stand out
  • Develop Android Pie applications with the latest mobile technologies, from set up to security
  • Get up-to-speed with Android Studio 3 and its impressive new features

Book Description

The Android OS has the largest installation base of any operating system in the world. There has never been a better time to learn Android development to write your own applications, or to make your own contributions to the open source community! With this extensively updated cookbook, you'll find solutions for working with the user interfaces, multitouch gestures, location awareness, web services, and device features such as the phone, camera, and accelerometer. You also get useful steps on packaging your app for the Android Market. Each recipe provides a clear solution and sample code you can use in your project from the outset. Whether you are writing your first app or your hundredth, this is a book that you will come back to time and time again, with its many tips and tricks on the rich features of Android Pie.

What you will learn

  • Develop applications using the latest Android framework while maintaining backward-compatibility with the support library
  • Create engaging applications using knowledge gained from recipes on graphics, animations, and multimedia
  • Work through succinct steps on specifics that will help you complete your project faster
  • Add location awareness to your own app with examples using the latest Google Play services API
  • Utilize Google Speech Recognition APIs for your app

Who this book is for

If you are new to Android development and want to take a hands-on approach to learning the framework, or if you are an experienced developer in need of clear working code to solve the many challenges in Android development, you will benefit from this book. Either way, this is a resource you'll want to keep on your desk as a quick reference to help you solve new problems as you tackle more challenging projects.

Trusted by 375,005 students

Access to over 1 million titles for a fair monthly price.

Study more efficiently using our study tools.

Information

Year
2018
Edition
3
eBook ISBN
9781788622967

Graphics and Animation

In this chapter, we will cover the following topics:
  • Scaling down large images to avoid Out of Memory exceptions
  • A transition animation: Defining scenes and applying a transition
  • Creating a Compass using sensor data and RotateAnimation
  • Creating a slideshow with ViewPager
  • Creating a Card Flip Animation with Fragments
  • Creating a Zoom Animation with a Custom Transition
  • Displaying an animated image (GIF/WebP) with the new ImageDecoder library
  • Creating a circle image with the new ImageDecoder

Introduction

Animations can be both visually appealing and functional, as demonstrated with the simple button press. The graphical representation of the button press brings the app alive, plus it provides a functional value by giving the user a visual response to the event.
The Android Framework provides several animation systems to make it easier to include animations in your own application. They include the following:
  • View Animation (the original animation system): It usually requires less code but has limited animation options
  • Property Animation: It's a more flexible system, allowing the animation of any property of any object
  • Drawable Animation: It uses drawable resources to create frame-by-frame animations (like a movie)
The Property Animation system was introduced in Android 3.0, and it is usually preferred over the View Animation because of the flexibility. The main drawbacks to the View Animation include the following:
  • Limited aspects of what can be animated, such as scale and rotation
  • Can only animate the contents of the view; it cannot change where on the screen the view is drawn (so it cannot animate moving a ball across the screen)
  • Can only animate View objects
Here is a simple example demonstrating a View Animation to "blink" a view (a simple simulation of a button press):
Animation blink =AnimationUtils.loadAnimation(this,R.anim.blink); view.startAnimation(blink); 
Here are the contents for the blink.xml resource file, located in the res/anim folder:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:background="#000000" android:interpolator="@android:anim/linear_interpolator" android:duration="100" android:repeatMode="restart" android:repeatCount="0"/> </set> 
As you can see, it's very simple to create this animation, so if the View Animation accomplishes your goal, use it. When it doesn't meet your needs, turn to the Property Animation system. We'll demonstrate Property Animation using the new objectAnimator in the Creating a Card Flip Animation with Fragments and Creating a Zoom Animation with a Custom Transition recipes.
The A transition animation – defining scenes and applying a transition recipe will provide additional information on the Android Transition Framework, which we will use in many of the recipes.
The Interpolator is a function that defines the rate of change for an animation.
Interpolators will be mentioned in several recipes in this chapter, as well as in the previous blink example. The Interpolator defines how the transition is calculated. A Linear Interpolator will calculate the change evenly over a set duration, whereas an AccelerateInterpolator function would create faster movement for the duration. Here is the full list of Interpolators available, along with the XML identifier:
  • AccelerateDecelerateInterpolator (@android:anim/accelerate_decelerate_interpolator)
  • AccelerateInterpolator (@android:anim/accelerate_interpolator)
  • AnticipateInterpolator (@android:anim/anticipate_interpolator)
  • AnticipateOvershootInterpolator (@android:anim/anticipate_overshoot_interpolator)
  • BounceInterpolator (@android:anim/bounce_interpolator)
  • CycleInterpolator (@android:anim/cycle_interpolator)
  • DecelerateInterpolator (@android:anim/decelerate_interpolator)
  • LinearInterpolator (@android:anim/linear_interpolator)
  • OvershootInterpolator (@android:anim/overshoot_interpolator)
Although animations don't generally require much memory, the graphic resources often do. Many of the images you may want to work with often exceed the available device memory. In the first recipe of this chapter, Scaling down large images to avoid Out of Memor...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. Dedication
  4. About Packt
  5. Contributors
  6. Preface
  7. Activities
  8. Layouts
  9. Views, Widgets, and Styles
  10. Menus and Action Mode
  11. Fragments
  12. Home Screen Widgets, Search, and the System UI
  13. Data Storage
  14. Alerts and Notifications
  15. Using the Touchscreen and Sensors
  16. Graphics and Animation
  17. A First Look at OpenGL ES
  18. Multimedia
  19. Telephony, Networks, and the Web
  20. Location and Using Geofencing
  21. Getting Your App Ready for the Play Store
  22. Getting Started with Kotlin
  23. Other Books You May Enjoy

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Android 9 Development Cookbook by Rick Boyer in PDF and/or ePUB format, as well as other popular books in Computer Science & Application Development. We have over one million books available in our catalogue for you to explore.