Exemple #1
0
  private void p1Graph() {

    p1Series = new LineGraphSeries();
    p1Series.setColor(Color.RED);

    // p1graph.setManualYAxisBounds(127, -127);
    p1graph.addSeries(p1Series); // data
    p1graph.getViewport().setYAxisBoundsManual(true);
    p1graph.getViewport().setMaxY(4096);
    p1graph.getViewport().setMinY(-1);
    p1graph.getViewport().setScalable(false);
    p1graph.getViewport().setScrollable(false);

    p1graph.setTitle("Upper Sensor Leg");
    p1graph.setTitleColor(R.color.PMDBlue);
    p1graph.getGridLabelRenderer().setHorizontalLabelsVisible(false);
    p1graph.getGridLabelRenderer().setVerticalLabelsVisible(false);

    RelativeLayout layout = (RelativeLayout) findViewById(R.id.p1Layout);
    layout.addView(p1graph);
    //////////////////////////////////////
    p2Series = new LineGraphSeries();
    p2Series.setColor(Color.BLUE);

    // p1graph.setManualYAxisBounds(127, -127);
    p2graph.addSeries(p2Series); // data
    p2graph.getViewport().setYAxisBoundsManual(true);
    p2graph.getViewport().setMaxY(4096);
    p2graph.getViewport().setMinY(-1);
    p2graph.getViewport().setScalable(false);
    p2graph.getViewport().setScrollable(false);

    p2graph.setTitle("Lower Sensor Leg");
    p2graph.setTitleColor(R.color.PMDBlue);
    p2graph.getGridLabelRenderer().setHorizontalLabelsVisible(false);
    p2graph.getGridLabelRenderer().setVerticalLabelsVisible(false);

    RelativeLayout layout2 = (RelativeLayout) findViewById(R.id.p2Layout);
    layout2.addView(p2graph);

    //////////////////////////////////////
    vSeries = new LineGraphSeries();
    vSeries.setColor(Color.rgb(0, 156, 2));

    // p1graph.setManualYAxisBounds(127, -127);
    vgraph.addSeries(vSeries); // data
    vgraph.getViewport().setYAxisBoundsManual(true);
    vgraph.getViewport().setMaxY(4096);
    vgraph.getViewport().setMinY(-1);
    vgraph.getViewport().setScalable(false);
    vgraph.getViewport().setScrollable(false);

    vgraph.setTitle("Reference Voltage");
    vgraph.setTitleColor(R.color.PMDBlue);
    vgraph.getGridLabelRenderer().setHorizontalLabelsVisible(false);
    vgraph.getGridLabelRenderer().setVerticalLabelsVisible(false);

    RelativeLayout layout3 = (RelativeLayout) findViewById(R.id.vRefLayout);
    layout3.addView(vgraph);
  }
