com.google.android.gms.wearable.DataMap Java Examples

The following examples show how to use com.google.android.gms.wearable.DataMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void syncFieldData(DataMap dataMap) {
    String dex_txid = dataMap.getString("dex_txid", "");
    byte[] G5_BATTERY_MARKER = dataMap.getByteArray(G5CollectionService.G5_BATTERY_MARKER);
    byte[] G5_FIRMWARE_MARKER = dataMap.getByteArray(G5CollectionService.G5_FIRMWARE_MARKER);
    if (dex_txid != null && dex_txid.equals(mPrefs.getString("dex_txid", "default"))) {
        if (G5_BATTERY_MARKER != null) {
            long watch_last_battery_query = dataMap.getLong(G5CollectionService.G5_BATTERY_FROM_MARKER);
            long phone_last_battery_query = PersistentStore.getLong(G5CollectionService.G5_BATTERY_FROM_MARKER + dex_txid);
            if (watch_last_battery_query > phone_last_battery_query) {
                G5CollectionService.setStoredBatteryBytes(dex_txid, G5_BATTERY_MARKER);
                PersistentStore.setLong(G5CollectionService.G5_BATTERY_FROM_MARKER + dex_txid, watch_last_battery_query);
                G5CollectionService.getBatteryStatusNow = false;
                Ob1G5CollectionService.getBatteryStatusNow = false;
            }
        }
        if (G5_FIRMWARE_MARKER != null) {
            G5CollectionService.setStoredFirmwareBytes(dex_txid, G5_FIRMWARE_MARKER);
        }
    }
}
 
Example #2
Source File: CircleWatchface.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void addDataMap(DataMap dataMap) {//KS
    double sgv = dataMap.getDouble("sgvDouble");
    double high = dataMap.getDouble("high");
    double low = dataMap.getDouble("low");
    double timestamp = dataMap.getDouble("timestamp");

    //Log.d(TAG, "addToWatchSet entry=" + dataMap);

    final int size = bgDataList.size();
    BgWatchData bgdata = new BgWatchData(sgv, high, low, timestamp);
    if (size > 0) {
        if (bgDataList.contains(bgdata)) {
            int i = bgDataList.indexOf(bgdata);
            BgWatchData bgd = bgDataList.get(bgDataList.indexOf(bgdata));
            //Log.d(TAG, "addToWatchSet replace indexOf=" + i + " bgDataList.sgv=" + bgd.sgv + " bgDataList.timestamp" + bgd.timestamp);
            bgDataList.set(i, bgdata);
        } else {
            //Log.d(TAG, "addToWatchSet add " + " entry.sgv=" + bgdata.sgv + " entry.timestamp" + bgdata.timestamp);
            bgDataList.add(bgdata);
        }
    }
    else {
        bgDataList.add(bgdata);
    }
}
 
Example #3
Source File: NOChart.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
private void loadBasalsAndTemps(DataMap dataMap) {
    ArrayList<DataMap> temps = dataMap.getDataMapArrayList("temps");
    if (temps != null) {
        tempWatchDataList = new ArrayList<>();
        for (DataMap temp : temps) {
            TempWatchData twd = new TempWatchData();
            twd.startTime = temp.getLong("starttime");
            twd.startBasal =  temp.getDouble("startBasal");
            twd.endTime = temp.getLong("endtime");
            twd.endBasal = temp.getDouble("endbasal");
            twd.amount = temp.getDouble("amount");
            tempWatchDataList.add(twd);
        }
    }
    ArrayList<DataMap> basals = dataMap.getDataMapArrayList("basals");
    if (basals != null) {
        basalWatchDataList = new ArrayList<>();
        for (DataMap basal : basals) {
            BasalWatchData bwd = new BasalWatchData();
            bwd.startTime = basal.getLong("starttime");
            bwd.endTime = basal.getLong("endtime");
            bwd.amount = basal.getDouble("amount");
            basalWatchDataList.add(bwd);
        }
    }
}
 
