You are previewing Android 3.0 Animations.
O'Reilly logo
Android 3.0 Animations

Book Description


Bring your Android applications to life with stunning animations.

  • The first and only book dedicated to creating animations for Android apps.

  • Covers all of the commonly used animation techniques for Android 3.0 and lower versions.

  • Create stunning animations to give your Android apps a fun and intuitive user experience.

  • A step-by-step guide for learning animation by building fun example applications and games.

In Detail

An enjoyable, understandable, and eye-catching user interface is a key part of getting users to love your app. Users today expect a polished multimedia experience on their mobile device, and animation is a core part of that. The Android operating system is at the forefront of tablet and smartphone technology, and there is a plethora of opportunities for developing exciting applications with animation.

Android 3.0 Animations Beginner’s Guide will introduce each of the most popular animation techniques to you. Using step-by-step instructions, you will learn how to create interactive dynamic forms, moving graphics, and 3D motion.

You will be taken on a journey from simple stop motion animations and fades, through to moving input forms, then on to 3D motion and game graphics.

In this book, you will create standalone animated graphics, three-dimensional lifts, fades, and spins. You will become adept at moving and transforming form data to bring boring old input forms and displays to life. Learn how game programmers create fast animations on the fly, and also build live wallpapers to liven up your users’ home-screens!

If you are tired of writing lifeless interfaces and want to add some animated excitement, this is the book for you!

A step-by step guide for creating, testing, and making use of stunning animations for android applications and games.


