@Override
    public void onDataChanged(DataEventBuffer dataEventBuffer) {
      for (DataEvent dataEvent : dataEventBuffer) {
        if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
          DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();
          String path = dataEvent.getDataItem().getUri().getPath();

          Log.v("BuntinLog", "onDataChanged hit");
          final String WEAR_PATH = "/sunshinewear";
          final String WEAR_HIGH = "high";
          final String WEAR_LOW = "low";
          final String WEAR_WEATHER_ID = "weatherId";

          if (path.equals(WEAR_PATH)) {
            if (dataMap.containsKey(WEAR_HIGH)) {
              mHigh = dataMap.getString(WEAR_HIGH);
            }
            if (dataMap.containsKey(WEAR_LOW)) {
              mLow = dataMap.getString(WEAR_LOW);
            }
            if (dataMap.containsKey(WEAR_WEATHER_ID)) {
              int weatherId = dataMap.getInt(WEAR_WEATHER_ID);
              mWeatherImage = Utility.getImages(weatherId);
            }
          }

          invalidate();
        }
      }
    }
  @Override
  public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent event : dataEvents) {
      if (event.getType() == DataEvent.TYPE_CHANGED) {

        DataMap map = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();

        String path = event.getDataItem().getUri().getPath();

        if ("/sunshine".equals(path)) {
          high = map.getDouble("temp-high");
          low = map.getDouble("temp-low");
          weatherId = map.getInt("weather-id");

          Log.d(LOG_TAG, high + "-" + low + "-" + weatherId);

          Intent intent = new Intent("weather-data");

          intent.putExtra("temp-high", high);
          intent.putExtra("temp-low", low);
          intent.putExtra("weather-id", weatherId);

          LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
        }
      }
    }
  }
 @Override
 public void onDataChanged(DataEventBuffer dataEvents) {
   for (DataEvent dataEvent : dataEvents) {
     if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
       if (Constants.NOTIFICATION_PATH.equals(dataEvent.getDataItem().getUri().getPath())) {
         DataMapItem dataMapItem = DataMapItem.fromDataItem(dataEvent.getDataItem());
         String title = dataMapItem.getDataMap().getString(Constants.NOTIFICATION_TITLE);
         String content = dataMapItem.getDataMap().getString(Constants.NOTIFICATION_CONTENT);
         sendNotification(title, content);
       }
     }
   }
 }