Example #4
Source File: NotificationUpdateService.java    From android-SynchronizedNotifications with Apache License 2.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
            DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();
            String content = dataMap.getString(Constants.KEY_CONTENT);
            String title = dataMap.getString(Constants.KEY_TITLE);
            if (Constants.WATCH_ONLY_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                buildWearableOnlyNotification(title, content, false);
            } else if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                buildWearableOnlyNotification(title, content, true);
            }
        } else if (dataEvent.getType() == DataEvent.TYPE_DELETED) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "DataItem deleted: " + dataEvent.getDataItem().getUri().getPath());
            }
            if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                // Dismiss the corresponding notification
                ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                        .cancel(Constants.WATCH_ONLY_ID);
            }
        }
    }
}
 
Example #5
Source File: CircleWatchface.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void addDataMap(DataMap dataMap) {//KS
    double sgv = dataMap.getDouble("sgvDouble");
    double high = dataMap.getDouble("high");
    double low = dataMap.getDouble("low");
    double timestamp = dataMap.getDouble("timestamp");

    //Log.d(TAG, "addToWatchSet entry=" + dataMap);

    final int size = bgDataList.size();
    BgWatchData bgdata = new BgWatchData(sgv, high, low, timestamp);
    if (size > 0) {
        if (bgDataList.contains(bgdata)) {
            int i = bgDataList.indexOf(bgdata);
            BgWatchData bgd = bgDataList.get(bgDataList.indexOf(bgdata));
            //Log.d(TAG, "addToWatchSet replace indexOf=" + i + " bgDataList.sgv=" + bgd.sgv + " bgDataList.timestamp" + bgd.timestamp);
            bgDataList.set(i, bgdata);
        } else {
            //Log.d(TAG, "addToWatchSet add " + " entry.sgv=" + bgdata.sgv + " entry.timestamp" + bgdata.timestamp);
            bgDataList.add(bgdata);
        }
    }
    else {
        bgDataList.add(bgdata);
    }
}
 
Example #6
Source File: DigitalWatchFaceCompanionConfigActivity.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
private void setUpColorPickerSelection(int spinnerId, final String configKey, DataMap config,
        int defaultColorNameResId) {
    String defaultColorName = getString(defaultColorNameResId);
    int defaultColor = Color.parseColor(defaultColorName);
    int color;
    if (config != null) {
        color = config.getInt(configKey, defaultColor);
    } else {
        color = defaultColor;
    }
    Spinner spinner = (Spinner) findViewById(spinnerId);
    String[] colorNames = getResources().getStringArray(R.array.color_array);
    for (int i = 0; i < colorNames.length; i++) {
        if (Color.parseColor(colorNames[i]) == color) {
            spinner.setSelection(i);
            break;
        }
    }
}
 
Example #7
Source File: PersistenceTest.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void whenDataUpdatedTest() {
    // GIVEN
    Persistence persistence = new Persistence();
    DataMap map = new DataMap();

    // WHEN
    final long whenNotUpdated = persistence.whenDataUpdated();

    Persistence.storeDataMap("data-map", map);
    final long whenUpdatedFirst = persistence.whenDataUpdated();

    WearUtilMocker.progressClock(60000);
    Persistence.storeDataMap("data-map", map);
    final long whenUpdatedNext = persistence.whenDataUpdated();

    // THEN
    assertThat(whenNotUpdated, is(0L));
    assertThat(whenUpdatedFirst, is(REF_NOW));
    assertThat(whenUpdatedNext, is(REF_NOW + 60000));
}
 
Example #8
Source File: IncomingRequestWearService.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
private void promptUserForSensorPermission() {
    Log.d(TAG, "promptUserForSensorPermission()");

    boolean sensorPermissionApproved =
            ActivityCompat.checkSelfPermission(this, Manifest.permission.BODY_SENSORS)
                    == PackageManager.PERMISSION_GRANTED;

    if (sensorPermissionApproved) {
        DataMap dataMap = new DataMap();
        dataMap.putInt(Constants.KEY_COMM_TYPE,
                Constants.COMM_TYPE_RESPONSE_USER_APPROVED_PERMISSION);
        sendMessage(dataMap);
    } else {
        // Launch Activity to grant sensor permissions.
        Intent startIntent = new Intent(this, MainWearActivity.class);
        startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startIntent.putExtra(MainWearActivity.EXTRA_PROMPT_PERMISSION_FROM_PHONE, true);
        startActivity(startIntent);
    }
}
 
