From 659fff083c289279accbe098a90ed0ecf58001fb Mon Sep 17 00:00:00 2001 From: koral-- Date: Sat, 25 Jan 2014 23:43:29 +0100 Subject: [PATCH] README and javadocs updated --- README.md | 36 +++++++++++++++++++---- src/pl/droidsonroids/gif/GifDrawable.java | 19 +++++++----- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 62c12c12..cd45db71 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ and install SDK level 19: `mvn install -P 4.4` (from maven-android-sdk-deployer pl.droidsonroids.gif android-gif-drawable - 1.0.4 + 1.0.5 apklib ``` @@ -38,9 +38,6 @@ and install SDK level 19: `mvn install -P 4.4` (from maven-android-sdk-deployer ###Requirements + Android 1.6+ (API level 4+) -####Using JAR in Eclipse (NOT recommended, use APKLIB instead) -+ following option **must be unchecked** Window>Preferences>Android>Build>**Force error when external jars contains native libraries** - ####Building from source + [Android NDK](http://developer.android.com/tools/sdk/ndk/index.html) needed to compile native sources @@ -121,13 +118,42 @@ Note that all input sources need to have ability to rewind to the begining. It i (where animation is repeatable) since subsequent frames are decoded on demand from source. ####Animation control -`GifDrawable` is an `Animatable` so you can use its methods and more: +`GifDrawable` implements an `Animatable` and `MediaPlayerControl` so you can use its methods and more: + `stop()` - stops the animation, can be called from any thread + `start()` - starts the animation, can be called from any thread + `isRunning()` - returns whether animation is currently running or not + `reset()` - rewinds the animation, does not restart stopped one + `setSpeed(float factor)` - sets new animation speed factor, eg. passing 2.0f will double the animation speed ++ `seekTo(int position)` - seeks animation (within current loop) to given `position` (in milliseconds) __Only seeking forward is supported__ ++ `getDuration()` - returns duration of one loop of the animation ++ `getCurrentPosition()` - returns elapsed time from the beginning of a current loop of animation + +#####Using [MediaPlayerControl](http://developer.android.com/reference/android/widget/MediaController.MediaPlayerControl.html) +Standard controls for a MediaPlayer (like in [VideoView](http://developer.android.com/reference/android/widget/VideoView.html)) can be used to control GIF animation and show its current progress. + +Just set `GifDrawable` as MediaPlayer on your [MediaController](http://developer.android.com/reference/android/widget/MediaController.html) like this: +```java + @Override + protected void onCreate ( Bundle savedInstanceState ) + { + super.onCreate( savedInstanceState ); + GifImageButton gib = new GifImageButton( this ); + setContentView( gib ); + gib.setImageResource( R.drawable.sample ); + final MediaController mc = new MediaController( this ); + mc.setMediaPlayer( ( GifDrawable ) gib.getDrawable() ); + mc.setAnchorView( gib ); + gib.setOnClickListener( new OnClickListener() + { + @Override + public void onClick ( View v ) + { + mc.show(); + } + } ); + } +``` ####Retrieving GIF metadata diff --git a/src/pl/droidsonroids/gif/GifDrawable.java b/src/pl/droidsonroids/gif/GifDrawable.java index 79ef2bf1..b87ea944 100644 --- a/src/pl/droidsonroids/gif/GifDrawable.java +++ b/src/pl/droidsonroids/gif/GifDrawable.java @@ -475,23 +475,26 @@ public int getCurrentPosition () /** * Seeks animation to given absolute position (within given loop) and refreshes the canvas.
* NOTE: only seeking forward is supported.
- * If pos is less than current position or GIF has only one frame then nothing happens. - * If pos is greater than duration of the loop of animation - * (or whole animation if there is no loop) then animation will be sought to the end. - * @param pos position to seek to in milliseconds - * @throws IllegalArgumentException if pos<0 + * If position is less than current position or GIF has only one frame then nothing happens. + * If position is greater than duration of the loop of animation + * (or whole animation if there is no loop) then animation will be sought to the end.
+ * NOTE: all frames from current to desired must be rendered sequentially to perform seeking. + * It may take a lot of time if number of such frames is large. + * This method can be called from any thread but actual work will be performed on UI thread. + * @param position position to seek to in milliseconds + * @throws IllegalArgumentException if position<0 */ @Override - public void seekTo ( final int pos ) + public void seekTo ( final int position ) { - if (pos<0) + if (position<0) throw new IllegalArgumentException( "Position is not positive" ); runOnUiThread( new Runnable() { @Override public void run () { - seekTo( mGifInfoPtr, pos, mColors ); + seekTo( mGifInfoPtr, position, mColors ); invalidateSelf(); } } );