You are previewing Learning Android Canvas.
O'Reilly logo
Learning Android Canvas

Book Description

If you want to create 2D graphics for Android from scratch, this book is the perfect guide. It covers all the angles of using Android Canvas with a step-by-step approach to give your apps the graphical edge.

  • Understand user interactions and respond to those actions

  • Discover how to work with graphics in Android from scratch

  • Using a step by step approach, create a graphics-rich, fully functional application

  • Use Nine-Patch image

  • In Detail

    When you're writing an application in which you would like to perform specialized drawing and/or control the animation of graphics, you should do so by drawing through a canvas. A canvas works for you as an interface to the actual surface upon which your graphics will be drawn — it holds all of your "draw" calls. Via the Android Canvas, your drawing is actually performed on an underlying Bitmap, which is placed into the window.

    Learning Android Canvas is a practical guide, which will help you develop applications that contain rich 2D graphics like backgrounds, buttons, and even some small games with static 2D graphics. The book is full of step-by-step lessons and practical examples. This book helps you develop rich graphical applications and some simple games.

    Learning Android Canvas will help you understand everything that is required to develop an Android application that involves creating 2D graphics from scratch to a fully functional complete application. You will start with zero knowledge of using graphics within Android applications and will then go step by step to learn about different objects and techniques. In the end you will be able to develop a complete application fully loaded with graphics and functions.

    The book will give you a detailed practical explanation of Nine-Patch images and its importance in designing layouts and backgrounds. We will also take a detailed look at user interactions such as touch, capturing the action, and responding to them accordingly. Finally we will have a working, fully functional graphic application that uses all the knowledge that we have acquired previously.

    Table of Contents

    1. Learning Android Canvas
      1. Table of Contents
      2. Learning Android Canvas
      3. Credits
      4. About the Author
      5. Acknowledgments
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
        2. Why Subscribe?
        3. Free Access for Packt account holders
      8. 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
      9. 1. Getting Started with Android Canvas
        1. Android Canvas
        2. Our first Android Canvas application
          1. Application Name
          2. Project Name
          3. Package Name
          4. Least possible version of SDK
          5. Target SDK
          6. Theme
        3. Mining our first application
          1. The configuration file
          2. The layout file
          3. The code file
        4. Summary
      10. 2. Drawing Threads
        1. The need for drawing threads
        2. The issue with multithreading in Android
        3. The Thread class
          1. Handler objects that run on the UI thread
          2. AsyncTask
        4. Summary
      11. 3. Drawing and Drawables in Android Canvas
        1. Drawing on a Canvas
          1. Drawing on a View
          2. Drawing on a SurfaceView
          3. Drawables
          4. Drawables from a resource image
          5. Drawables from resource XML
        2. Shape Drawables
        3. Summary
      12. 4. NinePatch Images
        1. Creating a NinePatch image
        2. Using a NinePatch image
        3. Summary
      13. 5. Touch Events and Drawing on Canvas
        1. Some background knowledge
        2. Application development
          1. Our custom-view class
            1. Defining class properties and objects
            2. Methods in our custom-view class
            3. The constructor
            4. The drawing method
            5. The measurement method
            6. The touch event
          2. Our main activity class and final output
        3. Summary
      14. 6. Putting it All Together
        1. The story board
        2. The project and application development
          1. The user interface
            1. Screen orientation
            2. The paint brush
            3. Designing the Control panel
            4. Setting up the layout
          2. Enabling the touch and painting using touch
          3. Enabling the color selection
          4. Spicing up our application with more functions
            1. Saving the painting
            2. Creating a new drawing
            3. Enabling eraser in our application
        3. Summary
      15. Index