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

The following examples show how to use com.google.android.gms.wearable.DataMap. These examples are extracted from open source projects. 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
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 2
@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 3
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 4
@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 5
Source Project: wear-os-samples   Source File: MainPhoneActivity.java    License: 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 6
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 7
Source Project: AndroidDemoProjects   Source File: WatchFace.java    License: 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 8
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 9
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 10
@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 11
Source Project: ibm-wearables-android-sdk   Source File: DataManager.java    License: 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 12
@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 13
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 Project: xDrip   Source File: BIGChart.java    License: 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 15
Source Project: xDrip   Source File: Simulation.java    License: 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 16
Source Project: ExceptionWear   Source File: ExceptionService.java    License: 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 17
Source Project: xDrip-plus   Source File: CircleWatchface.java    License: 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 18
Source Project: AndroidAPS   Source File: NOChart.java    License: 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 19
@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 20
Source Project: xDrip   Source File: CircleWatchface.java    License: 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 21
private DataMap basalMap(long startTime, long endTime, double amount) {
    DataMap dm = new DataMap();
    dm.putLong("starttime", startTime);
    dm.putLong("endtime", endTime);
    dm.putDouble("amount", amount);
    return dm;
}
 
Example 22
Source Project: AndroidAPS   Source File: BundleMock.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public static Bundle mock(DataMap dataMap) {
    HashMap<String, Object> hm = new HashMap<>();
    for (String key : dataMap.keySet()) {
        hm.put(key, dataMap.get(key));
    }
    return mock(hm);
}
 
Example 23
/**
 * Retrieve scene data from Wear cloud storage
 *
 * @return List of Scenes
 */
public ArrayList<Scene> getSceneData() {
    ArrayList<Scene> scenes = new ArrayList<>();

    if (!googleApiClient.isConnected()) {
        if (!blockingConnect()) {
            return null;
        }
    }

    ArrayList<DataMap> data;
    DataItemBuffer dataItemBuffer = Wearable.DataApi.getDataItems(googleApiClient).await();

    if (dataItemBuffer.getStatus().isSuccess()) {
        for (DataItem dataItem : dataItemBuffer) {
            DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
            data = dataMapItem.getDataMap().getDataMapArrayList(WearableConstants.EXTRA_DATA);
            if (data != null) {
                scenes = ListenerService.extractSceneDataMapItems(data);
                break;
            }
        }
    }
    dataItemBuffer.release();

    return scenes;
}
 
Example 24
Source Project: sms-ticket   Source File: ListenerService.java    License: Apache License 2.0 5 votes vote down vote up
private void processTicketsList(DataMap data) {
    ArrayList<City> cities = new ArrayList<City>();
    ArrayList<DataMap> dataCities = data.getDataMapArrayList("tickets");

    for (DataMap city : dataCities) {
        cities.add(new City(city.getLong("id"), city.getString("country"), city.getString("city"),
            city.getInt("validity"), city.getString("note"), city.getString("price"), city.getString("currency"),
            city.getString("price_note")));
    }

    BusProvider.getInstance().post(new TicketsEvent(cities));
}
 
Example 25
/**
 * Handles issuing a response to a layer request. A layer request indicates
 * that the Wear device wants a list of previously used layers to display to
 * the user.
 *
 * @param event the MessageEvent from the Wear device
 * @param client the Google API client used to communicate
 */
private void handleLayerRequest(MessageEvent event, GoogleApiClient client) {
  Log.i("Test", "Received Layer request, sending layer list");
  // Create a PutDataMapRequest with the Layer response path
  PutDataMapRequest req = PutDataMapRequest.create(LAYER_RESPONSE);
  DataMap dm = req.getDataMap();
  // Put an array list of layer names into the data map
  dm.putStringArrayList("layers", new ArrayList<>(sLayerMap.keySet()));
  // Put the current time into the data map, which forces an onDataChanged event (this event
  // only occurs when data actually changes, so putting the time ensures something always changes)
  dm.putLong("Time", System.currentTimeMillis());
  // Put the DataItem into the Data API stream
  Wearable.DataApi.putDataItem(client, req.asPutDataRequest());
}
 
Example 26
@Override // ResultCallback<DataApi.DataItemResult>
public void onResult(DataApi.DataItemResult dataItemResult) {
    if (dataItemResult.getStatus().isSuccess() && dataItemResult.getDataItem() != null) {
        DataItem configDataItem = dataItemResult.getDataItem();
        DataMapItem dataMapItem = DataMapItem.fromDataItem(configDataItem);
        DataMap config = dataMapItem.getDataMap();
        setUpAllPickers(config);
    } else {
        // If DataItem with the current config can't be retrieved, select the default items on
        // each picker.
        setUpAllPickers(null);
    }
}
 
