package com.galois.qrstream.lib;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

public class TorrentBar extends View {
    private int cellCount;
    private Paint mPaint;
    private int width;
    private int height;
    private int cellWidth;

    public TorrentBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        paintInit();
    }

    public void setTotalChunks(int total) {
        this.cellCount = total;
        this.cellWidth = width / total;
    }

    private void paintInit() {
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setColor(Color.BLUE);
    }

    protected void onSizeChanged (int w, int h, int oldw, int oldh) {
        Log.d("qrstream", "onSizeChanged w:"+w+" h:"+h+" ow:"+oldw+" oh:"+oldh);
        this.width = w;
        this.height= w/10;
    }

    protected void onDraw(Canvas canvas) {
        Log.d("qrstream", "onDraw total "+cellCount);
        super.onDraw(canvas);
        for(int i=0; i < cellCount; i++) {
            drawCell(canvas, i, true);
        }
    }

    protected void drawCell(Canvas canvas, int idx, boolean onoff) {
        RectF cellBounds = cellBounds(idx);
        canvas.drawOval(
                cellBounds,
                mPaint
        );
    }

    protected RectF cellBounds(int idx) {
        int top = 0;
        int left = idx * cellWidth;
        int right = left + this.height;
        int bottom = top + this.height;
        RectF bounds = new RectF();
        bounds.set(left, top, right, bottom);
        return bounds;
    }

    public void setProgress(int progressStatus) {
        invalidate();
    }

    public int getMax() {
        return 100;
    }
}
@@ -354,17 +354,28 @@
 e Paint 
-m
+onPaint, off
 Paint;%0A 
@@ -446,16 +446,46 @@
 llWidth;
+%0A    private boolean%5B%5D onoffs;
 %0A%0A    pu
@@ -621,19 +621,17 @@
  set
-TotalChunks
+CellCount
 (int
@@ -708,24 +708,133 @@
 th / total;%0A
+        onoffs = new boolean%5Btotal%5D;%0A    %7D%0A%0A    public int getTotalChunks() %7B%0A        return this.cellCount;%0A
     %7D%0A%0A    p
@@ -863,25 +863,26 @@
 ) %7B%0A        
-m
+on
 Paint = new 
@@ -915,25 +915,120 @@
 G);%0A        
-m
+onPaint.setColor(Color.YELLOW);%0A        offPaint = new Paint(Paint.ANTI_ALIAS_FLAG);%0A        off
 Paint.setCol
@@ -1382,24 +1382,57 @@
 aw(canvas);%0A
+        if(onoffs != null) %7B%0A    
         for(
@@ -1434,15 +1434,18 @@
  for
+ 
 (int i
-=
+ = 
 0; i
@@ -1477,16 +1477,20 @@
         
+    
 drawCell
@@ -1505,14 +1505,33 @@
  i, 
-true);
+onoffs%5Bi%5D);%0A            %7D
 %0A   
@@ -1657,16 +1657,143 @@
 s(idx);%0A
+        Paint paint;%0A        if(onoff) %7B%0A            paint = onPaint;%0A        %7D else %7B%0A            paint = offPaint;%0A        %7D%0A
         
@@ -1857,10 +1857,9 @@
     
-mP
+p
 aint
@@ -2214,24 +2214,63 @@
 ssStatus) %7B%0A
+        onoffs%5BprogressStatus%5D = true;%0A
         inva
@@ -2338,9 +2338,65 @@
 ;%0A    %7D%0A
+%0A    public void reset() %7B%0A        invalidate();%0A    %7D%0A%0A
 %7D

fill in blue/yellow