Advertisement
Guest User

Untitled

a guest
May 10th, 2011
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. package com.arayray.bootanimationutility;
  2.  
  3. import java.io.InputStream;
  4.  
  5. import android.app.Activity;
  6. import android.content.Context;
  7. import android.graphics.Canvas;
  8. import android.graphics.Movie;
  9. import android.os.Bundle;
  10. import android.view.View;
  11.  
  12. public class GifDemo extends Activity {
  13.  
  14. @Override
  15. public void onCreate(Bundle savedInstanceState) {
  16. super.onCreate(savedInstanceState);
  17. setContentView(new GIFView(this));
  18. }
  19. private static class GIFView extends View{
  20. Movie movie;
  21. InputStream is=null;
  22. long moviestart;
  23. public GIFView(Context context) {
  24. super(context);
  25. is = context.getResources().openRawResource(R.drawable.cm7);
  26. movie = Movie.decodeStream(is);
  27. }
  28.  
  29. @Override
  30. protected void onDraw(Canvas canvas) {
  31. super.onDraw(canvas);
  32. long now=android.os.SystemClock.uptimeMillis();
  33.  
  34. if (moviestart == 0) {
  35. // first time
  36. moviestart = now;
  37. }
  38. int relTime = (int)((now - moviestart) % movie.duration()) ;
  39. movie.setTime(relTime);
  40. movie.draw(canvas, 100, 200);
  41. this.invalidate();
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement