Java Code Examples for com.google.android.gms.wearable.DataMap#getDataMap()
The following examples show how to use
com.google.android.gms.wearable.DataMap#getDataMap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: 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 } } }
Example 2
Source File: ListenerService.java From sms-ticket with Apache License 2.0 | 4 votes |
private void processNotification(DataMap dataMap) { DataMap dataMap1 = dataMap.getDataMap("notification"); Ticket ticket = new Ticket(); ticket.setId(dataMap1.getLong("id")); ticket.setCityId(dataMap1.getLong("city_id")); ticket.setCity(dataMap1.getString("city")); ticket.setStatus(dataMap1.getInt("status")); ticket.setHash(dataMap1.getString("hash")); ticket.setText(dataMap1.getString("text")); ticket.setValidFrom(dataMap1.getLong("valid_from")); ticket.setValidTo(dataMap1.getLong("valid_to")); ticket.setNotificationId(dataMap1.getLong("notification_id")); Intent notificationIntent = new Intent(this, NotificationActivity.class); notificationIntent.putExtra("ticket", ticket); PendingIntent notificationPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); int notificationColor = 0; if (ticket.getStatus() == NotificationActivity.STATUS_VALID_EXPIRING) { notificationColor = getResources().getColor(R.color.background_city_yellow); } else if (ticket.getStatus() == NotificationActivity.STATUS_EXPIRING_EXPIRED) { notificationColor = getResources().getColor(R.color.background_city_red); } else if (ticket.getStatus() == NotificationActivity.STATUS_EXPIRED) { notificationColor = getResources().getColor(R.color.background_city_transparent); } // Create a big text style for the second page NotificationCompat.BigTextStyle secondPageStyle = new NotificationCompat.BigTextStyle(); secondPageStyle.setBigContentTitle(getResources().getString(R.string.sms)) .bigText(ticket.getText()); Notification secondPageNotification = new NotificationCompat.Builder(this) .setStyle(secondPageStyle) .build(); Intent intent = new Intent(this, OpenPhoneReceiver.class); intent.setAction("eu.inmite.apps.smsjizdenka.openphone"); intent.putExtra("ticket", ticket); PendingIntent openPhonePendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); int resourceIdForCity = Constants.CITIES_BACKGROUND_MAP.containsKey(ticket.getCityId()) ? Constants .CITIES_BACKGROUND_MAP.get(ticket.getCityId()) : 0; Notification notification = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentText(getStatusTitle(ticket)) .extend(new Notification.WearableExtender() .setDisplayIntent(notificationPendingIntent) .setCustomContentHeight(getResources().getDimensionPixelSize(R.dimen.notification_size)) .setStartScrollBottom(true) .setBackground(ImageUtil.combineTwoImages(this, resourceIdForCity, notificationColor)) .addPage(secondPageNotification) .addAction(new Notification.Action(R.drawable.go_to_phone_00156, "Open on phone", openPhonePendingIntent))) .build(); notification.defaults |= Notification.DEFAULT_VIBRATE; NotificationManager notificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify((int)ticket.getNotificationId(), notification); }
Example 3
Source File: DataBundleUtil.java From android_external_GmsLib with Apache License 2.0 | 4 votes |
@Override DataMap load(DataMap dataMap, String key) { return dataMap.getDataMap(key); }