private void previewY() {
   Viewport tempViewport = new Viewport(recordChart.getMaximumViewport());
   float dy = (tempViewport.height() + 0.2f) / 4;
   tempViewport.inset(0, dy);
   recordPreviewChart.setCurrentViewportWithAnimation(tempViewport);
   recordPreviewChart.setZoomType(ZoomType.VERTICAL);
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   int id = item.getItemId();
   if (id == R.id.action_reset) {
     getForecastData();
     chart.setLineChartData(data);
     previewChart.setLineChartData(previewData);
     previewX(true);
     return true;
   }
   if (id == R.id.action_preview_both) {
     previewXY();
     previewChart.setZoomType(ZoomType.HORIZONTAL_AND_VERTICAL);
     return true;
   }
   if (id == R.id.action_preview_horizontal) {
     previewX(true);
     return true;
   }
   if (id == R.id.action_preview_vertical) {
     previewY();
     return true;
   }
   if (id == R.id.action_change_color) {
     int color = ChartUtils.pickColor();
     while (color == previewChart.getPreviewColor()) {
       color = ChartUtils.pickColor();
     }
     previewChart.setPreviewColor(color);
     return true;
   }
   return super.onOptionsItemSelected(item);
 }
Example #3
0
 public void setViewport() {
   if (tempViewport.left == 0.0
       || holdViewport.left == 0.0
       || holdViewport.right >= (new Date().getTime())) {
     previewChart.setCurrentViewport(bgGraphBuilder.advanceViewport(chart, previewChart));
   } else {
     previewChart.setCurrentViewport(holdViewport);
   }
 }
Example #4
0
 private void previewX(boolean animate) {
   Viewport tempViewport = new Viewport(chart.getMaximumViewport());
   float dx = tempViewport.width() / 4;
   tempViewport.inset(dx, 0);
   if (animate) {
     previewChart.setCurrentViewportWithAnimation(tempViewport);
   } else {
     previewChart.setCurrentViewport(tempViewport);
   }
   previewChart.setZoomType(ZoomType.HORIZONTAL);
 }
