/** * 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(); } }); } }
@SuppressLint("CommitPrefEdits") @Override public void onResult(@NonNull DataItemBuffer dataItems) { // This is the callback from the getDataItems() call in resyncAll() SharedPreferences.Editor editor; if (TextUtils.isEmpty(sharedPrefsName)) { editor = PreferenceManager.getDefaultSharedPreferences(appContext).edit(); } else { editor = appContext.getSharedPreferences(sharedPrefsName, MODE_PRIVATE).edit(); } try { if (dataItems.getStatus().isSuccess()) { for (int i = dataItems.getCount() - 1; i >= 0; i--) { Log.d("PrefSyncService", "Resync onResult: " + dataItems.get(i)); saveItem(dataItems.get(i), editor, null); } } } finally { // We don't use apply() because we don't know what thread we're on editor.commit(); dataItems.release(); } }
private void getAllAvailableDataItems() { PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(mGoogleApiClient); results.setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(@NonNull DataItemBuffer dataItems) { if (dataItems.getCount() != 0) { for (DataItem item : dataItems) { if (item.getUri().getPath().contains(Statics.DATAIGC)) { getStringFromAsset(item); } if (item.getUri().getPath().contains(Statics.DATATHROWABLE)) { getExceptionFromWear(item); } if (item.getUri().getPath().contains(Statics.DATABTFAILED)) { getBTFailed(item); } } } dataItems.release(); } }); }
/** * Retrieves 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 calls {@link DataConsumer#onGetDataItems(int, DataItemBuffer)}. * * @see DataConsumer#onGetDataItems(int, DataItemBuffer) */ public void getDataItems(@Nullable final ResultCallback<? super DataItemBuffer> callback) { assertApiConnectivity(); Wearable.DataApi.getDataItems(mGoogleApiClient).setResultCallback( new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer dataItems) { try { int statusCode = dataItems.getStatus().getStatusCode(); if (!dataItems.getStatus().isSuccess()) { Log.e(TAG, "Failed to get items, status code: " + statusCode); } if (callback == null) { for (DataConsumer consumer : mDataConsumers) { consumer.onGetDataItems(statusCode, dataItems); } } else { callback.onResult(dataItems); } } finally { dataItems.release(); } } }); }
/** * Retrieves data items asynchronously from the Android Wear network, matching the provided URI * and filter type. 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 calls {@link DataConsumer#onGetDataItems(int, DataItemBuffer)}. * * @see DataApi#getDataItems(GoogleApiClient, Uri, int) */ public void getDataItems(Uri uri, int filterType, @Nullable final ResultCallback<? super DataItemBuffer> callback) { assertApiConnectivity(); Wearable.DataApi.getDataItems(mGoogleApiClient, uri, filterType).setResultCallback( new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer dataItems) { int statusCode = dataItems.getStatus().getStatusCode(); if (!dataItems.getStatus().isSuccess()) { Log.e(TAG, "Failed to get items, status code: " + statusCode); } if (callback == null) { for (DataConsumer consumer : mDataConsumers) { consumer.onGetDataItems(statusCode, dataItems); } } else { callback.onResult(dataItems); } dataItems.release(); } }); }
@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(); } }); }
public final PendingResult<DataItemBuffer> getDataItems(GoogleApiClient paramGoogleApiClient, final Uri paramUri, final int paramInt) { if (paramUri != null) {} for (boolean bool1 = true;; bool1 = false) { com.google.android.gms.common.internal.zzx.zzb(bool1, "uri must not be null"); boolean bool2; if (paramInt != 0) { bool2 = false; if (paramInt != 1) {} } else { bool2 = true; } com.google.android.gms.common.internal.zzx.zzb(bool2, "invalid filter type"); paramGoogleApiClient.zza(new zzi(paramGoogleApiClient) {}); } }
/** * Retrieve wear settings from Wear cloud storage */ public void updateSettings(Context context) { if (!googleApiClient.isConnected()) { if (!blockingConnect()) { return; } } ArrayList<DataMap> data; DataItemBuffer dataItemBuffer = Wearable.DataApi.getDataItems(googleApiClient).await(); if (dataItemBuffer.getStatus().isSuccess()) { for (DataItem dataItem : dataItemBuffer) { DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem); data = dataMapItem.getDataMap().getDataMapArrayList(WearableConstants.EXTRA_SETTINGS); if (data != null) { ListenerService.extractSettings(data); break; } } } dataItemBuffer.release(); }
/** * 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(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(); }); } }
public static ArrayList<String> getKeySet(GoogleApiClient apiClient, String path) { final DataItemBuffer buffer = Wearable.DataApi.getDataItems( apiClient, Uri.parse("wear:" + path)) .await(); ArrayList<String> keySet = null; try { if (buffer.getCount() > 0) { final DataMap map = DataMap.fromByteArray(buffer.get(0).getData()); keySet = map.getStringArrayList(KEY_KEY_SET); } }finally { buffer.release(); } return keySet==null?new ArrayList<String>():keySet; }
@Override public void onConnected(Bundle connectionHint) { Wearable.DataApi.addListener(googleApiClient, this); Wearable.DataApi.getDataItems(googleApiClient).setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer dataItems) { for (DataItem dataItem : dataItems) { String[] parts = dataItem.getUri().getPath().split("/"); switch (parts[1]) { case "image": photos.put(parts[2], dataItem); break; default: break; } } invalidate(); } }); }
@Override public void onConnected(Bundle bundle) { Wearable.DataApi.addListener(googleApiClient, this); Wearable.DataApi.getDataItems(googleApiClient).setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer dataItems) { for (DataItem dataItem : dataItems) { String[] parts = dataItem.getUri().getPath().split("/"); switch (parts[1]) { case "image": String photoId = parts[2]; enabledPhotos.add(photoId); PhotoListEntry photoListEntry = photosById.get(photoId); if (photoListEntry == null) continue; recyclerAdapter.notifyItemChanged(photoListEntry.getPosition()); break; default: break; } } } }); }
protected void reloadVehicleData(String dataType){ final String dataPath = WearUtils.VEHICLE_DATA_PREFIX + dataType; apiClientMgr.addTask(new GoogleApiClientTask() { @Override protected void doRun() { final Uri dataItemUri = new Uri.Builder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(dataPath) .build(); Wearable.DataApi.getDataItems(getGoogleApiClient(), dataItemUri) .setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer dataItemBuffer) { final int dataCount = dataItemBuffer.getCount(); for(int i = 0; i < dataCount; i++) { final DataItem dataItem = dataItemBuffer.get(i); if (dataItem != null) onDataItemReceived(dataItem, DataEvent.TYPE_CHANGED); } dataItemBuffer.release(); } }); } }); }
private void updateContextStreamNotification() { final String dataPath = WearUtils.VEHICLE_DATA_PREFIX + AttributeType.STATE; apiClientMgr.addTask(new GoogleApiClientTask() { @Override protected void doRun() { final Uri dataItemUri = new Uri.Builder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(dataPath).build(); Wearable.DataApi.getDataItems(getGoogleApiClient(), dataItemUri) .setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer dataItems) { final int dataCount = dataItems.getCount(); for (int i = 0; i < dataCount; i++) { final DataItem dataItem = dataItems.get(i); handleDataItem(dataItem, DataEvent.TYPE_CHANGED); } dataItems.release(); } }); } }); }
public void onDeleteEventsClicked(View v) { if (mGoogleApiClient.isConnected()) { Wearable.DataApi.getDataItems(mGoogleApiClient) .setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer result) { if (result.getStatus().isSuccess()) { deleteDataItems(result); } else { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "onDeleteEventsClicked(): failed to get Data Items"); } } result.close(); } }); } else { Log.e(TAG, "Failed to delete data items" + " - Client disconnected from Google Play Services"); } }
public void onDeleteEventsClicked(View view) { if (mGoogleApiClient.isConnected()) { Wearable.DataApi.getDataItems(mGoogleApiClient) .setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer result) { try { if (result.getStatus().isSuccess()) { deleteDataItems(result); } else { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "onDeleteEventsClicked(): failed to get Data " + "Items"); } } } finally { result.release(); } } }); } else { Log.e(TAG, "Failed to delete data items" + " - Client disconnected from Google Play Services"); } }
private void deleteDataItems(final DataItemBuffer dataItemList) { if (mGoogleApiClient.isConnected()) { for (final DataItem dataItem : dataItemList) { final Uri dataItemUri = dataItem.getUri(); /* * In a real calendar application, this might delete the corresponding calendar * events from the calendar data provider. However, we simply delete the DataItem, * but leave the phone's calendar data intact for this simple sample. */ Wearable.DataApi.deleteDataItems(mGoogleApiClient, dataItemUri) .setResultCallback(new ResultCallback<DataApi.DeleteDataItemsResult>() { @Override public void onResult(DataApi.DeleteDataItemsResult deleteResult) { if (deleteResult.getStatus().isSuccess()) { appendLog("Successfully deleted data item: " + dataItemUri); } else { appendLog("Failed to delete data item:" + dataItemUri); } } }); } } else { Log.e(TAG, "Failed to delete data items" + " - Client disconnected from Google Play Services"); } }
private void getDataItem(GoogleApiClient client){ PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(client); results.setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer dataItems) { if (dataItems.getCount() != 0) { DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItems.get(0)); // This should read the correct value. i = dataMapItem.getDataMap().getInt(COUNT_KEY); mTextView.setText(Integer.toString(i)); } dataItems.release(); } }); }
public Bundle retrieveRideValues() { Log.d(); Uri uri = createUri(CommConstants.PATH_RIDE_VALUES); PendingResult<DataItemBuffer> pendingResult = Wearable.DataApi.getDataItems(mGoogleApiClient, uri); DataItemBuffer dataItemBuffer = pendingResult.await(); if (dataItemBuffer.getCount() == 0) { Log.d("No result"); dataItemBuffer.release(); return null; } DataItem dataItem = dataItemBuffer.get(0); DataMap dataMap = DataMap.fromByteArray(dataItem.getData()); Bundle res = dataMap.toBundle(); Log.d("res=" + res); dataItemBuffer.release(); return res; }
public String retrievePreferences(String prefExtraName) { Log.d(); Uri uri = new Uri.Builder().scheme("wear").path(CommConstants.PATH_PREFERENCES).build(); PendingResult<DataItemBuffer> pendingResult = Wearable.DataApi.getDataItems(mGoogleApiClient, uri); DataItemBuffer dataItemBuffer = pendingResult.await(); if (dataItemBuffer.getCount() == 0) { Log.d("No result"); dataItemBuffer.release(); return null; } DataItem dataItem = dataItemBuffer.get(0); DataMap dataMap = DataMap.fromByteArray(dataItem.getData()); String res = dataMap.getString(prefExtraName); Log.d("res=" + res); dataItemBuffer.release(); return res; }
@Override public void onResult(DataItemBuffer dataItems) { for (DataItem item : dataItems) { processData(item); } dataItems.release(); invalidate(); }
@Override public void onConnected(@Nullable Bundle bundle) { if (debugMode) Log.d(TAG, "on connected"); Wearable.DataApi.addListener(mGoogleApiClient, this); PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(mGoogleApiClient); results.setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(@NonNull DataItemBuffer dataItems) { if (dataItems.getCount() != 0) { for (DataItem item : dataItems) { if (item.getUri().getPath().contains(Statics.DATAPREFERENCES)) { updatePreferencesFromDataItem(item); } else if (item.getUri().getPath().contains(Statics.DATADELETE)) { deleteSingleIgcFile(item); } } } dataItems.release(); } }); File dir = getFilesDir(); File[] subFiles = dir.listFiles(); if (subFiles != null) { for (File file : subFiles) { if (!file.getName().contains(".igc")) continue; Asset asset = createAssetFromTextfile(file); PutDataMapRequest dataMap = PutDataMapRequest.create(Statics.DATAIGC + file.getName()); dataMap.getDataMap().putString("igcname", file.getName()); dataMap.getDataMap().putAsset("igcfile", asset); PutDataRequest request = dataMap.asPutDataRequest(); request.setUrgent(); Wearable.DataApi.putDataItem(mGoogleApiClient, request); } } requestLocationUpdates(); //throw new RuntimeException("This is a wear croshhhhh"); }
/** * Retrieves data items synchronously from the Android Wear network. A {@code timeoutInMillis} * is required to specify the maximum length of time, in milliseconds, that the thread should * be blocked. Caller needs to call {@code release()} on the returned {@link DataItemBuffer} * when done. */ public DataItemBuffer getDataItemsSynchronous(long timeoutInMillis) { assertApiConnectivity(); WearUtil.assertNonUiThread(); return Wearable.DataApi.getDataItems(mGoogleApiClient).await( timeoutInMillis, TimeUnit.MILLISECONDS); }
private void handleDataItemsResult(DataItemBuffer paramDataItemBuffer) { for (;;) { try { Status localStatus = paramDataItemBuffer.zzUc; if (!localStatus.isSuccess()) { Object[] arrayOfObject = new Object[2]; arrayOfObject[0] = Integer.valueOf(localStatus.zzakr); arrayOfObject[1] = localStatus.zzanv; FinskyLog.w("Error %d getting data items. (%s)", arrayOfObject); return; } this.mPackageStates = new HashMap(); String str = this.mNodeId + "/package_info"; int i = 0; int j = paramDataItemBuffer.getCount(); if (i < j) { DataItem localDataItem = (DataItem)paramDataItemBuffer.get(i); if (localDataItem.getUri().toString().contains(str)) { PackageStateRepository.PackageState localPackageState = stateFromDataItem(localDataItem); this.mPackageStates.put(localPackageState.packageName, localPackageState); } } else { this.mLastUpdatedUptimeMs = SystemClock.uptimeMillis(); continue; } i++; } finally {} } }
private void updateConfigDataItemAndUiOnStartup() { Log.d(TAG, "updateConfigDataItemAndUiOnStartup..."); PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(mGoogleApiClient); results.setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer dataItems) { if (dataItems.getCount() != 0) { DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItems.get(0)); // IMAGE int value = dataMapItem.getDataMap().getInt(SunsetsWatchFaceUtil.KEY_BACKGROUND_COLOR); updateUiForKey(SunsetsWatchFaceUtil.KEY_BACKGROUND_COLOR, value); //BATTERY SAVING MODE int value2 = dataMapItem.getDataMap().getInt(SunsetsWatchFaceUtil.KEY_FLUID_MODE); updateUiForKey(SunsetsWatchFaceUtil.KEY_FLUID_MODE, value2); Log.d(TAG, "aggiorno a startup background..."); } dataItems.release(); } }); }
private void updateList() { // Retrieve the complete list of dataitems using DataApi // .getDataItems. Because this may involve a network sync and // may take some time, get the results back in a ResultCallback // at a later time. Wearable.DataApi.getDataItems(googleApiClient).setResultCallback( new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer dataItems) { try { // Before you start using dataItems, // you must "freeze" them to make sure they // don't change while you are iterating over them. List<DataItem> items = FreezableUtils.freezeIterable(dataItems); // Update the adapter with the new items. adapter.setResults(items); Log.d("MainActivity", "adapter.setResults"); } finally { // Always release the dataItems when you are // through. dataItems.release(); } } }); }
/** * Retrieve room data from Wear cloud storage * * @return List of Rooms */ public ArrayList<Room> getRoomData() { ArrayList<Room> rooms = new ArrayList<>(); if (!googleApiClient.isConnected()) { if (!blockingConnect()) { return null; } } ArrayList<DataMap> data; DataItemBuffer dataItemBuffer = Wearable.DataApi.getDataItems(googleApiClient).await(); if (dataItemBuffer.getStatus().isSuccess()) { for (DataItem dataItem : dataItemBuffer) { DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem); data = dataMapItem.getDataMap().getDataMapArrayList(WearableConstants.EXTRA_DATA); if (data != null) { rooms = ListenerService.extractRoomDataMapItems(data); break; } } } dataItemBuffer.release(); return rooms; }
/** * Retrieve scene data from Wear cloud storage * * @return List of Scenes */ public ArrayList<Scene> getSceneData() { ArrayList<Scene> scenes = new ArrayList<>(); if (!googleApiClient.isConnected()) { if (!blockingConnect()) { return null; } } ArrayList<DataMap> data; DataItemBuffer dataItemBuffer = Wearable.DataApi.getDataItems(googleApiClient).await(); if (dataItemBuffer.getStatus().isSuccess()) { for (DataItem dataItem : dataItemBuffer) { DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem); data = dataMapItem.getDataMap().getDataMapArrayList(WearableConstants.EXTRA_DATA); if (data != null) { scenes = ListenerService.extractSceneDataMapItems(data); break; } } } dataItemBuffer.release(); return scenes; }
private DataMap readConfigDataMapFromDataLayer() { long latestTimestamp = 0; DataItemBuffer dataItemBuffer = Wearable.DataApi.getDataItems(mGoogleApiClient).await(); if (!dataItemBuffer.getStatus().isSuccess()) { Log.e(TAG, "Error getting all data items: " + dataItemBuffer.getStatus().getStatusMessage()); } DataMap configDataMap = null; Iterator<DataItem> dataItemIterator = dataItemBuffer.singleRefIterator(); while (dataItemIterator.hasNext()) { DataItem dataItem = dataItemIterator.next(); if (!dataItem.getUri().getPath().equals("/config")) { continue; } DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem); DataMap dataMap = dataMapItem.getDataMap(); long timestamp = dataMap.getLong("timestamp"); if (timestamp >= latestTimestamp) { configDataMap = dataMapItem.getDataMap().getDataMap("config"); latestTimestamp = timestamp; } } dataItemBuffer.release(); return configDataMap; }
private void copyPreferenceToLocal(final String path) { final DataItemBuffer buffer = Wearable.DataApi.getDataItems( mApiClient, Uri.parse("wear:" + path)) .await(); try { copyPreferenceToLocal(buffer); }finally { buffer.release(); } }
@Override public void onResult(DataItemBuffer dataItems) { Log.v("Space Launch Wear", "onResult"); for (DataItem item : dataItems) { processConfigurationFor(item); } dataItems.release(); invalidateIfNecessary(); }
@Override public void onResult(DataItemBuffer dataItems) { for (DataItem item : dataItems) { processConfigurationFor(item); } dataItems.release(); invalidateIfNecessary(); }
/** * Resets the current quiz when Reset Quiz is pressed. */ public void resetQuiz(View view) { // Reset quiz status in phone layout. for(int i = 0; i < questionsContainer.getChildCount(); i++) { LinearLayout questionStatusElement = (LinearLayout) questionsContainer.getChildAt(i); TextView questionText = (TextView) questionStatusElement.findViewById(R.id.question); TextView questionStatus = (TextView) questionStatusElement.findViewById(R.id.status); questionText.setTextColor(Color.WHITE); questionStatus.setText(R.string.question_unanswered); } // Reset data items and notifications on wearable. if (mGoogleApiClient.isConnected()) { Wearable.DataApi.getDataItems(mGoogleApiClient) .setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer result) { if (result.getStatus().isSuccess()) { List<DataItem> dataItemList = FreezableUtils.freezeIterable(result); result.close(); resetDataItems(dataItemList); } else { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Reset quiz: failed to get Data Items to reset"); } } result.close(); } }); } else { Log.e(TAG, "Failed to reset data items because client is disconnected from " + "Google Play Services"); } setHasQuestionBeenAsked(false); mNumCorrect = 0; mNumIncorrect = 0; mNumSkipped = 0; }
/** * Clears the current quiz when user clicks on "New Quiz." * On this end, this involves clearing the quiz status layout and deleting all DataItems. The * wearable will then remove any outstanding question notifications upon receiving this change. */ public void newQuiz(View view) { clearQuizStatus(); if (mGoogleApiClient.isConnected()) { Wearable.DataApi.getDataItems(mGoogleApiClient) .setResultCallback(new ResultCallback<DataItemBuffer>() { @Override public void onResult(DataItemBuffer result) { if (result.getStatus().isSuccess()) { List<Uri> dataItemUriList = new ArrayList<Uri>(); for (final DataItem dataItem : result) { dataItemUriList.add(dataItem.getUri()); } result.close(); deleteDataItems(dataItemUriList); } else { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Clear quiz: failed to get Data Items for deletion"); } } result.close(); } }); } else { Log.e(TAG, "Failed to delete data items because client is disconnected from " + "Google Play Services"); } }
private void deleteDataItems(DataItemBuffer dataItems) { if (mGoogleApiClient.isConnected()) { // Store the DataItem URIs in a List and close the buffer. Then use these URIs // to delete the DataItems. final List<DataItem> dataItemList = FreezableUtils.freezeIterable(dataItems); dataItems.close(); for (final DataItem dataItem : dataItemList) { final Uri dataItemUri = dataItem.getUri(); // In a real calendar application, this might delete the corresponding calendar // event from the calendar data provider. In this sample, we simply delete the // DataItem, but leave the phone's calendar data intact. Wearable.DataApi.deleteDataItems(mGoogleApiClient, dataItemUri) .setResultCallback(new ResultCallback<DataApi.DeleteDataItemsResult>() { @Override public void onResult(DataApi.DeleteDataItemsResult deleteResult) { if (deleteResult.getStatus().isSuccess()) { appendLog("Successfully deleted data item: " + dataItemUri); } else { appendLog("Failed to delete data item:" + dataItemUri); } } }); } } else { Log.e(TAG, "Failed to delete data items" + " - Client disconnected from Google Play Services"); } }
@Override protected void onHandleIntent(Intent intent) { boolean foundArtwork = false; DataClient dataClient = Wearable.getDataClient(this); // Read all DataItems try { DataItemBuffer dataItemBuffer = Tasks.await(dataClient.getDataItems()); Iterator<DataItem> dataItemIterator = dataItemBuffer.singleRefIterator(); while (dataItemIterator.hasNext()) { DataItem dataItem = dataItemIterator.next(); foundArtwork = foundArtwork || processDataItem(dataClient, dataItem); } dataItemBuffer.release(); } catch (ExecutionException|InterruptedException e) { Log.e(TAG, "Error getting all data items", e); } if (foundArtwork) { // Enable the Full Screen Activity and Artwork Complication Provider Service only if we've found artwork enableComponents(FullScreenActivity.class, ArtworkComplicationProviderService.class); } if (!foundArtwork && intent != null && intent.getBooleanExtra(SHOW_ACTIVATE_NOTIFICATION_EXTRA, false)) { ActivateMuzeiIntentService.maybeShowActivateMuzeiNotification(this); } else { ActivateMuzeiIntentService.clearNotifications(this); } }
@Override public void onGetDataItems(int status, DataItemBuffer dataItemBuffer) { //no-op }
public zzs(zzmu.zzb<DataItemBuffer> paramzzb) { super(); }