Table of Contents

  1. Android 3.0 Animations
    1. Android 3.0 Animations
    2. Credits
    3. About the Author
    4. About the Reviewers
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Time for action—heading
        1. What just happened?
        2. Pop quiz—heading
        3. Have a go hero—heading
      6. Reader feedback
      7. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    7. 1. Animation Techniques on Android
      1. An animated application: counting calculator
      2. Time for action—learning to count with the counting calculator
        1. What just happened?
        2. Have a go hero—explore the counting calculator application
      3. Frame animation
      4. Time for action playing with the frames
        1. What just happened
        2. Fancy frame animations
        3. Simple fades using transition animations
      5. Tweening
      6. Time for action finding tweens
        1. What just happened?
        2. The tween jazz band
        3. Interpolations—meet the drummer
        4. Animation sets—meet the conductor
        5. Tweening elements in XML
        6. What are tweens good at?
      7. Animators - new in Android 3.0!
        1. Pop quiz view animations and drawable animations
      8. Beyond views: high-speed animating in 2 dimensions
        1. Drawing loops
        2. Doing your own housekeeping is hard
        3. Where to use surfaces
      9. What do views do anyway?
      10. Time for action—let's draw views
        1. What just happened?
      11. Animating awesome 3D
        1. Want to go faster?
        2. Have a go hero—what is right for your application
      12. Making a better application
        1. Always be helpful
        2. Small and powered by batteries
        3. Pop quiz—putting it all together
      13. Summary
    8. 2. Frame Animations
      1. Making a frame animation
      2. Time for action—the funky stick man
        1. What just happened?
        2. The anatomy of a frame animation
        3. XML elements
          1. <animation-list>
            1. xmlns:android
              1. android:oneshot
          2. <item>
            1. android:drawable
            2. android:duration
        4. Timing
        5. Images and Drawables
        6. Screen size
        7. Sometimes you run out of memory
        8. Pop quiz—making frame animations
        9. Have a go hero—improve your dancing
      3. Making frame animations in Java
      4. Time for action—making the stick man interactive
        1. What just happened?
        2. Controlling frame animations
          1. start() and stop()
          2. AnimationDrawable.setVisible(true,true)
        3. Creating new animations
      5. Time for action—programmatically defined animation
        1. What just happened?
          1. More neat methods on AnimationDrawable
            1. setOneShot(boolean oneShot)
            2. addFrame(Drawable frame, int duration)
            3. getFrame(int index)
            4. getDuration (int index)
            5. getNumberOfFrames()
          2. Working properly in the GUI thread
        2. Pop quiz—controlling frame animations
        3. Have a go hero—reactive frame animation
      6. Animating a transition between frames
      7. Time for action—make the transition
        1. What just happened?
        2. Writing XML for a transitionDrawable
          1. <transition>
            1. xmlns:android
          2. <item>
            1. android:drawable
        3. Working with other useful methods
          1. startTransition(int duration)
          2. reverseTransition(int duration)
          3. resetTransition()
        4. Pop quiz—transition drawables
        5. Have a go hero—transition Drawables
      8. Summary
    9. 3. Tweening and Using Animators
      1. Greeting the tween
      2. Time for action—making a tower of Hanoi puzzle
        1. What just happened?
        2. Defining starts and ends
      3. Assembling the building blocks of a tween
      4. Time for action—composing a tween animation
        1. What just happened?
        2. Taking a look at the different types of tween animation
          1. <translate>
          2. <rotate>
          3. <alpha>
          4. <scale>
          5. Common attributes
        3. Declaring tweens in the correct order
        4. Making tweens that last for ever
      5. Time for action—creating an everlasting tween
        1. What just happened?
        2. Pop quiz—all those tweens !
        3. Have a go hero—bouncing back
        4. Animating layouts
      6. Time for action—laying out blocks
        1. What just happened?
      7. Receiving animation events
      8. Time for action—receiving animation events
        1. What just happened?
        2. Pop quiz—AnimationListeners
      9. Interpolating animations
      10. Time for action—changing the rhythm with interpolators
        1. What just happened?
        2. Using the interpolators provided by Android
          1. Linear interpolator
          2. Accelerate interpolator
          3. Decelerate interpolator
          4. Accelerate-decelerate interpolator
          5. Bounce interpolator
          6. Anticipate interpolator
          7. Overshoot interpolator
          8. Anticipate overshoot interpolator
          9. Cycle interpolator
        3. Sharing interpolators
          1. android:sharedInterpolator="true"
          2. android:sharedInterpolator="false"
        4. Creating and parameterizing interpolators
        5. Pop quiz—interpolators
        6. Have a go hero—having fun with interpolators
      11. Finding out more
      12. Summary
    10. 4. Animating Properties and Tweening Pages
      1. Note for developers using versions of Android before 3.0
      2. Turning pages with a ViewFlipper
      3. Time for action—making an interactive book
        1. What just happened?
        2. Pop quiz—ViewFlippers
        3. Have a go hero—improving the ViewFlipper
      4. Creating tween animations in Java
      5. Time for action—creating a tween in Java
        1. What just happened?
      6. Writing the SlideAndScale animation in Java
        1. Writing the SlideAndScale animation In XML
        2. Pop quiz—Java tweens
        3. Have a go hero—tweening using Java
        4. Animating with ObjectAnimator
      7. Time for action—animating the rolling ball
        1. What just happened?
        2. Constructing ObjectAnimators
          1. Breaking down the construction of ballRoller
        3. Getting and setting with ObjectAnimators
        4. Pop quiz—ObjectAnimators
        5. Have a go hero—what else can you do with the ball?
      8. Animating values with ValueAnimator
      9. Time for action—making a ball bounce
        1. What just happened?
        2. Updating the frame rate
        3. Changing the interpolator
      10. Time for action—improving our bouncing ball
        1. What just happened?
        2. Pop quiz—ValueAnimators
      11. Comparing animators and tweens
        1. Advantages of animators
        2. Advantages of tweens
        3. Things that are common between animators and tweens
      12. Summary
    11. 5. Creating Classes for Tween Animation
      1. Creating multi-variable Animators
      2. Time for action—making an animated Orrery
        1. What just happened?
        2. The structure of the Orrery
        3. Animating LayerDrawables
        4. PropertyValuesHolder
        5. Helpful ValueAnimator parameters
        6. Using objects as parameters for value animations
      3. Time for action—animating between objects
        1. What just happened?
        2. Using a TypeEvaluator
        3. Setting Keyframes
      4. Time for action—defining fixed points with Keyframes
        1. What just happened?
        2. Using the Keyframe
        3. Keyframe timing
        4. Pop quiz—PropertyValuesHolders, ObjectAnimators, and TypeEvaluators
        5. Have a go hero—tweaking the animation objects
        6. Combining Fragments and XML Animators
      5. Time for action—adding a Description Pane
      6. What just happened?
      7. Declaring ObjectAnimator attributes
      8. Pop quiz—Fragment animation and XML Animators
      9. Have a go hero—animating Fragments
      10. Customizing the interpolator classes
        1. What do interpolators do?
      11. Time for action—making a teleport interpolator
        1. What just happened?
        2. Interpolator value ranges
        3. Pop quiz—custom interpolators
        4. Have a go hero—modifying the Interpolator
      12. Summary
    12. 6. Using 3D Visual Techniques
      1. Understanding 3D graphics
      2. Showing depth with 3D effects
      3. Raising elements
      4. Time for action—making a jigsaw with lifting pieces
        1. What just happened?
        2. Laying out the jigsaw
        3. Special classes we created to help animation
          1. Scaling the image with ScalableImageView.SetDepth
        4. Moving pieces with PieceSwapper
          1. Completing the animation with PieceSwapper.onAnimationEnd
        5. Adding drop shadows
      5. Time for action—using shadows with our jigsaw
        1. What just happened?
        2. Conjuring up a change in focus
      6. Time for action—changing the focus of the jigsaw
        1. What just happened?
        2. Setting the image focus on a RaisableImageView
        3. Applying image focus to the whole jigsaw
        4. Pop quiz—depth effects
        5. Have a go hero—parameterizing the depth effects
      7. Creating 3D rotations
      8. Time for action—spinning jigsaws
        1. What just happened?
        2. Examining
        3. Extending a tween animation
          1. initialize (int width, int height, int parentWidth, int parentHeight)
          2. applyTransformation (float interpolatedTime, Transformation t)
        4. Describing transformations with a Matrix (
        5. Doing 3D transformations with a Camera (
          1. rotateX (float), rotateY (float), rotateZ (float)
          2. translate (float x, float y, float z)
          3. save() and restore()
        6. Pop quiz—3D rotations
        7. Have a go hero—rotating along a different axis
      9. Summary
    13. 7. 2D Graphics with Surfaces
      1. Introducing game loops
      2. Drawing a surface on the screen
      3. Time for action—animating bubbles on a surface
        1. What just happened?
        2. The design of the Bubbles application
          1. Investigating
          2. Investigating
            1. Game loop
            2. calculateDisplay
        3. Seeing the game loop in action
        4. Using a SurfaceView
        5. Using a SurfaceHolder
          1. lockCanvas
          2. unlockCanvasAndPost
        6. Using a SurfaceHolder.Callback
          1. surfaceCreated (SurfaceHolder holder)
          2. surfaceDestroyed(SurfaceHolder holder)
          3. surfaceChanged(SurfaceHolder holder, int format, int width, int height)
        7. Using the Canvas as an animation tool
      4. Time for action—making more realistic bubbles
        1. What just happened?
        2. Getting to know the drawing tools in Canvas
          1. drawBitmap and drawPicture
          2. drawCircle
          3. drawColor and drawPaint
          4. drawLine and drawLines
          5. drawOval and drawArc
          6. drawPath
          7. drawRect and drawRoundRect
          8. drawText and drawTextOnPath
        3. Using Paint effects
          1. setAlpha
          2. setAntiAlias
          3. setColor
          4. setStrokeCap
          5. setStrokeWidth
          6. setStyle
          7. setTextAlign
          8. setTextScaleX
          9. setTextSize
          10. setTypeface
        4. Frame scheduling
      5. Time for action—creating smooth game loops
        1. What just happened?
        2. Adjusting the frame duration
        3. Taking the wait out of the game loop
        4. Pop quiz—surface animations
        5. Have a go hero—rainbow bubbles!
      6. Summary
    14. 8. Live Wallpapers
      1. Creating a live wallpaper
      2. Time for action—making our first live wallpaper
        1. What just happened?
        2. Declaring a live wallpaper
        3. How live wallpapers appear
        4. Understanding services
          1. WallpaperService
            1. WallpaperService.Engine
              1. onCreate(SurfaceHolder surfaceHolder)
              2. onDestroy()
              3. onSurfaceChanged (SurfaceHolder surfaceHolder, int format, int width, int height)
              4. onVisibilityChanged (boolean visible)
        5. Pop quiz—live wallpapers
      3. Adding interactivity to live wallpaper
      4. Time for action—making soapy fingers
        1. What just happened?
        2. Enabling WallpaperService.Engine interaction
        3. Registering live wallpaper interaction
        4. Pop quiz—interactivity
        5. Have a go hero—popping bubbles
      5. Using live wallpaper preferences
      6. Time for action—configuring a live wallpaper
        1. What just happened?
        2. Updating preferences as soon as they are set
      7. Time for action—updating live wallpaper configuration
        1. What just happened?
          1. Connecting our wallpaper to our prefereces
          2. Disconnecting our preferences when our wallpaper exits
        2. How the user will see preferences
        3. Storing preferences with SharedPreferences
          1. Reading from SharedPreferences
          2. Writing to SharedPreferences
          3. OnSharedPreferenceChangedListener
        4. Composing preference XML
          1. Defining preferences in XML
            1. <PreferenceScreen>
            2. <PreferenceCategory>
            3. <CheckBoxPreference>
            4. <EditTextPreference>
          2. Setting attributes on XML preferences
            1. android:key
            2. android:defaultValue
            3. android:order
        5. Pop quiz—preferences for live wallpapers
      8. Summary
    15. 9. Practicing Good Practice and Style
      1. Using focus and metaphor
        1. Looking at focus
      2. Time for action—don't confuse me with animation!
        1. What just happened?
        2. Have a go hero—usability testing
        3. Getting to grips with metaphors
      3. Time for action—getting messages from houses
        1. What just happened?
        2. Focus, redux
        3. Maintaining consistency within an application
        4. Pop quiz—usability
        5. Have a go hero—more usability testing
      4. Reducing power usage
      5. Time for action—measuring battery usage with PowerTutor
        1. What just happened?
        2. Precise estimation
        3. Changing the Application Viewer Timespan
        4. PowerTutor-supported devices
        5. Looking for problems
      6. Time for action—identifying a problem
        1. What just happened?
        2. Finding the power hogs
      7. Time for action—tracing to find optimizations
        1. What just happened?
        2. Removing the gremlin
      8. Time for action—squashing gremlins that use too much power
        1. What just happened?
        2. Optimizing using an easy recipe
        3. Pop quiz—power usage
        4. Have a go hero—using the Android performance guidelines
      9. Summary
    16. A. Pop quiz—Answers
      1. Chapter 1: Animation Techniques on Android
        1. View animations and Drawable animations
        2. Putting it all together
      2. Chapter 2: Frame Animations
        1. Making frame animations
        2. Controlling frame animations
        3. Transition Drawables
      3. Chapter 3: Tweening and Using Animators
        1. All those tweens!
        2. AnimationListeners
        3. Interpolators
      4. Chapter 4: Animating Properties and Tweening Pages
        1. ViewFlippers
        2. Java tweens
        3. ObjectAnimators
        4. Value Animators
      5. Chapter 5: Creating Classes for Tween Animation
        1. PropertyValueHolders, ObjectAnimators, and TypeEvaluators
        2. Fragment Animation and XML Animators
        3. Custom interpolators
      6. Chapter 6: Using 3D Visual Techniques
        1. Depth effects
        2. 3D rotations
      7. Chapter 7: 2D Graphics with Surfaces
        1. Surface animations
      8. Chapter 8: Live Wallpapers
        1. Live wallpapers
        2. Interactivity
        3. Preferences for live wallpapers
      9. Chapter 9: Practicing Good Practice and Style
        1. Usability
        2. Power usage