Example #9
Source File: DataLayerListenerService.java    From LibreAlarm with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            // Check the data path
            String path = event.getDataItem().getUri().getPath();
            if (WearableApi.SETTINGS.equals(path)) {
                HashMap<String, String> newSettings = new HashMap<>();
                DataMap dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                for (String key : dataMap.keySet()) {
                    newSettings.put(key, dataMap.getString(key, null));
                    PreferencesUtil.putString(this, key, newSettings.get(key));
                }

                WearableApi.sendMessage(mGoogleApiClient, WearableApi.SETTINGS, PreferencesUtil.toString(newSettings), null);

                sendStatus(mGoogleApiClient);
            }
        }
    }
}
 
Example #10
Source File: Simulation.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void Approve(View myview) {
    if (watchkeypad) {
        //Treatments.create(carbs, insulin, thisnotes, new Date().getTime());
        DataMap dataMap = new DataMap();
        dataMap.putDouble("timeoffset", timeoffset);
        dataMap.putDouble("carbs", carbs);
        dataMap.putDouble("insulin", insulin);
        dataMap.putDouble("bloodtest", bloodtest);
        dataMap.putString("notes", thisnotes);
        //dataMap.putLong("timestamp", System.currentTimeMillis());
        ListenerService.createTreatment(dataMap, this);
    }
    else
        SendData(this, WEARABLE_APPROVE_TREATMENT, null);
    finish();
}
 
Example #11
Source File: MainPhoneActivity.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d(TAG, "onActivityResult()");
    if (requestCode == REQUEST_WEAR_PERMISSION_RATIONALE) {

        if (resultCode == Activity.RESULT_OK) {
            logToUi("Requested permission on wear device(s).");

            DataMap dataMap = new DataMap();
            dataMap.putInt(Constants.KEY_COMM_TYPE,
                    Constants.COMM_TYPE_REQUEST_PROMPT_PERMISSION);
            sendMessage(dataMap);
        }
    }
}
 
Example #12
Source File: RawDisplayDataStatusTest.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
private DataMap dataMapForStatus() {
    DataMap dataMap = new DataMap();
    dataMap.putString("currentBasal", "120%");
    dataMap.putString("battery", "76");
    dataMap.putString("rigBattery", "40%");
    dataMap.putBoolean("detailedIob", true);
    dataMap.putString("iobSum", "12.5") ;
    dataMap.putString("iobDetail","(11,2|1,3)");
    dataMap.putString("cob","5(10)g");
    dataMap.putString("bgi", "13");
    dataMap.putBoolean("showBgi", false);
    dataMap.putString("externalStatusString", "");
    dataMap.putInt("batteryLevel", 1);
    dataMap.putLong("openApsStatus", WearUtilMocker.REF_NOW - Constants.MINUTE_IN_MS*2);
    return dataMap;
}
 
Example #13
Source File: SunsetsWatchFace.java    From american-sunsets-watch-face with Apache License 2.0 6 votes vote down vote up
private void updateUiForConfigDataMap(final DataMap config) {
    boolean uiUpdated = false;
    for (String configKey : config.keySet()) {
        if (!config.containsKey(configKey)) {
            continue;
        }
        int color = config.getInt(configKey);
        Log.d(TAG, "Found watch face config key: " + configKey + " -> "
                    + color);

        if (updateUiForKey(configKey, color)) {
            uiUpdated = true;
        }
    }
    if (uiUpdated) {
        invalidate();
    }
}
 
Example #14
Source File: WatchFace.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {

    for( DataEvent event : dataEvents ) {
        if( event.getType() == DataEvent.TYPE_CHANGED ) {
            DataItem item = event.getDataItem();
            if( item.getUri().getPath().compareTo( DATA_LAYER_PATH ) == 0 ) {
                DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
                int selectedBackgroundPosition = dataMap.getInt(KEY_BACKGROUND_POSITION);
                TypedArray typedArray = getResources().obtainTypedArray( R.array.background_resource_ids );
                initBackground( typedArray.getResourceId( selectedBackgroundPosition, 0 ) );
                SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                preferences.edit().putInt( SHARED_PREFERENCE_POSITION, selectedBackgroundPosition ).commit();
                typedArray.recycle();
                invalidate();
            }
        }
    }
}
 
