Java 类com.google.android.gms.wearable.DataMap 实例源码

项目:Android-DFU-App    文件:UARTConfigurationSynchronizer.java   
/**
 * Synchronizes the UART configurations between handheld and wearables.
 * Call this when configuration has been created or altered.
 * @return pending result
 */
public PendingResult<DataApi.DataItemResult> onConfigurationAddedOrEdited(final long id, final UartConfiguration configuration) {
    if (mGoogleApiClient == null || !mGoogleApiClient.isConnected())
        return null;

    final PutDataMapRequest mapRequest = PutDataMapRequest.create(Constants.UART.CONFIGURATIONS + "/" + id);
    final DataMap map = mapRequest.getDataMap();
    map.putString(Constants.UART.Configuration.NAME, configuration.getName());
    final ArrayList<DataMap> commands = new ArrayList<>(UartConfiguration.COMMANDS_COUNT);
    for (Command command : configuration.getCommands()) {
        if (command != null && command.isActive()) {
            final DataMap item = new DataMap();
            item.putInt(Constants.UART.Configuration.Command.ICON_ID, command.getIconIndex());
            item.putString(Constants.UART.Configuration.Command.MESSAGE, command.getCommand());
            item.putInt(Constants.UART.Configuration.Command.EOL, command.getEolIndex());
            commands.add(item);
        }
    }
    map.putDataMapArrayList(Constants.UART.Configuration.COMMANDS, commands);
    final PutDataRequest request = mapRequest.asPutDataRequest();
    return Wearable.DataApi.putDataItem(mGoogleApiClient, request);
}
项目:ibm-wearables-android-sdk    文件:DataManager.java   
/**
 * 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);
}
项目:SunshineApp    文件:DigitalWatchFaceUtil.java   
/**
 * Overwrites the current config {@link DataItem}'s {@link DataMap} with {@code newConfig}.
 * If the config DataItem doesn't exist, it's created.
 */
public static void putConfigDataItem(GoogleApiClient googleApiClient, DataMap newConfig) {
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_WITH_FEATURE);
    putDataMapRequest.setUrgent();
    DataMap configToPut = putDataMapRequest.getDataMap();
    configToPut.putAll(newConfig);
    Wearable.DataApi.putDataItem(googleApiClient, putDataMapRequest.asPutDataRequest())
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(DataApi.DataItemResult dataItemResult) {
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "putDataItem result status: " + dataItemResult.getStatus());
                    }
                }
            });
}
项目:ubiquitous    文件:MyWatchFace.java   
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    Log.d(LOG_TAG, " in data changed");
    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            // DataItem changed
            DataItem item = event.getDataItem();
            if (item.getUri().getPath().compareTo(WEATHER_PATH) == 0) {
                DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
                weather_id = dataMap.getInt(WEATHER_ID);
                high_temp = dataMap.getDouble(HIGH_TEMP);
                low_temp = dataMap.getDouble(LOW_TEMP);
            }
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            // DataItem deleted
        }
    }
    invalidate();
}
项目:WearVibrationCenter    文件:CrashlyticsExceptionWearHandler.java   
@Override
/**
 * Exception handler with Crashlytics support, also it will be shown in logcat.
 */
public void handleException(Throwable throwable, DataMap map) {
    Timber.d("HandleException %s", throwable);
    Crashlytics.setBool("wear_exception", true);
    Crashlytics.setString("board", map.getString("board"));
    Crashlytics.setString("fingerprint", map.getString("fingerprint"));
    Crashlytics.setString("model", map.getString("model"));
    Crashlytics.setString("manufacturer", map.getString("manufacturer"));
    Crashlytics.setString("product", map.getString("product"));
    Crashlytics.setString("api_level", map.getString("api_level"));

    Crashlytics.logException(throwable);
}
项目:Android-DFU-App    文件:UARTConfigurationsActivity.java   
/**
 * This method read the UART configurations from the DataApi and populates the adapter with them.
 */
