Back to project page interdroid-swan.
The source code is released under:
Copyright (c) 2008-2011 Vrije Universiteit, The Netherlands All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the follo...
If you think the Android project interdroid-swan listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package interdroid.swan.engine; // w ww . ja v a 2s . c o m import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.util.AttributeSet; import android.widget.ProgressBar; public class TextProgressBar extends ProgressBar { private String text = ""; private int textColor = Color.BLACK; private float textSize = 15; public TextProgressBar(Context context) { super(context); } public TextProgressBar(Context context, AttributeSet attrs) { super(context, attrs); } public TextProgressBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint textPaint = new Paint(); textPaint.setAntiAlias(true); textPaint.setColor(textColor); textPaint.setTextSize(textSize); Rect bounds = new Rect(); textPaint.getTextBounds(text, 0, text.length(), bounds); int x = getWidth() / 2 - bounds.centerX(); int y = getHeight() / 2 - bounds.centerY(); canvas.drawText(text, x, y, textPaint); } public String getText() { return text; } public void setText(String text) { if (text != null) { this.text = text; } else { this.text = ""; } postInvalidate(); } public int getTextColor() { return textColor; } public void setTextColor(int textColor) { this.textColor = textColor; postInvalidate(); } public float getTextSize() { return textSize; } public void setTextSize(float textSize) { this.textSize = textSize; postInvalidate(); } }