本文整理汇总了Java中com.google.android.gms.wearable.DataMap类的典型用法代码示例。如果您正苦于以下问题:Java DataMap类的具体用法?Java DataMap怎么用?Java DataMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataMap类属于com.google.android.gms.wearable包,在下文中一共展示了DataMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onConfigurationAddedOrEdited
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
/**
* 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);
}
示例2: sendNextGestureData
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
/**
* 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);
}
示例3: putConfigDataItem
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
/**
* 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());
}
}
});
}
示例4: onDataChanged
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
@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();
}
示例5: handleException
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
@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);
}
示例6: populateConfigurations
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
/**
* 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();
}
});
}
}
示例7: onDataChanged
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
@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());
}
}
}
}
示例8: onDataChanged
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
/**
* 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);
}
}
}
示例9: generateDataMap
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
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;
}
示例10: extractRulesFromDataMap
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
/**
*
* @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;
}
示例11: prepareDataMap
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
/**
* 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;
}
示例12: onDataChanged
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
@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);
}
}
}
}
示例13: sendActiveBtDeviceData
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
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");
}
}
示例14: doInBackground
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
@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;
}
示例15: overwriteKeysInConfigDataMap
import com.google.android.gms.wearable.DataMap; //导入依赖的package包/类
/**
* 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);
}