private void populateConfigurations() {
    if (mGoogleApiClient.isConnected()) {
        final PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(mGoogleApiClient, Uri.parse("wear:" + Constants.UART.CONFIGURATIONS), DataApi.FILTER_PREFIX);
        results.setResultCallback(new ResultCallback<DataItemBuffer>() {
            @Override
            public void onResult(final DataItemBuffer dataItems) {
                final List<UartConfiguration> configurations = new ArrayList<>(dataItems.getCount());
                for (int i = 0; i < dataItems.getCount(); ++i) {
                    final DataItem item = dataItems.get(i);
                    final long id = ContentUris.parseId(item.getUri());
                    final DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
                    final UartConfiguration configuration = new UartConfiguration(dataMap, id);
                    configurations.add(configuration);
                }
                mAdapter.setConfigurations(configurations);
                dataItems.release();
            }
        });
    }
}
项目:iosched-reader    文件:FeedbackWearableListenerService.java   
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    LOGD(TAG, "onDataChanged: " + dataEvents + " for " + getPackageName());

    for (DataEvent event : dataEvents) {
        LOGD(TAG, "Uri is: " + event.getDataItem().getUri());
        DataMapItem mapItem = DataMapItem.fromDataItem(event.getDataItem());
        String path = event.getDataItem().getUri().getPath();
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            if (PATH_RESPONSE.equals(path)) {
                // we have a response
                DataMap data = mapItem.getDataMap();
                saveFeedback(data);
            }
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            if (path.startsWith(SessionAlarmService.PATH_FEEDBACK)) {
                Uri uri = event.getDataItem().getUri();
                dismissLocalNotification(uri.getLastPathSegment());
            }
        }
    }
}
项目:Android_watch_magpie    文件:ListenerSyncRule.java   
/**
 * This method is activated when a data is receive from the phone
 * @param dataEvents
 */
@Override
public void onDataChanged(DataEventBuffer dataEvents) {

    DataMap dataMap;
    for (DataEvent event : dataEvents) {
        // Check the data type
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            // Check the data path
            dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();

            //get the new rule send by the phone
            CustomRules rule= getRuleFromMap(dataMap);

            //save the rule in the database
            RulesRepository.getInstance().insertOrUpdate(rule);

            //send the value to the activty to change the display of bar

            Intent messageIntent = new Intent();
            messageIntent.setAction(Intent.ACTION_SEND);
            messageIntent.putExtra(Const.KEY_BROADCASTdATA, dataMap.toBundle());
            LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
        }
    }
}
项目:Android_watch_magpie    文件:PushMeasureThread.java   
private DataMap generateDataMap(CustomRules aRule)
{
    DataMap dataMap=new DataMap();
    dataMap.putLong(Const.KEY_CURRENTTIMESTAMP,System.currentTimeMillis());
    dataMap.putLong(Const.KEY_RULE_ID,aRule.getId());
    dataMap.putString(Const.KEY_RULE_CATEGORY,aRule.getCategory());
    dataMap.putString(Const.KEY_RULE_CONSTRAINT1,aRule.getConstraint_1());
    dataMap.putString(Const.KEY_RULE_CONSTRAINT2,aRule.getConstraint_2());
    dataMap.putString(Const.KEY_RULE_CONSTRAINT3,aRule.getConstraint_3());

    //if null, we send the number -100000. We will have to check on the other side
    dataMap.putDouble(Const.KEY_RULE_VAL1_MIN, formatValue(aRule.getVal_1_min()));
    dataMap.putDouble(Const.KEY_RULE_VAL1_MAX,formatValue(aRule.getVal_1_max()));
    dataMap.putDouble(Const.KEY_RULE_VAL2_MIN,formatValue(aRule.getVal_2_min()));
    dataMap.putDouble(Const.KEY_RULE_VAL2_MAX, formatValue(aRule.getVal_2_max()));

    return dataMap;

}
项目:Android_watch_magpie    文件:Listener_data_rule.java   
/**
 *
 * @param dataMap the data map that contains rules information
 * @return the rules created though datamap
 */
