@Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    GraphView graph = (GraphView) rootView.findViewById(R.id.graph);
    LineGraphSeries<DataPoint> series =
        new LineGraphSeries<DataPoint>(
            new DataPoint[] {
              new DataPoint(0, 1),
              new DataPoint(1, 5),
              new DataPoint(2, 3),
              new DataPoint(3, 2),
              new DataPoint(4, 6)
            });
    graph.addSeries(series);

    // use static labels for horizontal and vertical labels
    StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph);
    staticLabelsFormatter.setHorizontalLabels(new String[] {"old", "middle", "new"});
    staticLabelsFormatter.setVerticalLabels(new String[] {"low", "middle", "high"});
    graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter);

    return rootView;
  }
  /**
   * add one data to current data
   *
   * @param value the new data to append
   * @param scrollToEnd true => graphview will scroll to the end (maxX)
   * @param maxDataCount if max data count is reached, the oldest data value will be lost
   */
  public void appendData(GraphViewDataInterface value, boolean scrollToEnd, int maxDataCount) {
    synchronized (values) {
      int curDataCount = values.length;
      GraphViewDataInterface[] newValues;
      if (curDataCount < maxDataCount) {
        // enough space
        newValues = new GraphViewDataInterface[curDataCount + 1];
        System.arraycopy(values, 0, newValues, 0, curDataCount);
        // append new data
        newValues[curDataCount] = value;
      } else {
        // we have to trim one data
        newValues = new GraphViewDataInterface[maxDataCount];
        System.arraycopy(values, 1, newValues, 0, curDataCount - 1);
        // append new data
        newValues[maxDataCount - 1] = value;
      }
      values = newValues;
    }

    // update linked graph views
    for (GraphView g : graphViews) {
      if (scrollToEnd) {
        g.scrollToEnd();
      }
    }
  }
Example #3
0
 public GraphView refreshGraph(double[] values) {
   GraphViewData[] data = new GraphViewData[Globals.NUMBER_DATA];
   for (int i = 0; i < Globals.NUMBER_DATA; i++) {
     data[i] = new GraphViewData((i * Globals.FACTOR_MULTIPLY), values[i]);
   }
   graphView = new LineGraphView(mContext, mContext.getString(R.string.titleGraph));
   graphView.addSeries(new GraphViewSeries(data));
   graphView.setViewPort(Globals.X_AXYS_MIN, Globals.X_AXYS_MAX);
   graphView.setScrollable(true);
   graphView.setScalable(true);
   return graphView;
 }
  private void updateView(List<ScanResult> aps) {
    SeriesManager seriesManager = new SeriesManager();
    ArrayList<String> list = new ArrayList<>();
    StringBuffer result = new StringBuffer();
    HashMap<String, Integer> dict = new HashMap<>();
    double totalPower = 0;
    int count = 0;

    HashMap<String, ShowAp> map = new HashMap<>();
    for (ScanResult ap : aps) {
      if (ap.SSID.trim().equals("")) {
        continue;
      }
      if (cb_filter.isChecked()) {
        if (!ap.SSID.equals(et_input.getText().toString())) {
          continue;
        }
      }
      ShowAp showAp = new ShowAp();
      if (map.containsKey(ap.SSID)) {
        showAp = map.get(ap.SSID);
      } else {
        showAp.ssid = ap.SSID;
      }
      double power = Math.pow(10, ap.level / 10) * 1000000;
      totalPower += power;
      count++;
      showAp.power += power;
      showAp.count++;
      showAp.color = Color.rgb(randomColor(), randomColor(), randomColor());
      map.put(ap.SSID, showAp);
      seriesManager.push(ap.SSID, ap.level, showAp.color);
    }

    result.append("Number of wireless AP : " + count + "\n");
    result.append("Total power : " + totalPower + "\n");
    ApsList apsList = new ApsList(context, map);
    graph.removeAllSeries();
    Iterator itr = seriesManager.getSeriesDict().entrySet().iterator();
    if (seriesManager.getSeriesDict().size() > 1) {
      while (itr.hasNext()) {
        HashMap.Entry entry = (HashMap.Entry) itr.next();
        SeriesManager.MySeries series = (SeriesManager.MySeries) entry.getValue();
        graph.addSeries(series.series);
      }
    } else {
      graph.addSeries(seriesManager.getAllPointsSeries());
    }
    lv_wifiList.setAdapter(apsList.normalModeAdapter);
    DecimalFormat df = new DecimalFormat("0.00");
    tv_total.setText("Total power is " + df.format(totalPower) + "nW");
  }
  /**
   * add one data to current data
   *
   * @param value the new data to append
   * @param scrollToEnd true => graphview will scroll to the end (maxX)
   * @deprecated please use {@link #appendData(GraphViewDataInterface, boolean, int)} to avoid
   *     memory overflow
   */
  @Deprecated
  public void appendData(GraphViewDataInterface value, boolean scrollToEnd) {
    GraphViewDataInterface[] newValues = new GraphViewDataInterface[values.length + 1];
    int offset = values.length;
    System.arraycopy(values, 0, newValues, 0, offset);

    newValues[values.length] = value;
    values = newValues;
    for (GraphView g : graphViews) {
      if (scrollToEnd) {
        g.scrollToEnd();
      }
    }
  }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_temp_graph);
   GraphView graph = (GraphView) findViewById(R.id.graph);
   LineGraphSeries<DataPoint> series =
       new LineGraphSeries<DataPoint>(
           new DataPoint[] {
             new DataPoint(0, 1),
             new DataPoint(1, 5),
             new DataPoint(2, 3),
             new DataPoint(3, 2),
             new DataPoint(4, 6)
           });
   graph.addSeries(series);
 }
  private View getChartView() {
    // init example series data
    final java.text.DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
    long now = new Date().getTime();
    long day = 86400000;

    GraphViewSeries exampleSeries =
        new GraphViewSeries(
            new GraphViewData[] {
              new GraphViewData(now - day * 5, .5d),
              new GraphViewData(now - day * 4.5, 1.7d),
              new GraphViewData(now - day * 4.0, 2.1d),
              new GraphViewData(now - day * 3.5, 2.5d),
              new GraphViewData(now - day * 3, 2.9d),
              new GraphViewData(now - day * 2.5, 3.2d),
              new GraphViewData(now - day * 2.0, 3.3d),
              new GraphViewData(now - day * 1.5, 3.4d),
              new GraphViewData(now - day * 1, 3.5d),
              new GraphViewData(now, 3.5d)
            });

    GraphView graphView =
        new LineGraphView(this, "Vital Capacity") {

          @Override
          protected String formatLabel(double value, boolean isValueX) {

            if (isValueX) {
              return dateFormat.format(new Date((long) value));
            }
            return super.formatLabel(value, isValueX);
          }
        };
    graphView.setGravity(Gravity.CENTER);

    graphView.addSeries(exampleSeries); // data
    return graphView;
  }
Example #8
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();
  }
  private void drawEstimationGraph() {
    double output[] = estimator.getEstimataion();

    GraphViewData data[] = new GraphViewData[output.length];
    for (int i = 0; i < output.length; ++i) {
      data[i] = new GraphViewData(i, output[i]);
    }

    // init example series data
    GraphViewSeries exampleSeries = new GraphViewSeries(data);

    // granica hiperglikemiczna
    data = new GraphViewData[output.length];
    for (int i = 0; i < output.length; ++i) {
      data[i] = new GraphViewData(i, 130);
    }

    GraphViewSeries hyperglycemicSeries1 =
        new GraphViewSeries("Hiperglikemia 1", Color.rgb(200, 50, 00), data);

    data = new GraphViewData[output.length];
    for (int i = 0; i < output.length; ++i) {
      data[i] = new GraphViewData(i, 180);
    }

    GraphViewSeries hyperglycemicSeries2 =
        new GraphViewSeries("Hiperglikemia 2", Color.rgb(220, 20, 60), data);

    data = new GraphViewData[output.length];
    for (int i = 0; i < output.length; ++i) {
      data[i] = new GraphViewData(i, 50);
    }

    GraphViewSeries lowSeries = new GraphViewSeries("Dolna granica", Color.rgb(255, 215, 00), data);

    GraphView graphView = new LineGraphView(this, "Poziom cukru [mg/dl]");

    graphView.setHorizontalLabels(new String[] {"0h", "1h", "2h", "3h", "4h", "5h", "6h"});

    graphView.addSeries(hyperglycemicSeries1);
    graphView.addSeries(hyperglycemicSeries2);
    graphView.addSeries(lowSeries);
    graphView.addSeries(exampleSeries); // data

    graphView.setViewPort(0, 360);

    LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
    layout.addView(graphView);
  }
