Advertisement
Guest User

Custom Progressbar

a guest
Oct 14th, 2013
1,329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. public class CustomBar extends ProgressBar {
  2.  
  3.     Paint p = new Paint();
  4.     int progress;
  5.     public CustomBar(Context context) {
  6.         super(context);
  7.         p.setColor(Color.GREEN);
  8.     }
  9.  
  10.     @Override
  11.     protected synchronized void onDraw(Canvas canvas) {
  12.         canvas.drawLine(0, 0, getWidth(), 0, p);
  13.         canvas.drawLine(0, 0, 0, getHeight(), p);
  14.         canvas.drawArc(new Rect(0, 0, getWidth(),  getHeight()), 40, true, p);
  15.         /**
  16.          * Whatever drawing is needed for your Layout
  17.          * But make sure you use relative lenghts and heights
  18.          * So you can reuse your Widget.
  19.          * Also use the Progress Variable to draw the filled part
  20.          * corresponding to getMax()
  21.          */
  22.     }
  23.    
  24.     protected void onValueChanged(){
  25.         /**
  26.          * Update your progress Variable and draw again
  27.          */
  28.         progress = getProgress();
  29.         this.invalidate();
  30.     }
  31.  
  32.     @Override
  33.     public synchronized void setMax(int max) {
  34.         onValueChanged();
  35.         super.setMax(max);
  36.     }
  37.  
  38.     @Override
  39.     public synchronized void setProgress(int progress) {
  40.         onValueChanged();
  41.         super.setProgress(progress);
  42.     }
  43.  
  44.     @Override
  45.     public synchronized void setSecondaryProgress(int secondaryProgress) {
  46.         onValueChanged();
  47.         super.setSecondaryProgress(secondaryProgress);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement