| /* |
| Copyright 2014 David Morrissey |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| */ |
| |
| package com.davemorrissey.labs.subscaleview.sample.extension.views; |
| |
| import android.content.Context; |
| import android.graphics.*; |
| import android.graphics.Paint.Cap; |
| import android.graphics.Paint.Style; |
| import android.util.AttributeSet; |
| import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; |
| |
| public class CircleView extends SubsamplingScaleImageView { |
| |
| private int strokeWidth; |
| |
| private final PointF sCenter = new PointF(); |
| private final PointF vCenter = new PointF(); |
| private final Paint paint = new Paint(); |
| |
| public CircleView(Context context) { |
| this(context, null); |
| } |
| |
| public CircleView(Context context, AttributeSet attr) { |
| super(context, attr); |
| initialise(); |
| } |
| |
| private void initialise() { |
| float density = getResources().getDisplayMetrics().densityDpi; |
| strokeWidth = (int)(density/60f); |
| } |
| |
| @Override |
| protected void onDraw(Canvas canvas) { |
| super.onDraw(canvas); |
| |
| // Don't draw pin before image is ready so it doesn't move around during setup. |
| if (!isReady()) { |
| return; |
| } |
| |
| sCenter.set(getSWidth()/2, getSHeight()/2); |
| sourceToViewCoord(sCenter, vCenter); |
| float radius = (getScale() * getSWidth()) * 0.25f; |
| |
| paint.setAntiAlias(true); |
| paint.setStyle(Style.STROKE); |
| paint.setStrokeCap(Cap.ROUND); |
| paint.setStrokeWidth(strokeWidth * 2); |
| paint.setColor(Color.BLACK); |
| canvas.drawCircle(vCenter.x, vCenter.y, radius, paint); |
| paint.setStrokeWidth(strokeWidth); |
| paint.setColor(Color.argb(255, 51, 181, 229)); |
| canvas.drawCircle(vCenter.x, vCenter.y, radius, paint); |
| } |
| |
| } |