Java Code Examples for com.google.android.gms.wearable.PutDataMapRequest#getDataMap()
The following examples show how to use
com.google.android.gms.wearable.PutDataMapRequest#getDataMap() .
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
Source File: UARTConfigurationSynchronizer.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * 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 (!hasConnectedApi()) 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(googleApiClient, request); }
Example 2
Source File: CalendarQueryService.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
public PutDataMapRequest toPutDataMapRequest(){ final PutDataMapRequest putDataMapRequest = PutDataMapRequest.create( makeDataItemPath(eventId, begin)); DataMap data = putDataMapRequest.getDataMap(); data.putString(DATA_ITEM_URI, putDataMapRequest.getUri().toString()); data.putLong(ID, id); data.putLong(EVENT_ID, eventId); data.putString(TITLE, title); data.putLong(BEGIN, begin); data.putLong(END, end); data.putBoolean(ALL_DAY, allDay); data.putString(DESCRIPTION, description); data.putAsset(PROFILE_PIC, ownerProfilePic); return putDataMapRequest; }
Example 3
Source File: MainActivity.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
@Override public void onResult(DataApi.DataItemResult dataItemResult) { if (dataItemResult.getStatus().isSuccess()) { PutDataMapRequest request = PutDataMapRequest.createFromDataMapItem( DataMapItem.fromDataItem(dataItemResult.getDataItem())); DataMap dataMap = request.getDataMap(); dataMap.putBoolean(QUESTION_WAS_ANSWERED, false); dataMap.putBoolean(QUESTION_WAS_DELETED, false); if (!mHasQuestionBeenAsked && dataMap.getInt(QUESTION_INDEX) == 0) { // Ask the first question now. Wearable.DataApi.putDataItem(mGoogleApiClient, request.asPutDataRequest()); setHasQuestionBeenAsked(true); } else { // Enqueue future questions. mFutureQuestions.add(new Question(dataMap.getString(QUESTION), dataMap.getInt(QUESTION_INDEX), dataMap.getStringArray(ANSWERS), dataMap.getInt(CORRECT_ANSWER_INDEX))); } } else { Log.e(TAG, "Failed to reset data item " + dataItemResult.getDataItem().getUri()); } }
Example 4
Source File: DeleteQuestionService.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
@Override public void onHandleIntent(Intent intent) { mGoogleApiClient.blockingConnect(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS); Uri dataItemUri = intent.getData(); if (!mGoogleApiClient.isConnected()) { Log.e(TAG, "Failed to update data item " + dataItemUri + " because client is disconnected from Google Play Services"); return; } DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem( mGoogleApiClient, dataItemUri).await(); PutDataMapRequest putDataMapRequest = PutDataMapRequest .createFromDataMapItem(DataMapItem.fromDataItem(dataItemResult.getDataItem())); DataMap dataMap = putDataMapRequest.getDataMap(); dataMap.putBoolean(QUESTION_WAS_DELETED, true); PutDataRequest request = putDataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(mGoogleApiClient, request).await(); mGoogleApiClient.disconnect(); }
Example 5
Source File: MainActivity.java From android-Quiz with Apache License 2.0 | 6 votes |
@Override public void onResult(DataApi.DataItemResult dataItemResult) { if (dataItemResult.getStatus().isSuccess()) { PutDataMapRequest request = PutDataMapRequest.createFromDataMapItem( DataMapItem.fromDataItem(dataItemResult.getDataItem())); DataMap dataMap = request.getDataMap(); dataMap.putBoolean(QUESTION_WAS_ANSWERED, false); dataMap.putBoolean(QUESTION_WAS_DELETED, false); if (!mHasQuestionBeenAsked && dataMap.getInt(QUESTION_INDEX) == 0) { // Ask the first question now. PutDataRequest putDataRequest = request.asPutDataRequest(); // Set to high priority in case it isn't already. putDataRequest.setUrgent(); Wearable.DataApi.putDataItem(mGoogleApiClient, putDataRequest); setHasQuestionBeenAsked(true); } else { // Enqueue future questions. mFutureQuestions.add(new Question(dataMap.getString(QUESTION), dataMap.getInt(QUESTION_INDEX), dataMap.getStringArray(ANSWERS), dataMap.getInt(CORRECT_ANSWER_INDEX))); } } else { Log.e(TAG, "Failed to reset data item " + dataItemResult.getDataItem().getUri()); } }
Example 6
Source File: DeleteQuestionService.java From android-Quiz with Apache License 2.0 | 6 votes |
@Override public void onHandleIntent(Intent intent) { mGoogleApiClient.blockingConnect(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS); Uri dataItemUri = intent.getData(); if (!mGoogleApiClient.isConnected()) { Log.e(TAG, "Failed to update data item " + dataItemUri + " because client is disconnected from Google Play Services"); return; } DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem( mGoogleApiClient, dataItemUri).await(); PutDataMapRequest putDataMapRequest = PutDataMapRequest .createFromDataMapItem(DataMapItem.fromDataItem(dataItemResult.getDataItem())); DataMap dataMap = putDataMapRequest.getDataMap(); dataMap.putBoolean(QUESTION_WAS_DELETED, true); PutDataRequest request = putDataMapRequest.asPutDataRequest(); request.setUrgent(); Wearable.DataApi.putDataItem(mGoogleApiClient, request).await(); mGoogleApiClient.disconnect(); }
Example 7
Source File: DigitalWatchFaceUtil.java From wear-os-samples with Apache License 2.0 | 6 votes |
/** * 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, final Callable<Void> callable) { 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) { try{ if (callable != null) { callable.call(); } } catch (Exception e) { Log.e(TAG, "Finish callback failed.", e); } if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "putDataItem result status: " + dataItemResult.getStatus()); } } }); }
Example 8
Source File: DataManager.java From ibm-wearables-android-sdk with Apache License 2.0 | 6 votes |
/** * 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 9
Source File: RequestListenerService.java From arcgis-runtime-demos-android with Apache License 2.0 | 5 votes |
/** * Handles issuing a response to a FeatureType request. A FeatureType request * indicates that the Wear devices wants a list of available FeatureTypes for * the selected layer to display to the user. * * @param event the MessageEvent from the Wear device * @param client the Google API client used to communicate */ private void handleFeatureTypeRequest(MessageEvent event, GoogleApiClient client) { // Get the name and URL of the layer that was selected String layerName = new String(event.getData()); String url = sLayerMap.get(layerName); // Create an ArcGISFeatureLayer with the specified URL sArcGISFeatureLayer = new ArcGISFeatureLayer(url, ArcGISFeatureLayer.MODE.SNAPSHOT); // While this isn't good practice, there is no way to be notified that an // ArcGISFeatureLayer has loaded its LayerServiceInfo. The OnStatusChangedListener // seems to be more relevant when the layer is actually being added to a MapView. // As such, we simply do a quick sleep until the LayerServiceInfo has been loaded try { while (sArcGISFeatureLayer.getLayerServiceInfo() == null) { Thread.sleep(500); } } catch (Exception e) { // } // Create a PutDataMapRequest with the FeatureType response path PutDataMapRequest req = PutDataMapRequest.create(FEATURE_TYPE_RESPONSE); DataMap dm = req.getDataMap(); // Put an array list of the FeatureType names into the data map dm.putStringArrayList("featureTypes", FeatureLayerUtil.getFeatureTypes(sArcGISFeatureLayer)); // 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 10
Source File: SunsetsWatchFaceUtil.java From american-sunsets-watch-face with Apache License 2.0 | 5 votes |
/** * 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()); } } }); }
Example 11
Source File: RequestListenerService.java From arcgis-runtime-demos-android with Apache License 2.0 | 5 votes |
/** * 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 12
Source File: Message.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static PendingResult<DataApi.DataItemResult> sendActionTypeMessage(int actionType, GoogleApiClient googleApiClient) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACTION_TYPE_PATH); DataMap dataMap = dataMapRequest.getDataMap(); //Data set dataMap.putInt(VALUE_STR, actionType); // Data Push PutDataRequest request = dataMapRequest.asPutDataRequest(); PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(googleApiClient, request); return pendingResult; }
Example 13
Source File: Message.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static PendingResult<DataApi.DataItemResult> sendInteractionTypeMessage(int interactionBitfield, GoogleApiClient googleApiClient) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(INTERACTION_TYPE_PATH); DataMap dataMap = dataMapRequest.getDataMap(); //Data set dataMap.putInt(VALUE_STR, interactionBitfield); // Data Push PutDataRequest request = dataMapRequest.asPutDataRequest(); PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(googleApiClient, request); return pendingResult; }
Example 14
Source File: UpdateQuestionService.java From android-Quiz with Apache License 2.0 | 5 votes |
@Override protected void onHandleIntent(Intent intent) { mGoogleApiClient.blockingConnect(TIME_OUT_MS, TimeUnit.MILLISECONDS); Uri dataItemUri = intent.getData(); if (!mGoogleApiClient.isConnected()) { Log.e(TAG, "Failed to update data item " + dataItemUri + " because client is disconnected from Google Play Services"); return; } DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem( mGoogleApiClient, dataItemUri).await(); PutDataMapRequest putDataMapRequest = PutDataMapRequest .createFromDataMapItem(DataMapItem.fromDataItem(dataItemResult.getDataItem())); DataMap dataMap = putDataMapRequest.getDataMap(); // Update quiz status variables, which will be reflected on the phone. int questionIndex = intent.getIntExtra(EXTRA_QUESTION_INDEX, -1); boolean chosenAnswerCorrect = intent.getBooleanExtra(EXTRA_QUESTION_CORRECT, false); dataMap.putInt(QUESTION_INDEX, questionIndex); dataMap.putBoolean(CHOSEN_ANSWER_CORRECT, chosenAnswerCorrect); dataMap.putBoolean(QUESTION_WAS_ANSWERED, true); PutDataRequest request = putDataMapRequest.asPutDataRequest(); request.setUrgent(); Wearable.DataApi.putDataItem(mGoogleApiClient, request).await(); // Remove this question notification. ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancel(questionIndex); mGoogleApiClient.disconnect(); }
Example 15
Source File: MainActivity.java From android-Quiz with Apache License 2.0 | 5 votes |
public PutDataRequest toPutDataRequest() { PutDataMapRequest request = PutDataMapRequest.create("/question/" + questionIndex); DataMap dataMap = request.getDataMap(); dataMap.putString(QUESTION, question); dataMap.putInt(QUESTION_INDEX, questionIndex); dataMap.putStringArray(ANSWERS, answers); dataMap.putInt(CORRECT_ANSWER_INDEX, correctAnswerIndex); PutDataRequest putDataRequest = request.asPutDataRequest(); putDataRequest.setUrgent(); return putDataRequest; }
Example 16
Source File: Message.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static PendingResult<DataApi.DataItemResult> sendJoystickMessage(JoystickData joystickData, GoogleApiClient googleApiClient) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(JOYSTICK_PATH); joystickMessageUri = dataMapRequest.getUri(); DataMap dataMap = dataMapRequest.getDataMap(); //Data set dataMap.putFloatArray(VALUE_STR, new float[]{joystickData.getPercentX(), joystickData.getPercentY()}); // Data Push PutDataRequest request = dataMapRequest.asPutDataRequest(); PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(googleApiClient, request); return pendingResult; }
Example 17
Source File: Message.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static PendingResult<DataApi.DataItemResult> sendAcceleroMessage(AccelerometerData accelerometerData, GoogleApiClient googleApiClient) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACC_PATH); acceleroMessageUri = dataMapRequest.getUri(); DataMap dataMap = dataMapRequest.getDataMap(); //Data set dataMap.putFloatArray(VALUE_STR, new float[]{accelerometerData.getAccX(), accelerometerData.getAccY(), accelerometerData.getAccZ()}); // Data Push PutDataRequest request = dataMapRequest.asPutDataRequest(); PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(googleApiClient, request); return pendingResult; }
Example 18
Source File: UpdateQuestionService.java From AndroidWearable-Samples with Apache License 2.0 | 5 votes |
@Override protected void onHandleIntent(Intent intent) { mGoogleApiClient.blockingConnect(TIME_OUT_MS, TimeUnit.MILLISECONDS); Uri dataItemUri = intent.getData(); if (!mGoogleApiClient.isConnected()) { Log.e(TAG, "Failed to update data item " + dataItemUri + " because client is disconnected from Google Play Services"); return; } DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem( mGoogleApiClient, dataItemUri).await(); PutDataMapRequest putDataMapRequest = PutDataMapRequest .createFromDataMapItem(DataMapItem.fromDataItem(dataItemResult.getDataItem())); DataMap dataMap = putDataMapRequest.getDataMap(); // Update quiz status variables, which will be reflected on the phone. int questionIndex = intent.getIntExtra(EXTRA_QUESTION_INDEX, -1); boolean chosenAnswerCorrect = intent.getBooleanExtra(EXTRA_QUESTION_CORRECT, false); dataMap.putInt(QUESTION_INDEX, questionIndex); dataMap.putBoolean(CHOSEN_ANSWER_CORRECT, chosenAnswerCorrect); dataMap.putBoolean(QUESTION_WAS_ANSWERED, true); PutDataRequest request = putDataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(mGoogleApiClient, request).await(); // Remove this question notification. ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancel(questionIndex); mGoogleApiClient.disconnect(); }
Example 19
Source File: DataManager.java From ibm-wearables-android-sdk with Apache License 2.0 | 5 votes |
/** * Create next data to send of the hear rate * @param event sensor event */ private void sendHeartRateData(SensorEvent event){ PutDataMapRequest dataMapRequest = getNewSensorsDataMapRequest(); DataMap dataMap = dataMapRequest.getDataMap(); dataMap.putFloat("heartrate",event.values[0]); dataSender.sendData(dataMapRequest); }
Example 20
Source File: RequestListenerService.java From arcgis-runtime-demos-android with Apache License 2.0 | 4 votes |
/** * Handles issuing a response to a FeatureType response. A FeatureType response * indicates that the Wear devices wants a feature of the specified FeatureType * to be collected at the current device location. * * @param event the MessageEvent from the Wear device * @param client the Google API client used to communicate */ private void handleFeatureTypeResponse(final MessageEvent event, final GoogleApiClient client) { // Create a PutDataMapRequest with the status response path final PutDataMapRequest req = PutDataMapRequest.create(STATUS_RESPONSE); final DataMap dm = req.getDataMap(); // 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()); try { // Request a single high precision location update LocationRequest request = LocationRequest.create() .setNumUpdates(1) .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); LocationServices.FusedLocationApi.requestLocationUpdates(client, request, new LocationListener() { @Override public void onLocationChanged(Location location) { // When we've got a location, get the FeatureType that matches the specified name Log.i("Test", "Received location"); String featureTypeName = new String(event.getData()); FeatureType type = null; for (FeatureType ft : sArcGISFeatureLayer.getTypes()) { if (ft.getName().equals(featureTypeName)) { type = ft; break; } } // Only proceed if we found a matching type (which we always should) if (type != null) { // Create a new feature of the specified type at the current location Graphic g = sArcGISFeatureLayer.createFeatureWithType(type, new Point(location.getLongitude(), location.getLatitude())); // Apply the edit to the service sArcGISFeatureLayer.applyEdits(new Graphic[]{g}, null, null, new CallbackListener<FeatureEditResult[][]>() { @Override public void onCallback(FeatureEditResult[][] featureEditResults) { // Check that we have a success and report success if (featureEditResults[0].length > 0) { FeatureEditResult fer = featureEditResults[0][0]; if (fer.isSuccess()) { Log.i("Test", "Successfully added feature"); // Put a boolean indicating success into the data map dm.putBoolean("success", true); } else { Log.e("Test", "Failed to add feature: " + fer.getError().getDescription()); // Put a boolean indicating failure into the data map dm.putBoolean("success", false); // Put a string with the reason for failure into the data map dm.putString("reason", "Error code: " + fer.getError().getCode()); } } // Put the DataItem into the Data API stream Wearable.DataApi.putDataItem(client, req.asPutDataRequest()); } @Override public void onError(Throwable throwable) { Log.d("Test", "Failed to add new graphic"); // Put a boolean indicating failure into the data map dm.putBoolean("success", false); // Put a string with the reason for failure into the data map dm.putString("reason", throwable.getLocalizedMessage()); // Put the DataItem into the Data API stream Wearable.DataApi.putDataItem(client, req.asPutDataRequest()); } }); } else { // If we don't have a matching feature type (which should never happen), log an error Log.e("Test", "Could not determine type"); // Put a boolean indicating failure into the data map dm.putBoolean("success", false); // Put a string with the reason for failure into the data map dm.putString("reason", "Specified type not found"); // Put the DataItem into the Data API stream Wearable.DataApi.putDataItem(client, req.asPutDataRequest()); } } }); } catch (SecurityException se) { // If we caught an exception trying to get the location, likelihood is that the location // permission has not been granted by the user Log.e("Test", "Could not access location"); // Put a boolean indicating failure into the data map dm.putBoolean("success", false); // Put a string with the reason for failure into the data map dm.putString("reason", "Could not access location. Check permissions."); // Put the DataItem into the Data API stream Wearable.DataApi.putDataItem(client, req.asPutDataRequest()); } }