Git Product home page Git Product logo

gifanimateddrawable's Introduction

GifAnimationDrawable

GifAnimationDrawable is a simple library (consisting of 2 classes) that makes it easy to display animated GIFs on the Android platform by converting the animated GIF file into an AnimationDrawable. This allows animated gifs to be used anywhere a Drawable is accepted, including backgrounds, standard ImageViews and anywhere else. For more detail, see http://engineering.hipmob.com/2013/12/03/GifAnimationDrawable-for-Android/

Animated GIFs are a simple way to make animations and are supported on Android using the Movie class: unfortunately the Movie class isn't quite as easy to use in many places as one might like. GifAnimationDrawable makes it trivial to use an animated gif as a standard Android Drawable, for backgrounds on buttons or views or as the main image in an ImageView. Solutions (such as this) require build-time processing, which isn't usable with downloaded images.

Enter http://droid-blog.net/2011/10/15/tutorial-how-to-play-animated-gifs-in-android-%E2%80%93-part-2/: this provides the key bit, the GifDecoder class that pulls out the individual frames. All that was missing was the final step, wrapping this in an AnimationDrawable instance.

And...we're done. See how to use it below.

How

Simply pass the image File or InputStream into the appropriate constructor:

AnimationDrawable drawable = new GifAnimationDrawable(File source);

or

AnimationDrawable drawable = new GifAnimationDrawable(InputStream source);

By default a Thread will be created to process the GIF frames (making the default operation safe to use on the main Android app thread): you can call the isDecoded method to be informed when the processing is complete. If you're loading this in an existing AsyncTask or other background thread, you can pass in a parameter to tell it to process the frames without spawning a new thread:

AnimationDrawable drawable = new GifAnimationDrawable(File source, true);

or

AnimationDrawable drawable = new GifAnimationDrawable(InputStream source, true);

Build

The library build uses ant: you will need to have the ANDROID_SDK environment variable setup (or edit the build.xml file to point to the right place).

Open a shell in the library directory and run ant. The JAR file produced (gifanimationdrawable.jar) will contain the required files: add it to your Android app's libs folder, and then import the com.hipmob.gifanimationdrawable.GifAnimationDrawable class.

Notes

Author

Developed by Femi Omojola ([email protected]) for Orthogonal Labs, Inc. (https://hipmob.com).

gifanimateddrawable's People

Contributors

fomojola avatar jween avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.