public void setupCharts() {

    // BG charts
    updateStuff = false;
    chart = (LineChartView) findViewById(R.id.chart);
    chart.setZoomType(ZoomType.HORIZONTAL);

    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);
    previewChart.setZoomType(ZoomType.HORIZONTAL);

    chart.setLineChartData(extendedGraphBuilder.lineData());
    previewChart.setLineChartData(extendedGraphBuilder.previewLineData());
    updateStuff = true;

    previewChart.setViewportCalculationEnabled(true);
    chart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportChangeListener(new ChartViewPortListener());

    setViewport();
  }
예제 #2
0
  public void setupCharts() {
    bgGraphBuilder = new BgGraphBuilder(this);
    updateStuff = false;
    chart = (LineChartView) findViewById(R.id.chart);

    if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
      ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) chart.getLayoutParams();
      params.topMargin = 130;
      chart.setLayoutParams(params);
    }

    chart.setZoomType(ZoomType.HORIZONTAL);

    // Transmitter Battery Level
    final Sensor sensor = Sensor.currentSensor();
    if (sensor != null
        && sensor.latest_battery_level != 0
        && sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_LOW) {
      Drawable background =
          new Drawable() {

            @Override
            public void draw(Canvas canvas) {

              DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics();
              int px = (int) (30 * (metrics.densityDpi / 160f));
              Paint paint = new Paint();
              paint.setTextSize(px);
              paint.setAntiAlias(true);
              paint.setColor(Color.parseColor("#FFFFAA"));
              paint.setStyle(Paint.Style.STROKE);
              paint.setAlpha(100);
              canvas.drawText(
                  "transmitter battery", 10, chart.getHeight() / 3 - (int) (1.2 * px), paint);
              if (sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_EMPTY) {
                paint.setTextSize((int) (px * 1.5));
                canvas.drawText("VERY LOW", 10, chart.getHeight() / 3, paint);
              } else {
                canvas.drawText("low", 10, chart.getHeight() / 3, paint);
              }
            }

            @Override
            public void setAlpha(int alpha) {}

            @Override
            public void setColorFilter(ColorFilter cf) {}

            @Override
            public int getOpacity() {
              return 0;
            }
          };
      chart.setBackground(background);
    }
    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);
    previewChart.setZoomType(ZoomType.HORIZONTAL);

    chart.setLineChartData(bgGraphBuilder.lineData());
    previewChart.setLineChartData(bgGraphBuilder.previewLineData());
    updateStuff = true;

    previewChart.setViewportCalculationEnabled(true);
    chart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportChangeListener(new ChartViewPortListener());
    setViewport();
  }