import android.app.Activity;
import android.util.Log;
import android.widget.ImageView;
/**
* Created by atiq.mumtaz on 25.04.2016.
*/
public class GifImage_Player extends Thread
{
Activity activity;
ImageView image_view;
boolean is_running=false;
int pause_time;
int[] drawables;
public GifImage_Player(Activity activity,ImageView img_view,int[] drawable)
{
this.activity=activity;
this.image_view=img_view;
this.is_running=true;
pause_time=25;
this.drawables=drawable;
}
public void set_pause_time(int interval)
{
this.pause_time=interval;
}
public void stop_playing()
{
this.is_running=false;
}
public void run()
{
Log.d("Gif Player","Gif Player Stopped");
int pointer=0;
while (this.is_running)
{
if(drawables.length>0)
{
if((drawables.length-1)==pointer)
{
pointer=0;
}
try
{
activity.runOnUiThread(new Run(pointer));
Thread.sleep(pause_time);
}
catch (Exception e)
{
Log.d("GifPlayer","Exception: "+e.getMessage());
is_running=false;
}
pointer++;
}
}
Log.d("Gif Player","Gif Player Stopped");
}
class Run implements Runnable
{
int pointer;
public Run(int pointer)
{
this.pointer=pointer;
}
public void run()
{
image_view.setImageResource(drawables[pointer]);
}
}
}
/////////////////////////////Usage///////////////////////////////////////
int[] int_array=new int[]{R.drawable.tmp_0,R.drawable.tmp_1,R.drawable.tmp_2,R.drawable.tmp_3
,R.drawable.tmp_4,R.drawable.tmp_5,R.drawable.tmp_6,R.drawable.tmp_7,R.drawable.tmp_8,R.drawable.tmp_9,
R.drawable.tmp_10,R.drawable.tmp_11,R.drawable.tmp_12,R.drawable.tmp_13,R.drawable.tmp_14,R.drawable.tmp_15,
R.drawable.tmp_16,R.drawable.tmp_17,R.drawable.tmp_18,R.drawable.tmp_19,R.drawable.tmp_20,R.drawable.tmp_21,R.drawable.tmp_22,R.drawable.tmp_23};
GifImage_Player gif_player;
gif_player=new GifImage_Player(this,(ImageView)findViewById(R.id.mygif),int_array);
gif_player.start();