//#####package package uk.co.metricrat.chartmakerplus; //##### //#####imports import android.util.Log; import android.webkit.*; import com.google.appinventor.components.annotations.SimpleFunction; import com.google.appinventor.components.runtime.AndroidNonvisibleComponent; import com.google.appinventor.components.runtime.Component; import com.google.appinventor.components.runtime.ComponentContainer; import com.google.appinventor.components.runtime.WebViewer; import com.google.appinventor.components.runtime.util.YailList; import gnu.commonlisp.lang.*; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.*; import static org.acra.ACRA.LOG_TAG; //##### public class ChartMakerPlus extends AndroidNonvisibleComponent implements Component { //##### private ComponentContainer container; public ChartMakerPlus(ComponentContainer container) { super(container.$form()); } //##### //##### builds pie chart @SimpleFunction(description = "Creates a pie chart from a title string and input lists of data, " + "in the WebViewer passed as the final argument. Provides for adding options, gives slice selection feedback and controls zoom") public void PieChart(Object webViewer, String arrayTable, String title, boolean zoom, String extraOptions) { WebView webView; if (webViewer instanceof WebViewer) { webView = (WebView) ((WebViewer)webViewer).getView(); } else { webView = (WebView)webViewer; } String zoomMeta ; String filePath ; if (!zoom) { zoomMeta = "\n"; } else { zoomMeta = "\n"; } try { String htmlCode = "\n" + " \n" + zoomMeta + " \n" + " \n" + " \n" + "\n" + " \n" + "
\n" + " \n" + " " ; File file = File.createTempFile("display", ".html"); filePath = file.getAbsolutePath(); FileWriter filewriter = new FileWriter(file); filewriter.write(htmlCode); filewriter.close(); if(webViewer instanceof WebViewer){ ((WebViewer) webViewer).GoToUrl("file://" + filePath); } else { ((WebView) webViewer).loadUrl("file://" + filePath); } file.deleteOnExit(); } catch (IOException e) { Log.e(LOG_TAG, "IOException", e); } } //##### //##### builds bar chart @SimpleFunction(description = "Creates a bar chart from a title string and input lists of data " + " and displays the chart in the WebViewer passed as the final argument. Provides for adding options, gives bar selection feedback and controls zoom") public void BarChart(Object webViewer, String arrayTable, String title, boolean zoom, String extraOptions) { WebView webView; if (webViewer instanceof WebViewer) { webView = (WebView) ((WebViewer)webViewer).getView(); } else { webView = (WebView)webViewer; } String zoomMeta ; String filePath ; if (!zoom) { zoomMeta = "\n"; } else { zoomMeta = "\n"; } try { String htmlCode = "\n" + " \n" + zoomMeta + " \n" + " \n" + " \n" + "\n" + " \n" + "
\n" + " \n" + " " ; File file = File.createTempFile("display", ".html"); filePath = file.getAbsolutePath(); FileWriter filewriter = new FileWriter(file); filewriter.write(htmlCode); filewriter.close(); if(webViewer instanceof WebViewer){ ((WebViewer) webViewer).GoToUrl("file://" + filePath); } else { ((WebView) webViewer).loadUrl("file://" + filePath); } file.deleteOnExit(); } catch (IOException e) { Log.e(LOG_TAG, "IOException", e); } } //##### //##### builds column chart @SimpleFunction(description = "Creates a column chart from a title string and input lists of data " + " and displays the chart in the WebViewer passed as the final argument. Provides for adding options, gives column selection feedback and controls" + " zoom") public void ColumnChart(Object webViewer, String arrayTable, String title, boolean zoom, String extraOptions) { WebView webView; if (webViewer instanceof WebViewer) { webView = (WebView) ((WebViewer)webViewer).getView(); } else { webView = (WebView)webViewer; } String zoomMeta ; String filePath ; if (!zoom) { zoomMeta = "\n"; } else { zoomMeta = "\n"; } try { String htmlCode = "\n" + " \n" + zoomMeta + " \n" + " \n" + " \n" + "\n" + " \n" + "
\n" + " \n" + " " ; File file = File.createTempFile("display", ".html"); filePath = file.getAbsolutePath(); FileWriter filewriter = new FileWriter(file); filewriter.write(htmlCode); filewriter.close(); if(webViewer instanceof WebViewer){ ((WebViewer) webViewer).GoToUrl("file://" + filePath); } else { ((WebView) webViewer).loadUrl("file://" + filePath); } file.deleteOnExit(); } catch (IOException e) { Log.e(LOG_TAG, "IOException", e); } } //##### //##### builds table chart @SimpleFunction(description = "Creates a table chart from an input list of data, " + "and displays in the WebViewer passed as the final argument. Provides for adding options, gives row selection feedback, and controls zoom") public void TableChart(Object webViewer, String arrayTable, boolean zoom, boolean rowNumbers, String headerAlign, String cellAlign, String extraOptions, String css) { WebView webView; if (webViewer instanceof WebViewer) { webView = (WebView) ((WebViewer)webViewer).getView(); } else { webView = (WebView)webViewer; } String zoomMeta ; String filePath ; if (!zoom) { zoomMeta = "\n"; } else { zoomMeta = "\n"; } try { String htmlCode = "\n" + "\n" + zoomMeta + "\n" + "\n" + "\n" + "\n" + "\n" + "
\n" + "\n" + "" ; File file = File.createTempFile("display", ".html"); filePath = file.getAbsolutePath(); FileWriter filewriter = new FileWriter(file); filewriter.write(htmlCode); filewriter.close(); if(webViewer instanceof WebViewer){ ((WebViewer) webViewer).GoToUrl("file://" + filePath); } else { ((WebView) webViewer).loadUrl("file://" + filePath); } file.deleteOnExit(); } catch (IOException e) { Log.e(LOG_TAG, "IOException", e); } } //##### //##### builds line graph @SimpleFunction(description = "Creates a line graph from a main title and input lists, and displays the chart " + "in the WebViewer passed as the final argument. Provides for options, click feedback and zoom control") public void LineChart( Object webViewer,String arrayTable, String title, boolean zoom, String extraOptions) { WebView webView; if (webViewer instanceof WebViewer) { webView = (WebView) ((WebViewer)webViewer).getView(); } else { webView = (WebView)webViewer; } String zoomMeta ; String filePath ; if (!zoom) { zoomMeta = "\n"; } else { zoomMeta = "\n"; } try { String htmlCode = "\n" + "\n" + zoomMeta + "\n" + "\n" + "\n" + "\n" + "
\n" + "\n" + ""; File file = File.createTempFile("display", ".html"); filePath = file.getAbsolutePath(); FileWriter filewriter = new FileWriter(file); filewriter.write(htmlCode); filewriter.close(); if(webViewer instanceof WebViewer){ ((WebViewer) webViewer).GoToUrl("file://" + filePath); } else { ((WebView) webViewer).loadUrl("file://" + filePath); } file.deleteOnExit(); } catch (IOException e) { Log.e(LOG_TAG, "IOException", e); } } //##### }