Пример #1
0
  @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);
        }
      }
    }
  }
Пример #2
0
  public void addToWatchSet(DataMap dataMap) {

    ArrayList<DataMap> entries = dataMap.getDataMapArrayList("entries");
    if (entries != null) {
      for (DataMap entry : entries) {
        double sgv = entry.getDouble("sgvDouble");
        double high = entry.getDouble("high");
        double low = entry.getDouble("low");
        double timestamp = entry.getDouble("timestamp");

        final int size = bgDataList.size();
        if (size > 0) {
          if (bgDataList.get(size - 1).timestamp == timestamp) continue; // Ignore duplicates.
        }

        bgDataList.add(new BgWatchData(sgv, high, low, timestamp));
      }
    } else {
      double sgv = dataMap.getDouble("sgvDouble");
      double high = dataMap.getDouble("high");
      double low = dataMap.getDouble("low");
      double timestamp = dataMap.getDouble("timestamp");

      final int size = bgDataList.size();
      if (size > 0) {
        if (bgDataList.get(size - 1).timestamp == timestamp) return; // Ignore duplicates.
      }

      bgDataList.add(new BgWatchData(sgv, high, low, timestamp));
    }

    for (int i = 0; i < bgDataList.size(); i++) {
      if (bgDataList.get(i).timestamp < (new Date().getTime() - (1000 * 60 * 60 * 5))) {
        bgDataList.remove(i); // Get rid of anything more than 5 hours old
        break;
      }
    }
  }
Пример #3
0
    @Override
    public void onReceive(Context context, Intent intent) {
      DataMap dataMap = DataMap.fromBundle(intent.getBundleExtra("data"));
      if (layoutSet) {
        wakeLock.acquire(50);
        sgvLevel = dataMap.getLong("sgvLevel");
        batteryLevel = dataMap.getInt("batteryLevel");
        datetime = dataMap.getDouble("timestamp");

        mSgv.setText(dataMap.getString("sgvString"));

        if (ageLevel() <= 0) {
          mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        } else {
          mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
        }

        final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this);
        mTime.setText(timeFormat.format(System.currentTimeMillis()));
        mTimestamp.setText(readingAge());

        mDirection.setText(dataMap.getString("slopeArrow"));
        mUploaderBattery.setText("Uploader: " + dataMap.getString("battery") + "%");
        mDelta.setText(dataMap.getString("delta"));

        mTimestamp.setText(readingAge());
        if (chart != null) {
          addToWatchSet(dataMap);
          setupCharts();
        }
        mRelativeLayout.measure(specW, specH);
        mRelativeLayout.layout(
            0, 0, mRelativeLayout.getMeasuredWidth(), mRelativeLayout.getMeasuredHeight());
        invalidate();
      } else {
        Log.d("ERROR: ", "DATA IS NOT YET SET");
      }
      setColor();
    }