本文整理匯總了Java中com.google.android.gms.wearable.DataApi類的典型用法代碼示例。如果您正苦於以下問題:Java DataApi類的具體用法?Java DataApi怎麽用?Java DataApi使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DataApi類屬於com.google.android.gms.wearable包,在下文中一共展示了DataApi類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onConfigurationAddedOrEdited
import com.google.android.gms.wearable.DataApi; //導入依賴的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: putConfigDataItem
import com.google.android.gms.wearable.DataApi; //導入依賴的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);
DataMap configToPut = putDataMapRequest.getDataMap();
configToPut.putAll(newConfig);
PutDataRequest putDataRequest = putDataMapRequest.asPutDataRequest();
putDataRequest.setUrgent();
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest)
.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());
}
}
});
}
示例3: loadAssetSynchronous
import com.google.android.gms.wearable.DataApi; //導入依賴的package包/類
/**
* Extracts byte array data from an
* {@link com.google.android.gms.wearable.Asset}, in a blocking way, hence should not be called
* on the UI thread. This may return {@code null}.
*/
public byte[] loadAssetSynchronous(Asset asset) throws IOException {
assertApiConnectivity();
WearUtil.assertNonUiThread();
if (asset == null) {
throw new IllegalArgumentException("Asset must be non-null");
}
InputStream assetInputStream = Wearable.DataApi.getFdForAsset(
mGoogleApiClient, asset).await().getInputStream();
if (assetInputStream == null) {
Log.w(TAG, "Requested an unknown Asset.");
return null;
}
ByteArrayOutputStream output = new ByteArrayOutputStream();
int n = 0;
byte[] buffer = new byte[4096];
while (-1 != (n = assetInputStream.read(buffer))) {
output.write(buffer, 0, n);
}
return output.toByteArray();
}
示例4: updateWearWeather
import com.google.android.gms.wearable.DataApi; //導入依賴的package包/類
private void updateWearWeather(int weather_id, double high_temp, double low_temp){
PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(WEATHER_PATH).setUrgent();
putDataMapRequest.getDataMap().putInt(WEATHER_ID, weather_id);
Log.d(LOG_TAG, "value of weather put : "+weather_id);
putDataMapRequest.getDataMap().putDouble(HIGH_TEMP, high_temp);
putDataMapRequest.getDataMap().putDouble(LOW_TEMP, low_temp);
PutDataRequest putDataRequest = putDataMapRequest.asPutDataRequest().setUrgent();
PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mWearClient, putDataRequest);
pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
@Override
public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
if (dataItemResult.getStatus().isSuccess()) {
Log.d(LOG_TAG, "Data item set: " + dataItemResult.getDataItem().getUri());
} else {
Log.d(LOG_TAG, "Error in sending data to watch");
}
}
});
}
示例5: populateConfigurations
import com.google.android.gms.wearable.DataApi; //導入依賴的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();
}
});
}
}
示例6: fetchConfigDataMap
import com.google.android.gms.wearable.DataApi; //導入依賴的package包/類
public static void fetchConfigDataMap(final GoogleApiClient client,
final FetchConfigDataMapCallback callback, final String path) {
Wearable.NodeApi.getLocalNode(client).setResultCallback(
new ResultCallback<NodeApi.GetLocalNodeResult>() {
@Override
public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) {
String localNode = getLocalNodeResult.getNode().getId();
Uri uri = new Uri.Builder()
.scheme("wear")
.path(path)
.authority(localNode)
.build();
Wearable.DataApi.getDataItem(client, uri)
.setResultCallback(new DataItemResultCallback(callback));
}
}
);
}
示例7: putConfigDataItem
import com.google.android.gms.wearable.DataApi; //導入依賴的package包/類
public static void putConfigDataItem(GoogleApiClient googleApiClient, DataMap newConfig, String path) {
PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(path);
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());
}
}
});
}
示例8: onConnected
import com.google.android.gms.wearable.DataApi; //導入依賴的package包/類
@Override
public void onConnected(Bundle bundle) {
Wearable.DataApi.addListener(mGoogleApiClient, this);
// get existing data
PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(mGoogleApiClient);
results.setResultCallback(new ResultCallback<DataItemBuffer>() {
@Override
public void onResult(@NonNull DataItemBuffer dataItems) {
for (DataItem dataItem : dataItems) {
switch (Message.getMessageType(dataItem)) {
case ACTION_TYPE:
int productAction = Message.decodeActionTypeMessage(dataItem);
onActionTypeChanged(productAction);
break;
case INTERACTION_TYPE:
int interactionType = Message.decodeInteractionTypeMessage(dataItem);
onInteractionTypeChanged(interactionType);
break;
}
}
dataItems.release();
}
});
}
示例9: loadBitmapFromAsset
import com.google.android.gms.wearable.DataApi; //導入依賴的package包/類
private Bitmap loadBitmapFromAsset(GoogleApiClient apiClient, Asset asset) {
if (asset == null) {
throw new IllegalArgumentException("Asset must be non-null");
}
/*InputStream assetInputStream = Wearable.DataApi.getFdForAsset(
apiClient, asset).await().getInputStream();
*/
final InputStream[] assetInputStream = new InputStream[1];
Wearable.DataApi.getFdForAsset(apiClient, asset).setResultCallback(new ResultCallback<DataApi.GetFdForAssetResult>() {
@Override
public void onResult(DataApi.GetFdForAssetResult getFdForAssetResult) {
assetInputStream[0] = getFdForAssetResult.getInputStream();
}
});
if (assetInputStream[0] == null) {
Log.w(TAG, "Requested an unknown Asset.");
return null;
}
return BitmapFactory.decodeStream(assetInputStream[0]);
}
示例10: fetchConfigDataMap
import com.google.android.gms.wearable.DataApi; //導入依賴的package包/類
/**
* Asynchronously fetches the current config {@link DataMap} for {@link com.dimitrioskanellopoulos.athletica.WatchFaceService}
* and passes it to the given callback.
* <p/>
* If the current config {@link DataItem} doesn't exist, it isn't created and the callback
* receives an empty DataMap.
*/
public static void fetchConfigDataMap(final GoogleApiClient client,
final FetchConfigDataMapCallback callback) {
Wearable.NodeApi.getLocalNode(client).setResultCallback(
new ResultCallback<NodeApi.GetLocalNodeResult>() {
@Override
public void onResult(@NonNull NodeApi.GetLocalNodeResult getLocalNodeResult) {
String localNode = getLocalNodeResult.getNode().getId();
Uri uri = new Uri.Builder()
.scheme("wear")
.path(ConfigurationHelper.PATH_WITH_FEATURE)
.authority(localNode)
.build();
Wearable.DataApi.getDataItem(client, uri)
.setResultCallback(new DataItemResultCallback(callback));
}
}
);
}
示例11: loadBitmapFromAsset
import com.google.android.gms.wearable.DataApi; //導入依賴的package包/類
/**
* Load bit map from asset provided
* @param asset
*/
public void loadBitmapFromAsset(Asset asset) {
if (asset == null) {
Log.e("WATCH", "Asset received on watch face is null");
return;
}
// convert asset into a file descriptor and get notified when it's ready
Wearable.DataApi.getFdForAsset(
mGoogleApiClient, asset).setResultCallback(new ResultCallback<DataApi.GetFdForAssetResult>() {
@Override
public void onResult(DataApi.GetFdForAssetResult getFdForAssetResult) {
InputStream assetInputStream = getFdForAssetResult.getInputStream();
if (assetInputStream == null) {
Log.w("WATCH", "Requested an unknown Asset.");
return;
}
mWeatherIconBitmap = BitmapFactory.decodeStream(assetInputStream);
}
});
}
示例12: deleteDataItems
import com.google.android.gms.wearable.DataApi; //導入依賴的package包/類
/**
* Deletes a data items asynchronously. Caller can specify a {@link ResultCallback} or
* pass a {@code null}; if a {@code null} is passed, a default {@link ResultCallback} will be
* used that would call {@link DataConsumer#onDeleteDataItemsResult(int)}.
*/
public void deleteDataItems(final Uri dataItemUri,
@Nullable final ResultCallback<? super DataApi.DeleteDataItemsResult> callback) {
assertApiConnectivity();
Wearable.DataApi.deleteDataItems(mGoogleApiClient, dataItemUri).setResultCallback(
new ResultCallback<DataApi.DeleteDataItemsResult>() {
@Override
public void onResult(DataApi.DeleteDataItemsResult deleteDataItemsResult) {
int statusCode = deleteDataItemsResult.getStatus().getStatusCode();
if (!deleteDataItemsResult.getStatus().isSuccess()) {
Log.e(TAG, String.format(
"Failed to delete data items (status code=%d): %s",
statusCode, dataItemUri));
}
if (callback == null) {
for (DataConsumer consumer : mDataConsumers) {
consumer.onDeleteDataItemsResult(statusCode);
}
} else {
callback.onResult(deleteDataItemsResult);
}
}
});
}
示例13: notifyWear
import com.google.android.gms.wearable.DataApi; //導入依賴的package包/類
private void notifyWear(String newBgColor) {
PutDataMapRequest dataMapRequest = PutDataMapRequest.create("/bg_change");
dataMapRequest.getDataMap().putString("new_color", newBgColor);
PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest();
Wearable.DataApi.putDataItem(mGoogleApiClient, putDataRequest)
.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
@Override
public void onResult(@NonNull DataApi.DataItemResult dataItemResult) {
//check if the message is delivered?
//If the status is failed, that means that the currently device is
//not connected. The data will get deliver when phone gets connected to the watch.
Log.d("Data saving", dataItemResult.getStatus().isSuccess() ? "Success" : "Failed");
}
});
}
示例14: onConnected
import com.google.android.gms.wearable.DataApi; //導入依賴的package包/類
@Override
public void onConnected(@Nullable Bundle bundle) {
Log.d("WatchUpdaterReceiver", "onConnected: " + bundle);
new Thread(new Runnable() {
@Override
public void run() {
if(config!=null && config.size()>0) {
PutDataMapRequest putDMR = PutDataMapRequest.create(PATH_WITH_FEATURE);
putDMR.getDataMap().putAll(config);
PutDataRequest request = putDMR.asPutDataRequest().setUrgent();
DataApi.DataItemResult result = Wearable.DataApi.putDataItem(mGoogleApiClient, request).await();
if (result.getStatus().isSuccess()) {
Log.v("WatchUpdaterReceiver", "DataMap: " + config + " sent successfully to data layer ");
}
else {
// Log an error
Log.v("WatchUpdaterReceiver", "ERROR: failed to send DataMap to data layer");
}
}
}
}).start();
}
示例15: fetchConfigDataMap
import com.google.android.gms.wearable.DataApi; //導入依賴的package包/類
/**
* Asynchronously fetches the current config {@link DataMap} for {@link SonicBoomFace}
* and passes it to the given callback.
* <p>
* If the current config {@link DataItem} doesn't exist, it isn't created and the callback
* receives an empty DataMap.
*/
public static void fetchConfigDataMap(final GoogleApiClient client,
final FetchConfigDataMapCallback callback) {
Wearable.NodeApi.getLocalNode(client).setResultCallback(
new ResultCallback<NodeApi.GetLocalNodeResult>() {
@Override
public void onResult(NodeApi.GetLocalNodeResult getLocalNodeResult) {
String localNode = getLocalNodeResult.getNode().getId();
Uri uri = new Uri.Builder()
.scheme("wear")
.path(WatchFaceUtil.PATH_WITH_FEATURE)
.authority(localNode)
.build();
Wearable.DataApi.getDataItem(client, uri)
.setResultCallback(new DataItemResultCallback(callback));
}
}
);
}