Example #15
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {//KS does not seem to get triggered; therefore use OnMessageReceived instead

    DataMap dataMap;

    for (DataEvent event : dataEvents) {

        if (event.getType() == DataEvent.TYPE_CHANGED) {

            String path = event.getDataItem().getUri().getPath();

            switch (path) {
                case WEARABLE_PREF_DATA_PATH:
                    dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
                    if (dataMap != null) {
                        Log.d(TAG, "onDataChanged WEARABLE_PREF_DATA_PATH dataMap=" + dataMap);
                        syncPrefData(dataMap);
                    }
                    break;
                default:
                    Log.d(TAG, "Unknown wearable path: " + path);
                    break;
            }
        }
    }
}
 
Example #16
Source File: DataManager.java    From ibm-wearables-android-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Create new Data Request and send it to the phone
 */
private void sendNextGestureData() {
    PutDataMapRequest dataMapRequest = getNewSensorsDataMapRequest();
    DataMap dataMap = dataMapRequest.getDataMap();

    List<GestureDataHolder.EventData> nextAccelerometerData = gestureDataHolder.pollNextAccelerometerData();
    if (nextAccelerometerData.size() > 0){
        dataMap.putDataMapArrayList("accelerometer", convertEventsToDataMapList(nextAccelerometerData));
    }

    List<GestureDataHolder.EventData> nextGyroscopeData = gestureDataHolder.pollNextGyroscopeData();
    if (nextGyroscopeData.size() > 0){
        dataMap.putDataMapArrayList("gyroscope", convertEventsToDataMapList(nextGyroscopeData));
    }

    dataSender.sendData(dataMapRequest);
}
 
Example #17
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void sendActiveBtDeviceData() {//KS
    if (is_using_bt) {//only required for Collector running on watch
        forceGoogleApiConnect();
        ActiveBluetoothDevice btDevice = ActiveBluetoothDevice.first();
        if (btDevice != null) {
            if (wear_integration) {
                DataMap dataMap = new DataMap();
                Log.d(TAG, "sendActiveBtDeviceData name=" + btDevice.name + " address=" + btDevice.address + " connected=" + btDevice.connected);

                dataMap.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP

                dataMap.putString("name", btDevice.name);
                dataMap.putString("address", btDevice.address);
                dataMap.putBoolean("connected", btDevice.connected);

                new SendToDataLayerThread(WEARABLE_ACTIVEBTDEVICE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, dataMap);
            }
        }
    } else {
        Log.d(TAG, "Not sending activebluetoothdevice data as we are not using bt");
    }
}
 
Example #18
Source File: NotificationUpdateService.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
            DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();
            String content = dataMap.getString(Constants.KEY_CONTENT);
            String title = dataMap.getString(Constants.KEY_TITLE);
            if (Constants.WATCH_ONLY_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                buildWearableOnlyNotification(title, content, false);
            } else if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                buildWearableOnlyNotification(title, content, true);
            }
        } else if (dataEvent.getType() == DataEvent.TYPE_DELETED) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "DataItem deleted: " + dataEvent.getDataItem().getUri().getPath());
            }
            if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
                // Dismiss the corresponding notification
                ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                        .cancel(Constants.BOTH_ID);
            }
        }
    }
}
 
Example #19
Source File: ExceptionService.java    From ExceptionWear with Apache License 2.0 6 votes vote down vote up
private DataMap createExceptionInformation(Intent intent){

        bos = new ByteArrayOutputStream();
        try {
            oos = new ObjectOutputStream(bos);
            oos.writeObject(intent.getSerializableExtra(EXTRA_EXCEPTION));
        } catch (IOException e) {
            Log.e(WearExceptionTools.EXCEPTION_WEAR_TAG, "createExceptionInformation error while getting exception information.");
        }

        byte[] exceptionData = bos.toByteArray();
        DataMap dataMap = new DataMap();

        // Add a bit of information on the Wear Device to pass a long with the exception
        dataMap.putString("board", Build.BOARD);
        dataMap.putString("fingerprint", Build.FINGERPRINT);
        dataMap.putString("model", Build.MODEL);
        dataMap.putString("manufacturer", Build.MANUFACTURER);
        dataMap.putString("product", Build.PRODUCT);
        dataMap.putString("api_level", Integer.toString(Build.VERSION.SDK_INT));

        dataMap.putByteArray("exception", exceptionData);

        return dataMap;
    }
 
