Mega Code Archive
Bars View
/*
Amarino - A prototyping software toolkit for Android and Arduino
Copyright (c) 2010 Bonifaz Kaufmann. All right reserved.
This application and its library is free software; you can redistribute
it and/or modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
import android.content.Context;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
class BarsView extends Visualizer {
private static final String TAG = "BarsView";
private static final int NUM_BARS = 3;
private int activeBars = 0;
private Bitmap mBitmap;
private Canvas mCanvas = new Canvas();
private int[] mColor = new int[3];
private float barHeight;
public BarsView(Context context) {
super(context);
init();
}
public BarsView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init(){
mColor[0] = Color.argb(255, 0, 200, 0); // g
mColor[1] = Color.argb(255, 200, 200, 0); // y
mColor[2] = Color.argb(255, 200, 0, 0); // r
activeBars = 1;
}
@Override
public void setBoundaries(float min, float max) {
super.setBoundaries(min, max);
}
@Override
public void setData(float value) {
mCanvas.drawColor(0xFF111111);
updateBar(value, 0);
invalidate();
}
@Override
public void setData(float[] values) {
mCanvas.drawColor(0xFF111111);
int length = values.length;
if (length > activeBars){
activeBars = length;
}
for (int i=0; i Exception
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
mCanvas.setBitmap(mBitmap);
mCanvas.drawColor(0xFF111111);
}
@Override
protected void onDraw(Canvas canvas) {
synchronized (this) {
if (mBitmap != null) {
// draw bars outline
final float v1 = minValue * mScaleX;
final Canvas cavas = mCanvas;
final Paint paint = mPaint;
paint.setColor(0x44996666);
for (int i=0; i