1 2 package com.android.browser.view; 3 4 import com.android.browser.R; 5 6 import android.content.Context; 7 import android.graphics.Canvas; 8 import android.graphics.drawable.Drawable; 9 import android.util.AttributeSet; 10 import android.widget.ProgressBar; 11 12 13 public class StopProgressView extends ProgressBar { 14 15 Drawable mOverlayDrawable; 16 Drawable mProgressDrawable; 17 int mWidth; 18 int mHeight; 19 20 /** 21 * @param context 22 * @param attrs 23 * @param defStyle 24 * @param styleRes 25 */ StopProgressView(Context context, AttributeSet attrs, int defStyle, int styleRes)26 public StopProgressView(Context context, AttributeSet attrs, int defStyle, int styleRes) { 27 super(context, attrs, defStyle, styleRes); 28 init(attrs); 29 } 30 31 /** 32 * @param context 33 * @param attrs 34 * @param defStyle 35 */ StopProgressView(Context context, AttributeSet attrs, int defStyle)36 public StopProgressView(Context context, AttributeSet attrs, int defStyle) { 37 super(context, attrs, defStyle); 38 init(attrs); 39 } 40 41 /** 42 * @param context 43 * @param attrs 44 */ StopProgressView(Context context, AttributeSet attrs)45 public StopProgressView(Context context, AttributeSet attrs) { 46 super(context, attrs); 47 init(attrs); 48 } 49 50 /** 51 * @param context 52 */ StopProgressView(Context context)53 public StopProgressView(Context context) { 54 super(context); 55 init(null); 56 } 57 init(AttributeSet attrs)58 private void init(AttributeSet attrs) { 59 mProgressDrawable = getIndeterminateDrawable(); 60 setImageDrawable(mContext.getResources() 61 .getDrawable(R.drawable.ic_stop_holo_dark)); 62 } 63 hideProgress()64 public void hideProgress() { 65 setIndeterminateDrawable(null); 66 } 67 showProgress()68 public void showProgress() { 69 setIndeterminateDrawable(mProgressDrawable); 70 } 71 72 @Override onLayout(boolean changed, int left, int top, int right, int bottom)73 protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 74 super.onLayout(changed, left, top, right, bottom); 75 mWidth = (right - left) * 2 / 3; 76 mHeight = (bottom - top) * 2 / 3; 77 } 78 79 @Override onDraw(Canvas canvas)80 protected void onDraw(Canvas canvas) { 81 super.onDraw(canvas); 82 if (mOverlayDrawable != null) { 83 int l = (getWidth() - mWidth) / 2; 84 int t = (getHeight() - mHeight) / 2; 85 mOverlayDrawable.setBounds(l, t, l + mWidth, t + mHeight); 86 mOverlayDrawable.draw(canvas); 87 } 88 } 89 getDrawable()90 public Drawable getDrawable() { 91 return mOverlayDrawable; 92 } 93 setImageDrawable(Drawable d)94 public void setImageDrawable(Drawable d) { 95 mOverlayDrawable = d; 96 } 97 98 } 99