summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/view/StopProgressView.java
blob: 64fa5d030801439d6634542d6b32f293dcd6e693 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

package com.android.browser.view;

import com.android.browser.R;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ProgressBar;


public class StopProgressView extends ProgressBar {

    Drawable mOverlayDrawable;
    Drawable mProgressDrawable;
    int mWidth;
    int mHeight;

    /**
     * @param context
     * @param attrs
     * @param defStyle
     * @param styleRes
     */
    public StopProgressView(Context context, AttributeSet attrs, int defStyle, int styleRes) {
        super(context, attrs, defStyle, styleRes);
        init(attrs);
    }

    /**
     * @param context
     * @param attrs
     * @param defStyle
     */
    public StopProgressView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(attrs);
    }

    /**
     * @param context
     * @param attrs
     */
    public StopProgressView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs);
    }

    /**
     * @param context
     */
    public StopProgressView(Context context) {
        super(context);
        init(null);
    }

    private void init(AttributeSet attrs) {
        mProgressDrawable = getIndeterminateDrawable();
        setImageDrawable(mContext.getResources()
                .getDrawable(R.drawable.ic_stop_holo_dark));
    }

    public void hideProgress() {
        setIndeterminateDrawable(null);
    }

    public void showProgress() {
        setIndeterminateDrawable(mProgressDrawable);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        mWidth = (right - left) * 2 / 3;
        mHeight = (bottom - top) * 2 / 3;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (mOverlayDrawable != null) {
            int l = (getWidth() - mWidth) / 2;
            int t = (getHeight() - mHeight) / 2;
            mOverlayDrawable.setBounds(l, t, l + mWidth, t + mHeight);
            mOverlayDrawable.draw(canvas);
        }
    }

    public Drawable getDrawable() {
        return mOverlayDrawable;
    }

    public void setImageDrawable(Drawable d) {
        mOverlayDrawable = d;
    }

}