Example #5
0
 private void updateChartView() {
   Viewport viewport = new Viewport(0, maxValueOfLineChartData + OFFSET, maxNumberToShow, 0);
   chart.setMaximumViewport(viewport);
   chart.setCurrentViewport(viewport);
   previewChart.setMaximumViewport(viewport);
   previewX(false);
 }
    private void disRecordHideReal() {
      realeChartTop.setVisibility(View.GONE);
      realButtonRecord.setVisibility(View.GONE);
      realTempleTextView.setVisibility(View.GONE);

      // setTimeButton.setVisibility(View.GONE);
      clearButton.setVisibility(View.GONE);
      readButton.setVisibility(View.GONE);
      lookRecordButton.setVisibility(View.GONE);
      recordState.setVisibility(View.GONE);

      recordChart.setVisibility(View.VISIBLE);
      recordPreviewChart.setVisibility(View.VISIBLE);
      // recordButtonReturnReal.setVisibility(View.VISIBLE);

      maxmunTextView.setVisibility(View.VISIBLE);
      maxmumTextView_num.setVisibility(View.VISIBLE);
      minmunTextView.setVisibility(View.VISIBLE);
      minmunTextView_num.setVisibility(View.VISIBLE);
      lookRecordButton1.setVisibility(View.VISIBLE);
      deleteFilesButton.setVisibility(View.VISIBLE);

      StartTime.setVisibility(View.VISIBLE);
      EndTime.setVisibility(View.VISIBLE);

      RealOrRecordBackState = false;
    }
    private void showRecoedData(int[] recordMsgBuffer) {
      generateDefaultData(recordMsgBuffer);

      //            Viewport maxV=recordChart.getMaximumViewport();
      //            recordChart.setMaximumViewport(new Viewport(maxV.left, 100, maxV.right, 0));

      recordChart.setLineChartData(data);
      recordChart.setZoomEnabled(false);
      recordChart.setScrollEnabled(false);

      recordPreviewChart.setLineChartData(previewData);

      recordPreviewChart.setViewportChangeListener(new ViewportListener());

      previewX(false);

      disRecordHideReal();
    }
 private void previewXY() {
   // Better to not modify viewport of any recordChart directly so create a copy.
   Viewport tempViewport = new Viewport(recordChart.getMaximumViewport());
   // Make temp viewport smaller.
   float dx = tempViewport.width() / 4;
   float dy = tempViewport.height() / 4;
   tempViewport.inset(dx, dy);
   recordPreviewChart.setCurrentViewportWithAnimation(tempViewport);
 }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment

    setHasOptionsMenu(true);
    View rootView = inflater.inflate(R.layout.fragment_temperature, container, false);

    chart = (LineChartView) rootView.findViewById(R.id.chart);
    previewChart = (PreviewLineChartView) rootView.findViewById(R.id.chart_preview);

    // Generate data for previewed chart and copy of that data for preview chart.

    if (getArguments() != null) {
      temperatureData = getArguments();
      latitude = temperatureData.getFloat("latitude");
      longitude = temperatureData.getFloat("longitude");
      temperatures = temperatureData.getDoubleArray("temperatureArr");
      times = temperatureData.getIntArray("timeArr");
      numData = temperatureData.getInt("numData");
      Log.d("ARRAY", Arrays.toString(temperatures));
      Log.d("ARRAY", Arrays.toString(times));
      getForecastData();

      Log.d("receiver", "OK");
    } else {
      generateDefaultData();
    }
    chart.setLineChartData(data);
    // Disable zoom/scroll for previewed chart, visible chart ranges depends on preview chart
    // viewport so
    // zoom/scroll is unnecessary.
    chart.setZoomEnabled(false);
    chart.setScrollEnabled(false);

    previewChart.setLineChartData(previewData);
    previewChart.setViewportChangeListener(new ViewportListener());

    previewX(false);

    return rootView;
  }
    public void setupChart() {
      basalvsTempBasalChart.setZoomType(ZoomType.HORIZONTAL);
      basalvsTempBasalChart.setLineChartData(extendedGraphBuilder.basalvsTempBasalData());

      Viewport iobv =
          new Viewport(
              basalvsTempBasalChart
                  .getMaximumViewport()); // Sets the min and max for Top and Bottom of the
                                          // viewpoint
      iobv.top = extendedGraphBuilder.maxBasal.floatValue();
      iobv.bottom = -(extendedGraphBuilder.maxBasal.floatValue() - 1);
      basalvsTempBasalChart.setMaximumViewport(iobv);
      iobv.left = previewChart.getCurrentViewport().left;
      iobv.right = previewChart.getCurrentViewport().right;
      basalvsTempBasalChart.setCurrentViewport(iobv);

      basalvsTempBasalChart.setViewportCalculationEnabled(true);
      // iobcobPastChart.setViewportChangeListener(new ChartViewPortListener());
      // //causes a crash, no idea why #// TODO: 28/08/2015
    }
    public void setupChart() {

      iobcobPastChart.setZoomType(ZoomType.HORIZONTAL);
      iobcobPastChart.setLineChartData(extendedGraphBuilder.iobcobPastLineData());

      Viewport iobv =
          new Viewport(
              iobcobPastChart
                  .getMaximumViewport()); // Sets the min and max for Top and Bottom of the
                                          // viewpoint
      iobv.top = Float.parseFloat(extendedGraphBuilder.yCOBMax.toString());
      iobv.bottom = Float.parseFloat(extendedGraphBuilder.yCOBMin.toString());
      iobcobPastChart.setMaximumViewport(iobv);
      iobv.left = previewChart.getCurrentViewport().left;
      iobv.right = previewChart.getCurrentViewport().right;
      iobcobPastChart.setCurrentViewport(iobv);

      iobcobPastChart.setViewportCalculationEnabled(true);
      // iobcobPastChart.setViewportChangeListener(new ChartViewPortListener());
      // //causes a crash, no idea why #// TODO: 28/08/2015
    }
  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();
  }
Example #13
0
  public void addListToChart(List<Day> days) {
    int currentValue;
    int size = days.size();
    maxValueOfLineChartData = 0;
    List<PointValue> valuePoints = new ArrayList<PointValue>();

    if (size == 1) {
      for (int i = 0; i < 24; i++) {
        currentValue = days.get(0).getHours().get(i).getMmm().getMean();
        if (currentValue > maxValueOfLineChartData) {
          maxValueOfLineChartData = currentValue;
        }
        valuePoints.add(new PointValue(i, currentValue));
      }
    } else {
      for (int i = 0; i < size; i++) {
        currentValue = days.get(i).getMmm().getMean();
        if (currentValue > maxValueOfLineChartData) {
          maxValueOfLineChartData = currentValue;
        }
        valuePoints.add(new PointValue(i, currentValue));
      }
    }

    dataLine = new Line(valuePoints);
    dataLine.setColor(ChartUtils.COLOR_ORANGE);
    dataLine.setHasPoints(false);

    List<Line> lines = new ArrayList<Line>();
    lines.add(dataLine);

    data = new LineChartData(lines);
    data.setAxisXBottom(new Axis());
    data.setAxisYLeft(new Axis().setHasLines(true));

    previewData = new LineChartData(data);
    previewData.getLines().get(0).setColor(ChartUtils.DEFAULT_DARKEN_COLOR);

    chart.setLineChartData(data);
    previewChart.setLineChartData(previewData);

    updateChartView();
  }