private CustomRules extractRulesFromDataMap(DataMap dataMap)
{
    CustomRules rule=new CustomRules();

    rule.setId(dataMap.getLong(Const.KEY_RULE_ID));
    rule.setCategory(dataMap.getString(Const.KEY_RULE_CATEGORY));

    rule.setVal_1_min(formatNumber(dataMap.getDouble(Const.KEY_RULE_VAL1_MIN)));
    rule.setVal_1_max(formatNumber(dataMap.getDouble(Const.KEY_RULE_VAL1_MAX)));
    rule.setVal_2_min(formatNumber(dataMap.getDouble(Const.KEY_RULE_VAL2_MIN)));
    rule.setVal_2_max(formatNumber(dataMap.getDouble(Const.KEY_RULE_VAL2_MAX)));

    rule.setConstraint_1(dataMap.getString(Const.KEY_RULE_CONSTRAINT1));
    rule.setConstraint_2(dataMap.getString(Const.KEY_RULE_CONSTRAINT2));
    rule.setConstraint_3(dataMap.getString(Const.KEY_RULE_CONSTRAINT3));

    return rule;
}
项目:Android_watch_magpie    文件:Fragment_display_settings.java   
/**
 * Used when a user update a rule. It will be send to the watch
 * @param rule : The current rule we want to send though a datamap (container)
 * @return The datamap that contain the rule
 */
