use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.
the class ListenerService method getWearStepSensorData.
private synchronized DataMap getWearStepSensorData(int count, long last_send_time, int min_count) {
// final int sensorType, final int accuracy, final long timestamp, final float[] values) {
forceGoogleApiConnect();
Log.d(TAG, "getWearStepSensorData last_send_time:" + JoH.dateTimeText(last_send_time));
PebbleMovement last_log = PebbleMovement.last();
if (last_log != null) {
Log.d(TAG, "getWearStepSensorData last_log.timestamp:" + JoH.dateTimeText((long) last_log.timestamp));
} else {
Log.d(TAG, "getWearStepSensorData PebbleMovement.last() = null:");
}
if (last_log != null && last_send_time <= last_log.timestamp) {
// startTime
long last_send_success = last_send_time;
Log.d(TAG, "getWearStepSensorData last_send_time < last_bg.timestamp:" + JoH.dateTimeText((long) last_log.timestamp));
List<PebbleMovement> logs = PebbleMovement.latestForGraph(count, last_send_time);
if (!logs.isEmpty() && logs.size() > min_count) {
// Log.d(TAG, "getWearStepSensorData count = " + logs.size());
DataMap entries = dataMap(last_log);
final ArrayList<DataMap> dataMaps = new ArrayList<>(logs.size());
for (PebbleMovement log : logs) {
dataMaps.add(dataMap(log));
last_send_success = (long) log.timestamp;
// Log.d(TAG, "getWearStepSensorData set last_send_sucess:" + JoH.dateTimeText(last_send_success) + " pw.metric: " + log.metric + " pw.timestamp: " + JoH.dateTimeText(log.timestamp));
}
// MOST IMPORTANT LINE FOR TIMESTAMP
entries.putLong("time", new Date().getTime());
entries.putDataMapArrayList("entries", dataMaps);
// Log.d(TAG, "getWearStepSensorData entries:" + entries);
Log.i(TAG, "getWearStepSensorData SYNCED steps up to " + JoH.dateTimeText(last_send_success) + " count = " + logs.size());
return entries;
} else
Log.i(TAG, "getWearStepSensorData SYNCED steps up to " + JoH.dateTimeText(last_send_success) + " count = 0");
}
return null;
}
use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.
the class ListenerService method sendLocalToast.
private void sendLocalToast(String msg, int length) {
DataMap dataMap = new DataMap();
dataMap.putString("msg", msg);
dataMap.putInt("length", length);
sendLocalMessage("msg", dataMap);
}
use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.
the class ListenerService method sendPersistentStore.
private synchronized void sendPersistentStore() {
if (DexCollectionType.getDexCollectionType().equals(DexCollectionType.DexcomG5)) {
DataMap dataMap = new DataMap();
String dex_txid = mPrefs.getString("dex_txid", "ABCDEF");
dataMap.putByteArray(G5_BATTERY_MARKER, PersistentStore.getBytes(G5_BATTERY_MARKER + dex_txid));
dataMap.putLong(G5_BATTERY_FROM_MARKER, PersistentStore.getLong(G5_BATTERY_FROM_MARKER + dex_txid));
dataMap.putString("dex_txid", dex_txid);
dataMap.putByteArray(G5_FIRMWARE_MARKER, PersistentStore.getBytes(G5_FIRMWARE_MARKER + dex_txid));
dataMap.putString("dex_txid", dex_txid);
sendData(WEARABLE_G5BATTERY_PAYLOAD, dataMap.toByteArray());
}
}
use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.
the class MegaStatus method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActivity = this;
setContentView(R.layout.activity_mega_status);
JoH.fixActionBar(this);
sectionList.clear();
sectionTitles.clear();
populateSectionList();
mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
// switch to last used position if it exists
int saved_position = (int) PersistentStore.getLong("mega-status-last-page");
// if triggered from pending intent, flip to named section if we can
final String action = getIntent().getAction();
if ((action != null) && (action.length() > 0)) {
int action_position = sectionList.indexOf(action);
if (action_position > -1)
saved_position = action_position;
}
if ((saved_position > 0) && (saved_position < sectionList.size())) {
currentPage = saved_position;
mViewPager.setCurrentItem(saved_position);
// run once activity becomes visible
autoStart = true;
keepScreenOn(sectionAlwaysOn.contains(sectionList.get(currentPage)));
}
mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
UserError.Log.d(TAG, "Page selected: " + position);
runnableView = null;
currentPage = position;
startAutoFresh();
keepScreenOn(sectionAlwaysOn.contains(sectionList.get(currentPage)));
PersistentStore.setLong("mega-status-last-page", currentPage);
}
});
// streamed data from android wear
requestWearCollectorStatus();
serviceDataReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context ctx, Intent intent) {
final String action = intent.getAction();
// final String msg = intent.getStringExtra("data");
Bundle bundle = intent.getBundleExtra("data");
if (bundle != null) {
DataMap dataMap = DataMap.fromBundle(bundle);
String lastState = dataMap.getString("lastState", "");
long last_timestamp = dataMap.getLong("timestamp", 0);
UserError.Log.d(TAG, "serviceDataReceiver onReceive:" + action + " :: " + lastState + " last_timestamp :: " + last_timestamp);
switch(action) {
case WatchUpdaterService.ACTION_BLUETOOTH_COLLECTION_SERVICE_UPDATE:
switch(DexCollectionType.getDexCollectionType()) {
case DexcomG5:
// as this is fairly lightweight just write the data to both G5 collectors
// msg, last_timestamp
G5CollectionService.setWatchStatus(dataMap);
// msg, last_timestamp
Ob1G5CollectionService.setWatchStatus(dataMap);
break;
case DexcomShare:
if (lastState != null && !lastState.isEmpty()) {
// setConnectionStatus(lastState);//TODO set System Status page connection_status.setText to lastState for non-G5 Services?
}
break;
default:
// msg, last_timestamp
DexCollectionService.setWatchStatus(dataMap);
if (lastState != null && !lastState.isEmpty()) {
// setConnectionStatus(lastState);//TODO set System Status page connection_status.setText to lastState for non-G5 Services?
}
break;
}
break;
}
}
}
};
}
use of com.google.android.gms.wearable.DataMap in project xDrip by NightscoutFoundation.
the class SendToDataLayerThread method sendToWear.
// Debug function to expose where it might be locking up
private synchronized void sendToWear(final DataMap... params) {
if (!lock.tryLock()) {
Log.d(TAG, "Concurrent access - waiting for thread unlock");
// enforce single threading
lock.lock();
Log.d(TAG, "Thread unlocked - proceeding");
}
lastlock = JoH.tsl();
try {
if (state != 0) {
UserError.Log.e(TAG, "WEAR STATE ERROR: state=" + state);
}
state = 1;
final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(15, TimeUnit.SECONDS);
state = 2;
for (Node node : nodes.getNodes()) {
state = 3;
for (DataMap dataMap : params) {
state = 4;
PutDataMapRequest putDMR = PutDataMapRequest.create(path);
state = 5;
putDMR.getDataMap().putAll(dataMap);
putDMR.setUrgent();
state = 6;
PutDataRequest request = putDMR.asPutDataRequest();
state = 7;
DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(15, TimeUnit.SECONDS);
state = 8;
if (result.getStatus().isSuccess()) {
UserError.Log.d(TAG, "DataMap: " + dataMap + " sent to: " + node.getDisplayName());
} else {
UserError.Log.e(TAG, "ERROR: failed to send DataMap");
result = Wearable.DataApi.putDataItem(googleApiClient, request).await(30, TimeUnit.SECONDS);
if (result.getStatus().isSuccess()) {
UserError.Log.d(TAG, "DataMap retry: " + dataMap + " sent to: " + node.getDisplayName());
} else {
UserError.Log.e(TAG, "ERROR on retry: failed to send DataMap: " + result.getStatus().toString());
}
}
state = 9;
}
}
state = 0;
} catch (Exception e) {
UserError.Log.e(TAG, "Got exception in sendToWear: " + e.toString());
} finally {
lastlock = 0;
lock.unlock();
}
}
Aggregations