Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.arayray.bootanimationutility;
- import java.io.InputStream;
- import android.app.Activity;
- import android.content.Context;
- import android.graphics.Canvas;
- import android.graphics.Movie;
- import android.os.Bundle;
- import android.view.View;
- public class GifDemo extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(new GIFView(this));
- }
- private static class GIFView extends View{
- Movie movie;
- InputStream is=null;
- long moviestart;
- public GIFView(Context context) {
- super(context);
- is = context.getResources().openRawResource(R.drawable.cm7);
- movie = Movie.decodeStream(is);
- }
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- long now=android.os.SystemClock.uptimeMillis();
- if (moviestart == 0) {
- // first time
- moviestart = now;
- }
- int relTime = (int)((now - moviestart) % movie.duration()) ;
- movie.setTime(relTime);
- movie.draw(canvas, 100, 200);
- this.invalidate();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement