@Override public void onDataChanged(DataEventBuffer dataEvents) { final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); for (DataEvent event : events) { Uri uri = event.getDataItem().getUri(); String path = uri.getPath(); if (WEAR_PATH.equals(path)) { DataMapItem item = DataMapItem.fromDataItem(event.getDataItem()); byte[] realmAsset = item.getDataMap().getByteArray(DATA_ASSET_FILE); if (realmAsset != null) { toFile(realmAsset); getBaseContext().sendBroadcast(new Intent(DATA_STORY_CHANGED)); } } } }
@Override public void onDataChanged(DataEventBuffer dataEventBuffer) { final List<DataEvent> events = FreezableUtils.freezeIterable(dataEventBuffer); for(DataEvent event : events) { if (WearMessages.MESSAGE_BOT_LIST.equalsIgnoreCase(event.getDataItem().getUri().getPath())) { final DataMap map = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); ArrayList<DataMap> botList = map.getDataMapArrayList(WearMessages.MAPENTRY_BOT_LIST); WearBot[] bots = new WearBot[botList.size()]; for (int i = 0; i < botList.size(); i++) { bots[i] = new WearBot(botList.get(i)); } getListener().updateBotList(bots); } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { Log.d(TAG, "onDataChanged"); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); for (DataEvent event : events) { Uri uri = event.getDataItem().getUri(); String path = uri.getPath(); if (Tools.WEAR_PATH.equals(path)) { DataMapItem item = DataMapItem.fromDataItem(event.getDataItem()); byte[] realmAsset = item.getDataMap().getByteArray(Tools.DATA_ASSET_FILE); if(realmAsset != null){ toFile(realmAsset); getBaseContext().sendBroadcast(new Intent(Tools.DATA_STORY_CHANGED)); } } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { Log.d(TAG, "onDataChanged: " + dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); for (DataEvent event : events) { Log.d(TAG, "Event: " + event.getDataItem().toString()); Uri uri = event.getDataItem().getUri(); String path = uri.getPath(); if (path.equals(Path.GRADE_SYSTEM)) { DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); String gradeSystem = dataMapItem.getDataMap().getString(Path.GRADE_SYSTEM_KEY); if (gradeSystem != null) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = sharedPref.edit(); editor.putString(Path.PREF_GRAD_SYSTEM_TYPE, gradeSystem); editor.commit(); } } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { super.onDataChanged(dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); if (!mGoogleApiClient.isConnected()) { ConnectionResult connectionResult = mGoogleApiClient .blockingConnect(30, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "Service failed to connect to GoogleApiClient."); return; } } for(DataEvent event : events) { if(event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); if(DataInterface.PATH_NOTIFICATION.equals(path)) { DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); updateOrShowNotification(dataMapItem); } } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { final ArrayList<DataEvent> events = FreezableUtils .freezeIterable(dataEvents); for (DataEvent event : events) { DataItem item = event.getDataItem(); String path = item.getUri().getPath(); Log.d("ggvp", "received data for " + path); if(event.getType() == DataEvent.TYPE_CHANGED && path.equals("/filters")) { DataMap map = DataMapItem.fromDataItem(item).getDataMap(); ArrayList<String> filters = map.getStringArrayList("filters"); WearApp.APP.updateFilters(filters); } } }
@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); } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { ArrayList<DataEvent> dataEvents1 = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); for (DataEvent event : dataEvents1) { DataItem dataItem = event.getDataItem(); String[] parts = dataItem.getUri().getPath().split("/"); switch (parts[1]) { case "image": String photoId = parts[2]; switch (event.getType()) { case DataEvent.TYPE_CHANGED: photos.put(photoId, dataItem); // Show new image immediately (even in ambient mode). updateImage(dataItem); extraWake(); break; case DataEvent.TYPE_DELETED: photos.remove(photoId); if (currentPhoto.equals(photoId)) setEmptyBackground(); break; } } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { Log.i(TAG, "onDataChanged: " + dataEvents); final List<DataEvent> events = FreezableUtils .freezeIterable(dataEvents); // Loop through the events and send a message // to the node that created the data item. for (DataEvent event : events) { Log.i(TAG, event.toString()); if(event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); if (path.equals(PLAYLISTS_PATH)) { DataMap dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap(); Log.v("myTag", "DataMap received on watch: " + dataMap.toString()); writeFile(dataMap.toByteArray()); } } } }
@Override //DataListener public void onDataChanged(DataEventBuffer dataEvents) { LOGD(TAG, "onDataChanged: " + dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); runOnUiThread(new Runnable() { @Override public void run() { for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED) { mDataItemListAdapter.add( new Event("DataItem Changed", event.getDataItem().toString())); } else if (event.getType() == DataEvent.TYPE_DELETED) { mDataItemListAdapter.add( new Event("DataItem Deleted", event.getDataItem().toString())); } } } }); }
@Override public void onDataChanged(DataEventBuffer dataEvents) { Log.d(TAG, "onDataChanged"); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); for (DataEvent event : events) { Uri uri = event.getDataItem().getUri(); String path = uri.getPath(); if (Tools.WEAR_PATH.equals(path)) { DataMapItem item = DataMapItem.fromDataItem(event.getDataItem()); String codeText = item.getDataMap().getString(Tools.WEAR_KEY_BANKS_CODE); if(codeText != null) { String contentArr [] = codeText.split("<<>>"); codeText = contentArr[0]; if(codeText != null && !codeText.equals("")){ makeNotification(codeText); } } } } }
@Override //DataListener public void onDataChanged(DataEventBuffer dataEvents) { LOGD(TAG, "onDataChanged: " + dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); runOnUiThread(new Runnable() { @Override public void run() { for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED) { // mDataItemListAdapter.clear(); // mDataItemListAdapter.notifyDataSetChanged(); // mDataItemListAdapter.add( new Event("Mobile DataItem Changed",event.getDataItem().toString())); } else if (event.getType() == DataEvent.TYPE_DELETED) { mDataItemListAdapter.add( new Event("DataItem Deleted", event.getDataItem().toString())); } } } }); }
@Override public void onDataChanged(DataEventBuffer dataEvents) { final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); if (IMAGE_PATH.equals(path)) { DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); Asset photo = dataMapItem.getDataMap() .getAsset(IMAGE_KEY); final Bitmap bitmap = loadBitmapFromAsset(googleApiClient, photo); handler.post(new Runnable() { @Override public void run() { imageView.setImageBitmap(bitmap); } }); } } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { super.onDataChanged(dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); for (final DataEvent event : events) { final BitcoinPrice bitcoinPrice = getBitcoinPriceFromDataEvent(event); storage.storePrice(bitcoinPrice); } }
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(); } } }); }
@Override public void onDataChanged(DataEventBuffer dataEvents) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "onDataChanged: " + dataEvents); } final List<DataEvent> events = FreezableUtils .freezeIterable(dataEvents); ConnectionResult connectionResult = mGoogleApiClient.blockingConnect(30, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "Failed to connect to GoogleApiClient."); return; } // Loop through the events and send a message // to the node that created the data item. for (DataEvent event : events) { Uri uri = event.getDataItem().getUri(); // Get the node id from the host value of the URI String nodeId = uri.getHost(); // Set the data of the message to be the bytes of the URI. byte[] payload = uri.toString().getBytes(); // Send the RPC Wearable.MessageApi.sendMessage(mGoogleApiClient, nodeId, DATA_ITEM_RECEIVED_PATH, payload); } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED) { DataItem item = event.getDataItem(); DataManager.getInstance(this).fetchDataFromService(item); } else if (event.getType() == DataEvent.TYPE_DELETED) { // TODO: What does it mean when the DataItem was deleted? } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { super.onDataChanged(dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); for (DataEvent event : events) { Intent intent = new Intent(); intent.setAction("pl.tajchert.servicewear.wearservice"); intent.putExtra(ServiceWearConst.WEAR_EVENT_KEY, ServiceWearConst.ON_DATA_CHANGE_EVENT); intent.putExtra(ServiceWearConst.INTENT_DATA_PATH, event.getDataItem().getUri().toString()); intent.putExtra(ServiceWearConst.INTENT_DATA_DATA, event.getDataItem().getData()); sendBroadcast(intent); } }
/** * 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; }
@Override public void onDataChanged(DataEventBuffer dataEvents) { LOGD(TAG, "onDataChanged: " + dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); if(!mGoogleApiClient.isConnected()) { ConnectionResult connectionResult = mGoogleApiClient .blockingConnect(30, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "DataLayerListenerService failed to connect to GoogleApiClient."); return; } } // Loop through the events and send a message back to the node that created the data item. for (DataEvent event : events) { Uri uri = event.getDataItem().getUri(); String path = uri.getPath(); if (COUNT_PATH.equals(path)) { // Get the node id of the node that created the data item from the host portion of // the uri. String nodeId = uri.getHost(); // Set the data of the message to be the bytes of the Uri. byte[] payload = uri.toString().getBytes(); // Send the rpc Wearable.MessageApi.sendMessage(mGoogleApiClient, nodeId, DATA_ITEM_RECEIVED_PATH, payload); } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { LOGD(TAG, "onDataChanged(): " + dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); if (DataLayerListenerService.IMAGE_PATH.equals(path)) { DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); Asset photo = dataMapItem.getDataMap() .getAsset(DataLayerListenerService.IMAGE_KEY); final Bitmap bitmap = loadBitmapFromAsset(mGoogleApiClient, photo); mHandler.post(new Runnable() { @Override public void run() { Log.d(TAG, "Setting background image.."); mLayout.setBackground(new BitmapDrawable(getResources(), bitmap)); } }); } else if (DataLayerListenerService.COUNT_PATH.equals(path)) { LOGD(TAG, "Data Changed for COUNT_PATH"); generateEvent("DataItem Changed", event.getDataItem().toString()); } else { LOGD(TAG, "Unrecognized path: " + path); } } else if (event.getType() == DataEvent.TYPE_DELETED) { generateEvent("DataItem Deleted", event.getDataItem().toString()); } else { generateEvent("Unknown data event type", "Type = " + event.getType()); } } }
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 public void onDataChanged(DataEventBuffer dataEvents) { Log.d(TAG, "onDataChanged"); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "onDataChanged: " + dataEvents); } GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this) .addApi(Wearable.API) .build(); ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "Failed to connect to GoogleApiClient."); return; } //dataEvents.close(); for (DataEvent event : events) { Uri uri = event.getDataItem().getUri(); String path = uri.getPath(); Log.d(TAG, "Update, path: " +path); if (Tools.WEAR_PATH.equals(path)) { DataMapItem item = DataMapItem.fromDataItem(event.getDataItem()); String weatherText = item.getDataMap().getString(Tools.WEAR_KEY_SWEAR_TEXT); Log.d(TAG, "got: " + weatherText); if(weatherText != null) { weatherText = weatherText.replaceAll("\\d",""); if(!weatherText.equals("")){ getBaseContext().getSharedPreferences(Tools.PREFS, MODE_PRIVATE).edit().putString(Tools.PREFS_KEY_SWEAR_TEXT, weatherText).commit(); getBaseContext().sendBroadcast(new Intent(Tools.DATA_CHANGED_ACTION)); } } } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { LOGD(TAG, "onDataChanged: " + dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); if(!mGoogleApiClient.isConnected()) { ConnectionResult connectionResult = mGoogleApiClient .blockingConnect(10, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "DataLayerListenerService failed to connect to GoogleApiClient."); return; } } // Loop through the events and send a message back to the node that created the data item. for (DataEvent event : events) { Uri uri = event.getDataItem().getUri(); String path = uri.getPath(); if (COUNT_PATH.equals(path)) { // Get the node id of the node that created the data item from the host portion of String str=linear_acceleration[0]+","+linear_acceleration[1]+","+linear_acceleration[2]+ ";"+rotation[0]+","+rotation[1]+","+rotation[2] + ";" +steps+ ";"+heartRate; Wearable.MessageApi.sendMessage(mGoogleApiClient,"nodeId",str,str.getBytes()); } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { super.onDataChanged(dataEvents); Log.d(TAG_LOG, "onDataChanged(" + dataEvents + ")"); // Extracting the DataEvent(s). final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); // Running through all the events for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED) { // Checking if it's the same node that has fired the event final String node = event.getDataItem().getUri().getHost(); final String localNode = WearableUtil.getLocalNode(this).getId(); if (node.equals(localNode)) { Log.d(TAG_LOG, "Skipping Event because fired from the same receiver."); continue; } final Event.DataApi.Item item = Event.DataApi.Item.from(event.getDataItem()); String where = item.where(); String[] whereArgs = item.whereArgs(); // In a real application case you can create a builder for these kind of operations, // it definitely keeps the code cleaner, more readable and maintainable. if (TextUtils.isEmpty(where)) { where = WHERE_BEFORE; whereArgs = new String[]{String.valueOf(item.time())}; } else { where = "(" + where + ") AND " + WHERE_BEFORE; whereArgs = ArraysUtil.concatenate(whereArgs, new String[]{String.valueOf(item.time())}); } getContentResolver().update(item.uri(), item.values(), where, whereArgs); } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { Log.d(TAG, "onDataChanged: " + dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); String gradeSystemType = sharedPref.getString(Path.PREF_GRAD_SYSTEM_TYPE, GradeList.SYSTEM_DEFAULT); Location lastLocation = null; if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { lastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); } for (DataEvent event : events) { Log.d(TAG, "Event: " + event.getDataItem().toString()); Uri uri = event.getDataItem().getUri(); String path = uri.getPath(); if (path.startsWith(Path.CLIMB)) { DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); String routeGradeLabel = dataMapItem.getDataMap().getString(Path.ROUTE_GRADE_LABEL_KEY); Date climbDate = new Date(dataMapItem.getDataMap().getLong(Path.CLIMB_DATE_KEY)); // check that climb date and location date are not too far, do not save location if so. double latitude = 0; double longitude = 0; if(lastLocation != null && Math.abs(lastLocation.getTime() - climbDate.getTime()) < MAX_TIME_FOR_LOCATION) { latitude = lastLocation.getLatitude(); longitude = lastLocation.getLongitude(); } if (routeGradeLabel != null) { Log.d(TAG, "New Climb, grade : " + routeGradeLabel + " " + climbDate.toString()); AuthData authData = mFirebaseRef.getAuth(); if (authData != null) { Climb newClimb = new Climb(climbDate, routeGradeLabel, gradeSystemType, latitude, longitude); mFirebaseRef.child("users") .child(authData.getUid()) .child("climbs") .push().setValue(newClimb); } } } } }
@Override //Whenever data is changed, this is launched public void onDataChanged(DataEventBuffer dataEvents) { //Get all of our evnets and put into a list final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); //If our client has lost connection, try reconnecting, if we cant, return and leave if (!GoogClient.isConnected()) { ConnectionResult connectionResult = GoogClient .blockingConnect(30, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { //Could not connect to the api return; } } //For all of our data events that we receive, do this for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); //Put our path if else statements here if(path.equals(PATHNEXT)) { handler.post(new Runnable() { public void run() { Ui.next(Ui.filePath); } }); } else if(path.equals(PATHPLAY)) { handler.post(new Runnable() { public void run() { Ui.playPause(Ui.filePath); } }); } else if(path.equals(PATHPREV)) { handler.post(new Runnable() { public void run() { Ui.prev(Ui.filePath); } }); } else if(path.equals(PATHQUIT)) { // send a quit broadcast Intent quit = new Intent(Intent.ACTION_MEDIA_BUTTON, null); KeyEvent quitEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ESCAPE, 0); quit.setAction(Intent.ACTION_MEDIA_BUTTON); quit.putExtra(Intent.EXTRA_KEY_EVENT, quitEvent); sendBroadcast(quit); } else { //The path is not recognized } } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { LOGD(TAG, "onDataChanged: " + dataEvents); final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); if(!mGoogleApiClient.isConnected()) { ConnectionResult connectionResult = mGoogleApiClient.blockingConnect(30, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "BinaryWatchFaceConfigListenerService failed to connect to GoogleApiClient."); return; } } // Loop through the events and send a message back to the node that created the data item. for (DataEvent event : events) { Uri uri = event.getDataItem().getUri(); String path = uri.getPath(); DataMapItem item = DataMapItem.fromDataItem(event.getDataItem()); switch (path) { case CommonConstants.DATA_PATH_DOT_COLOR: putIntPreference(KEY_DOT_COLOR, item.getDataMap().getInt(CommonConstants.DATA_VALUE)); break; case CommonConstants.DATA_PATH_BACKGROUND_COLOR: putIntPreference(KEY_BACKGROUND_COLOR, item.getDataMap().getInt(CommonConstants.DATA_VALUE)); break; case CommonConstants.DATA_PATH_DOT_COLOR_RESET: removePreference(KEY_DOT_COLOR); break; case CommonConstants.DATA_PATH_BACKGROUND_COLOR_RESET: removePreference(KEY_BACKGROUND_COLOR); break; case CommonConstants.DATA_PATH_CHANGE_LAYOUT: putIntPreference(KEY_LAYOUT, item.getDataMap().getInt(CommonConstants.DATA_VALUE, CommonConstants.PREFS_LAYOUT_VERTICAL)); break; case CommonConstants.DATA_PATH_SHOW_DIGITAL_TIME: putBooleanPreference(KEY_SHOW_DIGITAL_TIME, item.getDataMap().getBoolean(CommonConstants.DATA_VALUE, false)); } getBaseContext().sendBroadcast(new Intent(Constants.NEW_CONFIGURATION_RECEIVED)); } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { LOGD(TAG, "onDataChanged(): " + dataEvents); int i=0; final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); if (DataLayerListenerService.IMAGE_PATH.equals(path)) { DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); Asset photo = dataMapItem.getDataMap() .getAsset(DataLayerListenerService.IMAGE_KEY); final Bitmap bitmap = loadBitmapFromAsset(mGoogleApiClient, photo); mHandler.post(new Runnable() { @Override public void run() { Log.d(TAG, "Setting background image.."); mLayout.setBackground(new BitmapDrawable(getResources(), bitmap)); } }); } else if (DataLayerListenerService.COUNT_PATH.equals(path)) { LOGD(TAG, "Data Changed for COUNT_PATH"); if(mDataItemListAdapter.getCount()<=1){ history_path=path; generateEvent("DataItem Changed", path); } if(!history_path.equals(path)){ generateEvent("DataItem Changed", path); history_path=path; } } else { LOGD(TAG, "Unrecognized path: " + path); } } else if (event.getType() == DataEvent.TYPE_DELETED) { generateEvent("DataItem Deleted", event.getDataItem().toString()); } else { generateEvent("Unknown data event type", "Type = " + event.getType()); } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); if (!mGoogleApiClient.isConnected()) { ConnectionResult connectionResult = mGoogleApiClient .blockingConnect(30, TimeUnit.SECONDS); if (!connectionResult.isSuccess()) { Log.e(TAG, "Service failed to connect to GoogleApiClient."); return; } } for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED) { String path = event.getDataItem().getUri().getPath(); if (Constants.PATH_NOTIFICATION.equals(path)) { // Get the data out of the event DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); final String title = dataMapItem.getDataMap().getString(Constants.KEY_TITLE); Asset asset = dataMapItem.getDataMap().getAsset(Constants.KEY_IMAGE); // Build the intent to display our custom notification Intent notificationIntent = new Intent(this, NotificationActivity.class); notificationIntent.putExtra(NotificationActivity.EXTRA_TITLE, title); notificationIntent.putExtra(NotificationActivity.EXTRA_IMAGE, asset); PendingIntent notificationPendingIntent = PendingIntent.getActivity( this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Create the ongoing notification // Use this for multipage notifications // Notification secondPageNotification = // new Notification.Builder(this) // .extend(new Notification.WearableExtender() // .setDisplayIntent(notificationPendingIntent)) // .build(); Notification.Builder notificationBuilder = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .extend(new Notification.WearableExtender() .setDisplayIntent(notificationPendingIntent) // .addPage(secondPageNotification) ); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .notify(NOTIFICATION_ID, notificationBuilder.build()); } else { Log.d(TAG, "Unrecognized path: " + path); } } } }
@Override public void onDataChanged(DataEventBuffer dataEvents) { // TODO TODO TODO check that // it's for usage outside the callscope final List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents); dataEvents.close(); Log.d(TAG, "onDataChanged"); for (DataEvent event : events) { if (event.getType() == DataEvent.TYPE_CHANGED) { Log.d(TAG, "DataItem changed: " + event.getDataItem().getUri()); if (event.getDataItem().getUri().getPath().equals(Util.GAC_PATH_SENSOR_DATA)) { Intent mServiceIntent = new Intent(this, AssetConsumer.class); mServiceIntent.setAction(AssetConsumer.ACTION_START_SERVICE); this.startService(mServiceIntent); /* Log.d(TAG, "trying to extract asset"); DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem()); String fileName = dataMapItem.getDataMap().getString(Util.SENSOR_FILE_NAME); Asset profileAsset = dataMapItem.getDataMap().getAsset(Util.SENSOR_FILE); saveFileFromAsset(fileName, profileAsset); // TODO error handling ConnectionResult result = mGoogleApiClient.blockingConnect(1000, TimeUnit.MILLISECONDS); if (!result.isSuccess()) { Log.d(TAG, "GoogleClientConnect was false"); return; } Uri.Builder uri = new Uri.Builder().scheme(PutDataRequest.WEAR_URI_SCHEME).path(Util.GAC_PATH_SENSOR_DATA); Wearable.DataApi.deleteDataItems(mGoogleApiClient, uri.build()).await(); sendMessage(this, Util.GAC_PATH_CONFIRM_FILE_RECEIVED, fileName); mGoogleApiClient.disconnect(); Log.d(TAG, "SensorDataFileName: " + fileName); */ } } } // mGoogleApiClient.disconnect(); }