Example 27
Source Project: xDrip   Source File: WatchUpdaterService.java    License: GNU General Public License v3.0 5 votes vote down vote up
private synchronized void syncHeartSensorData(DataMap dataMap, boolean bBenchmark) {
    Log.d(TAG, "syncHeartSensorData");

    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    long timeOfLastEntry = 0;
    Log.d(TAG, "syncHeartSensorData add to Table");
    if (entries != null) {

        final Gson gson = JoH.defaultGsonInstance();

        //final HeartRate pm = HeartRate.last();
        Log.d(TAG, "syncHeartSensorData add Table entries count=" + entries.size());
        for (DataMap entry : entries) {
            if (entry != null) {
                Log.d(TAG, "syncHeartSensorData add Table entry=" + entry);
                String record = entry.getString("entry");
                if (record != null) {
                    Log.d(TAG, "syncHeartSensorData add Table record=" + record);
                    final HeartRate data = gson.fromJson(record, HeartRate.class);
                    if (data != null) {
                        timeOfLastEntry = (long) data.timestamp + 1;
                        Log.d(TAG, "syncHeartSensorData add Entry Wear=" + data.toString() + " " + record);
                        Log.d(TAG, "syncHeartSensorData WATCH data.metric=" + data.bpm + " timestamp=" + JoH.dateTimeText((long) data.timestamp));
                        if (!bBenchmark)
                            data.saveit();
                    }
                }
            }
        }
        sendDataReceived(DATA_ITEM_RECEIVED_PATH, "DATA_RECEIVED_LOGS count=" + entries.size(), timeOfLastEntry, bBenchmark ? "BM" : "HEART", -1);
    }
}
 
Example 28
private void sendConfigUpdateMessage(String configKey, int color) {
    if (mPeerId != null) {
        DataMap config = new DataMap();
        config.putInt(configKey, color);
        byte[] rawData = config.toByteArray();
        Wearable.MessageApi.sendMessage(mGoogleApiClient, mPeerId, PATH_WITH_FEATURE, rawData);

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Sent watch face config message: " + configKey + " -> "
                    + Integer.toHexString(color));
        }
    }
}
 
Example 29
Source Project: xDrip-plus   Source File: ListenerService.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void sendPrefSettings() {//KS

        Log.d(TAG, "sendPrefSettings enter");
        forceGoogleApiConnect();
        DataMap dataMap = new DataMap();
        boolean enable_wearG5 = mPrefs.getBoolean("enable_wearG5", false);
        boolean force_wearG5 = mPrefs.getBoolean("force_wearG5", false);
        String node_wearG5 = mPrefs.getString("node_wearG5", "");
        String dex_txid = mPrefs.getString("dex_txid", "ABCDEF");
        boolean show_wear_treatments = mPrefs.getBoolean("show_wear_treatments", false);

        if (localnode == null || (localnode != null && localnode.isEmpty())) setLocalNodeName();
        Log.d(TAG, "sendPrefSettings enable_wearG5: " + enable_wearG5 + " force_wearG5:" + force_wearG5 + " node_wearG5:" + node_wearG5 + " localnode:" + localnode + " dex_txid:" + dex_txid + " show_wear_treatments:" + show_wear_treatments);
        dataMap.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP
        dataMap.putBoolean("enable_wearG5", enable_wearG5);
        dataMap.putBoolean("force_wearG5", force_wearG5);
        if (force_wearG5) {
            dataMap.putString("node_wearG5", localnode);
        } else {
            if (node_wearG5.equals(localnode)) {
                dataMap.putString("node_wearG5", "");
            } else {
                dataMap.putString("node_wearG5", node_wearG5);
            }
        }
        dataMap.putString("dex_txid", dex_txid);
        dataMap.putInt("bridge_battery", mPrefs.getInt("bridge_battery", -1));//Used in DexCollectionService
        dataMap.putInt("nfc_sensor_age", mPrefs.getInt("nfc_sensor_age", -1));//Used in DexCollectionService for LimiTTer
        dataMap.putBoolean("bg_notifications_watch", mPrefs.getBoolean("bg_notifications", false));
        dataMap.putBoolean("persistent_high_alert_enabled_watch", mPrefs.getBoolean("persistent_high_alert_enabled", false));
        dataMap.putBoolean("show_wear_treatments", show_wear_treatments);
        sendData(WEARABLE_PREF_DATA_PATH, dataMap.toByteArray());

        SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(this).edit();
        if (!node_wearG5.equals(dataMap.getString("node_wearG5", ""))) {
            Log.d(TAG, "sendPrefSettings save to SharedPreferences - node_wearG5:" + dataMap.getString("node_wearG5", ""));
            prefs.putString("node_wearG5", dataMap.getString("node_wearG5", ""));
            prefs.apply();
        }
    }
 
Example 30
Source Project: wear-os-samples   Source File: MainWearActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // Check which request we're responding to
    if (requestCode == REQUEST_PHONE_PERMISSION) {
        // Make sure the request was successful
        if (resultCode == RESULT_OK) {
            logToUi("Requested permission on phone.");
            DataMap dataMap = new DataMap();
            dataMap.putInt(Constants.KEY_COMM_TYPE,
                    Constants.COMM_TYPE_REQUEST_PROMPT_PERMISSION);
            sendMessage(dataMap);
        }
    }
}