Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.arayray.bootanimationutility;
- import java.io.File;
- 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.os.Environment;
- import android.view.View;
- public class GifDemo extends Activity {
- static File PREVIEW_LOCATION = new File(Environment.getExternalStorageDirectory() + "/bootanimation/preview/");
- @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);
- String location = PREVIEW_LOCATION + DownloadActivity.getBOOTANIMATION() + ".gif";
- is = context.getResources().openRawResource(location);
- 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