Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cardio graph for android

I want to make an app which shows cardio graph in real time. That means i want to measure heart bit and want to show the bit rate in graph in my application. But i wondering to draw the cardio graph. I have gone through many sample graph codes but dint get any clue to draw cardio graph. Is there any clue from any body?

like image 950
Sudipta Som Avatar asked May 18 '11 07:05

Sudipta Som


People also ask

Is there a heart monitor app for Android?

Cardiograph is specifically designed with Android Wear support. You can measure your pulse using the hear rate sensor in your smartwatch. Please note that Cardiograph will work on smartwatches with a heart rate sensor only.

Can an Android phone measure heart rate?

You can track your heart rate on some Android phones.

Can I check my heart rhythm on my phone?

CardioSignal is a mobile application and a CE marked class IIa medical device available for iOS and Android. Just place your phone on your chest for one minute and relax. A powerful tool for atrial fibrillation detection now accessible to you anywhere with internet access.


1 Answers

For this specific application, you may want to draw the graph "by hand" using Path and a SurfaceView.

Get a Paint instance ready during initialization:

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(3);
paint.setColor(Color.GREEN);  //Change to what you want

When you need to update the graphic, clear the scene and build the line path (adapt this to your needs) :

canvas.drawColor(Color.WHITE);

Path path = new Path();
path.moveTo(0, yourValueAt(0));
for(int sec = 1; sec < 30; sec++)
    path.lineTo(sec, yourValueAt(sec));

canvas.drawPath(path, paint);

You may also use quadTo or cubicTo instead of lineTo.

If you want your graph to have a realtime animation effect (i.e. sliding to the left while data is coming on the right), you may draw on a SurfaceView in a similar way to the famous LunarLander example (following code is a simplified version):

class DrawingThread extends Thread {
    @Override
    public void run() {
        while (running) {
            Canvas c = null;
            try {
                c = mSurfaceHolder.lockCanvas(null);
                synchronized (mSurfaceHolder) {
                    doDraw(c);
                }
            } finally {
                if (c != null) mSurfaceHolder.unlockCanvasAndPost(c);
            }
            synchronized (this) {
                //Optional but saves battery life.
                //You may compute the value to match a given max framerate..
                this.wait(SOME_DELAY_IN_MS); 
            }
        }
    }
}

Where mSurfaceHolder is obtained by calling yourSurfaceView.getHolder() and doDraw is where you call canvas.drawPath() and all your drawing code.

like image 140
aberaud Avatar answered Oct 03 '22 02:10

aberaud