Back to project page FisgoDroid.
The source code is released under:
The smiley icons bundled with this application belong to Meneame.NET and are licensed under the Creative Commons by-sa 3.0 license. For more information, please visit http://creativecommons.org/licens...
If you think the Android project FisgoDroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package net.meneame.fisgodroid; /*ww w .j ava2 s . c o m*/ import java.io.InputStream; import jp.tomorrowkey.android.GifDecoder; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Rect; import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.SystemClock; public class AnimatedGifDrawable extends AnimationDrawable { private int mCurrentIndex = 0; private long mLastUpdate = 0; public AnimatedGifDrawable(Context context, InputStream source, float scale) { GifDecoder decoder = new GifDecoder(); decoder.read(source); // Iterate through the gif frames, add each as animation frame for (int i = 0; i < decoder.getFrameCount(); i++) { Bitmap bitmap = decoder.getFrame(i); BitmapDrawable drawable = new BitmapDrawable(context.getResources(), bitmap); // Explicitly set the bounds in order for the frames to display drawable.setBounds(0, 0, (int) (bitmap.getWidth() * scale), (int) (bitmap.getHeight() * scale)); addFrame(drawable, decoder.getDelay(i)); if ( i == 0 ) { // Also set the bounds for this container drawable setBounds(0, 0, (int) (bitmap.getWidth() * scale), (int) (bitmap.getHeight() * scale)); } } mLastUpdate = SystemClock.elapsedRealtime(); } /** * Naive method to proceed to next frame. Also notifies listener. */ public void nextFrame() { long currentUpdate = SystemClock.elapsedRealtime(); if ((currentUpdate - mLastUpdate) > getFrameDuration()) { mCurrentIndex = (mCurrentIndex + 1) % getNumberOfFrames(); mLastUpdate = currentUpdate; } } public void rewind() { mCurrentIndex = 0; } /** * Return display duration for current frame */ public int getFrameDuration() { return getDuration(mCurrentIndex); } /** * Return drawable for current frame */ public Drawable getDrawable() { return getFrame(mCurrentIndex); } }