Exemplo n.º 1
0
  @SuppressWarnings("deprecation")
  public void drawGraph(
      XYPlot plot, List<Number> xseries, List<Number> yseries, String datatitle, String title) {
    //		Log.d(SystemInfo.TIG, TAG + "::drawGraph()");

    // set up data series
    plot.removeSeries(series);

    series = new SimpleXYSeries(xseries, yseries, datatitle);

    // create a formatter
    // TODO solve deprecation waring
    LineAndPointFormatter format =
        new LineAndPointFormatter(
            Color.rgb(0, 200, 0) // line color
            ,
            Color.rgb(0, 100, 0) // point color
            ,
            Color.rgb(150, 190, 150)); // fill color (optional)

    // add series1 and series2 to the XYPlot
    plot.addSeries(series, format);

    // Reduce the number of range labels
    plot.setTicksPerRangeLabel(3);
    plot.getBackgroundPaint().setAlpha(0);
    plot.getGraphWidget().getBackgroundPaint().setAlpha(0);
    plot.getGraphWidget().getGridBackgroundPaint().setAlpha(0);

    // TODO implement an on-the-fly refresh of the plot
    // this is just a small "stubbed" redraw for demonstration purposes
    plot.setDomainStepMode(XYStepMode.SUBDIVIDE);
    plot.setDomainStepValue(1);
    plot.setGridPadding(0, 5, 0, 5);

    plot.setDomainLabel("Time [s]");
    if (title.equals(SystemInfo.DB_TABLENAME_BATTERY)) {
      plot.setTitle(SystemInfo.DB_TABLENAME_BATTERY);
      plot.setRangeLabel("[%]");
      plot.setRangeBoundaries(0, 100, BoundaryMode.FIXED);

    } else if (title.equals(SystemInfo.DB_TABLENAME_WIFI)) {
      plot.setTitle(SystemInfo.DB_TABLENAME_WIFI);
      plot.setRangeLabel("[~mW]");
      plot.setRangeBoundaries(0, 500, BoundaryMode.FIXED);

    } else if (title.equals(SystemInfo.DB_TABLENAME_THREEG)) {
      plot.setTitle(SystemInfo.DB_TABLENAME_THREEG);
      plot.setRangeLabel("[~mW]");
      plot.setRangeBoundaries(0, 500, BoundaryMode.FIXED);

    } else if (title.equals(SystemInfo.DB_TABLENAME_BLUETOOTH)) {
      plot.setTitle(SystemInfo.DB_TABLENAME_BLUETOOTH);
      plot.setRangeLabel("[~mW]");
      plot.setRangeBoundaries(0, 500, BoundaryMode.FIXED); // XXX scale
    }
    plot.redraw();
  }
Exemplo n.º 2
0
 @Override
 public void onStart() {
   super.onStart();
   // default display
   //		displayData( SystemInfo.PLOT_BATTERY_COMMENT, SystemInfo.DB_TABLENAME_BATTERY );
   XYPlot plot = (XYPlot) findViewById(R.id.xyplot);
   plot.setTitle("EMPTY");
 }
Exemplo n.º 3
0
  public GraphUpdater(Activity activity) {
    this.activity = activity;
    wifi = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
    plot = (XYPlot) activity.findViewById(R.id.graph);
    hash = new HashMap<String, WifiStrengthXYSeries>();

    plot.setTitle("");
    plot.setTicksPerRangeLabel(2);
    plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 1);
    plot.setDomainBoundaries(-1, 15, BoundaryMode.FIXED);
    plot.setDomainLabel("Channel");
    DecimalFormat df = new DecimalFormat("#0");
    df.setParseIntegerOnly(true);
    plot.setDomainValueFormat(df);
    plot.setRangeBoundaries(-100, -20, BoundaryMode.FIXED);
    plot.setRangeLabel("Strength");
    plot.getLegendWidget().setVisible(false);
  }
