1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-03 17:02:13 +01:00

remove SleepChartActivityOld, as the new one is usable now ;)

This commit is contained in:
Andreas Shimokawa 2015-06-17 08:18:24 +02:00
parent a5ae7acc63
commit bffd7f332f
4 changed files with 3 additions and 254 deletions

View File

@ -55,13 +55,6 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".ControlCenter" />
</activity>
<activity
android:name=".activities.SleepChartActivityOld"
android:label="@string/title_activity_sleepmonitor" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ControlCenter" />
</activity>
<activity
android:name=".activities.SleepChartActivity"
android:label="@string/title_activity_sleepmonitor" >

View File

@ -8,7 +8,7 @@ import android.support.v4.content.LocalBroadcastManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.activities.SleepChartActivityOld;
import nodomain.freeyourgadget.gadgetbridge.activities.SleepChartActivity;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommand;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandAppInfo;
import nodomain.freeyourgadget.gadgetbridge.protocol.GBDeviceCommandCallControl;
@ -127,7 +127,7 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
public void handleGBDeviceCommand(GBDeviceCommandSleepMonitorResult sleepMonitorResult) {
Context context = getContext();
LOG.info("Got command for SLEEP_MONIOR_RES");
Intent sleepMontiorIntent = new Intent(SleepChartActivityOld.ACTION_REFRESH);
Intent sleepMontiorIntent = new Intent(SleepChartActivity.ACTION_REFRESH);
sleepMontiorIntent.putExtra("smartalarm_from", sleepMonitorResult.smartalarm_from);
sleepMontiorIntent.putExtra("smartalarm_to", sleepMonitorResult.smartalarm_to);
sleepMontiorIntent.putExtra("recording_base_timestamp", sleepMonitorResult.recording_base_timestamp);

View File

@ -28,7 +28,6 @@ import java.util.List;
import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.activities.SleepChartActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.SleepChartActivityOld;
import nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapter;
import nodomain.freeyourgadget.gadgetbridge.discovery.DiscoveryActivity;
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst;
@ -179,12 +178,7 @@ public class ControlCenter extends Activity {
case R.id.controlcenter_start_sleepmonitor:
if (selectedDevice != null) {
Intent startIntent;
if (selectedDevice.getType() == DeviceType.MIBAND) {
startIntent = new Intent(ControlCenter.this, SleepChartActivity.class);
}
else {
startIntent =new Intent(ControlCenter.this, SleepChartActivityOld.class);
}
startIntent = new Intent(ControlCenter.this, SleepChartActivity.class);
startIntent.putExtra("device", selectedDevice);
startActivity(startIntent);
}

View File

@ -1,238 +0,0 @@
package nodomain.freeyourgadget.gadgetbridge.activities;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v4.content.LocalBroadcastManager;
import android.view.MenuItem;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.TextView;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import nodomain.freeyourgadget.gadgetbridge.ControlCenter;
import nodomain.freeyourgadget.gadgetbridge.GBActivitySample;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.R;
public class SleepChartActivityOld extends Activity implements SurfaceHolder.Callback {
public static final String ACTION_REFRESH
= "nodomain.freeyourgadget.gadgetbride.sleepmonitor.action.refresh";
private static final Logger LOG = LoggerFactory.getLogger(SleepChartActivityOld.class);
private SurfaceView surfaceView;
private TextView textView;
private int mSmartAlarmFrom = -1;
private int mSmartAlarmTo = -1;
private int mTimestampFrom = -1;
private int mSmartAlarmGoneOff = -1;
private GBDevice mGBDevice = null;
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(ControlCenter.ACTION_QUIT)) {
finish();
} else if (action.equals(ACTION_REFRESH)) {
mSmartAlarmFrom = intent.getIntExtra("smartalarm_from", -1);
mSmartAlarmTo = intent.getIntExtra("smartalarm_to", -1);
mTimestampFrom = intent.getIntExtra("recording_base_timestamp", -1);
mSmartAlarmGoneOff = intent.getIntExtra("alarm_gone_off", -1);
refresh();
}
}
};
private void refresh() {
if (mGBDevice == null) {
return;
}
if (mTimestampFrom == -1) {
Long ts = System.currentTimeMillis();
mTimestampFrom = (int) ((ts / 1000) - (24 * 60 * 60) & 0xffffffff); // -24 hours
}
byte provider = -1;
switch (mGBDevice.getType()) {
case MIBAND:
provider = GBActivitySample.PROVIDER_MIBAND;
break;
case PEBBLE:
provider = GBActivitySample.PROVIDER_PEBBLE_MORPHEUZ; // FIXME
break;
}
ArrayList<GBActivitySample> samples = GBApplication.getActivityDatabaseHandler().getGBActivitySamples(mTimestampFrom, -1, provider);
Calendar cal = Calendar.getInstance();
Date date;
String dateStringFrom = "";
String dateStringTo = "";
SurfaceHolder surfaceHolder = surfaceView.getHolder();
LOG.info("number of samples:" + samples.size());
if (surfaceHolder.getSurface().isValid() && samples.size() > 1) {
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
Canvas canvas = surfaceHolder.lockCanvas();
paint.setColor(Color.WHITE);
paint.setStrokeWidth(2);
paint.setTextSize(20);
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(true);
canvas.drawRGB(100, 100, 100);
int width = canvas.getWidth();
int height = canvas.getHeight();
RectF r = new RectF(0.0f, 0.0f, 0.0f, height);
float movement_divisor;
boolean annotate;
boolean use_steps_as_movement;
switch (provider) {
case GBActivitySample.PROVIDER_MIBAND:
movement_divisor = 256.0f;
annotate = false; // sample density to high?
use_steps_as_movement = true;
break;
default: // Morpheuz
movement_divisor = 5000.0f;
annotate = true;
use_steps_as_movement = false;
break;
}
byte last_type = GBActivitySample.TYPE_UNKNOWN;
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
SimpleDateFormat annotationDateFormat = new SimpleDateFormat("HH:mm");
for (int i = 0; i < samples.size(); i++) {
GBActivitySample sample = samples.get(i);
byte type = sample.getType();
if (i == 0) {
cal.setTimeInMillis((long) sample.getTimestamp() * 1000L);
date = cal.getTime();
dateStringFrom = dateFormat.format(date);
} else if (i == samples.size() - 1) {
cal.setTimeInMillis((long) sample.getTimestamp() * 1000L);
date = cal.getTime();
dateStringTo = dateFormat.format(date);
}
short movement = sample.getIntensity();
r.left = r.right;
r.right = (float) (i + 1) / (samples.size()) * width;
if (type == GBActivitySample.TYPE_DEEP_SLEEP) {
paint.setColor(Color.BLUE);
r.top = 0.98f * height;
} else {
if (type == GBActivitySample.TYPE_LIGHT_SLEEP) {
paint.setColor(Color.CYAN);
} else {
if (use_steps_as_movement) {
movement = sample.getSteps();
}
paint.setColor(Color.YELLOW);
}
r.top = (1.0f - (float) movement / movement_divisor) * height;
}
canvas.drawRect(r, paint);
boolean annotate_this = false;
if (annotate) {
if (type != GBActivitySample.TYPE_DEEP_SLEEP && type != GBActivitySample.TYPE_LIGHT_SLEEP &&
(last_type == GBActivitySample.TYPE_DEEP_SLEEP || last_type == GBActivitySample.TYPE_LIGHT_SLEEP)) {
// seems that we woke up
annotate_this = true;
}
if (annotate_this) {
cal.setTimeInMillis((long) (sample.getTimestamp()) * 1000L);
date = cal.getTime();
String dateString = annotationDateFormat.format(date);
paint.setColor(Color.WHITE);
canvas.save();
canvas.rotate(-90.0f, r.left, r.top);
canvas.drawText(dateString, r.left + 10, r.top + 10, paint);
canvas.restore();
}
last_type = type;
}
}
textView.setText(dateStringFrom + " to " + dateStringTo);
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null) {
mGBDevice = extras.getParcelable("device");
}
setContentView(R.layout.activity_sleepmonitor);
textView = (TextView) findViewById(R.id.textView);
surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
getActionBar().setDisplayHomeAsUpEnabled(true);
IntentFilter filter = new IntentFilter();
filter.addAction(ControlCenter.ACTION_QUIT);
filter.addAction(ACTION_REFRESH);
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
surfaceView.getHolder().addCallback(this);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onDestroy() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
super.onDestroy();
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
refresh();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
refresh();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
}