Exemple #4
0
 @Override
 public void onDataChanged(DataEventBuffer dataEventBuffer) {
   for (DataEvent event : dataEventBuffer) {
     if (event.getType() == DataEvent.TYPE_CHANGED) {
       DataItem item = event.getDataItem();
       DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
       if (item.getUri().getPath().compareTo("/headReq") == 0) {
         if (dataMap.getInt("head") == 1 && gameStatus == true) {
           sendHeadVector();
         }
       } else if (item.getUri().getPath().compareTo("/" + RESUME) == 0) {
         if (dataMap.getInt(RESUME) == 1) {
           gameStatus = true;
         }
       } else if (item.getUri().getPath().compareTo("/" + PAUSE) == 0) {
         if (dataMap.getInt(PAUSE) == 1) {
           gameStatus = false;
         }
       } else if (item.getUri().getPath().compareTo("/" + RESTART) == 0) {
         if (dataMap.getInt(RESTART) == 1) {
           gameStatus = true;
         }
       }
     }
   }
 }
  @Override
  public void onDataChanged(DataEventBuffer dataEvents) {
    DataMap dataMap;
    for (DataEvent event : dataEvents) {
      if (event.getType() == DataEvent.TYPE_CHANGED) {
        String path = event.getDataItem().getUri().getPath();

        if (path.equals(PATH_WEATHER_INFO)) {}
        dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();

        Intent messageIntent = new Intent();
        messageIntent.setAction(Intent.ACTION_SEND);
        messageIntent.putExtras(dataMap.toBundle());
        LocalBroadcastManager.getInstance(this).sendBroadcast(messageIntent);
      }
    }
  }
  @Override
  public void onDataChanged(DataEventBuffer dataEvents) {
    DataMap dataMap;
    for (DataEvent event : dataEvents) {

      // Check the data type
      if (event.getType() == DataEvent.TYPE_CHANGED) {
        // Check the data path
        dataMap = DataMapItem.fromDataItem(event.getDataItem()).getDataMap();
        String path = event.getDataItem().getUri().getPath();

        if (path.equals(WEARABLE_TO_PHONE_DATA_PATH) && dataMap.containsKey(ACTION_KEY)) {
          doAction(dataMap.getString(ACTION_KEY), dataMap);
        }
      }
    }
  }
  /**
   * Returns the data item modified in this event. An event of TYPE_DELETED will only have its
   * {DataItem#getUri} populated.
   *
   * @param dataEvents The data buffer
   * @param dataPath The data path
   * @return The data item corresponding to the data path or null.
   */
  public DataItem getData(DataEventBuffer dataEvents, String dataPath) {
    if (dataPath == null) {
      if (mConnectionCallBacks != null) {
        mConnectionCallBacks.onConnectionFailed(WearConnectionCallBacks.PATH_NULL_ERROR);
      }
      return null;
    }

    List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents);
    dataEvents.release();
    for (DataEvent event : events) {
      String path = event.getDataItem().getUri().getPath();
      if (dataPath.equalsIgnoreCase(path)) {
        return event.getDataItem();
      }
    }
    return null;
  }
  @Override
  public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent event : dataEvents) {
      if (event.getType() == DataEvent.TYPE_DELETED) {
        Log.d("TAG", "DataItem deleted: " + event.getDataItem().getUri());
      } else if (event.getType() == DataEvent.TYPE_CHANGED) {
        Log.d("TAG", "DataItem changed: " + event.getDataItem().getUri());
        DataMap dataMap = DataMap.fromByteArray(event.getDataItem().getData());
        // variable = dataMap.get~("keyname"); で受け取る

        runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                // 受け取り後の処理をここに
                // resultview.setText(resultstr);
              }
            });
      }
    }
  }
  @Override
  public void onDataChanged(DataEventBuffer dataEvents) {
    for (DataEvent dataEvent : dataEvents) {
      if (dataEvent.getType() == DataEvent.TYPE_CHANGED) {
        DataMap dataMap = DataMapItem.fromDataItem(dataEvent.getDataItem()).getDataMap();
        String message = dataMap.getString(Constants.KEY_TEXT_FROM_SERVER);
        String type = dataMap.getString(Constants.KEY_MESSAGE_TYPE);
        String path = dataEvent.getDataItem().getUri().getPath();

        if (Constants.MESSAGE_WEARABLE_TO_MOBILE_PATH.equals(path)) {
          sendMessageToActivity(message, type);
        }
      } else if (dataEvent.getType() == DataEvent.TYPE_DELETED) {
        Log.d(TAG, "Message deleted");
        if (Log.isLoggable(TAG, Log.DEBUG)) {
          Log.d(TAG, "DataItem deleted: " + dataEvent.getDataItem().getUri().getPath());
        }
        if (Constants.MESSAGE_WEARABLE_TO_MOBILE_PATH.equals(
            dataEvent.getDataItem().getUri().getPath())) {}
      }
    }
  }
