コード例 #1
0
  /**
   * 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;
  }
コード例 #2
0
 @Override
 public void onDataChanged(DataEventBuffer 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) {
               DataItem dataItem = event.getDataItem();
               DataMap dataMap = DataMapItem.fromDataItem(dataItem).getDataMap();
               double steps = dataMap.getDouble("steps");
               testTextView.setText("" + steps);
             }
           }
         }
       });
 }