Example #20
Source File: BIGChart.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void addToWatchSet(DataMap dataMap) {

        if (d) Log.d(TAG, "addToWatchSet bgDataList.size()=" + bgDataList.size());

        ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
        if (entries != null) {
            if (d) Log.d(TAG, "addToWatchSet entries.size()=" + entries.size());
            for (DataMap entry : entries) {
                addDataMap(entry);
            }
        } else {
            addDataMap(dataMap);
        }

        for (int i = 0; i < bgDataList.size(); i++) {
            if (bgDataList.get(i).timestamp < (new Date().getTime() - (1000 * 60 * 60 * 5))) {
                bgDataList.remove(i); //Get rid of anything more than 5 hours old
                break;
            }
        }
    }
 
Example #21
Source File: MainActivity.java    From TutosAndroidFrance with MIT License 5 votes vote down vote up
/**
 * Récupère un element depuis sa position
 */
public Element getElement(DataMap elementDataMap) {
    return new Element(
            elementDataMap.getString("titre"),
            elementDataMap.getString("description"),
            elementDataMap.getString("url"));
}
 
Example #22
Source File: CircleWatchface.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
            "MyWakelockTag");
    wakeLock.acquire(30000);

    DataMap dataMap = DataMap.fromBundle(intent.getBundleExtra("data"));
    setSgvLevel((int) dataMap.getLong("sgvLevel"));
    Log.d("CircleWatchface", "sgv level : " + getSgvLevel());
    setSgvString(dataMap.getString("sgvString"));
    Log.d("CircleWatchface", "sgv string : " + getSgvString());
    setRawString(dataMap.getString("rawString"));
    setDelta(dataMap.getString("delta"));
    setDatetime(dataMap.getDouble("timestamp"));
    addToWatchSet(dataMap);


    //start animation?
    // dataMap.getDataMapArrayList("entries") == null -> not on "resend data".
    if (sharedPrefs.getBoolean("animation", false) && dataMap.getDataMapArrayList("entries") == null && (getSgvString().equals("100") || getSgvString().equals("5.5") || getSgvString().equals("5,5"))) {
        startAnimation();
    }

    prepareLayout();
    prepareDrawTime();
    invalidate();
    wakeLock.release();
}
 
Example #23
Source File: DexCollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static DataMap getWatchStatus() {
    DataMap dataMap = new DataMap();
    dataMap.putString("lastState", lastState);
    if (last_transmitter_Data != null)
        dataMap.putLong("timestamp", last_transmitter_Data.timestamp);
    dataMap.putInt("mStaticState", mStaticState);
    dataMap.putInt("last_battery_level", last_battery_level);
    dataMap.putLong("retry_time", retry_time);
    dataMap.putLong("failover_time", failover_time);
    dataMap.putString("static_last_hexdump", static_last_hexdump);
    dataMap.putString("static_last_sent_hexdump", static_last_sent_hexdump);
    return dataMap;
}
 
Example #24
Source File: DataManager.java    From ibm-wearables-android-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * Create next data to send of the hear rate
 * @param event sensor event
 */
private void sendHeartRateData(SensorEvent event){
    PutDataMapRequest dataMapRequest = getNewSensorsDataMapRequest();

    DataMap dataMap = dataMapRequest.getDataMap();
    dataMap.putFloat("heartrate",event.values[0]);

    dataSender.sendData(dataMapRequest);
}
 
Example #25
Source File: DataManager.java    From ibm-wearables-android-sdk with Apache License 2.0 5 votes vote down vote up
/**+
 * Convert the sensors event to data that will be sent to the phone
 * @param eventsList all the events to convert
 * @return converted list
 */
private ArrayList<DataMap> convertEventsToDataMapList(List<GestureDataHolder.EventData> eventsList){
    ArrayList<DataMap> dataMapsList = new ArrayList<>();

    for (GestureDataHolder.EventData event : eventsList){
        DataMap eventDataMap = new DataMap();
        eventDataMap.putLong("timeStamp", event.timestamp);
        eventDataMap.putFloatArray("values", event.values);
        dataMapsList.add(eventDataMap);
    }

    return dataMapsList;
}
 