private DataMap prepareDataMap(CustomRules rule)
{
    //create the value container
    DataMap dataContainer=new DataMap();

    //insert the rule value
    dataContainer.putLong(Const.KEY_RULE_ID,rule.getId());
    dataContainer.putString(Const.KEY_RULE_CATEGORY,rule.getCategory());
    dataContainer.putString(Const.KEY_RULE_CONSTRAINT1,rule.getConstraint_1());
    dataContainer.putString(Const.KEY_RULE_CONSTRAINT2,rule.getConstraint_2());
    dataContainer.putString(Const.KEY_RULE_CONSTRAINT3,rule.getConstraint_3());

    dataContainer.putDouble(Const.KEY_RULE_VAL1_MIN,formatDataMapValue( rule.getVal_1_min()));
    dataContainer.putDouble(Const.KEY_RULE_VAL1_MAX,formatDataMapValue(rule.getVal_1_max()));
    dataContainer.putDouble(Const.KEY_RULE_VAL2_MIN,formatDataMapValue(rule.getVal_2_min()));
    dataContainer.putDouble(Const.KEY_RULE_VAL2_MAX,formatDataMapValue(rule.getVal_2_max()));
    dataContainer.putLong(Const.KEY_CURRENTTIMESTAMP,System.currentTimeMillis());

    return dataContainer;
}
项目:Excuser    文件:DataLayerListenerService.java   
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    super.onDataChanged(dataEvents);

    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            // DataItem changed
            DataItem item = event.getDataItem();
            if (item.getUri().getPath().compareTo("/SHAKEINTENSITY") == 0) {
                DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();

                Log.e("Data Event", "value->"+dataMap.getString(SHAKE_INTENSITY_KEY));
                LocalStoreUtils.setShakeIntensity(dataMap.getString(SHAKE_INTENSITY_KEY), this);
            }
        }
    }

}
项目:xDrip-plus    文件:WatchUpdaterService.java   
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");
    }
}
项目:AndroidAPS    文件:SendToDataLayerThread.java   
@Override
protected Void doInBackground(DataMap... params) {
    try {
        final NodeApi.GetConnectedNodesResult nodes = Wearable.NodeApi.getConnectedNodes(googleApiClient).await(15, TimeUnit.SECONDS);
        for (Node node : nodes.getNodes()) {
            for (DataMap dataMap : params) {
                PutDataMapRequest putDMR = PutDataMapRequest.create(path);
                putDMR.getDataMap().putAll(dataMap);
                PutDataRequest request = putDMR.asPutDataRequest();
                DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(15, TimeUnit.SECONDS);
                if (result.getStatus().isSuccess()) {
                    Log.d(TAG, "DataMap: " + dataMap + " sent to: " + node.getDisplayName());
                } else {
                    Log.d(TAG, "ERROR: failed to send DataMap");
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Got exception sending data to wear: " + e.toString());
    }
    return null;
}
项目:Advanced_Android_Development_Wear    文件:DigitalWatchFaceUtil.java   
/**
 * Overwrites (or sets, if not present) the keys in the current config {@link com.google.android.gms.wearable.DataItem} with
 * the ones appearing in the given {@link com.google.android.gms.wearable.DataMap}. If the config DataItem doesn't exist,
 * it's created.
 * <p>
 * It is allowed that only some of the keys used in the config DataItem appear in
 * {@code configKeysToOverwrite}. The rest of the keys remains unmodified in this case.
 */
public static void overwriteKeysInConfigDataMap(final GoogleApiClient googleApiClient,
                                                final DataMap configKeysToOverwrite, final String path) {

    DigitalWatchFaceUtil.fetchConfigDataMap(googleApiClient,
            new FetchConfigDataMapCallback() {
                @Override
                public void onConfigDataMapFetched(DataMap currentConfig) {
                    DataMap overwrittenConfig = new DataMap();
                    overwrittenConfig.putAll(currentConfig);
                    overwrittenConfig.putAll(configKeysToOverwrite);
                    DigitalWatchFaceUtil.putConfigDataItem(googleApiClient, overwrittenConfig, path);
                }
            }
    , path);
}
项目:SunshineApp    文件:WatchFace.java   
/**
 * Updates the color of a UI item according to the given {@code configKey}. Does nothing if
 * {@code configKey} isn't recognized.
 *
 * @return whether UI has been updated
 */
private boolean updateUiForKey(String configKey, DataMap config) {
    if (configKey.equals(DigitalWatchFaceUtil.KEY_MAX_TEMP)) {
        maxTV.setText(config.getString(DigitalWatchFaceUtil.KEY_MAX_TEMP)+(char) 0x00B0 );
    } else if (configKey.equals(DigitalWatchFaceUtil.KEY_MIN_TEMP)) {
        minTV.setText(config.getString(DigitalWatchFaceUtil.KEY_MIN_TEMP)+(char) 0x00B0 );
    } else if (configKey.equals(DigitalWatchFaceUtil.KEY_BATTERY_PERCENATGE)) {
        batteryPercent.setText(config.getString(DigitalWatchFaceUtil.KEY_BATTERY_PERCENATGE));
    } else if (configKey.equals(DigitalWatchFaceUtil.KEY_WEATHER_TYPE)) {
        String id = config.getString(DigitalWatchFaceUtil.KEY_WEATHER_TYPE);
        resId = DigitalWatchFaceUtil.getArtResourceForWeatherCondition(Integer.parseInt(id));
        weatherIcon.setImageDrawable(getResources().getDrawable(resId));
    } else {
        Log.w("WatchFace", "Ignoring unknown config key: " + configKey);
        return false;
    }
    return true;
}
项目:2015-Google-I-O-app    文件:FeedbackWearableListenerService.java   
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    LOGD(TAG, "onDataChanged: " + dataEvents + " for " + getPackageName());

    for (DataEvent event : dataEvents) {
        LOGD(TAG, "Uri is: " + event.getDataItem().getUri());
        DataMapItem mapItem = DataMapItem.fromDataItem(event.getDataItem());
        String path = event.getDataItem().getUri().getPath();
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            if (PATH_RESPONSE.equals(path)) {
                // we have a response
                DataMap data = mapItem.getDataMap();
                saveFeedback(data);
            }
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            if (path.startsWith(SessionAlarmService.PATH_FEEDBACK)) {
                Uri uri = event.getDataItem().getUri();
                dismissLocalNotification(uri.getLastPathSegment());
            }
        }
    }
}
项目:nano-go-ubiquitous    文件:SunshineWearListenerService.java   
@Override
public void onDataChanged(DataEventBuffer dataEvents) {

    for (int i = 0; i < dataEvents.getCount(); i++) {
        DataEvent event = dataEvents.get(i);

        if (event.getType() == DataEvent.TYPE_CHANGED &&
                event.getDataItem().getUri().getPath().equals(APP_DATA_UPDATE_REQUEST)) {
            DataMap dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();

            Asset asset = dataMap.getAsset("dataIcon");
            WatchFaceService.highTemp = dataMap.getInt("dataHigh");
            WatchFaceService.lowTemp = dataMap.getInt("dataLow");

            doLoadBitmap(asset);
        }
    }
}
项目:xDrip-plus    文件:BaseWatchFace.java   
public void addToWatchSet(DataMap dataMap) {

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

        ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
        if (entries != null) {
            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))) {
                Log.d(TAG, "addToWatchSet Remove bgDataList.get(i).timestamp: " + JoH.dateTimeText((long)bgDataList.get(i).timestamp)+ " i: " + i);
                bgDataList.remove(i); //Get rid of anything more than 5 hours old
            }
        }
    }
