Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21569 rajender 1
package com.saholic.profittill;
2
 
3
import android.content.Context;
4
import android.graphics.Canvas;
5
import android.graphics.Color;
6
import android.graphics.Movie;
7
import android.util.AttributeSet;
8
import android.view.View;
9
 
10
import java.io.InputStream;
11
 
12
/**
13
 * Created by rajender on 24/5/17.
14
 */
15
public class GIFView extends View {
16
 
17
    public Movie mMovie;
18
    public long movieStart;
19
    public GIFView(Context context) {
20
 
21
        super(context);
22
        initializeView();
23
    }
24
 
25
    public GIFView(Context context, AttributeSet attrs) {
26
        super(context, attrs);
27
        initializeView();
28
 
29
    }
30
    public GIFView(Context context, AttributeSet attrs, int defStyle) {
31
        super(context, attrs, defStyle);
32
        initializeView();
33
    }
34
    private void initializeView() {
35
        InputStream is = getContext().getResources().openRawResource(R.drawable.progressbar);
36
        mMovie = Movie.decodeStream(is);
37
    }
38
 
39
    @Override
40
    protected void onDraw(Canvas canvas) {
41
 
42
        canvas.drawColor(Color.TRANSPARENT);
43
        super.onDraw(canvas);
44
        long now = android.os.SystemClock.uptimeMillis();
45
        if (movieStart == 0) {
46
            movieStart = now;
47
        }
48
        if (mMovie != null) {
49
            int relTime = (int) ((now - movieStart) % mMovie.duration());
50
            mMovie.setTime(relTime);
51
            mMovie.draw(canvas, getWidth() - mMovie.width(), getHeight() - mMovie.height());
52
            this.invalidate();
53
        }}
54
    private int gifId;
55
    public void setGIFResource(int resId) {
56
        this.gifId = resId;
57
        initializeView();
58
    }
59
 
60
    public int getGIFResource() {
61
        return this.gifId;
62
 
63
    }}
64