Blame | Last modification | View Log | Download | RSS feed
package ioio.debugger;import java.util.LinkedList;import com.androidplot.Plot.BorderStyle;import com.androidplot.xy.BoundaryMode;import com.androidplot.xy.LineAndPointFormatter;import com.androidplot.xy.StepFormatter;import com.androidplot.xy.XYPlot;import com.androidplot.xy.XYStepMode;import android.graphics.Color;import android.os.Handler;import android.view.View;import android.widget.TextView;public class ViewWidgetGraphText implements ViewWidget {private View view;private Runnable run;private Thread thread;private Handler handler = new Handler();private GenericXYSeries plotData;private XYPlot historyPlot;private int pin;public ViewWidgetGraphText() {}@Overridepublic void stopThread() {thread.interrupt();}@Overridepublic void startThread() {// Kill the thread if it is already runningif (thread != null && thread.isAlive())thread.interrupt();// Start a new thread and run the passed Runnablethread = new Thread (run);thread.start();}@Overridepublic View getView() {return view;}@Overridepublic Thread getThread() {return thread;}@Overridepublic void clearData() {plotData.clearData();}@Overridepublic void setStopSignal() {handler.post(new Runnable() {@Overridepublic void run() {TextView tv = (TextView)view.findViewById(R.id.layout_graphText_status);tv.setTextColor(Color.RED);}});}@Overridepublic void resetStopSignal() {handler.post(new Runnable() {@Overridepublic void run() {TextView tv = (TextView)view.findViewById(R.id.layout_graphText_status);tv.setTextColor(Color.WHITE);}});}@Overridepublic void sendDataHistory() {LinkedList<Number> data = plotData.getData();Double[] data2 = data.toArray(new Double[data.size()]);IOIODebuggerActivity.get_networkMgr().sendData(pin, data2);}@Overridepublic int getPin() {return pin;}public void setPin(final int p) {pin = p;}public void updateText(final String str) {handler.post(new Runnable() {@Overridepublic void run() {TextView tv = (TextView)view.findViewById(R.id.layout_graphText_text);tv.setText(str);}});}public void updateStatus(final String str) {handler.post(new Runnable() {@Overridepublic void run() {TextView tv = (TextView)view.findViewById(R.id.layout_graphText_status);tv.setText(str);}});}public void setView(View view, boolean useStep, int historyLength) {this.view = view;// Set graph plot detailsplotData = new GenericXYSeries("Analog In", historyLength);historyPlot = (XYPlot) view.findViewById(R.id.layout_graphText_graph);// Add data to plotif (!useStep)historyPlot.addSeries(plotData, new LineAndPointFormatter(Color.rgb(0, 0, 200), Color.rgb(0, 0, 100),Color.rgb(150, 150, 190)));else {StepFormatter stepFormatter = new StepFormatter(Color.rgb(0, 0, 0), Color.rgb(150, 190, 150));stepFormatter.getLinePaint().setStrokeWidth(1);historyPlot.addSeries(plotData, stepFormatter);}// Set boundary and tickshistoryPlot.setRangeBoundaries(0, 3.3, BoundaryMode.FIXED);historyPlot.setDomainBoundaries(0, historyLength, BoundaryMode.FIXED);historyPlot.setDomainStepValue(5);historyPlot.setRangeStep(XYStepMode.SUBDIVIDE, 4);historyPlot.setTicksPerRangeLabel(3);// Remove labels and legendhistoryPlot.getLegendWidget().setVisible(false);historyPlot.getDomainLabelWidget().setVisible(false);historyPlot.getRangeLabelWidget().setVisible(false);historyPlot.getTitleWidget().setVisible(false);// Remove extra margin spacehistoryPlot.getGraphWidget().setMargins(0, 10, 10, 0);historyPlot.getGraphWidget().setRangeLabelWidth(30);historyPlot.getGraphWidget().setDomainLabelWidth(15);historyPlot.getGraphWidget().setMarginLeft(-5);historyPlot.getGraphWidget().setMarginRight(25);historyPlot.setPlotMargins(0, 0, 0, 0);historyPlot.setPlotPadding(0, 0, 0, 0);// Remove background colorhistoryPlot.getGraphWidget().setBackgroundPaint(null);historyPlot.setBackgroundPaint(null);historyPlot.setBorderPaint(null);historyPlot.setBorderStyle(BorderStyle.SQUARE, null, null);historyPlot.disableAllMarkup();}public void setRunnable(Runnable r) {run = r;}public void updateData(Number num) {plotData.addDataToList(num);}public void refreshGraph() {handler.post(new Runnable() {@Overridepublic void run() {historyPlot.redraw();}});}public void setRange(Number start, Number end) {historyPlot.setRangeBoundaries(start, end, BoundaryMode.FIXED);}public void setDomain(Number length) {historyPlot.setDomainBoundaries(0, length, BoundaryMode.FIXED);}}