Skip to content

Commit

Permalink
Pebble: Add preference switch for Health data
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed Nov 16, 2016
1 parent 05ae1ea commit bd652b3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 50 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/eveningoutpost/dexdrip/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,6 @@ public void onClick(View v) {
processIncomingBundle(bundle);

checkBadSettings();

// lower priority
PlusSyncService.startSyncService(getApplicationContext(), "HomeOnCreate");
ParakeetHelper.notifyOnNextCheckin(false);
Expand Down Expand Up @@ -1562,7 +1561,8 @@ public void toggleStepsVisibility(View v) {

private void updateHealthInfo(String caller) {
final PebbleMovement pm = PebbleMovement.last();
if (pm != null) {
final boolean use_pebble_health = prefs.getBoolean("use_pebble_health", true);
if ((use_pebble_health) && (pm != null)) {
stepsButton.setText(Integer.toString(pm.metric));
stepsButton.setVisibility(View.VISIBLE);
stepsButton.setAlpha(getPreferencesBoolean("show_pebble_movement_line", true) ? 1.0f : 0.3f);
Expand All @@ -1571,7 +1571,7 @@ private void updateHealthInfo(String caller) {
}

final HeartRate hr = HeartRate.last();
if (hr != null) {
if ((use_pebble_health) && (hr != null)) {
bpmButton.setText(Integer.toString(hr.bpm));
bpmButton.setVisibility(View.VISIBLE);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ private void extend_line(List<PointValue> points, float x, float y) {
// line illustrating result from step counter
private List<Line> stepsLines() {
final List<Line> stepsLines = new ArrayList<>();
if (prefs.getBoolean("show_pebble_movement_line", true)) {
if ((prefs.getBoolean("use_pebble_health", true)
&& prefs.getBoolean("show_pebble_movement_line", true))) {
final List<PebbleMovement> pmlist = PebbleMovement.deltaListFromMovementList(PebbleMovement.latestForGraph(2000, loaded_start, loaded_end));
PointValue last_point = null;
final boolean d = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.os.IBinder;
import android.preference.PreferenceManager;

import com.eveningoutpost.dexdrip.Home;
import com.eveningoutpost.dexdrip.Models.HeartRate;
import com.eveningoutpost.dexdrip.Models.JoH;
import com.eveningoutpost.dexdrip.Models.PebbleMovement;
Expand Down Expand Up @@ -168,63 +169,63 @@ public void receiveData(Context context, UUID logUuid, Long timestamp,
public void receiveData(Context context, UUID logUuid, Long timestamp,
Long tag, Long data) {
Log.d(TAG, "receiveLogData: uuid:" + logUuid + " started: " + JoH.dateTimeText(timestamp * 1000) + " tag:" + tag + " data: " + data);
if (Home.getPreferencesBoolean("use_pebble_health", true)) {
if ((tag != null) && (data != null)) {
final int s = (int) (long) tag;

if ((tag != null) && (data != null)) {
final int s = (int) (long) tag;


switch (s) {
case HEARTRATE_LOG:
if (data > sanity_timestamp) {
if (last_heartrate_timestamp > 0) {
Log.e(TAG, "Out of sequence heartrate timestamp received!");
}
last_heartrate_timestamp = data;
} else {
if (data > 0) {
switch (s) {
case HEARTRATE_LOG:
if (data > sanity_timestamp) {
if (last_heartrate_timestamp > 0) {
final HeartRate hr = new HeartRate();
hr.timestamp = last_heartrate_timestamp * 1000;
hr.bpm = (int) (long) data;
Log.d(TAG, "Saving HeartRate: " + hr.toS());
hr.saveit();
last_heartrate_timestamp = 0; // reset state
} else {
Log.e(TAG, "Out of sequence heartrate value received!");
Log.e(TAG, "Out of sequence heartrate timestamp received!");
}
last_heartrate_timestamp = data;
} else {
if (data > 0) {
if (last_heartrate_timestamp > 0) {
final HeartRate hr = new HeartRate();
hr.timestamp = last_heartrate_timestamp * 1000;
hr.bpm = (int) (long) data;
Log.d(TAG, "Saving HeartRate: " + hr.toS());
hr.saveit();
last_heartrate_timestamp = 0; // reset state
} else {
Log.e(TAG, "Out of sequence heartrate value received!");
}
}
}
}
break;
break;

case MOVEMENT_LOG:
if (data > sanity_timestamp) {
if (last_movement_timestamp > 0) {
Log.e(TAG, "Out of sequence movement timestamp received!");
}
last_movement_timestamp = data;
} else {
if (data > 0) {
case MOVEMENT_LOG:
if (data > sanity_timestamp) {
if (last_movement_timestamp > 0) {
final PebbleMovement pm = new PebbleMovement();
pm.timestamp = last_movement_timestamp * 1000;
pm.metric = (int) (long) data;
Log.d(TAG, "Saving Movement: " + pm.toS());
pm.saveit();
last_movement_timestamp = 0; // reset state
} else {
Log.e(TAG, "Out of sequence movement value received!");
Log.e(TAG, "Out of sequence movement timestamp received!");
}
last_movement_timestamp = data;
} else {
if (data > 0) {
if (last_movement_timestamp > 0) {
final PebbleMovement pm = new PebbleMovement();
pm.timestamp = last_movement_timestamp * 1000;
pm.metric = (int) (long) data;
Log.d(TAG, "Saving Movement: " + pm.toS());
pm.saveit();
last_movement_timestamp = 0; // reset state
} else {
Log.e(TAG, "Out of sequence movement value received!");
}
}
}
}
break;
break;

default:
Log.e(TAG, "Unknown pebble data log type received: " + s);
break;
default:
Log.e(TAG, "Unknown pebble data log type received: " + s);
break;

}
} else {
Log.e(TAG, "Got null Long in receive data");
}
} else {
Log.e(TAG, "Got null Long in receive data");
}
}

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/pref_advanced_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@
android:key="pebble_special_text"
android:summary="@string/message_to_display_when_bgl_hits"
android:title="@string/text_to_display_when_hitting_special_value" />
<SwitchPreference
android:defaultValue="true"
android:key="use_pebble_health"
android:summary="Collect and display Step counter and Heart rate when available"
android:switchTextOff="@string/short_off_text_for_switches"
android:switchTextOn="@string/short_on_text_for_switches"
android:title="Use Pebble Health Data" />
</PreferenceCategory>
<PreferenceCategory
android:key="pebble_installers"
Expand Down

0 comments on commit bd652b3

Please sign in to comment.