Java Code Examples for com.google.android.gms.wearable.DataApi#DataItemResult
The following examples show how to use
com.google.android.gms.wearable.DataApi#DataItemResult .
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: MainActivity.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override protected void onPause() { super.onPause(); Message.sendInteractionTypeMessage(InteractionType.NONE, mGoogleApiClient); PendingResult<DataApi.DataItemResult> pendingResult = Message.sendActionTypeMessage(ActionType.NONE, mGoogleApiClient); pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(@NonNull DataApi.DataItemResult dataItemsResult) { if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { Wearable.DataApi.removeListener(mGoogleApiClient, MainActivity.this); mGoogleApiClient.disconnect(); } } }); mDiscoverer.cleanup(); }
Example 2
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 3
Source File: DaVinci.java From DaVinci with Apache License 2.0 | 6 votes |
public Bitmap getBitmapFromDataApi(String path) { final Uri uri = getUriForDataItem(path); Log.d(TAG, "Load bitmap " + path + " " + uri.toString()); if (uri != null) { final DataApi.DataItemResult result = Wearable.DataApi.getDataItem(mApiClient, uri).await(); if (result != null && result.getDataItem() != null) { Log.d(TAG, "From DataApi"); final DataMapItem dataMapItem = DataMapItem.fromDataItem(result.getDataItem()); final Asset firstAsset = dataMapItem.getDataMap().getAsset(imageAssetName); if (firstAsset != null) { Bitmap bitmap = loadBitmapFromAsset(firstAsset); return bitmap; } } } Log.d(TAG, "can't find " + path + " [" + imageAssetName + "] in DataApi"); return null; }
Example 4
Source File: UtilityService.java From PowerSwitch_Android with GNU General Public License v3.0 | 5 votes |
/** * Sends current Wearable Settings made in Smartphone app over to the Wearable companion app */ private void sendSettingsToWearable() { Log.d("Sending Settings to Wearable..."); GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API).build(); // It's OK to use blockingConnect() here as we are running in an // IntentService that executes work on a separate (background) thread. ConnectionResult connectionResult = googleApiClient.blockingConnect( SettingsConstants.GOOGLE_API_CLIENT_TIMEOUT, TimeUnit.SECONDS); ArrayList<DataMap> settings = new ArrayList<>(); DataMap settingsDataMap = getSettingsDataMap(); settings.add(settingsDataMap); if (connectionResult.isSuccess() && googleApiClient.isConnected() && settings.size() > 0) { PutDataMapRequest dataMap = PutDataMapRequest.create(WearableConstants.SETTINGS_PATH); dataMap.getDataMap().putDataMapArrayList(WearableConstants.EXTRA_SETTINGS, settings); PutDataRequest request = dataMap.asPutDataRequest(); // Send the data over DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(); if (!result.getStatus().isSuccess()) { Log.e("", String.format("Error sending settings using DataApi (error code = %d)", result.getStatus().getStatusCode())); } else { Log.d("Updated settings sent"); } } else { // GoogleApiClient connection error Log.e("Error connecting GoogleApiClient"); } }
Example 5
Source File: DigitalWatchFaceUtil.java From wear-os-samples with Apache License 2.0 | 5 votes |
@Override public void onResult(DataApi.DataItemResult dataItemResult) { if (dataItemResult.getStatus().isSuccess()) { if (dataItemResult.getDataItem() != null) { DataItem configDataItem = dataItemResult.getDataItem(); DataMapItem dataMapItem = DataMapItem.fromDataItem(configDataItem); DataMap config = dataMapItem.getDataMap(); mCallback.onConfigDataMapFetched(config); } else { mCallback.onConfigDataMapFetched(new DataMap()); } } }
Example 6
Source File: Message.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static PendingResult<DataApi.DataItemResult> sendActionMessage(GoogleApiClient googleApiClient) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACTION_PATH); actionMessageUri = dataMapRequest.getUri(); // Data Push PutDataRequest request = dataMapRequest.asPutDataRequest(); PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(googleApiClient, request); return pendingResult; }
Example 7
Source File: ConnectionHelper.java From OkWear with Apache License 2.0 | 5 votes |
/** * you need to renew the data if it uses same key * * @param request * @param listener */ public void syncData(@NonNull final PutDataRequest request, @Nullable final SendResultListener<DataApi.DataItemResult> listener) { final PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mGoogleApiClient, request); pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() { @Override public void onResult(DataApi.DataItemResult dataItemResult) { if (listener != null) { listener.onResult(dataItemResult); } } }); }
Example 8
Source File: SendDataTask.java From OkWear with Apache License 2.0 | 5 votes |
public SendDataTask(@NonNull final GoogleApiClient googleApiClient, @NonNull final PutDataRequest request, @Nullable final SendResultListener<DataApi.DataItemResult> listener) { this.googleApiClient = googleApiClient; this.request = request; this.listener = listener; }
Example 9
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 10
Source File: SunsetsWatchFaceUtil.java From american-sunsets-watch-face with Apache License 2.0 | 5 votes |
@Override public void onResult(DataApi.DataItemResult dataItemResult) { if (dataItemResult.getStatus().isSuccess()) { if (dataItemResult.getDataItem() != null) { DataItem configDataItem = dataItemResult.getDataItem(); DataMapItem dataMapItem = DataMapItem.fromDataItem(configDataItem); DataMap config = dataMapItem.getDataMap(); mCallback.onConfigDataMapFetched(config); } else { mCallback.onConfigDataMapFetched(new DataMap()); } } }
Example 11
Source File: WearService.java From ETSMobile-Android2 with Apache License 2.0 | 5 votes |
public void run() { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context) .addApi(Wearable.API) .build(); ConnectionResult connectionResult = googleApiClient.blockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); if (!connectionResult.isSuccess() || !googleApiClient.isConnected()) { Log.e("ETSMobile-Wear", connectionResult.getErrorMessage()); return; } PutDataMapRequest dataMapReq = PutDataMapRequest.create(path); ArrayList<DataMap> dataMapArrayList = new ArrayList<>(); for (Seances seance : seances) { dataMapArrayList.add(seance.putData()); } dataMapReq.getDataMap().putDataMapArrayList("list_seances", dataMapArrayList); PutDataRequest request = dataMapReq.asPutDataRequest(); DataApi.DataItemResult dataItemResult = Wearable .DataApi .putDataItem(googleApiClient, request) .await(); if (dataItemResult.getStatus().isSuccess()) { if (BuildConfig.DEBUG) Log.d("SendToDataLayerThread", "Data sent successfully!!"); } else { // Log an error if (BuildConfig.DEBUG) Log.d("SendToDataLayerThread", "ERROR: failed to send Message"); } }
Example 12
Source File: WearableApi.java From LibreAlarm with GNU General Public License v3.0 | 5 votes |
public static boolean sendData(GoogleApiClient client, String command, HashMap<String, String> pairs, ResultCallback<DataApi.DataItemResult> listener) { PutDataMapRequest putDataMapReq = PutDataMapRequest.create(command); for (String key : pairs.keySet()) { putDataMapReq.getDataMap().putString(key, pairs.get(key)); } return sendData(client, putDataMapReq, listener); }
Example 13
Source File: MessageReceiverService.java From ibm-wearables-android-sdk with Apache License 2.0 | 5 votes |
/** * Send the sensors data to the phone * @param dataMapRequest data map to send * @return send result */ @Override public PendingResult<DataApi.DataItemResult> sendData(PutDataMapRequest dataMapRequest) { PutDataRequest dataRequest = dataMapRequest.asPutDataRequest(); dataRequest.setUrgent(); return Wearable.DataApi.putDataItem(apiClient, dataRequest); }
Example 14
Source File: AttractionsActivity.java From io2015-codelabs with Apache License 2.0 | 4 votes |
@Override protected ArrayList<Attraction> doInBackground(Uri... params) { mAttractions.clear(); // Connect to Play Services and the Wearable API GoogleApiClient googleApiClient = new GoogleApiClient.Builder(mContext) .addApi(Wearable.API) .build(); ConnectionResult connectionResult = googleApiClient.blockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); if (!connectionResult.isSuccess() || !googleApiClient.isConnected()) { Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG, connectionResult.getErrorCode())); return null; } Uri attractionsUri = params[0]; DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem(googleApiClient, attractionsUri).await(); if (dataItemResult.getStatus().isSuccess() && dataItemResult.getDataItem() != null) { DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItemResult.getDataItem()); List<DataMap> attractionsData = dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS); // Loop through each attraction, adding them to the list Iterator<DataMap> itr = attractionsData.iterator(); while (itr.hasNext()) { DataMap attractionData = itr.next(); Attraction attraction = new Attraction(); attraction.name = attractionData.getString(Constants.EXTRA_TITLE); attraction.description = attractionData.getString(Constants.EXTRA_DESCRIPTION); attraction.city = attractionData.get(Constants.EXTRA_CITY); attraction.distance = attractionData.getString(Constants.EXTRA_DISTANCE); attraction.location = new LatLng( attractionData.getDouble(Constants.EXTRA_LOCATION_LAT), attractionData.getDouble(Constants.EXTRA_LOCATION_LNG)); attraction.image = Utils.loadBitmapFromAsset(googleApiClient, attractionData.getAsset(Constants.EXTRA_IMAGE)); attraction.secondaryImage = Utils.loadBitmapFromAsset(googleApiClient, attractionData.getAsset(Constants.EXTRA_IMAGE_SECONDARY)); mAttractions.add(attraction); } } googleApiClient.disconnect(); return mAttractions; }
Example 15
Source File: UtilityService.java From io2015-codelabs with Apache License 2.0 | 4 votes |
/** * Transfer the required data over to the wearable * @param attractions list of attraction data to transfer over */ private void sendDataToWearable(List<Attraction> attractions) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .build(); // It's OK to use blockingConnect() here as we are running in an // IntentService that executes work on a separate (background) thread. ConnectionResult connectionResult = googleApiClient.blockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); // Limit attractions to send int count = attractions.size() > Constants.MAX_ATTRACTIONS ? Constants.MAX_ATTRACTIONS : attractions.size(); ArrayList<DataMap> attractionsData = new ArrayList<>(count); for (int i = 0; i < count; i++) { Attraction attraction = attractions.get(i); Bitmap image = null; Bitmap secondaryImage = null; try { // Fetch and resize attraction image bitmap image = Glide.with(this) .load(attraction.imageUrl) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.SOURCE) .into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE) .get(); secondaryImage = Glide.with(this) .load(attraction.secondaryImageUrl) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.SOURCE) .into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE) .get(); } catch (InterruptedException | ExecutionException e) { Log.e(TAG, "Exception loading bitmap from network"); } if (image != null && secondaryImage != null) { DataMap attractionData = new DataMap(); String distance = Utils.formatDistanceBetween( Utils.getLocation(this), attraction.location); attractionData.putString(Constants.EXTRA_TITLE, attraction.name); attractionData.putString(Constants.EXTRA_DESCRIPTION, attraction.description); attractionData.putDouble( Constants.EXTRA_LOCATION_LAT, attraction.location.latitude); attractionData.putDouble( Constants.EXTRA_LOCATION_LNG, attraction.location.longitude); attractionData.putString(Constants.EXTRA_DISTANCE, distance); attractionData.putString(Constants.EXTRA_CITY, attraction.city); attractionData.putAsset(Constants.EXTRA_IMAGE, Utils.createAssetFromBitmap(image)); attractionData.putAsset(Constants.EXTRA_IMAGE_SECONDARY, Utils.createAssetFromBitmap(secondaryImage)); attractionsData.add(attractionData); } } if (connectionResult.isSuccess() && googleApiClient.isConnected() && attractionsData.size() > 0) { PutDataMapRequest dataMap = PutDataMapRequest.create(Constants.ATTRACTION_PATH); dataMap.getDataMap().putDataMapArrayList(Constants.EXTRA_ATTRACTIONS, attractionsData); dataMap.getDataMap().putLong(Constants.EXTRA_TIMESTAMP, new Date().getTime()); PutDataRequest request = dataMap.asPutDataRequest(); // Send the data over DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(); if (!result.getStatus().isSuccess()) { Log.e(TAG, String.format("Error sending data using DataApi (error code = %d)", result.getStatus().getStatusCode())); } } else { Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG, connectionResult.getErrorCode())); } googleApiClient.disconnect(); }
Example 16
Source File: UtilityService.java From wear-os-samples with Apache License 2.0 | 4 votes |
/** * Transfer the required data over to the wearable * @param attractions list of attraction data to transfer over */ private void sendDataToWearable(List<Attraction> attractions) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .build(); // It's OK to use blockingConnect() here as we are running in an // IntentService that executes work on a separate (background) thread. ConnectionResult connectionResult = googleApiClient.blockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); // Limit attractions to send int count = attractions.size() > Constants.MAX_ATTRACTIONS ? Constants.MAX_ATTRACTIONS : attractions.size(); ArrayList<DataMap> attractionsData = new ArrayList<>(count); for (int i = 0; i < count; i++) { Attraction attraction = attractions.get(i); Bitmap image = null; Bitmap secondaryImage = null; try { // Fetch and resize attraction image bitmap image = Glide.with(this) .load(attraction.imageUrl) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.SOURCE) .into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE) .get(); secondaryImage = Glide.with(this) .load(attraction.secondaryImageUrl) .asBitmap() .diskCacheStrategy(DiskCacheStrategy.SOURCE) .into(Constants.WEAR_IMAGE_SIZE_PARALLAX_WIDTH, Constants.WEAR_IMAGE_SIZE) .get(); } catch (InterruptedException | ExecutionException e) { Log.e(TAG, "Exception loading bitmap from network"); } if (image != null && secondaryImage != null) { DataMap attractionData = new DataMap(); String distance = Utils.formatDistanceBetween( Utils.getLocation(this), attraction.location); attractionData.putString(Constants.EXTRA_TITLE, attraction.name); attractionData.putString(Constants.EXTRA_DESCRIPTION, attraction.description); attractionData.putDouble( Constants.EXTRA_LOCATION_LAT, attraction.location.latitude); attractionData.putDouble( Constants.EXTRA_LOCATION_LNG, attraction.location.longitude); attractionData.putString(Constants.EXTRA_DISTANCE, distance); attractionData.putString(Constants.EXTRA_CITY, attraction.city); attractionData.putAsset(Constants.EXTRA_IMAGE, Utils.createAssetFromBitmap(image)); attractionData.putAsset(Constants.EXTRA_IMAGE_SECONDARY, Utils.createAssetFromBitmap(secondaryImage)); attractionsData.add(attractionData); } } if (connectionResult.isSuccess() && googleApiClient.isConnected() && attractionsData.size() > 0) { PutDataMapRequest dataMap = PutDataMapRequest.create(Constants.ATTRACTION_PATH); dataMap.getDataMap().putDataMapArrayList(Constants.EXTRA_ATTRACTIONS, attractionsData); dataMap.getDataMap().putLong(Constants.EXTRA_TIMESTAMP, new Date().getTime()); PutDataRequest request = dataMap.asPutDataRequest(); request.setUrgent(); // Send the data over DataApi.DataItemResult result = Wearable.DataApi.putDataItem(googleApiClient, request).await(); if (!result.getStatus().isSuccess()) { Log.e(TAG, String.format("Error sending data using DataApi (error code = %d)", result.getStatus().getStatusCode())); } } else { Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG, connectionResult.getErrorCode())); } googleApiClient.disconnect(); }
Example 17
Source File: AttractionsActivity.java From wear-os-samples with Apache License 2.0 | 4 votes |
@Override protected ArrayList<Attraction> doInBackground(Uri... params) { mAttractions.clear(); // Connect to Play Services and the Wearable API GoogleApiClient googleApiClient = new GoogleApiClient.Builder(mContext) .addApi(Wearable.API) .build(); ConnectionResult connectionResult = googleApiClient.blockingConnect( Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS); if (!connectionResult.isSuccess() || !googleApiClient.isConnected()) { Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG, connectionResult.getErrorCode())); return null; } Uri attractionsUri = params[0]; DataApi.DataItemResult dataItemResult = Wearable.DataApi.getDataItem(googleApiClient, attractionsUri).await(); if (dataItemResult.getStatus().isSuccess() && dataItemResult.getDataItem() != null) { DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItemResult.getDataItem()); List<DataMap> attractionsData = dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS); // Loop through each attraction, adding them to the list Iterator<DataMap> itr = attractionsData.iterator(); while (itr.hasNext()) { DataMap attractionData = itr.next(); Attraction attraction = new Attraction(); attraction.name = attractionData.getString(Constants.EXTRA_TITLE); attraction.description = attractionData.getString(Constants.EXTRA_DESCRIPTION); attraction.city = attractionData.get(Constants.EXTRA_CITY); attraction.distance = attractionData.getString(Constants.EXTRA_DISTANCE); attraction.location = new LatLng( attractionData.getDouble(Constants.EXTRA_LOCATION_LAT), attractionData.getDouble(Constants.EXTRA_LOCATION_LNG)); attraction.image = Utils.loadBitmapFromAsset(googleApiClient, attractionData.getAsset(Constants.EXTRA_IMAGE)); attraction.secondaryImage = Utils.loadBitmapFromAsset(googleApiClient, attractionData.getAsset(Constants.EXTRA_IMAGE_SECONDARY)); mAttractions.add(attraction); } } googleApiClient.disconnect(); return mAttractions; }
Example 18
Source File: SendDataTask.java From OkWear with Apache License 2.0 | 4 votes |
@Override protected DataApi.DataItemResult doInBackground(Object... args) { final DataApi.DataItemResult dataResult = Wearable.DataApi.putDataItem(googleApiClient, request).await(); return dataResult; }
Example 19
Source File: ConnectionHelper.java From OkWear with Apache License 2.0 | 2 votes |
/** * you need to renew the data if it uses same key * using AsyncTask * * @param request * @param listener */ public void syncDataAsync(@NonNull final PutDataRequest request, @Nullable final SendResultListener<DataApi.DataItemResult> listener) { if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) { new SendDataTask(mGoogleApiClient, request, listener).execute(); } }
Example 20
Source File: DataSender.java From ibm-wearables-android-sdk with Apache License 2.0 | votes |
PendingResult<DataApi.DataItemResult> sendData(PutDataMapRequest dataRequest);