项目:SunshineApp    文件:WatchFace.java   
@Override
public void onDataChanged(DataEventBuffer dataEventBuffer) {
    for (DataEvent dataEvent : dataEventBuffer) {
        if (dataEvent.getType() != DataEvent.TYPE_CHANGED) {
            continue;
        }

        DataItem dataItem = dataEvent.getDataItem();
        if (!dataItem.getUri().getPath().equals(
                DigitalWatchFaceUtil.PATH_WITH_FEATURE)) {
            continue;
        }

        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
        DataMap config = dataMapItem.getDataMap();
        Log.d("WatchFace", "Config DataItem updated:" + config);
        updateUiForConfigDataMap(config);
    }
}
项目:xDrip    文件:WatchUpdaterService.java   
public static boolean sendWearTreatmentsDataDelete(List<String> list) {
    if (googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) {
        googleApiClient.connect();
    }
    if (googleApiClient != null) {
        if (!list.isEmpty()) {
            Log.d(TAG, "sendWearTreatmentsDataDelete graph size=" + list.size());
            DataMap entries = new DataMap();
            entries.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP
            entries.putString("action", "delete");
            entries.putStringArrayList("entries", (new ArrayList<String>(list)));
            new SendToDataLayerThread(WEARABLE_TREATMENTS_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, entries);
        }
        else
            Log.d(TAG, "sendWearTreatmentsDataDelete treatments count = 0");
    } else {
        Log.e(TAG, "sendWearTreatmentsData No connection to wearable available for send treatment!");
        return false;
    }
    return true;
}
项目:Athletica    文件:WatchFaceService.java   
@Override // DataApi.DataListener
public void onDataChanged(DataEventBuffer dataEvents) {
    Log.d(TAG, "Data changed");
    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() != DataEvent.TYPE_CHANGED) {
            continue;
        }

        DataItem dataItem = dataEvent.getDataItem();
        if (!dataItem.getUri().getPath().equals(
                ConfigurationHelper.PATH_WITH_FEATURE)) {
            continue;
        }

        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
        DataMap config = dataMapItem.getDataMap();
        Log.d(TAG, "Config DataItem updated:" + config);
        // This can happen from this method more often when phone changes
        updateUiForConfigDataMap(config);
    }
}
项目:xDrip-plus    文件:Simulation.java   
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();
}
项目:ubiquitous    文件:MyWatchFace.java   
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
    Log.d(LOG_TAG, " in data changed");
    for (DataEvent event : dataEvents) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            // DataItem changed
            DataItem item = event.getDataItem();
            if (item.getUri().getPath().compareTo(WEATHER_PATH) == 0) {
                DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
                weather_id = dataMap.getInt(WEATHER_ID);
                high_temp = dataMap.getDouble(HIGH_TEMP);
                low_temp = dataMap.getDouble(LOW_TEMP);
            }
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            // DataItem deleted
        }
    }
    invalidate();
}
项目:adrenaline_watch_face    文件:SonicBoomFace.java   
@Override // DataApi.DataListener
public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent dataEvent : dataEvents) {
        if (dataEvent.getType() != DataEvent.TYPE_CHANGED) {
            continue;
        }

        DataItem dataItem = dataEvent.getDataItem();
        if (!dataItem.getUri().getPath().equals(
                WatchFaceUtil.PATH_WITH_FEATURE)) {
            continue;
        }

        DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem);
        DataMap config = dataMapItem.getDataMap();
        Log.d(TAG, "Config DataItem updated:" + config);

        updateUiForConfigDataMap(config);
    }
}
项目:xDrip-plus    文件:WatchUpdaterService.java   
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);
        }
    }
}
项目:Sunshine-Android-Wear    文件:DigitalWatchFace.java   
@Override
public void onDataChanged(DataEventBuffer dataEventBuffer) {
    Log.i("WATCH", "onDataChanged");
    for (DataEvent event : dataEventBuffer) {
        if (event.getType() == DataEvent.TYPE_CHANGED) {
            // DataItem changed
            DataItem item = event.getDataItem();
            if (item.getUri().getPath().compareTo(DATA_PATH) == 0) {
                DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();

                extractWeatherData(dataMap);
            }
        } else if (event.getType() == DataEvent.TYPE_DELETED) {
            // DataItem deleted
        }
    }
}
项目:go-ubiquitous    文件:SunshineWatchFace.java   
@Override
public void onDataChanged(DataEventBuffer dataEventBuffer) {
    Log.d(LOG_TAG, "Weather data has been changed!");
    for (DataEvent event : dataEventBuffer) {
        DataItem item = event.getDataItem();
        if (WEATHER_DATA_PATH.equals(item.getUri().getPath())) {
            DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
            double high = dataMap.getDouble(WEATHER_DATA_HIGH);
            double low = dataMap.getDouble(WEATHER_DATA_LOW);
            long id = dataMap.getLong(WEATHER_DATA_ID);

            mWeather = (int) Math.round(high) + "/" +  (int) Math.round(low);
            mWeatherId = (int) id;

            loadIconForWeatherId();

            SharedPreferences preferences = getSharedPreferences(PREFERENCES, MODE_PRIVATE);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putString(KEY_WEATHER, mWeather);
            editor.putInt(KEY_WEATHER_ID, mWeatherId);
            editor.apply();
        }
    }
}
项目:adrenaline_watch_face    文件:WatchFaceUtil.java   
/**
 * Overwrites (or sets, if not present) the keys in the current config {@link DataItem} with
 * the ones appearing in the given {@link DataMap}. If the config DataItem doesn't exist,
 * it's created.
 * <p>
 * It is allowed that only some of the keys used in the config DataItem appear in
 * {@code configKeysToOverwrite}. The rest of the keys remains unmodified in this case.
 */
