public class MyAnimationDrawable extends AnimationDrawable
{
Handler finishHandler;
// ᅤ쐬ᄑ£ᅧ샤Handler
AnimationCallBack callback = null;
public int type = 0;
public String name = null;
SoundPool soundPool = null;
ArrayList<String> soundInfo = null;
ArrayList<Animations> soundList = null;
int soundIndex = 0;
public void setAnimationCallback(AnimationCallBack call)
{
callback = call;
}
{
if(soundInfo == null)
{
soundInfo = new ArrayList<String>();
}
soundInfo.add(sound);
}
public void cancel()
{
if(finishHandler != null)
{
finishHandler.removeCallbacks(runnable);
}
if(soundInfo != null)
{
soundInfo.clear();
soundInfo = null;
}
if(soundPool != null)
{
soundPool.release();
soundPool = null;
}
if(soundList != null)
{
soundList.clear();
soundList = null;
}
}
@Override
public void start()
{
super.start();
soundIndex = 0;
Animations animation = null;
if(soundInfo != null)
{
int len = soundInfo.size();
if(len > 0)
{
soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 100);
soundList = new ArrayList<Animations>();
String []values = null;
int result = -1;
int duration = 0;
animation = null;
for (String str : soundInfo)
if(str != null)
duration = Integer.parseInt(values[1]);
}
}
}
finishHandler = new Handler();
finishHandler.postDelayed(runnable, getTotalDuration());
if(soundList != null && soundIndex < soundList.size())
{
animation = soundList.get(soundIndex);
if(animation != null)
{
finishHandler.postDelayed(soundRunnable, animation.duration);
}
}
}
public int getTotalDuration()
{
int durationTime = 0;
for (int i = 0; i < this.getNumberOfFrames(); i++)
{
durationTime += this.getDuration(i);
}
return durationTime;
}
private Runnable runnable = new Runnable()
{
@Override
public void run()
{
if(callback != null)
{
callback.animationEnd();
}
}
};
private Runnable soundRunnable = new Runnable()
{
@Override
public void run()
{
if(soundList != null && soundIndex < soundList.size())
{
Animations animation = soundList.get(soundIndex);
if(animation != null)
{
soundPool.play(animation.soundID, 1, 1, 0, 0, 1);
System.out.println("===============================soundIndex " + soundIndex);
}
soundIndex += 1;
if(soundIndex < soundList.size())
{
animation = soundList.get(soundIndex);
if(animation != null)
{
finishHandler.postDelayed(soundRunnable, animation.duration);
}
}
animation = null;
}
}
};
public interface AnimationCallBack
{
public
void animationEnd();
}
class Animations
{
int soundID = -1;
int duration = -1;
}
}