Java Code Examples for com.google.android.gms.wearable.DataEvent#getDataItem()
The following examples show how to use
com.google.android.gms.wearable.DataEvent#getDataItem() .
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: 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 2
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 3
Source File: CollectionActivity.java From arcgis-runtime-demos-android with Apache License 2.0 | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEventBuffer) { Log.i("Test", "Data changed event received"); // Get the data changed event and handle it appropriately for(DataEvent event : dataEventBuffer) { if (event.getType() == DataEvent.TYPE_CHANGED) { DataItem item = event.getDataItem(); String path = item.getUri().getPath(); switch (path) { case LAYER_RESPONSE: handleLayerResponse(item); break; case FEATURE_TYPE_RESPONSE: handleFeatureTypeResponse(item); break; case STATUS_RESPONSE: handleStatusResponse(item); break; } } } }
Example 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
Source File: SensorReceiverService.java From wearabird with MIT License | 6 votes |
@Override public void onDataChanged(DataEventBuffer 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("/sensors/")) { unpackSensorData( Integer.parseInt(uri.getLastPathSegment()), DataMapItem.fromDataItem(dataItem).getDataMap() ); } } } }
Example 12
Source File: MainActivity.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent event : dataEvents) { if (event.getType() == DataEvent.TYPE_CHANGED) { DataItem dataItem = event.getDataItem(); 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; } } } }
Example 13
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 14
Source File: ListenerService.java From ETSMobile-Android2 with Apache License 2.0 | 5 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 && event.getDataItem().getUri().getPath().equals("/today_req")) { DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); ArrayList<DataMap> seancesDataMapList = dataMapItem.getDataMap().getDataMapArrayList("list_seances"); ArrayList<Seances> seances = new ArrayList<>(); for (DataMap seanceDataMap : seancesDataMapList) { Seances seance = new Seances(); seance.getData(seanceDataMap); seances.add(seance); } Intent intent = new Intent("seances_update"); intent.putExtra("seances", seances); LocalBroadcastManager.getInstance(this).sendBroadcast(intent); } } super.onDataChanged(dataEvents); }
Example 15
Source File: AndroidWear.java From ibm-wearables-android-sdk with Apache License 2.0 | 5 votes |
@Override public void onDataChanged(final DataEventBuffer dataEvents) { for (DataEvent event : dataEvents) { if (event.getType() == DataEvent.TYPE_CHANGED) { DataItem item = event.getDataItem(); if (item.getUri().getPath().compareTo("/sensors") == 0) { DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap(); parseDataMap(dataMap); } } } }
Example 16
Source File: MainActivity.java From DronesWear with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent event : dataEvents) { DataItem dataItem = event.getDataItem(); Message.MESSAGE_TYPE messageType = Message.getMessageType(dataItem); if (event.getType() == DataEvent.TYPE_DELETED) { switch (messageType) { case ACC: synchronized (mDroneLock) { if (mDrone != null && mUseWatchAccelero) { mDrone.stopPiloting(); } } break; case JOYSTICK: synchronized (mDroneLock) { if (mDrone != null) { mDrone.stopPiloting(); } } break; } } else if (event.getType() == DataEvent.TYPE_CHANGED) { switch (messageType) { case ACC: synchronized (mDroneLock) { if (mDrone != null && mUseWatchAccelero) { AccelerometerData accelerometerData = Message.decodeAcceleroMessage(dataItem); if (accelerometerData != null) { mDrone.pilotWithAcceleroData(accelerometerData); } else { mDrone.stopPiloting(); } } } break; case JOYSTICK: synchronized (mDroneLock) { if (mDrone != null) { JoystickData joystickData = Message.decodeJoystickMessage(dataItem); if (joystickData != null) { mDrone.pilotWithJoystickData(joystickData); } else { mDrone.stopPiloting(); } } } break; case ACTION: if (mDrone != null) { mDrone.sendAction(); } break; } } } }
Example 17
Source File: QuizListenerService.java From android-Quiz with Apache License 2.0 | 4 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .build(); ConnectionResult connectionResult = googleApiClient.blockingConnect(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "QuizListenerService failed to connect to GoogleApiClient."); return; } for (DataEvent event : dataEvents) { if (event.getType() == DataEvent.TYPE_CHANGED) { DataItem dataItem = event.getDataItem(); DataMap dataMap = DataMapItem.fromDataItem(dataItem).getDataMap(); if (dataMap.getBoolean(QUESTION_WAS_ANSWERED) || dataMap.getBoolean(QUESTION_WAS_DELETED)) { // Ignore the change in data; it is used in MainActivity to update // the question's status (i.e. was the answer right or wrong or left blank). continue; } String question = dataMap.getString(QUESTION); int questionIndex = dataMap.getInt(QUESTION_INDEX); int questionNum = questionIndex + 1; String[] answers = dataMap.getStringArray(ANSWERS); int correctAnswerIndex = dataMap.getInt(CORRECT_ANSWER_INDEX); Intent deleteOperation = new Intent(this, DeleteQuestionService.class); deleteOperation.setData(dataItem.getUri()); PendingIntent deleteIntent = PendingIntent.getService(this, 0, deleteOperation, PendingIntent.FLAG_UPDATE_CURRENT); // First page of notification contains question as Big Text. Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle() .setBigContentTitle(getString(R.string.question, questionNum)) .bigText(question); Notification.Builder builder = new Notification.Builder(this) .setStyle(bigTextStyle) .setSmallIcon(R.drawable.ic_launcher) .setLocalOnly(true) .setDeleteIntent(deleteIntent); // Add answers as actions. Notification.WearableExtender wearableOptions = new Notification.WearableExtender(); for (int i = 0; i < answers.length; i++) { Notification answerPage = new Notification.Builder(this) .setContentTitle(question) .setContentText(answers[i]) .extend(new Notification.WearableExtender() .setContentAction(i)) .build(); boolean correct = (i == correctAnswerIndex); Intent updateOperation = new Intent(this, UpdateQuestionService.class); // Give each intent a unique action. updateOperation.setAction("question_" + questionIndex + "_answer_" + i); updateOperation.setData(dataItem.getUri()); updateOperation.putExtra(UpdateQuestionService.EXTRA_QUESTION_INDEX, questionIndex); updateOperation.putExtra(UpdateQuestionService.EXTRA_QUESTION_CORRECT, correct); PendingIntent updateIntent = PendingIntent.getService(this, 0, updateOperation, PendingIntent.FLAG_UPDATE_CURRENT); Notification.Action action = new Notification.Action.Builder( questionNumToDrawableId.get(i), null, updateIntent) .build(); wearableOptions.addAction(action).addPage(answerPage); } builder.extend(wearableOptions); Notification notification = builder.build(); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .notify(questionIndex, notification); } else if (event.getType() == DataEvent.TYPE_DELETED) { Uri uri = event.getDataItem().getUri(); // URI's are of the form "/question/0", "/question/1" etc. // We use the question index as the notification id. int notificationId = Integer.parseInt(uri.getLastPathSegment()); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .cancel(notificationId); } // Delete the quiz report, if it exists. ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .cancel(QUIZ_REPORT_NOTIF_ID); } googleApiClient.disconnect(); }
Example 18
Source File: QuizListenerService.java From AndroidWearable-Samples with Apache License 2.0 | 4 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .build(); ConnectionResult connectionResult = googleApiClient.blockingConnect(CONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "QuizListenerService failed to connect to GoogleApiClient."); return; } for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED) { DataItem dataItem = event.getDataItem(); DataMap dataMap = DataMapItem.fromDataItem(dataItem).getDataMap(); if (dataMap.getBoolean(QUESTION_WAS_ANSWERED) || dataMap.getBoolean(QUESTION_WAS_DELETED)) { // Ignore the change in data; it is used in MainActivity to update // the question's status (i.e. was the answer right or wrong or left blank). continue; } String question = dataMap.getString(QUESTION); int questionIndex = dataMap.getInt(QUESTION_INDEX); int questionNum = questionIndex + 1; String[] answers = dataMap.getStringArray(ANSWERS); int correctAnswerIndex = dataMap.getInt(CORRECT_ANSWER_INDEX); Intent deleteOperation = new Intent(this, DeleteQuestionService.class); deleteOperation.setData(dataItem.getUri()); PendingIntent deleteIntent = PendingIntent.getService(this, 0, deleteOperation, PendingIntent.FLAG_UPDATE_CURRENT); // First page of notification contains question as Big Text. Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle() .setBigContentTitle(getString(R.string.question, questionNum)) .bigText(question); Notification.Builder builder = new Notification.Builder(this) .setStyle(bigTextStyle) .setSmallIcon(R.drawable.ic_launcher) .setLocalOnly(true) .setDeleteIntent(deleteIntent); // Add answers as actions. Notification.WearableExtender wearableOptions = new Notification.WearableExtender(); for (int i = 0; i < answers.length; i++) { Notification answerPage = new Notification.Builder(this) .setContentTitle(question) .setContentText(answers[i]) .extend(new Notification.WearableExtender() .setContentAction(i)) .build(); boolean correct = (i == correctAnswerIndex); Intent updateOperation = new Intent(this, UpdateQuestionService.class); // Give each intent a unique action. updateOperation.setAction("question_" + questionIndex + "_answer_" + i); updateOperation.setData(dataItem.getUri()); updateOperation.putExtra(UpdateQuestionService.EXTRA_QUESTION_INDEX, questionIndex); updateOperation.putExtra(UpdateQuestionService.EXTRA_QUESTION_CORRECT, correct); PendingIntent updateIntent = PendingIntent.getService(this, 0, updateOperation, PendingIntent.FLAG_UPDATE_CURRENT); Notification.Action action = new Notification.Action.Builder( questionNumToDrawableId.get(i), null, updateIntent) .build(); wearableOptions.addAction(action).addPage(answerPage); } builder.extend(wearableOptions); Notification notification = builder.build(); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .notify(questionIndex, notification); } else if (event.getType() == DataEvent.TYPE_DELETED) { Uri uri = event.getDataItem().getUri(); // URI's are of the form "/question/0", "/question/1" etc. // We use the question index as the notification id. int notificationId = Integer.parseInt(uri.getLastPathSegment()); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .cancel(notificationId); } // Delete the quiz report, if it exists. ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .cancel(QUIZ_REPORT_NOTIF_ID); } googleApiClient.disconnect(); }
Example 19
Source File: PixelWatchFace.java From PixelWatchFace with GNU General Public License v3.0 | 4 votes |
@Override public void onDataChanged(DataEventBuffer dataEvents) { String TAG = "onDataChanged"; Log.d(TAG, "Data changed"); DataMap dataMap = new DataMap(); for (DataEvent event : dataEvents) { if (event.getType() == DataEvent.TYPE_CHANGED) { // DataItem changed DataItem item = event.getDataItem(); Log.d(TAG, "DataItem uri: " + item.getUri()); if (item.getUri().getPath().compareTo("/settings") == 0) { Log.d(TAG, "Companion app changed a setting!"); dataMap = DataMapItem.fromDataItem(item).getDataMap(); Log.d(TAG, dataMap.toString()); // handle legacy nested data map if (dataMap.containsKey("com.corvettecole.pixelwatchface")) { dataMap = dataMap.getDataMap("com.corvettecole.pixelwatchface"); } Log.d(TAG, dataMap.toString()); for (UpdatesRequired updateRequired : mSettings.updateSettings(dataMap)) { switch (updateRequired) { case WEATHER: initWeatherUpdater(true); break; case FONT: updateFontConfig(); break; } } invalidate();// forces redraw //syncToPhone(); } else if (item.getUri().getPath().compareTo("/requests") == 0) { if (dataMap.containsKey("settings-update")) { } } } else if (event.getType() == DataEvent.TYPE_DELETED) { // DataItem deleted } } }