public static void overwriteKeysInConfigDataMap(final GoogleApiClient googleApiClient,
                                                final DataMap configKeysToOverwrite) {

    WatchFaceUtil.fetchConfigDataMap(googleApiClient,
            new FetchConfigDataMapCallback() {
                @Override
                public void onConfigDataMapFetched(DataMap currentConfig) {
                    DataMap overwrittenConfig = new DataMap();
                    overwrittenConfig.putAll(currentConfig);
                    overwrittenConfig.putAll(configKeysToOverwrite);
                    WatchFaceUtil.putConfigDataItem(googleApiClient, overwrittenConfig);
                }
            }
    );
}
项目:adrenaline_watch_face    文件:WatchFaceUtil.java   
/**
 * Overwrites the current config {@link DataItem}'s {@link DataMap} with {@code newConfig}.
 * If the config DataItem doesn't exist, it's created.
 */
public static void putConfigDataItem(GoogleApiClient googleApiClient, DataMap newConfig) {
    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(PATH_WITH_FEATURE);
    DataMap configToPut = putDataMapRequest.getDataMap();
    configToPut.putAll(newConfig);
    Wearable.DataApi.putDataItem(googleApiClient, putDataMapRequest.asPutDataRequest())
            .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(DataApi.DataItemResult dataItemResult) {
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "putDataItem result status: " + dataItemResult.getStatus());
                    }
                }
            });
}
项目:xDrip    文件:BaseWatchFace.java   
public void addToWatchSet(DataMap dataMap) {

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

        ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
        if (entries != null) {
            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))) {
                Log.d(TAG, "addToWatchSet Remove bgDataList.get(i).timestamp: " + JoH.dateTimeText((long)bgDataList.get(i).timestamp)+ " i: " + i);
                bgDataList.remove(i); //Get rid of anything more than 5 hours old
            }
        }
    }
