当前位置: 首页>>代码示例>>Java>>正文


Java DataApi类代码示例

本文整理汇总了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);
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:27,代码来源:UARTConfigurationSynchronizer.java

示例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());
                    }
                }
            });
}
 
开发者ID:marcouberti,项目名称:adrenaline_watch_face,代码行数:21,代码来源:WatchFaceUtil.java

示例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();
}
 
开发者ID:csarron,项目名称:GmsWear,代码行数:31,代码来源:GmsWear.java

示例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");
            }
        }

    });
}
 
开发者ID:rashikaranpuria,项目名称:ubiquitous,代码行数:23,代码来源:SunshineSyncIntentService.java

示例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();
			}
		});
	}
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:24,代码来源:UARTConfigurationsActivity.java

示例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));
                }
            }
    );
}
 
开发者ID:mladenbabic,项目名称:Advanced_Android_Development_Wear,代码行数:20,代码来源:DigitalWatchFaceUtil.java

示例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());
                    }
                }
            });
}
 
开发者ID:mladenbabic,项目名称:Advanced_Android_Development_Wear,代码行数:15,代码来源:DigitalWatchFaceUtil.java

示例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();
        }
    });
}
 
开发者ID:Parrot-Developers,项目名称:DronesWear,代码行数:26,代码来源:MainActivity.java

示例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]);
            }
 
开发者ID:Hitesh880443,项目名称:SunshineWithWear,代码行数:25,代码来源:MyDigitalWatchFace.java

示例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));
                }
            }
    );
}
 
开发者ID:jimmykane,项目名称:Athletica,代码行数:26,代码来源:ConfigurationHelper.java

示例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);
        }
    });
}
 
开发者ID:frank-tan,项目名称:Sunshine-Android-Wear,代码行数:24,代码来源:DigitalWatchFace.java

示例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);
                    }
                }
            });
}
 
开发者ID:csarron,项目名称:GmsWear,代码行数:29,代码来源:GmsWear.java

示例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");
                }
            });
}
 
开发者ID:kevalpatel2106,项目名称:android-samples,代码行数:18,代码来源:WatchFaceConfigActivity.java

示例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();
}
 
开发者ID:passiondroid,项目名称:SunshineApp,代码行数:23,代码来源:WatchUpdaterReceiver.java

示例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));
                }
            }
    );
}
 
开发者ID:marcouberti,项目名称:adrenaline_watch_face,代码行数:26,代码来源:WatchFaceUtil.java


注:本文中的com.google.android.gms.wearable.DataApi类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。