Advertisement
Guest User

Untitled

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