项目:xDrip-plus    文件:WatchUpdaterService.java   
private void resendData() {
    Log.d(TAG, "resendData ENTER");
    forceGoogleApiConnect();
    Log.d(TAG, "resendData googleApiClient connected ENTER");
    long startTime = new Date().getTime() - (60000 * 60 * 24);
    BgReading last_bg = BgReading.last();
    if (last_bg != null) {
        List<BgReading> graph_bgs = BgReading.latestForGraph(60, startTime);
        BgGraphBuilder bgGraphBuilder = new BgGraphBuilder(getApplicationContext());
        if (!graph_bgs.isEmpty()) {
            final int battery = PowerStateReceiver.getBatteryLevel(getApplicationContext());
            DataMap entries = dataMap(last_bg, mPrefs, bgGraphBuilder, battery);
            final ArrayList<DataMap> dataMaps = new ArrayList<>(graph_bgs.size());
            for (BgReading bg : graph_bgs) {
                dataMaps.add(dataMap(bg, mPrefs, bgGraphBuilder, battery));
            }
            entries.putLong("time", new Date().getTime()); // MOST IMPORTANT LINE FOR TIMESTAMP
            entries.putDataMapArrayList("entries", dataMaps);
            if (mPrefs.getBoolean("extra_status_line", false)) {
                entries.putString("extra_status_line", Home.extraStatusLine());
            }

            new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient).executeOnExecutor(xdrip.executor, entries);
        }
    }
}
项目:xDrip    文件:BIGChart.java   
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);
    }
}
项目:xDrip    文件:BIGChart.java   
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;
            }
        }
    }