Example #26
Source File: BgSendQueue.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static DataMap getSensorSteps(SharedPreferences prefs) {
    Log.d("BgSendQueue", "getSensorSteps");
    DataMap dataMap = new DataMap();
    final long t = System.currentTimeMillis();
    final PebbleMovement pm = PebbleMovement.last();
    final boolean show_steps = prefs.getBoolean("showSteps", true);
    final boolean show_heart_rate = prefs.getBoolean("showHeartRate", true);
    final boolean use_wear_health = prefs.getBoolean("use_wear_health", true);
    if (use_wear_health || show_steps) {
        boolean sameDay = pm != null ? ListenerService.isSameDay(t, pm.timestamp) : false;
        if (!sameDay) {
            dataMap.putInt("steps", 0);
            dataMap.putLong("steps_timestamp", t);
            Log.d("BgSendQueue", "getSensorSteps isSameDay false t=" + JoH.dateTimeText(t));
        }
        else {
            dataMap.putInt("steps", pm.metric);
            dataMap.putLong("steps_timestamp", pm.timestamp);
            Log.d("BgSendQueue", "getSensorSteps isSameDay true pm.timestamp=" + JoH.dateTimeText(pm.timestamp) + " metric=" + pm.metric);
        }
    }

    if (use_wear_health && show_heart_rate) {
        final HeartRate lastHeartRateReading = HeartRate.last();
        if (lastHeartRateReading != null) {
            dataMap.putInt("heart_rate", lastHeartRateReading.bpm);
            dataMap.putLong("heart_rate_timestamp", lastHeartRateReading.timestamp);
        }
    }
    return dataMap;
}
 
Example #27
Source File: HeartRateService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static synchronized DataMap getWearHeartSensorData(int count, long last_send_time, int min_count) {
    UserError.Log.d(TAG, "getWearHeartSensorData last_send_time:" + JoH.dateTimeText(last_send_time));

    if ((count != 0) || (JoH.ratelimit("heartrate-datamap", 5))) {
        HeartRate last_log = HeartRate.last();
        if (last_log != null) {
            UserError.Log.d(TAG, "getWearHeartSensorData last_log.timestamp:" + JoH.dateTimeText((long) last_log.timestamp));
        } else {
            UserError.Log.d(TAG, "getWearHeartSensorData HeartRate.last() = null:");
            return null;
        }

        if (last_log != null && last_send_time <= last_log.timestamp) {//startTime
            long last_send_success = last_send_time;
            UserError.Log.d(TAG, "getWearHeartSensorData last_send_time < last_bg.timestamp:" + JoH.dateTimeText((long) last_log.timestamp));
            List<HeartRate> logs = HeartRate.latestForGraph(count, last_send_time);
            if (!logs.isEmpty() && logs.size() > min_count) {
                DataMap entries = dataMap(last_log);
                final ArrayList<DataMap> dataMaps = new ArrayList<>(logs.size());
                for (HeartRate log : logs) {
                    dataMaps.add(dataMap(log));
                    last_send_success = (long) log.timestamp;
                }
                entries.putLong("time", JoH.tsl()); // MOST IMPORTANT LINE FOR TIMESTAMP
                entries.putDataMapArrayList("entries", dataMaps);
                UserError.Log.i(TAG, "getWearHeartSensorData SYNCED up to " + JoH.dateTimeText(last_send_success) + " count = " + logs.size());
                return entries;
            } else
                UserError.Log.i(TAG, "getWearHeartSensorData SYNCED up to " + JoH.dateTimeText(last_send_success) + " count = 0");
        }
        return null;
    } else {
        UserError.Log.d(TAG, "Ratelimitted getWearHeartSensorData");
        return null;
    }
}
 
