1 /*** 2 * Ambient - A music player for the Android platform 3 Copyright (C) 2007 Martin Vysny 4 5 This program is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 package sk.baka.ambient.views; 19 20 import sk.baka.ambient.commons.MiscUtils; 21 import android.content.Context; 22 import android.graphics.Canvas; 23 import android.graphics.Paint; 24 import android.util.AttributeSet; 25 import android.widget.ProgressBar; 26 27 /*** 28 * Adds support for showing a text in the progress bar. 29 * 30 * @author Martin Vysny 31 */ 32 public class TextProgressBar extends ProgressBar { 33 34 /*** 35 * The text being shown on the progress bar. 36 */ 37 private String text; 38 39 /*** 40 * @param context 41 */ 42 public TextProgressBar(Context context) { 43 super(context); 44 } 45 46 /*** 47 * @param context 48 * @param attrs 49 */ 50 public TextProgressBar(Context context, AttributeSet attrs) { 51 super(context, attrs); 52 } 53 54 /*** 55 * @param context 56 * @param attrs 57 * @param defStyle 58 */ 59 public TextProgressBar(Context context, AttributeSet attrs, int defStyle) { 60 super(context, attrs, defStyle); 61 } 62 63 /*** 64 * Returns currently shown text. 65 * 66 * @return the text. 67 */ 68 public String getText() { 69 return text; 70 } 71 72 /*** 73 * Sets the text currently being shown. 74 * 75 * @param text 76 * non-<code>null</code> text. 77 */ 78 public void setText(final String text) { 79 this.text = MiscUtils.emptyIfNull(text); 80 invalidate(); 81 } 82 83 private final Paint textColor = new Paint(); 84 { 85 textColor.setColor(0xFF000000); 86 textColor.setAntiAlias(true); 87 } 88 89 @Override 90 protected synchronized void onDraw(Canvas canvas) { 91 super.onDraw(canvas); 92 canvas.drawText(text, 3, 14, textColor); 93 } 94 95 /*** 96 * Sets the text currently being shown. 97 * 98 * @param id 99 * the text resource ID. 100 */ 101 public void setText(int id) { 102 setText(getResources().getString(id)); 103 } 104 }