com.google.android.gms.wearable.DataMapItem Java Examples
The following examples show how to use
com.google.android.gms.wearable.DataMapItem.
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: 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 #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: MainActivity.java From TutosAndroidFrance with MIT License | 6 votes |
/** * Récupère une bitmap partagée avec le smartphone depuis une position */ public Bitmap getBitmap(int position) { final Uri uri = getUriForDataItem("/image/" + position); if (uri != null) { final DataApi.DataItemResult result = Wearable.DataApi.getDataItem(mApiClient, uri).await(); if (result != null && result.getDataItem() != null) { final DataMapItem dataMapItem = DataMapItem.fromDataItem(result.getDataItem()); final Asset firstAsset = dataMapItem.getDataMap().getAsset("image"); if (firstAsset != null) { return loadBitmapFromAsset(firstAsset); } } } return null; }
Example #4
Source File: DataLayerListenerService.java From LibreAlarm with GNU General Public License v3.0 | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent event : dataEvents) { if (event.getType() == DataEvent.TYPE_CHANGED) { // Check the data path String path = event.getDataItem().getUri().getPath(); if (WearableApi.SETTINGS.equals(path)) { HashMap<String, String> newSettings = new HashMap<>(); DataMap dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); for (String key : dataMap.keySet()) { newSettings.put(key, dataMap.getString(key, null)); PreferencesUtil.putString(this, key, newSettings.get(key)); } WearableApi.sendMessage(mGoogleApiClient, WearableApi.SETTINGS, PreferencesUtil.toString(newSettings), null); sendStatus(mGoogleApiClient); } } } }
Example #5
Source File: WatchUpdaterService.java From xDrip with GNU General Public License v3.0 | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) {//KS does not seem to get triggered; therefore use OnMessageReceived instead DataMap dataMap; for (DataEvent event : dataEvents) { if (event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); switch (path) { case WEARABLE_PREF_DATA_PATH: dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); if (dataMap != null) { Log.d(TAG, "onDataChanged WEARABLE_PREF_DATA_PATH dataMap=" + dataMap); syncPrefData(dataMap); } break; default: Log.d(TAG, "Unknown wearable path: " + path); break; } } } }
Example #6
Source File: CollectionActivity.java From arcgis-runtime-demos-android with Apache License 2.0 | 6 votes |
/** * Handles a status response. The status response indicates whether the * feature was successfully collected or not, and if not, a reason why. * * @param item the DataItem received from the mobile device */ private void handleStatusResponse(DataItem item) { // Gets the TextView that will be used to display the status TextView text = (TextView) findViewById(R.id.text); DataMap dm = DataMapItem.fromDataItem(item).getDataMap(); boolean success = dm.getBoolean("success"); // If the event was successfully, show a success message in green if (success) { text.setText(R.string.collect_success); text.setTextColor(Color.GREEN); } else { // If it failed, show the failure reason in red String reason = dm.getString("reason"); text.setText(String.format("%s\n%s", getString(R.string.collect_failure), reason)); text.setTextColor(Color.RED); } // After 2 seconds, finish the activity new Handler().postDelayed(new Runnable() { @Override public void run() { CollectionActivity.this.finish(); } }, 2000); }
Example #7
Source File: WatchFace.java From AndroidDemoProjects with Apache License 2.0 | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { for( DataEvent event : dataEvents ) { if( event.getType() == DataEvent.TYPE_CHANGED ) { DataItem item = event.getDataItem(); if( item.getUri().getPath().compareTo( DATA_LAYER_PATH ) == 0 ) { DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap(); int selectedBackgroundPosition = dataMap.getInt(KEY_BACKGROUND_POSITION); TypedArray typedArray = getResources().obtainTypedArray( R.array.background_resource_ids ); initBackground( typedArray.getResourceId( selectedBackgroundPosition, 0 ) ); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); preferences.edit().putInt( SHARED_PREFERENCE_POSITION, selectedBackgroundPosition ).commit(); typedArray.recycle(); invalidate(); } } } }
Example #8
Source File: MainActivity.java From wear with MIT License | 6 votes |
@Override public void onDataChanged(DataEvent event) { if (DataEvent.TYPE_CHANGED == event.getType()) { DataMapItem item = DataMapItem.fromDataItem(event.getDataItem()); Asset asset = item.getDataMap().getAsset(ASSET_KEY); ConnectionResult result = mGoogleApiClient .blockingConnect(TIMEOUT, TimeUnit.SECONDS); if (result.isSuccess()) { InputStream stream = Wearable.DataApi .getFdForAsset(mGoogleApiClient, asset) .await().getInputStream(); if (null != asset) { Bitmap bitmap = BitmapFactory.decodeStream(stream); showAsset(bitmap); } } } else if (DataEvent.TYPE_DELETED == event.getType()) { hideAsset(); } }
Example #9
Source File: ListenerService.java From wear-os-samples with Apache License 2.0 | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { Log.d(TAG, "onDataChanged: " + dataEvents); for (DataEvent event : dataEvents) { if (event.getType() == DataEvent.TYPE_CHANGED && event.getDataItem() != null && Constants.ATTRACTION_PATH.equals(event.getDataItem().getUri().getPath())) { DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); ArrayList<DataMap> attractionsData = dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS); showNotification(dataMapItem.getUri(), attractionsData); } } }
Example #10
Source File: MainActivity.java From wearable with Apache License 2.0 | 6 votes |
@Override public void onDataChanged(@NonNull DataEventBuffer dataEventBuffer) { Log.d(TAG, "onDataChanged: " + dataEventBuffer); for (DataEvent event : dataEventBuffer) { if (event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); if (datapath.equals(path)) { DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); String message = dataMapItem.getDataMap().getString("message"); Log.v(TAG, "Wear activity received message: " + message); // Display message in UI mTextView.setText(message); } else { Log.e(TAG, "Unrecognized path: " + path); } } else if (event.getType() == DataEvent.TYPE_DELETED) { Log.v(TAG, "Data deleted : " + event.getDataItem().toString()); } else { Log.e(TAG, "Unknown data event Type = " + event.getType()); } } }
Example #11
Source File: MainActivity.java From wearable with Apache License 2.0 | 6 votes |
/** * Receives the data, note since we are using the same data base, we will also receive * data that we sent as well. Likely should add some kind of id number to datamap, so it * can tell between mobile device and wear device. or this maybe the functionality you want. */ @Override public void onDataChanged(@NonNull DataEventBuffer dataEventBuffer) { Log.d(TAG, "onDataChanged: " + dataEventBuffer); for (DataEvent event : dataEventBuffer) { if (event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); if (datapath.equals(path)) { DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); String message = dataMapItem.getDataMap().getString("message"); Log.v(TAG, "Wear activity received message: " + message); // Display message in UI logthis(message); } else { Log.e(TAG, "Unrecognized path: " + path); } } else if (event.getType() == DataEvent.TYPE_DELETED) { Log.v(TAG, "Data deleted : " + event.getDataItem().toString()); } else { Log.e(TAG, "Unknown data event Type = " + event.getType()); } } }
Example #12
Source File: DigitalWatchFaceService.java From wear-os-samples with Apache License 2.0 | 6 votes |
@Override // DataApi.DataListener public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent dataEvent : dataEvents) { if (dataEvent.getType() != DataEvent.TYPE_CHANGED) { continue; } DataItem dataItem = dataEvent.getDataItem(); if (!dataItem.getUri().getPath().equals( DigitalWatchFaceUtil.PATH_WITH_FEATURE)) { continue; } DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem); DataMap config = dataMapItem.getDataMap(); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Config DataItem updated:" + config); } updateUiForConfigDataMap(config); } }
Example #13
Source File: WatchUpdaterService.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) {//KS does not seem to get triggered; therefore use OnMessageReceived instead DataMap dataMap; for (DataEvent event : dataEvents) { if (event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); switch (path) { case WEARABLE_PREF_DATA_PATH: dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); if (dataMap != null) { Log.d(TAG, "onDataChanged WEARABLE_PREF_DATA_PATH dataMap=" + dataMap); syncPrefData(dataMap); } break; default: Log.d(TAG, "Unknown wearable path: " + path); break; } } } }
Example #14
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 #15
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 #16
Source File: NotificationUpdateService.java From AndroidWearable-Samples with Apache License 2.0 | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent dataEvent : dataEvents) { if (dataEvent.getType() == DataEvent.TYPE_CHANGED) { DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap(); String content = dataMap.getString(Constants.KEY_CONTENT); String title = dataMap.getString(Constants.KEY_TITLE); if (Constants.WATCH_ONLY_PATH.equals(dataEvent.getDataItem().getUri().getPath())) { buildWearableOnlyNotification(title, content, false); } else if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) { buildWearableOnlyNotification(title, content, true); } } else if (dataEvent.getType() == DataEvent.TYPE_DELETED) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "DataItem deleted: " + dataEvent.getDataItem().getUri().getPath()); } if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) { // Dismiss the corresponding notification ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .cancel(Constants.BOTH_ID); } } } }
Example #17
Source File: DataApiHandler.java From PowerSwitch_Android with GNU General Public License v3.0 | 6 votes |
/** * 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(); }
Example #18
Source File: SunsetsWatchFace.java From american-sunsets-watch-face with Apache License 2.0 | 6 votes |
@Override // DataApi.DataListener public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent dataEvent : dataEvents) { if (dataEvent.getType() != DataEvent.TYPE_CHANGED) { continue; } DataItem dataItem = dataEvent.getDataItem(); if (!dataItem.getUri().getPath().equals( SunsetsWatchFaceUtil.PATH_WITH_FEATURE)) { continue; } DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem); DataMap config = dataMapItem.getDataMap(); Log.d(TAG, "Config DataItem updated:" + config); updateUiForConfigDataMap(config); } }
Example #19
Source File: SensorReceiverService.java From SensorDashboard with Apache License 2.0 | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { Log.d(TAG, "onDataChanged()"); for (DataEvent dataEvent : dataEvents) { if (dataEvent.getType() == DataEvent.TYPE_CHANGED) { DataItem dataItem = dataEvent.getDataItem(); Uri uri = dataItem.getUri(); String path = uri.getPath(); if (path.startsWith("/sensors/")) { unpackSensorData( Integer.parseInt(uri.getLastPathSegment()), DataMapItem.fromDataItem(dataItem).getDataMap() ); } } } }
Example #20
Source File: MessageReceiverService.java From SensorDashboard with Apache License 2.0 | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { super.onDataChanged(dataEvents); for (DataEvent dataEvent : dataEvents) { if (dataEvent.getType() == DataEvent.TYPE_CHANGED) { DataItem dataItem = dataEvent.getDataItem(); Uri uri = dataItem.getUri(); String path = uri.getPath(); if (path.startsWith("/filter")) { DataMap dataMap = DataMapItem.fromDataItem(dataItem).getDataMap(); int filterById = dataMap.getInt(DataMapKeys.FILTER); deviceClient.setSensorFilter(filterById); } } } }
Example #21
Source File: WatchFaceCompanionConfigActivity.java From american-sunsets-watch-face with Apache License 2.0 | 6 votes |
@Override // DataApi.DataListener public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent dataEvent : dataEvents) { if (dataEvent.getType() != DataEvent.TYPE_CHANGED) { continue; } DataItem dataItem = dataEvent.getDataItem(); if (!dataItem.getUri().getPath().equals(SunsetsWatchFaceUtil.PATH_WITH_FEATURE)) { continue; } DataMapItem dataMapItem = DataMapItem.fromDataItem(dataItem); DataMap config = dataMapItem.getDataMap(); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Config DataItem updated:" + config); } updateUiForConfigDataMap(config); } }
Example #22
Source File: NotificationUpdateService.java From android-SynchronizedNotifications with Apache License 2.0 | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent dataEvent : dataEvents) { if (dataEvent.getType() == DataEvent.TYPE_CHANGED) { DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap(); String content = dataMap.getString(Constants.KEY_CONTENT); String title = dataMap.getString(Constants.KEY_TITLE); if (Constants.WATCH_ONLY_PATH.equals(dataEvent.getDataItem().getUri().getPath())) { buildWearableOnlyNotification(title, content, false); } else if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) { buildWearableOnlyNotification(title, content, true); } } else if (dataEvent.getType() == DataEvent.TYPE_DELETED) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "DataItem deleted: " + dataEvent.getDataItem().getUri().getPath()); } if (Constants.BOTH_PATH.equals(dataEvent.getDataItem().getUri().getPath())) { // Dismiss the corresponding notification ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .cancel(Constants.WATCH_ONLY_ID); } } } }
Example #23
Source File: Emmet.java From Wear-Emmet with Apache License 2.0 | 6 votes |
public Emmet onDataChanged(DataEventBuffer dataEvents) { for (DataEvent dataEvent : dataEvents) { String path = dataEvent.getDataItem().getUri().getPath(); if (ENABLE_LOG) Log.d(TAG, "onDataChanged(" + path + ")"); if (path.startsWith(PATH)) { //if it's an Emmet path if (ENABLE_LOG) Log.d(TAG, "emmet-onDataChanged " + path); try { DataMap methodDataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap(); callMethodOnInterfaces(methodDataMap); } catch (Throwable t) { Log.e(TAG, "error decoding datamap", t); } } } return this; }
Example #24
Source File: UARTCommandsActivity.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void onDataChanged(final DataEventBuffer dataEventBuffer) { for (final DataEvent event : dataEventBuffer) { final DataItem item = event.getDataItem(); final long id = ContentUris.parseId(item.getUri()); // Update the configuration only if ID matches if (id != configurationId) continue; // Configuration added or edited if (event.getType() == DataEvent.TYPE_CHANGED) { final DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap(); final UartConfiguration configuration = new UartConfiguration(dataMap, id); // Update UI on UI thread runOnUiThread(() -> adapter.setConfiguration(configuration)); } else if (event.getType() == DataEvent.TYPE_DELETED) { // Configuration removed // Update UI on UI thread runOnUiThread(() -> adapter.setConfiguration(null)); } } }
Example #25
Source File: UARTConfigurationsActivity.java From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * This method read the UART configurations from the DataApi and populates the adapter with them. */ private void populateConfigurations() { if (googleApiClient.isConnected()) { final PendingResult<DataItemBuffer> results = Wearable.DataApi.getDataItems(googleApiClient, 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); } adapter.setConfigurations(configurations); dataItems.release(); }); } }
Example #26
Source File: DaVinci.java From DaVinci with Apache License 2.0 | 6 votes |
/** * When received assets from DataApi * * @param dataEvents */ @Override public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent dataEvent : dataEvents) { String path = dataEvent.getDataItem().getUri().getPath(); Log.d(TAG, "onDataChanged(" + path + ")"); if (path.startsWith(DAVINCI_PATH)) { //if it's a davinci path Log.d(TAG, "davinci-onDataChanged " + path); //download the bitmap and add it to cache Asset asset = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap().getAsset(DAVINCI_ASSET_IMAGE); Bitmap bitmap = loadBitmapFromAsset(asset); if (bitmap != null) saveBitmap(getKey(path), bitmap); //callbacks callIntoWaiting(path); } } }
Example #27
Source File: ListenerService.java From io2015-codelabs with Apache License 2.0 | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { Log.d(TAG, "onDataChanged: " + dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED && event.getDataItem() != null && Constants.ATTRACTION_PATH.equals(event.getDataItem().getUri().getPath())) { DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); ArrayList<DataMap> attractionsData = dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS); showNotification(dataMapItem.getUri(), attractionsData); } } }
Example #28
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 #29
Source File: ListenerService.java From io2015-codelabs with Apache License 2.0 | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { Log.d(TAG, "onDataChanged: " + dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED && event.getDataItem() != null && Constants.ATTRACTION_PATH.equals(event.getDataItem().getUri().getPath())) { DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); ArrayList<DataMap> attractionsData = dataMapItem.getDataMap().getDataMapArrayList(Constants.EXTRA_ATTRACTIONS); showNotification(dataMapItem.getUri(), attractionsData); } } }
Example #30
Source File: MainActivity.java From DaVinci with Apache License 2.0 | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent event : dataEvents) { if (event.getType() == DataEvent.TYPE_CHANGED && event.getDataItem().getUri().getPath().startsWith("/elements/")) { DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); List<DataMap> elementsDataMap = dataMapItem.getDataMap().getDataMapArrayList("/list/"); if (elementList == null || elementList.isEmpty()) { elementList = new ArrayList<>(); for (DataMap dataMap : elementsDataMap) { elementList.add(getElement(dataMap)); } startMainScreen(); } } } }