/* * File: CircleView.java * This file is part of Tico, an application to create and perform * interactive communication boards to be used by people with * severe motor disabilities. * * Author: Eduardo Ferrer * * Date: May-2012 * * Company: Dept. of Computer Sciences and Systems Engineering, Universidad de Zaragoza, Spain * * * License: * This program is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package android.TICO.Views; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.graphics.Paint.Style; import android.graphics.drawable.GradientDrawable; import android.view.View; /** * Implementation of a CircleView view. * * @author Eduardo Ferrer * @version 1.0 May, 2012 */ public class CircleView extends View{ Paint paint=new Paint(); Paint paintInterior=new Paint(); int startX,startY,stopX,stopY; GradientDrawable gradient_color; /** * Creates a new CircleView for the specified params. * * @param startX The starting coordinate in X of the rectangle which contents the oval * @param startY The starting coordinate in Y of the rectangle which contents the oval * @param stopX The ending coordinate in X of the rectangle which contents the oval * @param stopY The ending coordinate in Y of the rectangle which contents the oval * @param context The Context the view is running in, through which it can access the current theme, resources, etc. */ public CircleView(int startX,int startY,int stopX,int stopY,Context context){ super(context); paint.setColor(Color.WHITE); this.startX=startX; this.startY=startY; this.stopX=stopX; this.stopY=stopY; paint.setStyle(Style.STROKE); paintInterior.setStyle(Style.FILL); paintInterior.setColor(Color.TRANSPARENT); gradient_color=null; } public void onDraw(Canvas canvas){ RectF oval=new RectF(); oval.set(startX, startY, stopX, stopY); oval.inset(paint.getStrokeWidth(), paint.getStrokeWidth()); //interior if(gradient_color!=null){ gradient_color.setBounds((int)oval.left, (int)oval.top, (int)oval.right, (int)oval.bottom); gradient_color.draw(canvas); } else if(paintInterior.getColor()!=Color.TRANSPARENT) canvas.drawOval(oval, paintInterior); //exterior canvas.drawOval(oval, paint); } /** * Set de CircleView color of the line. Note that the color is an int containing alpha as well as r,g,b. * This 32bit value is not premultiplied, meaning that its alpha can be any value, regardless of the values of r,g,b. * See the Color class for more details. * * @param color The new color (including alpha) to set as color of the circle line. */ public void setColor(int color){ paint.setColor(color); } /** * Set the CircleView color of the oval interior. Note that the color is an int containing alpha as well as r,g,b. * This 32bit value is not premultiplied, meaning that its alpha can be any value, regardless of the values of r,g,b. * See the Color class for more details. * * @param color The new color (including alpha) to set as color of the oval interior. */ public void setBackgroundColor(int color){ gradient_color=null; paintInterior.setColor(color); this.invalidate(); } /** * Set the background frame gradient color for the CircleView * @param colorIn The gradient color of the CircleView background */ public void setBackgroundDrawable(GradientDrawable colorIn){ gradient_color=colorIn; gradient_color.setShape(GradientDrawable.OVAL); //color.draw(canvas); this.invalidate();//force a redraw } /** * Set the width for stroking. Pass 0 to stroke in hairline mode. Hairlines always draws a single pixel independent of the canva's matrix. * * @param border set the CircleView's stroke width of the line. * */ public void setBorderWidth(int border){ paint.setStrokeWidth(border); } }