Skip to content

Commit

Permalink
README and javadocs updated
Browse files Browse the repository at this point in the history
  • Loading branch information
koral-- committed Jan 25, 2014
1 parent c3e27c3 commit 659fff0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ and install SDK level 19: `mvn install -P 4.4` (from maven-android-sdk-deployer
<dependency>
<groupId>pl.droidsonroids.gif</groupId>
<artifactId>android-gif-drawable</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
<type>apklib</type>
</dependency>
```
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions src/pl/droidsonroids/gif/GifDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,23 +475,26 @@ public int getCurrentPosition ()
/**
* Seeks animation to given absolute position (within given loop) and refreshes the canvas.<br>
* <b>NOTE: only seeking forward is supported.<b><br>
* 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.<br>
* 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();
}
} );
Expand Down

0 comments on commit 659fff0

Please sign in to comment.