1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-02 23:12:57 +01:00

SleepMonitor: draw colored bars instead of a graph

red = awake
yellow = light sleep
greep = deep sleep
This commit is contained in:
Andreas Shimokawa 2015-05-27 00:59:05 +02:00
parent 06ee7efe79
commit 08fbbb9152

View File

@ -8,7 +8,7 @@ import android.content.IntentFilter;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Path; import android.graphics.RectF;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.NavUtils; import android.support.v4.app.NavUtils;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
@ -44,13 +44,16 @@ public class SleepMonitorActivity extends Activity {
int smartalarm_to = intent.getIntExtra("smartalarm_to", -1); int smartalarm_to = intent.getIntExtra("smartalarm_to", -1);
int recording_base_timestamp = intent.getIntExtra("recording_base_timestamp", -1); int recording_base_timestamp = intent.getIntExtra("recording_base_timestamp", -1);
int alarm_gone_off = intent.getIntExtra("alarm_gone_off", -1); int alarm_gone_off = intent.getIntExtra("alarm_gone_off", -1);
short[] points = intent.getShortArrayExtra("points");
Calendar cal = Calendar.getInstance(); Calendar cal = Calendar.getInstance();
cal.setTimeInMillis((long) recording_base_timestamp * 1000L); cal.setTimeInMillis((long) recording_base_timestamp * 1000L);
Date date = cal.getTime(); Date date = cal.getTime();
String dateString = new SimpleDateFormat("dd.MM.yyyy HH:mm").format(date); String dateString = new SimpleDateFormat("dd.MM.yyyy HH:mm").format(date);
textView.setText(dateString + " till " + alarm_gone_off / 60 + ":" + alarm_gone_off % 60); cal.setTimeInMillis((long) (recording_base_timestamp + 600 * (points.length - 1)) * 1000L);
short[] points = intent.getShortArrayExtra("points"); date = cal.getTime();
String dateStringTo = new SimpleDateFormat("dd.MM.yyyy HH:mm").format(date);
textView.setText(dateString + " to " + dateStringTo);
SurfaceHolder surfaceHolder = surfaceView.getHolder(); SurfaceHolder surfaceHolder = surfaceView.getHolder();
@ -59,22 +62,41 @@ public class SleepMonitorActivity extends Activity {
Canvas canvas = surfaceHolder.lockCanvas(); Canvas canvas = surfaceHolder.lockCanvas();
paint.setColor(Color.WHITE); paint.setColor(Color.WHITE);
paint.setStrokeWidth(2); paint.setStrokeWidth(2);
paint.setTextSize(20);
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
canvas.drawRGB(100, 100, 100); canvas.drawRGB(100, 100, 100);
int width = canvas.getWidth(); int width = canvas.getWidth();
int height = canvas.getHeight(); int height = canvas.getHeight();
Path path = new Path(); RectF r = new RectF(0.0f, 0.0f, 0.0f, height);
path.moveTo(0.0f, height); short last_movement = 5000;
float x = 0.0f;
for (int i = 0; i < points.length; i++) { for (int i = 0; i < points.length; i++) {
float y = (1.0f - (float) points[i] / 5000.0f) * height; boolean annotate = false;
x = (float) i / (points.length - 1) * width; short movement = points[i];
path.lineTo(x, y); r.left = r.right;
r.right = (float) (i + 1) / (points.length) * width;
r.top = (1.0f - (float) movement / 5000.0f) * height;
if (movement > 1000) {
paint.setColor(Color.RED);
if (last_movement <= 1000) {
annotate = true;
}
} else if (movement > 120) {
paint.setColor(Color.YELLOW);
} else {
paint.setColor(Color.GREEN);
}
canvas.drawRect(r, paint);
if (annotate) {
cal.setTimeInMillis((long) (recording_base_timestamp + 600 * i) * 1000L);
date = cal.getTime();
dateString = new SimpleDateFormat("HH:mm").format(date);
paint.setColor(Color.WHITE);
canvas.drawText(dateString, r.left - 20, r.top - 20, paint);
}
last_movement = movement;
} }
path.lineTo(x, height);
path.close();
canvas.drawPath(path, paint);
surfaceHolder.unlockCanvasAndPost(canvas); surfaceHolder.unlockCanvasAndPost(canvas);
} }
} }