コード例 #1
0
        @Override
        public void onDataReceived(DataReadResult dataReadResult) {
          Log.d(TAG, "Received step result");

          final String DATE_FORMAT = "dd/MM";
          SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
          List<Column> columns = new ArrayList<>();
          List<SubcolumnValue> values;
          List<AxisValue> xAxisValues = new ArrayList<>();

          if (dataReadResult.getBuckets().size() > 0) {
            fitnessFragment.mColumnChart.clearAnimation();
            for (Bucket bucket : dataReadResult.getBuckets()) { // days/hours, depends on request
              DataSet dataset = bucket.getDataSet(DataType.TYPE_STEP_COUNT_DELTA);
              List<DataPoint> dataPointList = dataset.getDataPoints();
              for (DataPoint dp : dataPointList) {
                // add to bar chart
                String timestamp = dateFormat.format(dp.getTimestamp(TimeUnit.MILLISECONDS));
                float steps = (float) dp.getValue(Field.FIELD_STEPS).asInt();

                // Set axis labels
                xAxisValues.add(new AxisValue(columns.size()).setLabel(timestamp));

                values = new ArrayList<>();
                values.add(new SubcolumnValue(steps, ChartUtils.COLOR_RED));
                columns.add(new Column(values));
              }
            }
            fitnessFragment.setStepsData(xAxisValues, columns);
          }
        }
コード例 #2
0
        @Override
        public void onDataReceived(DataReadResult dataReadResult) {
          Log.d(TAG, "Received activity result");
          final String DATE_FORMAT = "dd/MM";
          SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);

          List<Line> lines = new ArrayList<>(); // all lines
          List<PointValue> calories; // a single line
          calories = new ArrayList<>();
          int x_val = 0;
          List<AxisValue> xAxisValues = new ArrayList<>();

          if (dataReadResult.getBuckets().size() > 0) {
            for (Bucket bucket : dataReadResult.getBuckets()) {
              String date = dateFormat.format(bucket.getStartTime(TimeUnit.MILLISECONDS));
              DataSet dataSet = bucket.getDataSet(DataType.AGGREGATE_CALORIES_EXPENDED);
              Log.d(TAG, "New databucket with date: " + date);

              // Increase counter
              x_val = x_val + 1;

              // Set axis labels
              xAxisValues.add(new AxisValue(x_val).setLabel(date));

              // Add a zero measurement point
              calories.add(new PointValue(x_val, 0));

              List<DataPoint> dataPointList = dataSet.getDataPoints();
              for (DataPoint dp : dataPointList) {
                String timestamp = dateFormat.format(dp.getTimestamp(TimeUnit.MILLISECONDS));
                float calorie = dp.getValue(Field.FIELD_CALORIES).asFloat();

                // Set graph values
                calories.set(x_val - 1, new PointValue(x_val, calorie));
                Log.d(TAG, "timestamp: " + timestamp + ", calories: " + calorie);
              }
            }
            Line line = new Line(calories);
            line.setColor(ChartUtils.COLOR_BLUE);
            line.setHasLines(true);
            line.setHasPoints(false);
            line.setCubic(false);
            line.setHasLabels(false);
            line.setHasLabelsOnlyForSelected(true);
            lines.add(line);

            fitnessFragment.setCalorieData(xAxisValues, lines);
          }
        }
コード例 #3
0
        @Override
        public void onDataReceived(DataReadResult dataReadResult) {
          Log.d(TAG, "Received activity result");
          final String DATE_FORMAT = "dd/MM";
          SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
          // GoogleApiSubscription.printData(dataReadResult);

          List<Line> lines = new ArrayList<>(); // all lines
          List<PointValue> walking = new ArrayList<>(); // a single line
          List<PointValue> biking = new ArrayList<>();
          List<PointValue> in_vehicle = new ArrayList<>();
          List<AxisValue> xAxisValues = new ArrayList<>();

          int x_val = 0;

          if (dataReadResult.getBuckets().size() > 0) {
            for (Bucket bucket : dataReadResult.getBuckets()) {
              String date = dateFormat.format(bucket.getStartTime(TimeUnit.MILLISECONDS));
              DataSet dataSet = bucket.getDataSet(DataType.AGGREGATE_ACTIVITY_SUMMARY);
              Log.d(TAG, "New databucket with date: " + date);

              // Increase counter
              x_val = x_val + 1;

              // Set axis labels
              xAxisValues.add(new AxisValue(x_val).setLabel(date));

              // Add a zero measurement point
              walking.add(new PointValue(x_val, 0));
              biking.add(new PointValue(x_val, 0));
              in_vehicle.add(new PointValue(x_val, 0));

              List<DataPoint> dataPointList = dataSet.getDataPoints();
              for (DataPoint dp : dataPointList) {
                String timestamp = dateFormat.format(dp.getTimestamp(TimeUnit.MILLISECONDS));
                String activity = dp.getValue(Field.FIELD_ACTIVITY).asActivity();
                int duration = dp.getValue(Field.FIELD_DURATION).asInt();

                if (dp.getValue(Field.FIELD_ACTIVITY).asActivity() == "walking") {
                  walking.set(x_val - 1, new PointValue(x_val, duration / 60000));
                } else if (dp.getValue(Field.FIELD_ACTIVITY).asActivity() == "biking") {
                  biking.set(x_val - 1, new PointValue(x_val, duration / 60000));
                } else if (dp.getValue(Field.FIELD_ACTIVITY).asActivity() == "in_vehicle") {
                  in_vehicle.set(x_val - 1, new PointValue(x_val, duration / 60000));
                }
                Log.d(
                    TAG,
                    "timestamp: "
                        + timestamp
                        + ", activity: "
                        + activity
                        + ", duration: "
                        + duration / 60000);
              }
            }
            Line line = new Line(walking);
            line.setColor(ChartUtils.COLOR_GREEN);
            line.setHasLines(true);
            line.setHasPoints(false);
            line.setCubic(false);
            lines.add(line);

            line = new Line(biking);
            line.setColor(ChartUtils.COLOR_BLUE);
            line.setHasLines(true);
            line.setHasPoints(false);
            line.setCubic(false);
            lines.add(line);

            line = new Line(in_vehicle);
            line.setColor(ChartUtils.COLOR_VIOLET);
            line.setHasLines(true);
            line.setHasPoints(false);
            line.setCubic(false);
            lines.add(line);

            fitnessFragment.setActivityData(xAxisValues, lines);
          }
        }