Example #28
Source File: BaseWatchFace.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public void addDataMapTreats(DataMap dataMap, ArrayList<BgWatchData> dataList) {//KS
    double sgv = dataMap.getDouble("sgvDouble");
    double high = dataMap.getDouble("high");//carbs
    double low = dataMap.getDouble("low");//insulin
    double timestamp = dataMap.getDouble("timestamp");

     if (d) Log.d(TAG, "addDataMapTreats entry=" + dataMap);

    final int size = (dataList != null ? dataList.size() : 0);
    BgWatchData bgdata = new BgWatchData(sgv, high, low, timestamp);
    if (d) Log.d(TAG, "addDataMapTreats bgdata.sgv=" + bgdata.sgv + " bgdata.carbs=" + bgdata.high  + " bgdata.insulin=" + bgdata.low + " bgdata.timestamp=" + bgdata.timestamp + " timestamp=" + JoH.dateTimeText((long)bgdata.timestamp));
    if (size > 0) {
        if (dataList.contains(bgdata)) {
            int i = dataList.indexOf(bgdata);
            if (d) {
                BgWatchData data = dataList.get(dataList.indexOf(bgdata));
                Log.d(TAG, "addDataMapTreats replace indexOf=" + i + " treatsDataList.carbs=" + data.high + " treatsDataList.insulin=" + data.low + " treatsDataList.timestamp=" + data.timestamp);
            }
            dataList.set(i, bgdata);
        } else {
            if (d) Log.d(TAG, "addDataMapTreats add " + " treatsDataList.carbs=" + bgdata.high  + " treatsDataList.insulin=" + bgdata.low + " entry.timestamp=" + bgdata.timestamp);
            dataList.add(bgdata);
        }
    }
    else {
        dataList.add(bgdata);
    }
     if (d) Log.d(TAG, "addDataMapTreats dataList.size()=" + dataList.size());
}
 
Example #29
Source File: RetrieveService.java    From wear-notify-for-reddit with Apache License 2.0 5 votes vote down vote up
private void sendPostsToWearable(@NonNull List<Post> posts, @NonNull final String msg,
                                 @Nullable SimpleArrayMap<String, Asset> assets) {
    if (mGoogleApiClient.isConnected()) {
        // convert to json for sending to watch and to save to shared prefs
        // don't need to preserve the order like having separate String lists, can more easily add/remove fields
        PutDataMapRequest mapRequest = PutDataMapRequest.create(Constants.PATH_REDDIT_POSTS);
        DataMap dataMap = mapRequest.getDataMap();

        if (assets != null && !assets.isEmpty()) {
            for (int i = 0; i < assets.size(); i++) {
                dataMap.putAsset(assets.keyAt(i), assets.valueAt(i));
            }
        }

        dataMap.putLong("timestamp", System.currentTimeMillis());
        dataMap.putString(Constants.KEY_REDDIT_POSTS, mGson.toJson(posts));
        dataMap.putBoolean(Constants.KEY_DISMISS_AFTER_ACTION,
                mUserStorage.openOnPhoneDismissesAfterAction());
        dataMap.putIntegerArrayList(Constants.KEY_ACTION_ORDER,
                mWearableActionStorage.getSelectedActionIds());

        PutDataRequest request = mapRequest.asPutDataRequest();
        Wearable.DataApi.putDataItem(mGoogleApiClient, request)
                .setResultCallback(dataItemResult -> {
                    Timber.d(msg + ", final timestamp: " + mUserStorage.getTimestamp() + " result: " + dataItemResult
                            .getStatus());

                    if (dataItemResult.getStatus().isSuccess()) {
                        if (mGoogleApiClient.isConnected()) {
                            mGoogleApiClient.disconnect();
                        }
                    } else {
                        Timber.d("Failed to send posts to wearable " + dataItemResult.getStatus()
                                .getStatusMessage());
                    }
                });
    }
}
 
Example #30
Source File: ListenerService.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onDataChanged(DataEventBuffer dataEvents) {

    Log.d(TAG, "onDataChanged: " + dataEvents);

    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED
                && event.getDataItem() != null
                && event.getDataItem().getUri().getPath().equals("/today_req")) {

            DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
            ArrayList<DataMap> seancesDataMapList = dataMapItem.getDataMap().getDataMapArrayList("list_seances");

            ArrayList<Seances> seances = new ArrayList<>();

            for (DataMap seanceDataMap : seancesDataMapList) {
                Seances seance = new Seances();
                seance.getData(seanceDataMap);
                seances.add(seance);
            }

            Intent intent = new Intent("seances_update");
            intent.putExtra("seances", seances);
            LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
        }
    }
    super.onDataChanged(dataEvents);
}