Example #10
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.i("RequestData", String.valueOf(REQUEST_DATA));
    Log.i("RequestOk", String.valueOf(resultCode));
    if (requestCode == REQUEST_DATA && resultCode == RESULT_OK) {
      /*
                  Bundle extras = data.getExtras();
                  Log.i("Received", String.valueOf(extras.getString(PlotActivity.SCALE)));

                  int ageX = Integer.parseInt(extras.getString(PlotActivity.AGE_RANGE));
                  int progressY = Integer.parseInt(extras.getString(PlotActivity.SCALE));
                  String description = extras.getString(PlotActivity.DESCRIPTION);
                  DataPoint dataPoint = new DataPoint(ageX, progressY);

                  memories.add(ageX, description);
                  //then place on graph via appendDataPoint
                  series.appendData(dataPoint,false, memories.size());

      */
      Log.i("AGERANGE", String.valueOf(data.getIntExtra("AGE_RANGE", 3)));
      Log.i("SCALE", String.valueOf(data.getIntExtra("SCALE", 5)));
      Log.i("DESCRIPTION", String.valueOf(data.getStringExtra("DESCRIPTION")));
      Log.i("NAME", String.valueOf(data.getStringExtra("TITLE")));

      int ageX = data.getIntExtra("AGE_RANGE", 3);
      int progressY = data.getIntExtra("SCALE", 5);
      String description = data.getStringExtra("DESCRIPTION");
      DataPoint dataPoint = new DataPoint(ageX, progressY);

      // add to a Datapoint linked list which will use Datapoint as key for a class of info
      memories.add(ageX, description);
      // then place on graph via appendDataPoint
      series.appendData(dataPoint, false, 25);
      graph.addSeries(series);
    }
  }
Example #11
0
  protected void readHR() {
    if (hrProvider != null) {
      long age = hrProvider.getHRValueTimestamp();
      int hrValue = hrProvider.getHRValue();
      tvHR.setText(Integer.toString(hrValue));

      if (age != lastTimestamp) {
        if (graphViewSeries == null) {
          timerStartTime = System.currentTimeMillis();
          GraphViewData empty[] = {};
          graphViewSeries = new GraphViewSeries(empty);
          graphView.addSeries(graphViewSeries);
        }

        graphViewListData.add(new GraphViewData((age - timerStartTime) / 1000, hrValue));
        while (graphViewListData.size() > GRAPH_HISTORY_SECONDS) {
          graphViewListData.remove(0);
        }
        graphViewArrayData = graphViewListData.toArray(graphViewArrayData);
        graphViewSeries.resetData(graphViewArrayData);
        lastTimestamp = age;
      }
    }
  }
Example #12
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);
  }
Example #13
0
  /**
   * 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);
    }
  }
Example #14
0
 private void clearGraph() {
   graphView.removeAllSeries();
   graphViewSeries = null;
   graphViewListData.clear();
   graphViewArrayData = new GraphViewData[0];
 }
Example #15
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, "");
    }
  }
Example #16
0
  @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();
  }
 /**
  * clears the current data and set the new. redraws the graphview(s)
  *
  * @param values new data
  */
 public void resetData(GraphViewDataInterface[] values) {
   this.values = values;
   for (GraphView g : graphViews) {
     g.redrawAll();
   }
 }
  @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);
  }
Example #19
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.graphs);

    // init example series data
    exampleSeries1 =
        new GraphViewSeries(
            new GraphViewData[] {
              new GraphViewData(1, 2.0d),
              new GraphViewData(2, 1.5d),
              new GraphViewData(2.5, 3.0d) // another frequency
              ,
              new GraphViewData(3, 2.5d),
              new GraphViewData(4, 1.0d),
              new GraphViewData(5, 3.0d)
            });

    // graph with dynamically genereated horizontal and vertical labels
    if (getIntent().getStringExtra("type").equals("bar")) {
      graphView =
          new BarGraphView(
              this // context
              ,
              "GraphViewDemo" // heading
              );
    } else {
      graphView =
          new LineGraphView(
              this // context
              ,
              "GraphViewDemo" // heading
              );
    }
    graphView.addSeries(exampleSeries1); // data

    LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
    layout.addView(graphView);

    // ----------
    exampleSeries2 =
        new GraphViewSeries(
            new GraphViewData[] {
              new GraphViewData(1, 2.0d),
              new GraphViewData(2, 1.5d),
              new GraphViewData(2.5, 3.0d) // another frequency
              ,
              new GraphViewData(3, 2.5d),
              new GraphViewData(4, 1.0d),
              new GraphViewData(5, 3.0d)
            });

    // graph with custom labels and drawBackground
    if (getIntent().getStringExtra("type").equals("bar")) {
      graphView = new BarGraphView(this, "GraphViewDemo");
    } else {
      graphView = new LineGraphView(this, "GraphViewDemo");
      ((LineGraphView) graphView).setDrawBackground(true);
    }
    graphView.addSeries(exampleSeries2); // data
    graphView.setViewPort(1, 4);
    graphView.setScalable(true);

    layout = (LinearLayout) findViewById(R.id.graph2);
    layout.addView(graphView);
  }