FileDocCategorySizeDatePackage
VUMeter.javaAPI DocAndroid 1.5 API2849Wed May 06 22:42:48 BST 2009com.android.soundrecorder

VUMeter

public class VUMeter extends android.view.View

Fields Summary
static final float
PIVOT_RADIUS
static final float
PIVOT_Y_OFFSET
static final float
SHADOW_OFFSET
static final float
DROPOFF_STEP
static final float
SURGE_STEP
static final long
ANIMATION_INTERVAL
android.graphics.Paint
mPaint
android.graphics.Paint
mShadow
float
mCurrentAngle
Recorder
mRecorder
Constructors Summary
public VUMeter(android.content.Context context)


       
        super(context);
        init(context);
    
public VUMeter(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs);
        init(context);
    
Methods Summary
voidinit(android.content.Context context)

        Drawable background = context.getResources().getDrawable(R.drawable.vumeter);
        setBackgroundDrawable(background);
        
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setColor(Color.WHITE);
        mShadow = new Paint(Paint.ANTI_ALIAS_FLAG);
        mShadow.setColor(Color.argb(60, 0, 0, 0));
        
        mRecorder = null;
        
        mCurrentAngle = 0;
    
protected voidonDraw(android.graphics.Canvas canvas)

        super.onDraw(canvas);

        final float minAngle = (float)Math.PI/8;
        final float maxAngle = (float)Math.PI*7/8;
                
        float angle = minAngle;
        if (mRecorder != null)
        	angle += (float)(maxAngle - minAngle)*mRecorder.getMaxAmplitude()/32768;

        if (angle > mCurrentAngle)
            mCurrentAngle = angle;
        else
            mCurrentAngle = Math.max(angle, mCurrentAngle - DROPOFF_STEP);

        mCurrentAngle = Math.min(maxAngle, mCurrentAngle);

        float w = getWidth();
        float h = getHeight();
        float pivotX = w/2;
        float pivotY = h - PIVOT_RADIUS - PIVOT_Y_OFFSET;
        float l = h*4/5;
        float sin = (float) Math.sin(mCurrentAngle);
        float cos = (float) Math.cos(mCurrentAngle);
        float x0 = pivotX - l*cos;
        float y0 = pivotY - l*sin;
        canvas.drawLine(x0 + SHADOW_OFFSET, y0 + SHADOW_OFFSET, pivotX + SHADOW_OFFSET, pivotY + SHADOW_OFFSET, mShadow);
        canvas.drawCircle(pivotX + SHADOW_OFFSET, pivotY + SHADOW_OFFSET, PIVOT_RADIUS, mShadow);
        canvas.drawLine(x0, y0, pivotX, pivotY, mPaint);
        canvas.drawCircle(pivotX, pivotY, PIVOT_RADIUS, mPaint);
        
        if (mRecorder != null && mRecorder.state() == Recorder.RECORDING_STATE)
        	postInvalidateDelayed(ANIMATION_INTERVAL);
    
public voidsetRecorder(Recorder recorder)

    	mRecorder = recorder;
    	invalidate();