Search in sources :

Example 21 with DataMap

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;
}
Also used : ArrayList(java.util.ArrayList) PebbleMovement(com.eveningoutpost.dexdrip.Models.PebbleMovement) Date(java.util.Date) DataMap(com.google.android.gms.wearable.DataMap)

Example 22 with DataMap

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);
}
Also used : DataMap(com.google.android.gms.wearable.DataMap)

Example 23 with 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());
    }
}
Also used : DataMap(com.google.android.gms.wearable.DataMap)

Example 24 with DataMap

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;
                }
            }
        }
    };
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) ViewPager(android.support.v4.view.ViewPager) DataMap(com.google.android.gms.wearable.DataMap)

Example 25 with DataMap

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();
    }
}
Also used : Node(com.google.android.gms.wearable.Node) NodeApi(com.google.android.gms.wearable.NodeApi) PutDataRequest(com.google.android.gms.wearable.PutDataRequest) PutDataMapRequest(com.google.android.gms.wearable.PutDataMapRequest) DataApi(com.google.android.gms.wearable.DataApi) DataMap(com.google.android.gms.wearable.DataMap)

Aggregations

DataMap (com.google.android.gms.wearable.DataMap)157 Date (java.util.Date)42 ArrayList (java.util.ArrayList)38 Gson (com.google.gson.Gson)20 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)18 GsonBuilder (com.google.gson.GsonBuilder)18 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)18 Intent (android.content.Intent)17 Sensor (com.eveningoutpost.dexdrip.Models.Sensor)14 SuppressLint (android.annotation.SuppressLint)12 PendingIntent (android.app.PendingIntent)11 Context (android.content.Context)8 Calibration (com.eveningoutpost.dexdrip.Models.Calibration)8 Treatments (com.eveningoutpost.dexdrip.Models.Treatments)8 Bundle (android.os.Bundle)6 HeartRate (com.eveningoutpost.dexdrip.Models.HeartRate)6 Paint (android.graphics.Paint)5 BloodTest (com.eveningoutpost.dexdrip.Models.BloodTest)5 BroadcastReceiver (android.content.BroadcastReceiver)4 SharedPreferences (android.content.SharedPreferences)4