Exemplo n.º 4
0
  private void ShowPlot() {
    mySimpleXYPlot = (XYPlot) findViewById(R.id.chartPlot);
    mySimpleXYPlot.setTitle("Weight");

    if (plotLine != null) mySimpleXYPlot.removeSeries(plotLine);

    mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);
    mySimpleXYPlot.getGraphWidget().getGridLinePaint().setColor(Color.BLACK);
    mySimpleXYPlot
        .getGraphWidget()
        .getGridLinePaint()
        .setPathEffect(new DashPathEffect(new float[] {1, 1}, 1));
    mySimpleXYPlot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    mySimpleXYPlot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    mySimpleXYPlot.setBorderStyle(Plot.BorderStyle.SQUARE, null, null);
    mySimpleXYPlot.getBorderPaint().setStrokeWidth(1);
    mySimpleXYPlot.getBorderPaint().setAntiAlias(false);
    mySimpleXYPlot.getBorderPaint().setColor(Color.WHITE);
    mySimpleXYPlot.getGraphWidget().setPaddingRight(5);

    // Create a formatter to use for drawing a series using LineAndPointRenderer:
    LineAndPointFormatter series1Format =
        new LineAndPointFormatter(
            Color.rgb(0, 100, 0), // line color
            Color.rgb(0, 100, 0), // point color
            Color.rgb(100, 200, 0)); // fill color

    // setup our line fill paint to be a slightly transparent gradient:
    Paint lineFill = new Paint();
    lineFill.setAlpha(200);
    lineFill.setShader(
        new LinearGradient(0, 0, 0, 250, Color.WHITE, Color.GREEN, Shader.TileMode.MIRROR));

    LineAndPointFormatter formatter =
        new LineAndPointFormatter(Color.rgb(0, 0, 0), Color.BLUE, Color.RED);
    formatter.setFillPaint(lineFill);

    plotLine = new SimpleXYSeries(Arrays.asList(dates), Arrays.asList(weights), "Weight over time");
    mySimpleXYPlot.addSeries(plotLine, formatter);
    mySimpleXYPlot.redraw();

    // draw a domain tick for each year:
    int min = DomainMin();
    int max = DomainMax();
    int domainStep = domainStep(min, max);
    mySimpleXYPlot.setDomainStep(XYStepMode.SUBDIVIDE, domainStep);
    // mySimpleXYPlot.setDomainBoundaries(min, max, BoundaryMode.AUTO);

    // customize our domain/range labels
    mySimpleXYPlot.setDomainLabel("Date");
    mySimpleXYPlot.setRangeLabel("Weight");

    Double minimum = FindMinimum();
    Double maximum = FindMaximum();
    Double stepSize = FindStep(maximum, minimum);
    mySimpleXYPlot.setRangeBoundaries(minimum, maximum, BoundaryMode.FIXED);
    mySimpleXYPlot.setRangeStep(XYStepMode.INCREMENT_BY_VAL, stepSize);

    mySimpleXYPlot.setDomainValueFormat(
        new Format() {
          private SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM");

          @Override
          public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {

            // because our timestamps are in seconds and SimpleDateFormat expects milliseconds
            // we multiply our timestamp by 1000:
            long timestamp = ((Number) obj).longValue() * 1000;
            Date date = new Date(timestamp);
            return dateFormat.format(date, toAppendTo, pos);
          }

          @Override
          public Object parseObject(String source, ParsePosition pos) {
            return null;
          }
        });

    // by default, AndroidPlot displays developer guides to aid in laying out your plot.
    // To get rid of them call disableAllMarkup():
    mySimpleXYPlot.disableAllMarkup();
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // fun little snippet that prevents users from taking screenshots
    // on ICS+ devices :-)
    // getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
    //        WindowManager.LayoutParams.FLAG_SECURE);

    setContentView(R.layout.simple_xy_plot_example);

    // initialize our XYPlot reference:
    plot = (XYPlot) findViewById(R.id.mySimpleXYPlot);

    StockProvider sHelper = new StockProvider(this);
    Uri stockUri = null;

    String stockName = getIntent().getStringExtra("KEY");
    plot.setTitle(stockName);
    switch (stockName) {
      case "IBM":
        stockUri = StockContract.StockEntry.CONTENT_URI_IBM;
        break;
      case "MSFT":
        stockUri = StockContract.StockEntry.CONTENT_URI_MSFT;
        break;
      case "GOOG":
        stockUri = StockContract.StockEntry.CONTENT_URI_GOOG;
        break;
      case "AAPL":
        stockUri = StockContract.StockEntry.CONTENT_URI_AAPL;
    }

    Cursor values = sHelper.query(stockUri, null, null, null, null);

    ArrayList<Double> open = new ArrayList<Double>();
    ArrayList<Double> high = new ArrayList<Double>();
    ArrayList<Double> low = new ArrayList<Double>();
    ArrayList<Double> close = new ArrayList<Double>();

    for (values.moveToFirst(); !values.isAfterLast(); values.moveToNext()) {

      open.add(Double.parseDouble(values.getString(2)));
      high.add(Double.parseDouble(values.getString(3)));
      low.add(Double.parseDouble(values.getString(4)));
      close.add(Double.parseDouble(values.getString(5)));
    }
    Double[] openArray = new Double[open.size()];
    Double[] highArray = new Double[open.size()];
    Double[] lowArray = new Double[open.size()];
    Double[] closeArray = new Double[open.size()];
    double openI = open.get(0);
    for (int i = 0; i < open.size(); i++) {
      openArray[i] = open.get(i) / openI * 100;
      highArray[i] = high.get(i);
      lowArray[i] = low.get(i);
      closeArray[i] = close.get(i);
    }
    Double[] open5Array = new Double[open.size() / 5 + 1];
    Double[] high5Array = new Double[open.size() / 5 + 1];
    Double[] low5Array = new Double[open.size() / 5 + 1];
    Double[] close5Array = new Double[open.size() / 5 + 1];

    for (int i = 0; i < open.size(); i += 5) {
      open5Array[i / 5] = open.get(i) / openI * 100;
      double localHigh = high.get(i);
      double localLow = low.get(i);
      for (int j = 0; j < 5; j++) {
        if (i + j > 387) break;
        if ((i + j) < 388 && localHigh < high.get(i + j)) {
          localHigh = high.get(i + j);
        }
        if ((i + j) < 388 && localLow < low.get(i + j)) {
          localLow = low.get(i + j);
        }
        if (j == 4) {
          close5Array[i / 5] = close.get(i + j);
        }
      }
      high5Array[i / 5] = localHigh;
      low5Array[i / 5] = localLow;
    }

    // Create a couple arrays of y-values to plot:
    Number[] series1Numbers = open5Array; // {1, 8, 5, 2, 7, 4};
    Number[] series2Numbers = high5Array; // {4, 6, 3, 8, 2, 10};
    Number[] series3Numbers = low5Array;
    Number[] series4Numbers = close5Array;

    // Turn the above arrays into XYSeries':
    XYSeries series1 =
        new SimpleXYSeries(
            Arrays.asList(series1Numbers),
            SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
            "Open"); // Set the display title of the series

    XYSeries series2 =
        new SimpleXYSeries(
            Arrays.asList(series2Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "High");
    XYSeries series3 =
        new SimpleXYSeries(
            Arrays.asList(series3Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Low");
    XYSeries series4 =
        new SimpleXYSeries(
            Arrays.asList(series4Numbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Close");

    // Create a formatter to use for drawing a series using LineAndPointRenderer
    // and configure it from xml:
    myLineAndPointFormatter series1Format = new myLineAndPointFormatter();
    series1Format.setPointLabelFormatter(new myPointLabelFormatter());
    series1Format.configure(getApplicationContext(), R.xml.line_point_formatter_with_plf1);

    // add a new series' to the xyplot:
    plot.addSeries(series1, series1Format);
    //
    //        // same as above:
    //        myLineAndPointFormatter series2Format = new myLineAndPointFormatter();
    //        series2Format.setPointLabelFormatter(new myPointLabelFormatter() );
    //        series2Format.configure(getApplicationContext(),
    //                R.xml.line_point_formatter_with_plf2);
    //        plot.addSeries(series2, series2Format);
    //
    //        myLineAndPointFormatter series3Format = new myLineAndPointFormatter();
    //        series3Format.setPointLabelFormatter(new myPointLabelFormatter() );
    //        series3Format.configure(getApplicationContext(),
    //                R.xml.line_point_formatter_with_plf3);
    //        plot.addSeries(series3, series3Format);
    //
    //        myLineAndPointFormatter series4Format = new myLineAndPointFormatter();
    //        series4Format.setPointLabelFormatter(new myPointLabelFormatter() );
    //        series4Format.configure(getApplicationContext(),
    //                R.xml.line_point_formatter_with_plf4);
    //        plot.addSeries(series4, series4Format);

    // reduce the number of range labels
    plot.setTicksPerRangeLabel(1);
    plot.getGraphWidget().setDomainLabelOrientation(-90);
    plot.getGraphWidget().setDomainValueFormat(new DecimalFormat("####"));
  }