Android Open Source - Swinedroid Alert Chart






From Project

Back to project page Swinedroid.

License

The source code is released under:

GNU General Public License

If you think the Android project Swinedroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.achartengine.chartlib;
//w w w .ja va  2s.  c  o  m
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

import org.achartengine.ChartFactory;
import org.achartengine.chart.PointStyle;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.content.Context;
import android.graphics.Color;
import android.view.View;

public class AlertChart extends AbstractChart {
  private String mTitleString;
  private String mXAxisString;
  private int mHighPoint;
  private int mLowPoint;
  public LinkedList<AlertMoment> alertMoments;

  public class AlertMoment{
    public String mLabel;
    public int mHigh;
    public int mMedium;
    public int mLow;
  }
  
  public void addAlertMoment(){
    alertMoments.add(new AlertMoment());
  }
  
  public void setLastMomentHighAlert(int point){
    alertMoments.getLast().mHigh = point;
    if(point > mHighPoint)
      mHighPoint = point;
    if(point < mLowPoint)
      mLowPoint = point;
  }
  
  public void setLastMomentMediumAlert(int point){
    alertMoments.getLast().mMedium = point;
    if(point > mHighPoint)
      mHighPoint = point;
    if(point < mLowPoint)
      mLowPoint = point;
  }
  
  public void setLastMomentLowAlert(int point){
    alertMoments.getLast().mLow = point;
    if(point > mHighPoint)
      mHighPoint = point;
    if(point < mLowPoint)
      mLowPoint = point;
  }
  
  public void setLastMomentLabel(String label){
    alertMoments.getLast().mLabel = label;
  }
  
  public AlertChart(){
    alertMoments = new LinkedList<AlertMoment>();
  }
  
  public void setTitleString(String titleString){
    mTitleString = titleString;
  }
  
  public void setXAxisString(String xAxisString){
    mXAxisString = xAxisString;
  }
  
  /**
  * Executes the chart demo.
  * @param context the context
  * @return the built intent
  */
  public View execute(Context context) {
    String[] titles = new String[] { "High", "Medium", "Low"};
    List<double[]> x = new ArrayList<double[]>();
    for(int i = 0; i < titles.length; i++) {
      double[] xDoubles = new double[alertMoments.size()];
      for(int i2 = 0; i2 < alertMoments.size(); i2++){
        xDoubles[i2] = i2 + 1; 
      }
      x.add(xDoubles);
    }
    
    int[] colors = new int[] { Color.RED, Color.YELLOW, Color.GREEN};
    PointStyle[] styles = new PointStyle[] {PointStyle.CIRCLE, PointStyle.DIAMOND, PointStyle.TRIANGLE};
    XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
    
    List<double[]> values = new ArrayList<double[]>();
    double[] highValueDoubles = new double[alertMoments.size()];
    double[] mediumValueDoubles = new double[alertMoments.size()];
    double[] lowValueDoubles = new double[alertMoments.size()];
    ListIterator<AlertMoment> itr = alertMoments.listIterator();
    while(itr.hasNext()){
      int i = itr.nextIndex();
      AlertMoment thisAlertMoment = (AlertMoment) itr.next();
      highValueDoubles[i] = thisAlertMoment.mHigh;
      mediumValueDoubles[i] = thisAlertMoment.mMedium;
      lowValueDoubles[i] = thisAlertMoment.mLow;
      renderer.addTextLabel(i + 1, thisAlertMoment.mLabel);
    }
    values.add(highValueDoubles);
    values.add(mediumValueDoubles);
    values.add(lowValueDoubles);
    int length = renderer.getSeriesRendererCount();
    for (int i = 0; i < length; i++) {
      ((XYSeriesRenderer) renderer.getSeriesRendererAt(i)).setFillPoints(true);
    }
    setChartSettings(renderer, mTitleString, mXAxisString, "Alerts", 0.5, alertMoments.size() + 0.5, 0, mHighPoint + (mHighPoint * .1), Color.LTGRAY, Color.GRAY);
    renderer.setYLabels(8);
    View view = ChartFactory.getLineChartView(context, buildDataset(titles, x, values), renderer);

      return view;
  }

}




Java Source Code List

com.legind.Dialogs.ErrorMessageHandler.java
com.legind.Dialogs.MessageHandler.java
com.legind.sqlite.AlertDbAdapter.java
com.legind.sqlite.DbAdapter.java
com.legind.sqlite.ServerDbAdapter.java
com.legind.ssl.CertificateInspect.CertificateInspect.java
com.legind.ssl.SSLHandler.SSLHandler.java
com.legind.ssl.TrustManagerFactory.TrustManagerFactory.java
com.legind.swinedroid.AlertList.java
com.legind.swinedroid.AlertSearch.java
com.legind.swinedroid.AlertView.java
com.legind.swinedroid.ServerEdit.java
com.legind.swinedroid.ServerHashDialog.java
com.legind.swinedroid.ServerView.java
com.legind.swinedroid.Swinedroid.java
com.legind.swinedroid.NetworkRunnable.NetworkRunnableBindRequires.java
com.legind.swinedroid.NetworkRunnable.NetworkRunnableManager.java
com.legind.swinedroid.NetworkRunnable.NetworkRunnableRequires.java
com.legind.swinedroid.NetworkRunnable.NetworkRunnableUniqueRequires.java
com.legind.swinedroid.NetworkRunnable.NetworkRunnable.java
com.legind.swinedroid.RequestService.RequestElement.java
com.legind.swinedroid.RequestService.Request.java
com.legind.swinedroid.xml.AlertListXMLElement.java
com.legind.swinedroid.xml.AlertListXMLHandler.java
com.legind.swinedroid.xml.AlertXMLElement.java
com.legind.swinedroid.xml.AlertXMLHandler.java
com.legind.swinedroid.xml.OverviewXMLElement.java
com.legind.swinedroid.xml.OverviewXMLHandler.java
com.legind.swinedroid.xml.XMLHandlerException.java
com.legind.swinedroid.xml.XMLHandler.java
com.legind.web.WebTransport.WebTransportConnection.java
com.legind.web.WebTransport.WebTransportException.java
com.legind.web.WebTransport.WebTransport.java
org.achartengine.chartlib.AbstractChart.java
org.achartengine.chartlib.AlertChart.java