Exemple #10
0
 public g(DataEvent dataevent) {
   AQ = dataevent.getType();
   alE = (DataItem) dataevent.getDataItem().freeze();
 }
 @Override
 public void onDataChanged(DataEventBuffer dataEvents) {
   Log.d("onDataChanged", "Received a data change");
   for (DataEvent event : dataEvents) {
     DataItem item = event.getDataItem();
     if (item.getUri().getPath().compareTo(PATH) == 0) {
       DataMap dataMap = DataMapItem.fromDataItem(item).getDataMap();
       String key = dataMap.getString(ACTION_KEY);
       String checkString, dateString, newGroupName, newItemName;
       switch (key) {
         case MAKE_GROUP_KEY:
           Log.d("DATA", "MAKE_GROUP_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           groupReaderDbHelper.insertGroup(groupName);
           updateGroupList();
           break;
         case DELETE_GROUP_KEY:
           Log.d("DATA", "DELETE_GROUP_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           groupReaderDbHelper.deleteGroup(groupName);
           itemReaderDbHelper.deleteItemsInGroup(groupName);
           updateGroupList();
           break;
         case DELETE_ALL_GROUPS_KEY:
           Log.d("DATA", "DELETE_ALL_GROUPS_KEY RECEIVED");
           groupReaderDbHelper.deleteAllGroups();
           itemReaderDbHelper.deleteAllItems();
           updateGroupList();
           break;
         case MAKE_ITEM_KEY:
           Log.d("DATA", "MAKE_ITEM_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemName = dataMap.getString(ITEM_NAME_KEY);
           itemReaderDbHelper.insertItem(groupName, itemName);
           updateItemList();
           break;
         case DELETE_ITEM_KEY:
           Log.d("DATA", "DELETE_ITEM_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemName = dataMap.getString(ITEM_NAME_KEY);
           itemReaderDbHelper.deleteItem(groupName, itemName);
           updateItemList();
           break;
         case DELETE_ALL_ITEMS_IN_GROUP_KEY:
           Log.d("DATA", "DELETE_ALL_ITEMS_IN_GROUP_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemReaderDbHelper.deleteItemsInGroup(groupName);
           updateItemList();
           break;
         case CHECK_KEY:
           Log.d("DATA", "CHECK_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemName = dataMap.getString(ITEM_NAME_KEY);
           checkString = dataMap.getString(CHECK_KEY);
           switch (checkString) {
             case "0":
               itemReaderDbHelper.uncheckItem(groupName, itemName);
               uncheckItem(itemName);
               break;
             case "1":
               // TODOs : change to using broadcast receiver instead
               itemReaderDbHelper.checkItem(groupName, itemName);
               checkItem(itemName);
               break;
           }
           break;
         case DATE_KEY:
           Log.d("DATA", "DATE_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemName = dataMap.getString(ITEM_NAME_KEY);
           dateString = dataMap.getString(DATE_KEY);
           SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd");
           try {
             Date date = sdf.parse(dateString);
             itemReaderDbHelper.updateDateCheckedItem(groupName, itemName, date);
             updateItemList();
           } catch (Exception e) {
             System.out.println(e);
           }
           break;
         case COPY_KEY:
           Log.d("DATA", "COPY_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemName = dataMap.getString(ITEM_NAME_KEY);
           newGroupName = dataMap.getString(NEW_GROUP_NAME_KEY);
           itemReaderDbHelper.copyItem(groupName, newGroupName, itemName);
           updateItemList();
           break;
         case RENAME_ITEM_KEY:
           Log.d("DATA", "RENAME_ITEM_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           itemName = dataMap.getString(ITEM_NAME_KEY);
           newItemName = dataMap.getString(NEW_ITEM_NAME_KEY);
           itemReaderDbHelper.renameItem(groupName, itemName, newItemName);
           updateItemList();
           break;
         case RENAME_GROUP_KEY:
           Log.d("DATA", "RENAME_GROUP_KEY RECEIVED");
           groupName = dataMap.getString(GROUP_NAME_KEY);
           newGroupName = dataMap.getString(NEW_GROUP_NAME_KEY);
           groupReaderDbHelper.renameGroup(groupName, newGroupName);
           itemReaderDbHelper.renameGroup(groupName, newGroupName);
           updateGroupList();
           break;
         case DONE_KEY:
           groupName = dataMap.getString(GROUP_NAME_KEY);
           doneScanning(groupName);
           break;
       }
     }
   }
 }