Generating a Synchronized ProgressBar and Animating Visualization For A Voice Recorder

Initializations

/* The progressbar which will be synchronized with the on going voice recording.*/

ProgressBar mProgressBar = (ProgressBar) findViewById(R.id.mSeekBar);

mProgressBar.setMax(120);

/*The relative layout and textview which will show the  animation with the voice recording.*/

mRelativeLayout = (RelativeLayout) findViewById(R.id.voicerec_progresslayout);

mProgressTxv = (TextView) findViewById(R.id.voicerec_progressText);

A countdowntimer is used to increase progress regularly after an interval of 1 sec .
Also we have set the max time to 2 minutes for each recording. Hence countdonetimer  spans only for 2 minutes.

Attach a progressbar and a relative layout showing visualization.

public void showAnimation(final MediaRecorder mRec, final ProgressBar mProgressBar)

{

cdTimer = new CountDownTimer(120000, 1000)

{

Random rand = new Random();

int freq = rand.nextInt(6);

@Override

public void onTick(long millisUntilFinished)

{

                              /*Call to this method will take random inputs(freq)
to fill the relative layout with the freq  multiplied to height of textview. And hence showing a different height each time.*/

createStatisticalGraphs(6, 6 – freq, mProgressTxv);

/*Continous increment in the progress bar’s level */

mProgressBar.setProgress(++ctr);

}

@Override

public void onFinish()

{

if (cdTimer != null)

{

mProgressBar.setVisibility(View.GONE);

mStop.setVisibility(View.GONE);

mPlayBtn.setVisibility(View.VISIBLE);

displayDialog(“Recording Complete”);

cdTimer.cancel();

}

}

};

cdTimer.start();

}

Method for visualization

private void createStatisticalGraphs(int fMax, int frequency, TextView statsBar)

{

Displaydisplay=((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int screenHeight = display.getHeight();

float ans = ((((float) (screenHeight * (4.0 / 5))) / fMax) * frequency);

int setWidth = (int) ans;

RelativeLayout.LayoutParams mLayoutParams = new RelativeLayout.LayoutParams(20, setWidth);

statsBar.setLayoutParams(mLayoutParams);

}

150 150 Burnignorance | Where Minds Meet And Sparks Fly!