Home | History | Annotate | Download | only in view
      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      */
     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      */
     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      */
     45     public StopProgressView(Context context, AttributeSet attrs) {
     46         super(context, attrs);
     47         init(attrs);
     48     }
     49 
     50     /**
     51      * @param context
     52      */
     53     public StopProgressView(Context context) {
     54         super(context);
     55         init(null);
     56     }
     57 
     58     private void init(AttributeSet attrs) {
     59         mProgressDrawable = getIndeterminateDrawable();
     60         setImageDrawable(mContext.getResources()
     61                 .getDrawable(R.drawable.ic_stop_holo_dark));
     62     }
     63 
     64     public void hideProgress() {
     65         setIndeterminateDrawable(null);
     66     }
     67 
     68     public void showProgress() {
     69         setIndeterminateDrawable(mProgressDrawable);
     70     }
     71 
     72     @Override
     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
     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 
     90     public Drawable getDrawable() {
     91         return mOverlayDrawable;
     92     }
     93 
     94     public void setImageDrawable(Drawable d) {
     95         mOverlayDrawable = d;
     96     }
     97 
     98 }
     99