If you think the Android project bitfynd-wallet-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2011 the original author or authors.
*/*www.java2s.com*/
* 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 <http://www.gnu.org/licenses/>.
*/package de.schildbach.wallet.util;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
/**
* @author Andreas Schildbach
*/publicclass CircularProgressView extends View
{
privateint width;
privateint height;
privateint progress = 1;
privateint maxProgress = 1;
privateint size = 1;
privateint maxSize = 1;
privatefinal Path path = new Path();
privatefinal Paint fillPaint = new Paint();
privatefinal Paint strokePaint = new Paint();
public CircularProgressView(final Context context, final AttributeSet attrs)
{
super(context, attrs);
finalfloat density = getResources().getDisplayMetrics().density;
fillPaint.setStyle(Style.FILL);
fillPaint.setColor(Color.parseColor("#44ff44"));
fillPaint.setAntiAlias(true);
strokePaint.setStyle(Style.STROKE);
strokePaint.setColor(Color.DKGRAY);
strokePaint.setStrokeWidth(1 * density);
strokePaint.setAntiAlias(true);
}
@Override
protectedvoid onDraw(final Canvas canvas)
{
super.onDraw(canvas);
canvas.drawPath(path, fillPaint);
canvas.drawPath(path, strokePaint);
}
publicvoid setColors(finalint fillColor, finalint strokeColor)
{
fillPaint.setColor(fillColor);
strokePaint.setColor(strokeColor);
postInvalidate();
}
publicvoid setProgress(finalint progress)
{
this.progress = progress;
updatePath(getWidth(), getHeight());
postInvalidate();
}
publicvoid setMaxProgress(finalint maxProgress)
{
this.maxProgress = maxProgress;
updatePath(getWidth(), getHeight());
postInvalidate();
}
publicvoid setSize(finalint size)
{
this.size = size;
updatePath(getWidth(), getHeight());
postInvalidate();
}
publicvoid setMaxSize(finalint maxSize)
{
this.maxSize = maxSize;
updatePath(getWidth(), getHeight());
postInvalidate();
}
@Override
protectedvoid onSizeChanged(finalint w, finalint h, finalint oldw, finalint oldh)
{
updatePath(w, h);
super.onSizeChanged(w, h, oldw, oldh);
}
privatevoid updatePath(finalint w, finalint h)
{
finalfloat maxAbsSize = Math.min(w, h) / 2f;
finalfloat absSize = size < maxSize ? maxAbsSize * size / maxSize : maxAbsSize - 1;
path.reset();
if (progress == 0)
{
path.close();
}
elseif (progress < maxProgress)
{
finalfloat angle = progress * 360 / maxProgress;
finalfloat x = w / 2f;
finalfloat y = h / 2f;
path.moveTo(x, y);
path.arcTo(new RectF(x - absSize, y - absSize, x + absSize, y + absSize), 270, angle);
path.close();
}
else
{
path.addCircle(w / 2f, h / 2f, absSize, Direction.CW);
}
}
@Override
protectedvoid onMeasure(finalint wMeasureSpec, finalint hMeasureSpec)
{
finalint wMode = MeasureSpec.getMode(wMeasureSpec);
finalint wSize = MeasureSpec.getSize(wMeasureSpec);
if (wMode == MeasureSpec.EXACTLY)
width = wSize;
elseif (wMode == MeasureSpec.AT_MOST)
width = Math.min(width, wSize);
finalint hMode = MeasureSpec.getMode(hMeasureSpec);
finalint hSize = MeasureSpec.getSize(hMeasureSpec);
if (hMode == MeasureSpec.EXACTLY)
height = hSize;
elseif (hMode == MeasureSpec.AT_MOST)
height = Math.min(height, hSize);
setMeasuredDimension(this.width, this.height);
}
@Override
publicint getBaseline()
{
return getMeasuredHeight() - 1;
}
}