Example #14
0
  @Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    chart = (LineChartView) view.findViewById(R.id.chart);
    chart.setLineChartData(data);
    chart.setZoomEnabled(true);
    chart.setScrollEnabled(true);

    previewChart = (PreviewLineChartView) view.findViewById(R.id.chart_preview);
    previewChart.setLineChartData(previewData);
    previewChart.setViewportChangeListener(new ViewportListener());

    final Button selectButton = (Button) view.findViewById(R.id.button_left);
    selectButton.setText(selectString[userChoice]);
    selectButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (dialogSelect == null) {
              dialogSelect = new Dialog(v.getContext());
            }

            dialogSelect.setContentView(R.layout.dialog_select);
            dialogSelect.setTitle(dialogSelectPeriodTitle);

            numberPicker = (NumberPicker) dialogSelect.findViewById(R.id.number_picker);
            numberPicker.setMinValue(0);
            numberPicker.setMaxValue(selectString.length - 1);
            numberPicker.setDisplayedValues(selectString);
            numberPicker.setWrapSelectorWheel(true);

            Button dialogButton = (Button) dialogSelect.findViewById(R.id.apply_button_select);
            dialogButton.setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    userChoice = numberPicker.getValue();
                    selectButton.setText(selectString[userChoice]);
                    dialogSelect.dismiss();
                    dateButton.callOnClick();
                  }
                });

            dialogSelect.show();
          }
        });

    dateButton = (Button) view.findViewById(R.id.button_right);
    if (pickedCalendar == null) {
      dateButton.setText("Datum");
    } else {
      setDateButtonText();
    }
    dateButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (dialog == null) {
              dialog = new Dialog(v.getContext());
            }
            switch (userChoice) {
              case DAY:
              case WEEK:
                dialog.setContentView(R.layout.dialog);
                datePicker = (DatePicker) dialog.findViewById(R.id.dpResult);
                break;
              case MONTH:
                dialog.setContentView(R.layout.dialog_month);
                monthPicker = (NumberPicker) dialog.findViewById(R.id.picker_month_month);
                monthPicker.setMinValue(0);
                monthPicker.setMaxValue(11);
                monthPicker.setDisplayedValues(monthString);
                monthPicker.setWrapSelectorWheel(true);
                yearPicker = (NumberPicker) dialog.findViewById(R.id.picker_month_year);
                yearPicker.setMinValue(2015);
                yearPicker.setMaxValue(2100);
                yearPicker.setWrapSelectorWheel(true);
                break;
              case YEAR:
                dialog.setContentView(R.layout.dialog_year);
                yearPicker = (NumberPicker) dialog.findViewById(R.id.picker_year_year);
                yearPicker.setMinValue(2015);
                yearPicker.setMaxValue(2100);
                yearPicker.setWrapSelectorWheel(true);
                break;
            }
            dialog.setTitle(dialogSelectDateTilte);

            Button dialogButton = (Button) dialog.findViewById(R.id.apply_button);
            dialogButton.setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    setPickedDate();
                    handleUserChoice();
                    updateChartView();
                    dialog.dismiss();
                  }
                });

            dialog.show();
          }
        });
    updateChartView();
  }
Example #15
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();
  }
Example #16
0
 private void cleanChart() {
   chart.setLineChartData(null);
   previewChart.setLineChartData(null);
 }
    @Override
    public View onCreateView(
        LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_view_pager_charts, container, false);
      RelativeLayout layout = (RelativeLayout) rootView;
      int sectionNum = getArguments().getInt(ARG_SECTION_NUMBER);
      switch (sectionNum) {
        case 1:
          LineChartView lineChartView = new LineChartView(getActivity());
          lineChartView.setLineChartData(generateLineChartData());
          lineChartView.setZoomType(ZoomType.HORIZONTAL);

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          lineChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          layout.addView(lineChartView);
          break;
        case 2:
          ColumnChartView columnChartView = new ColumnChartView(getActivity());
          columnChartView.setColumnChartData(generateColumnChartData());
          columnChartView.setZoomType(ZoomType.HORIZONTAL);

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          columnChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          layout.addView(columnChartView);
          break;
        case 3:
          BubbleChartView bubbleChartView = new BubbleChartView(getActivity());
          bubbleChartView.setBubbleChartData(generateBubbleChartData());
          bubbleChartView.setZoomType(ZoomType.HORIZONTAL_AND_VERTICAL);

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          bubbleChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          layout.addView(bubbleChartView);
          break;
        case 4:
          PreviewLineChartView previewLineChartView = new PreviewLineChartView(getActivity());
          previewLineChartView.setLineChartData(generatePreviewLineChartData());

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          previewLineChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          Viewport tempViewport = new Viewport(previewLineChartView.getMaximumViewport());
          float dx = tempViewport.width() / 6;
          tempViewport.inset(dx, 0);
          previewLineChartView.setCurrentViewport(tempViewport);
          previewLineChartView.setZoomType(ZoomType.HORIZONTAL);

          layout.addView(previewLineChartView);
          break;
        case 5:
          PieChartView pieChartView = new PieChartView(getActivity());
          pieChartView.setPieChartData(generatePieChartData());

          /** Note: Chart is within ViewPager so enable container scroll mode. * */
          pieChartView.setContainerScrollEnabled(true, ContainerScrollType.HORIZONTAL);

          layout.addView(pieChartView);
          break;
      }

      return rootView;
    }