项目:xDrip    文件:WatchUpdaterService.java   
@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;
            }
        }
    }
}
项目:xDrip    文件:ListenerService.java   
public synchronized static void createTreatment(DataMap dataMap, Context context) {
    Log.d(TAG, "createTreatment dataMap=" + dataMap);
    double timeoffset = dataMap.getDouble("timeoffset", 0);
    double carbs = dataMap.getDouble("carbs", 0);
    double insulin = dataMap.getDouble("insulin", 0);
    double bloodtest = dataMap.getDouble("bloodtest", 0);
    String notes = dataMap.getString("notes", "");

    long timestamp_ms = Treatments.getTimeStampWithOffset(timeoffset);
    Treatments treatment = Treatments.create(carbs, insulin, notes, timestamp_ms);
    if (bloodtest > 0) {
        Log.d(TAG, "createTreatment bloodtest=" + bloodtest);
        BloodTest.createFromCal(bloodtest, timeoffset, "Manual Entry", treatment.uuid);
    }
    else Log.d(TAG, "createTreatment bloodtest=0 " + bloodtest);
    showTreatments(context, "all");
    SendData(context, SYNC_TREATMENTS_PATH, null);
    //requestData(context);//send to phone if connected
}
项目:xDrip-plus    文件:ListenerService.java   
public synchronized static void createTreatment(DataMap dataMap, Context context) {
    Log.d(TAG, "createTreatment dataMap=" + dataMap);
    double timeoffset = dataMap.getDouble("timeoffset", 0);
    double carbs = dataMap.getDouble("carbs", 0);
    double insulin = dataMap.getDouble("insulin", 0);
    double bloodtest = dataMap.getDouble("bloodtest", 0);
    String notes = dataMap.getString("notes", "");

    long timestamp_ms = Treatments.getTimeStampWithOffset(timeoffset);
    Treatments treatment = Treatments.create(carbs, insulin, notes, timestamp_ms);
    if (bloodtest > 0) {
        Log.d(TAG, "createTreatment bloodtest=" + bloodtest);
        BloodTest.createFromCal(bloodtest, timeoffset, "Manual Entry", treatment.uuid);
    }
    else Log.d(TAG, "createTreatment bloodtest=0 " + bloodtest);
    showTreatments(context, "all");
    SendData(context, SYNC_TREATMENTS_PATH, null);
    //requestData(context);//send to phone if connected
}
项目:xDrip    文件:ListenerService.java   
public static DataMap getBloodTests(long startTime) {
    BloodTest last = BloodTest.last();
    if (last != null) {
        Log.d(TAG, "getBloodTests last.timestamp:" +  JoH.dateTimeText(last.timestamp));
    }
    List<BloodTest> graph = BloodTest.latestForGraph(60, startTime);
    if (!graph.isEmpty()) {
        Log.d(TAG, "getBloodTests graph size=" + graph.size());
        final ArrayList<DataMap> dataMaps = new ArrayList<>(graph.size());
        DataMap entries = dataMapForWatchface(graph.get(0));
        for (BloodTest data : graph) {
            dataMaps.add(dataMapForWatchface(data));
        }
        entries.putDataMapArrayList("entries", dataMaps);
        Log.d(TAG, "getBloodTests entries=" + entries);
        return entries;
    }
    else {
        Log.d(TAG, "getBloodTests no entries for startTime=" + JoH.dateTimeText(startTime));
        return null;
    }
}
项目:AndroidAPS    文件:BIGChart.java   
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);
        }
    }
}
项目:Android_Sunshine_Watch    文件:MyWatchFace.java   
@Override
public void onDataChanged(DataEventBuffer dataEventBuffer) {

    Log.d("test", "onDataChanged is called !!!");

    for (DataEvent event : dataEventBuffer) {
        DataItem item = event.getDataItem();
        if (item.getUri().getPath().compareTo("/weather") == 0) {
            DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
            if (dataMap.getInt("highTemp") != 0) {
                int highTemp_notformatted = dataMap.getInt("highTemp");
                highTemp = "" + highTemp_notformatted + "°";

                Log.d("Test", "hight Temp: " + highTemp);
            }
            if (dataMap.getInt("lowTemp") != 0) {
                int lowTemp_notformatted = dataMap.getInt("lowTemp");
                lowTemp = "" + lowTemp_notformatted + "°";

                Log.d("Test", "low Temp: " + lowTemp);
            }
            if (dataMap.getInt("weatherId") != 0) {
                weatherId = dataMap.getInt("weatherId");

                Log.d("Test", "weatherId: " + weatherId);
            }
            invalidate();
        } else {
            Log.d("test", "Can not parse data sent from mobile");
        }
    }
}