Exemple #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cpuinfo);

    activeCores = (TextView) findViewById(R.id.activeCores);
    processor = (TextView) findViewById(R.id.processor);
    featuresCPU = (TextView) findViewById(R.id.features);
    hardWareCpu = (TextView) findViewById(R.id.cpuHardware);
    cpuMaxFrequency = (TextView) findViewById(R.id.cpuMaxFrequency);
    cpuCurrentFreq = (TextView) findViewById(R.id.cpuCurrentFrequency);
    updateView();

    // graph settings
    graph = (GraphView) findViewById(R.id.graph1);

    seriesLive = new LineGraphSeries<DataPoint>();
    seriesLive.setColor(getResources().getColor(R.color.tabs));
    seriesLive.setDrawBackground(true);
    seriesLive.setBackgroundColor(getResources().getColor(R.color.graph_filling));
    seriesLive.setThickness(2);
    seriesLive.setTitle("CPU Usage");
    graph.addSeries(seriesLive);
    graph.getViewport().setYAxisBoundsManual(true);
    graph.getViewport().setXAxisBoundsManual(true);
    graph.getViewport().setMinX(0);
    graph.getViewport().setMaxX(10);
    graph.getViewport().setScrollable(true);
    graph.getViewport().setMinY(0);
    graph.getViewport().setMaxY(100);
    graph.getViewport().setBackgroundColor(Color.WHITE);

    graph.getGridLabelRenderer().setGridColor(Color.WHITE);
    graph.getGridLabelRenderer().setHorizontalLabelsVisible(false);
    graph.getGridLabelRenderer().setNumVerticalLabels(5);
    graph.getGridLabelRenderer().setNumHorizontalLabels(4);
    graph.getGridLabelRenderer().setVerticalLabelsVisible(false);
    graph.getGridLabelRenderer().reloadStyles();
  }
  /**
   * plots the series draws the line and the background
   *
   * @param graphView graphview
   * @param canvas canvas
   * @param isSecondScale flag if it is the second scale
   */
  @Override
  public void draw(GraphView graphView, Canvas canvas, boolean isSecondScale) {
    resetDataPoints();

    // get data
    double maxX = graphView.getViewport().getMaxX(false);
    double minX = graphView.getViewport().getMinX(false);

    double maxY;
    double minY;
    if (isSecondScale) {
      maxY = graphView.getSecondScale().getMaxY();
      minY = graphView.getSecondScale().getMinY();
    } else {
      maxY = graphView.getViewport().getMaxY(false);
      minY = graphView.getViewport().getMinY(false);
    }

    Iterator<E> values = getValues(minX, maxX);

    // draw background
    double lastEndY = 0;
    double lastEndX = 0;

    // draw data
    mPaint.setStrokeWidth(mStyles.thickness);
    mPaint.setColor(getColor());
    mPaintBackground.setColor(mStyles.backgroundColor);

    Paint paint;
    if (mCustomPaint != null) {
      paint = mCustomPaint;
    } else {
      paint = mPaint;
    }

    if (mStyles.drawBackground) {
      mPathBackground.reset();
    }

    double diffY = maxY - minY;
    double diffX = maxX - minX;

    float graphHeight = graphView.getGraphContentHeight();
    float graphWidth = graphView.getGraphContentWidth();
    float graphLeft = graphView.getGraphContentLeft();
    float graphTop = graphView.getGraphContentTop();

    lastEndY = 0;
    lastEndX = 0;
    double lastUsedEndX = 0;
    float firstX = 0;
    int i = 0;
    while (values.hasNext()) {
      E value = values.next();

      double valY = value.getY() - minY;
      double ratY = valY / diffY;
      double y = graphHeight * ratY;

      double valX = value.getX() - minX;
      double ratX = valX / diffX;
      double x = graphWidth * ratX;

      double orgX = x;
      double orgY = y;

      if (i > 0) {
        // overdraw
        if (x > graphWidth) { // end right
          double b = ((graphWidth - lastEndX) * (y - lastEndY) / (x - lastEndX));
          y = lastEndY + b;
          x = graphWidth;
        }
        if (y < 0) { // end bottom
          double b = ((0 - lastEndY) * (x - lastEndX) / (y - lastEndY));
          x = lastEndX + b;
          y = 0;
        }
        if (y > graphHeight) { // end top
          double b = ((graphHeight - lastEndY) * (x - lastEndX) / (y - lastEndY));
          x = lastEndX + b;
          y = graphHeight;
        }
        if (lastEndY < 0) { // start bottom
          double b = ((0 - y) * (x - lastEndX) / (lastEndY - y));
          lastEndX = x - b;
          lastEndY = 0;
        }
        if (lastEndX < 0) { // start left
          double b = ((0 - x) * (y - lastEndY) / (lastEndX - x));
          lastEndY = y - b;
          lastEndX = 0;
        }
        if (lastEndY > graphHeight) { // start top
          double b = ((graphHeight - y) * (x - lastEndX) / (lastEndY - y));
          lastEndX = x - b;
          lastEndY = graphHeight;
        }

        float startX = (float) lastEndX + (graphLeft + 1);
        float startY = (float) (graphTop - lastEndY) + graphHeight;
        float endX = (float) x + (graphLeft + 1);
        float endY = (float) (graphTop - y) + graphHeight;

        // draw data point
        if (mStyles.drawDataPoints) {
          // fix: last value was not drawn. Draw here now the end values
          canvas.drawCircle(endX, endY, mStyles.dataPointsRadius, paint);
        }
        registerDataPoint(endX, endY, value);

        mPath.reset();
        mPath.moveTo(startX, startY);
        mPath.lineTo(endX, endY);
        canvas.drawPath(mPath, paint);
        if (mStyles.drawBackground) {
          if (i == 1) {
            firstX = startX;
            mPathBackground.moveTo(startX, startY);
          }
          mPathBackground.lineTo(endX, endY);
        }
        lastUsedEndX = endX;
      } else if (mStyles.drawDataPoints) {
        // fix: last value not drawn as datapoint. Draw first point here, and then on every step the
        // end values (above)
        float first_X = (float) x + (graphLeft + 1);
        float first_Y = (float) (graphTop - y) + graphHeight;
        // TODO canvas.drawCircle(first_X, first_Y, dataPointsRadius, mPaint);
      }
      lastEndY = orgY;
      lastEndX = orgX;
      i++;
    }

    if (mStyles.drawBackground) {
      // end / close path
      mPathBackground.lineTo((float) lastUsedEndX, graphHeight + graphTop);
      mPathBackground.lineTo(firstX, graphHeight + graphTop);
      mPathBackground.close();
      canvas.drawPath(mPathBackground, mPaintBackground);
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    Log.i(LOG_TAG, "---New Session---");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    icmpPingSettings = new PingSettings();
    icmpPingSettings.setTimeout(1000);
    icmpPingSettings.setRepeat(3000);
    icmpPingSettings.setDomain("www.google.com");
    icmpPingSettings.setSlow(300);

    httpPingSettings = new PingSettings();
    httpPingSettings.setTimeout(1500);
    httpPingSettings.setRepeat(3000);
    httpPingSettings.setDomain("www.google.com");
    httpPingSettings.setSlow(500);

    httpsPingSettings = new PingSettings();
    httpsPingSettings.setTimeout(2000);
    httpsPingSettings.setRepeat(3000);
    httpsPingSettings.setDomain("www.google.com");
    httpsPingSettings.setSlow(1000);

    pingReceiver = new PingReceiver();

    gv = (GraphView) findViewById(R.id.graph_view);

    gv.setTitle("Ping Times");
    gv.getGridLabelRenderer().setHighlightZeroLines(true);
    gv.getGridLabelRenderer().setPadding(36);

    icmpLineSeries = new PointsGraphSeries<DataPoint>();
    icmpLineSeries.setColor(Color.parseColor("#A00000"));
    icmpLineSeries.setSize(10);
    icmpLineSeries.setTitle("ICMP");
    gv.addSeries(icmpLineSeries);

    httpLineSeries = new PointsGraphSeries<DataPoint>();
    httpLineSeries.setColor(Color.parseColor("#00A000"));
    httpLineSeries.setSize(10);
    httpLineSeries.setTitle("HTTP");
    gv.addSeries(httpLineSeries);

    httpsLineSeries = new PointsGraphSeries<DataPoint>();
    httpsLineSeries.setColor(Color.parseColor("#0000A0"));
    httpsLineSeries.setSize(10);
    httpsLineSeries.setTitle("HTTPS");
    gv.addSeries(httpsLineSeries);

    gv.getLegendRenderer().setVisible(true);
    gv.getLegendRenderer().setAlign(LegendRenderer.LegendAlign.MIDDLE);

    gv.getViewport().setXAxisBoundsManual(true);
    gv.getViewport().setMinX(0);
    gv.getViewport().setMaxX(60);

    // gv.getViewport().setYAxisBoundsManual(true);
    // gv.getViewport().setMinY(0);
    // gv.getViewport().setMaxY(1);

    alertToggle = (CheckBox) findViewById(R.id.alert_toggle);
    alertThresh = (EditText) findViewById(R.id.alert_input);
    alertToggle.setOnClickListener(this);

    icmp_set_btn = (Button) findViewById(R.id.icmp_settings);
    icmp_start_btn = (Button) findViewById(R.id.icmp_start);
    icmp_end_btn = (Button) findViewById(R.id.icmp_end);
    icmp_information = (TextView) findViewById(R.id.icmp_information);
    icmp_result = (TextView) findViewById(R.id.icmp_result);
    icmp_icon = (ImageView) findViewById(R.id.icmp_icon);

    icmp_start_btn.setOnClickListener(this);
    icmp_end_btn.setOnClickListener(this);
    icmp_set_btn.setOnClickListener(this);

    http_set_btn = (Button) findViewById(R.id.http_settings);
    http_start_btn = (Button) findViewById(R.id.http_start);
    http_end_btn = (Button) findViewById(R.id.http_end);
    http_information = (TextView) findViewById(R.id.http_information);
    http_result = (TextView) findViewById(R.id.http_result);
    http_icon = (ImageView) findViewById(R.id.http_icon);

    http_set_btn.setOnClickListener(this);
    http_start_btn.setOnClickListener(this);
    http_end_btn.setOnClickListener(this);

    https_set_btn = (Button) findViewById(R.id.https_settings);
    https_start_btn = (Button) findViewById(R.id.https_start);
    https_end_btn = (Button) findViewById(R.id.https_end);
    https_information = (TextView) findViewById(R.id.https_information);
    https_result = (TextView) findViewById(R.id.https_result);
    https_icon = (ImageView) findViewById(R.id.https_icon);

    https_set_btn.setOnClickListener(this);
    https_start_btn.setOnClickListener(this);
    https_end_btn.setOnClickListener(this);

    endHTTP();
    endHTTPS();
    endICMP();

    updateInformation();
  }
Exemple #5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    setContentView(R.layout.activity_graph);

    memories = new LinkedList();
    series = new LineGraphSeries<DataPoint>();
    DataPoint dataPoint = new DataPoint(0, 0);
    series.appendData(dataPoint, false, 25);
    graph = (GraphView) findViewById(R.id.graph);
    graph.setTitle("Life Music");
    graph.addSeries(series);

    // sets min/max values for graph
    graph.getViewport().setXAxisBoundsManual(true);
    graph.getViewport().setMaxX(25);
    graph.getViewport().setMinX(0);
    graph.getViewport().setYAxisBoundsManual(true);
    graph.getViewport().setMaxY(1);
    graph.getViewport().setMinY(-1);

    // determines how many digits for fraction/integer
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumFractionDigits(0);
    nf.setMaximumIntegerDigits(2);

    // organizes the labeling
    graph.getGridLabelRenderer().setLabelFormatter(new DefaultLabelFormatter(nf, nf));
    graph.getGridLabelRenderer().setNumHorizontalLabels(6);
    graph.getGridLabelRenderer().setNumVerticalLabels(3);
    graph.getGridLabelRenderer().setHorizontalAxisTitle("Age");
    graph.getGridLabelRenderer().setHighlightZeroLines(true);
    //
    // Log.v("LabelVisible",String.valueOf(graph.getGridLabelRenderer().isHorizontalLabelsVisible()));
    /*
            OnDataPointTapListener dat = new OnDataPointTapListener() {
                @Override
                public void onTap(Series series, DataPointInterface dataPoint) {
                    Iterator<DataPoint> it = series.getValues(series.getLowestValueX(), series.getHighestValueX());
                    while (it.hasNext())
                    {
                        if(it.next() == dataPoint)
                        {

                            try {
                                play(dataPoint.getY());
                            } catch (IOException e) {
                                e.printStackTrace();
                            }

                            Dialog dialog = new Dialog((Context) dataPoint);
                            dialog.setContentView(R.layout.activity_graph);
                            dialog.setTitle("Memory:");
                            TextView text = (TextView) memories.get((int) dataPoint.getX());
                            dialog.show();
                        }
                    }
                }
            };

            series.setOnDataPointTapListener(dat);

            series.setOnDataPointTapListener(new OnDataPointTapListener() {
                @Override
                public void onTap(Series series, DataPointInterface dataPoint) {
                    Toast.makeText(GraphActivity.this, "Series1: On Data Point clicked: " + dataPoint, Toast.LENGTH_SHORT).show();
                }
            });
    */
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    for (int i = 0; i < 24; i++) {
      memories.add(i, "");
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.graph);
    // generate Dates
    Calendar calendar = Calendar.getInstance();
    Date d1 = calendar.getTime();
    calendar.add(Calendar.DATE, 1);
    Date d2 = calendar.getTime();
    calendar.add(Calendar.DATE, 1);
    Date d3 = calendar.getTime();

    Date d4 = calendar.getTime();
    calendar.add(Calendar.DATE, 1);
    Date d5 = calendar.getTime();
    calendar.add(Calendar.DATE, 1);
    Date d6 = calendar.getTime();

    Date d7 = calendar.getTime();
    calendar.add(Calendar.DATE, 1);
    Date d8 = calendar.getTime();
    calendar.add(Calendar.DATE, 1);
    Date d9 = calendar.getTime();

    GraphView graph = (GraphView) findViewById(R.id.graph);

    // you can directly pass Date objects to DataPoint-Constructor
    // this will convert the Date to double via Date#getTime()
    LineGraphSeries<DataPoint> series =
        new LineGraphSeries<DataPoint>(
            new DataPoint[] {
              new DataPoint(d1, 1),
              new DataPoint(d2, 5),
              new DataPoint(d3, 3),
              new DataPoint(d4, 4),
              new DataPoint(d5, 6),
              new DataPoint(d6, 5),
              new DataPoint(d7, 7),
              new DataPoint(d8, 4),
              new DataPoint(d9, 6),
            });
    series.setColor(getResources().getColor(android.R.color.holo_green_dark));
    LineGraphSeries<DataPoint> series2 =
        new LineGraphSeries<DataPoint>(
            new DataPoint[] {
              new DataPoint(d1, 2),
              new DataPoint(d2, 3),
              new DataPoint(d3, 3),
              new DataPoint(d4, 4),
              new DataPoint(d5, 5),
              new DataPoint(d6, 5),
              new DataPoint(d7, 7),
              new DataPoint(d8, 4),
              new DataPoint(d9, 6),
            });
    series.setColor(getResources().getColor(android.R.color.holo_red_dark));
    graph.addSeries(series);
    graph.addSeries(series2);

    // set date label formatter
    graph
        .getGridLabelRenderer()
        .setLabelFormatter(new DateAsXAxisLabelFormatter(NativeGraphActivity.this));
    graph.getGridLabelRenderer().setNumHorizontalLabels(8); // only 4 because of the space

    // set manual x bounds to have nice steps
    graph.getViewport().setMinX(d1.getTime());
    graph.getViewport().setMaxX(d9.getTime());
    graph.getViewport().setXAxisBoundsManual(true);

    lecho.lib.hellocharts.view.LineChartView chartView = (LineChartView) findViewById(R.id.chart);
    List<PointValue> values = new ArrayList<PointValue>();
    values.add(new PointValue(0, 2));
    values.add(new PointValue(1, 4));
    values.add(new PointValue(2, 3));
    values.add(new PointValue(3, 4));

    // In most cased you can call data model methods in builder-pattern-like manner.
    Line line =
        new Line(values)
            .setColor(getResources().getColor(android.R.color.holo_red_dark))
            .setCubic(false);

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

    LineChartData data = new LineChartData();
    data.setLines(lines);
    Axis axis = new Axis();
    axis.setHasTiltedLabels(true);

    data.setAxisXBottom(new Axis().setAutoGenerated(true));
    data.setAxisYLeft(new Axis().setAutoGenerated(true));
    data.setBaseValue(20);

    chartView.setLineChartData(data);
  }