1 package com.davemorrissey.labs.subscaleview.test.extension.views;
2 
3 import android.content.Context;
4 import android.graphics.*;
5 import android.graphics.Paint.Cap;
6 import android.graphics.Paint.Style;
7 import android.util.AttributeSet;
8 import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
9 
10 public class CircleView extends SubsamplingScaleImageView {
11 
12     private int strokeWidth;
13 
14     private final PointF sCenter = new PointF();
15     private final PointF vCenter = new PointF();
16     private final Paint paint = new Paint();
17 
CircleView(Context context)18     public CircleView(Context context) {
19         this(context, null);
20     }
21 
CircleView(Context context, AttributeSet attr)22     public CircleView(Context context, AttributeSet attr) {
23         super(context, attr);
24         initialise();
25     }
26 
initialise()27     private void initialise() {
28         float density = getResources().getDisplayMetrics().densityDpi;
29         strokeWidth = (int)(density/60f);
30     }
31 
32     @Override
onDraw(Canvas canvas)33     protected void onDraw(Canvas canvas) {
34         super.onDraw(canvas);
35 
36         // Don't draw pin before image is ready so it doesn't move around during setup.
37         if (!isReady()) {
38             return;
39         }
40 
41         sCenter.set(getSWidth()/2, getSHeight()/2);
42         sourceToViewCoord(sCenter, vCenter);
43         float radius = (getScale() * getSWidth()) * 0.25f;
44 
45         paint.setAntiAlias(true);
46         paint.setStyle(Style.STROKE);
47         paint.setStrokeCap(Cap.ROUND);
48         paint.setStrokeWidth(strokeWidth * 2);
49         paint.setColor(Color.BLACK);
50         canvas.drawCircle(vCenter.x, vCenter.y, radius, paint);
51         paint.setStrokeWidth(strokeWidth);
52         paint.setColor(Color.argb(255, 51, 181, 229));
53         canvas.drawCircle(vCenter.x, vCenter.y, radius, paint);
54     }
55 
56 }
57