diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a67b73e..6e7d611 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -22,6 +22,7 @@
-
+
+
\ No newline at end of file
diff --git a/res/layout/activity_garmin_series_demo.xml b/res/layout/activity_garmin_series_demo.xml
new file mode 100644
index 0000000..626dc3e
--- /dev/null
+++ b/res/layout/activity_garmin_series_demo.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/main.xml b/res/layout/main.xml
index 3867ade..1dc97dd 100644
--- a/res/layout/main.xml
+++ b/res/layout/main.xml
@@ -58,5 +58,10 @@
android:layout_height="wrap_content"
android:id="@+id/btn_negativevalues"
android:text="Negative Values" />
+
diff --git a/res/menu/garmin_series_demo.xml b/res/menu/garmin_series_demo.xml
new file mode 100644
index 0000000..c002028
--- /dev/null
+++ b/res/menu/garmin_series_demo.xml
@@ -0,0 +1,9 @@
+
diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml
new file mode 100644
index 0000000..44f01db
--- /dev/null
+++ b/res/values-sw600dp/dimens.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
diff --git a/res/values-sw720dp-land/dimens.xml b/res/values-sw720dp-land/dimens.xml
new file mode 100644
index 0000000..61e3fa8
--- /dev/null
+++ b/res/values-sw720dp-land/dimens.xml
@@ -0,0 +1,9 @@
+
+
+
+ 128dp
+
+
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
new file mode 100644
index 0000000..55c1e59
--- /dev/null
+++ b/res/values/dimens.xml
@@ -0,0 +1,7 @@
+
+
+
+ 16dp
+ 16dp
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d5bdc00..9e88e00 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1,5 +1,10 @@
+
Hello World, SimpleGraph!GraphViewDemos
+ Data selection example
+ Settings
+ Hello world!
+
diff --git a/src/com/jjoe64/graphviewdemos/ColorUtil.java b/src/com/jjoe64/graphviewdemos/ColorUtil.java
new file mode 100644
index 0000000..3c7d494
--- /dev/null
+++ b/src/com/jjoe64/graphviewdemos/ColorUtil.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2013 by Garmin Ltd. or its subsidiaries.
+ */
+
+package com.jjoe64.graphviewdemos;
+
+/**
+ * @author becze
+ *
+ */
+public class ColorUtil {
+ // ------------------------------------------------------------------------
+ // TYPES
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // STATIC FIELDS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // STATIC INITIALIZERS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // STATIC METHODS
+ // ------------------------------------------------------------------------
+
+ /**
+ * Changes the alpha component of the given color to the newAlpha value.
+ * @param color the input color
+ * @param newAlpha the alpha component between the values [0, 255]
+ * @return the new color
+ */
+ public static int changeColorAlpha(int color, int newAlpha) {
+
+ int mask = 0xFF;
+ int a = (color >> 24) & mask;
+ int r = (color >> 16) & mask;
+ int g = (color >> 8) & mask;
+ int b = color & mask;
+
+ // Put it all back in place
+ return (newAlpha << 24) + (r << 16) + (g << 8) + b;
+
+ }
+
+ // ------------------------------------------------------------------------
+ // FIELDS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // INITIALIZERS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // CONSTRUCTORS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // METHODS
+ // ------------------------------------------------------------------------
+}
diff --git a/src/com/jjoe64/graphviewdemos/MainActivity.java b/src/com/jjoe64/graphviewdemos/MainActivity.java
index a02403c..0a79a32 100644
--- a/src/com/jjoe64/graphviewdemos/MainActivity.java
+++ b/src/com/jjoe64/graphviewdemos/MainActivity.java
@@ -1,5 +1,7 @@
package com.jjoe64.graphviewdemos;
+import com.jjoe64.graphviewdemos.dataselection.SampleSeriesDemoActivity;
+
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
@@ -69,6 +71,12 @@ public void onClick(View v) {
startGraphActivity(NegativeValuesGraph.class);
}
});
+ ((Button) findViewById(R.id.btn_sampleSelection)).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ startGraphActivity(SampleSeriesDemoActivity.class);
+ }
+ });
}
private void startGraphActivity(Class extends Activity> activity) {
diff --git a/src/com/jjoe64/graphviewdemos/dataselection/SampleGraphViewData.java b/src/com/jjoe64/graphviewdemos/dataselection/SampleGraphViewData.java
new file mode 100644
index 0000000..7635652
--- /dev/null
+++ b/src/com/jjoe64/graphviewdemos/dataselection/SampleGraphViewData.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2013 by Garmin Ltd. or its subsidiaries.
+ */
+
+package com.jjoe64.graphviewdemos.dataselection;
+
+import com.jjoe64.graphview.GraphViewDataInterface;
+
+/**
+ * @author becze
+ */
+public class SampleGraphViewData implements GraphViewDataInterface {
+
+ // ------------------------------------------------------------------------
+ // TYPES
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // STATIC FIELDS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // STATIC INITIALIZERS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // STATIC METHODS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // FIELDS
+ // ------------------------------------------------------------------------
+ private double x;
+
+ private double y;
+
+
+ // The parent series where this data value belongs to.
+ private SampleGraphViewSeries parentSeries;
+
+ // ------------------------------------------------------------------------
+ // INITIALIZERS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // CONSTRUCTORS
+ // ------------------------------------------------------------------------
+ /**
+ * Makes a new sample.
+ *
+ * @param parentSeries the series where the data element will belong to.
+ * @param x the value on the x axes (horizontal axes)
+ * @param y the value on the y axes (the vertical axes)
+ */
+ public SampleGraphViewData(SampleGraphViewSeries parentSeries, double x, double y) {
+ this.parentSeries = parentSeries;
+ this.x = x;
+ this.y = y;
+ }
+
+ // ------------------------------------------------------------------------
+ // METHODS
+ // ------------------------------------------------------------------------
+ /**
+ * Just simply return the stored X value. We don't have to scale it.
+ *
+ * @return
+ * @see com.jjoe64.graphview.GraphViewDataInterface#getX()
+ */
+ @Override
+ public double getX() {
+ return x;
+ }
+
+ /**
+ * This value is scaled down to fit between the [-1, 1] interval. we will
+ * use the parent series max. value and min. value to determine it.
+ *
+ * @return
+ * @see com.jjoe64.graphview.GraphViewDataInterface#getY()
+ */
+ @Override
+ public double getY() {
+ return y/parentSeries.getMaxScaleSize();
+ }
+
+ /**
+ * Setter for Y
+ * @param y
+ */
+ public void setY(double y) {
+ this.y = y;
+ }
+}
diff --git a/src/com/jjoe64/graphviewdemos/dataselection/SampleGraphViewSeries.java b/src/com/jjoe64/graphviewdemos/dataselection/SampleGraphViewSeries.java
new file mode 100644
index 0000000..1590837
--- /dev/null
+++ b/src/com/jjoe64/graphviewdemos/dataselection/SampleGraphViewSeries.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2013 by Garmin Ltd. or its subsidiaries.
+ */
+
+package com.jjoe64.graphviewdemos.dataselection;
+
+import com.jjoe64.graphview.GraphViewSeries;
+
+/**
+ * @author becze
+ */
+public class SampleGraphViewSeries extends GraphViewSeries {
+ // ------------------------------------------------------------------------
+ // TYPES
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // STATIC FIELDS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // STATIC INITIALIZERS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // STATIC METHODS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // FIELDS
+ // ------------------------------------------------------------------------
+ /**
+ * The possible minimum and maximum values displayed by the series. These
+ * values are fixed and predefined
+ */
+ private final double minY;
+
+ private final double maxY;
+
+ // ------------------------------------------------------------------------
+ // INITIALIZERS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // CONSTRUCTORS
+ // ------------------------------------------------------------------------
+
+ /**
+ * Just use the super constructor
+ *
+ * @param name - name of the series
+ * @param style - associated style of the series
+ * @param maxValue - the predefined maximum value of the series. No greater
+ * values can be added to this one. This maximum value will be
+ * the maximum on the scale too.
+ * @param minValue - the predefined minimum value of the series. It behaves
+ * similarly to maximum value.
+ */
+ public SampleGraphViewSeries(String name, double minValue, double maxValue) {
+
+ super(name, null, null);
+ // ensure that the minumum value is indeed smaller than the maximum
+ // value
+ if (minValue > maxValue)
+ throw new IllegalArgumentException(
+ "The minumum value must be larger than the maximum value");
+
+ minY = minValue;
+ maxY = maxValue;
+ }
+
+ // ------------------------------------------------------------------------
+ // METHODS
+ // ------------------------------------------------------------------------
+
+ /**
+ * @return The scale size can be determined by taking the maximum from from
+ * the absolute values of the minY and maxY
+ */
+ public double getMaxScaleSize() {
+ return Math.max(Math.abs(minY), Math.abs(maxY));
+ }
+
+ /**
+ * Append the data to the graph ensuring that the Y value is between the
+ * bounds.
+ *
+ * @param value
+ * @param scrollToEnd
+ * @param maxDataCount
+ */
+ public void appendData(SampleGraphViewData value, boolean scrollToEnd, int maxDataCount) {
+
+ // be sure that the Y value is always between the bounds.
+ if (value.getY() > maxY)
+ value.setY(maxY);
+ if (value.getY() < minY)
+ value.setY(minY);
+
+
+ super.appendData(value, scrollToEnd, maxDataCount);
+ }
+
+ /**
+ * Initializes the graph data with values given as arguments, ensuring that
+ * the values are between the bounds.
+ *
+ * @param values
+ */
+ public void initializeData(SampleGraphViewData[] values) {
+ // be sure that the Y value is always between the bounds.
+ for (SampleGraphViewData value : values) {
+ if (value.getY() > maxY)
+ value.setY(maxY);
+ if (value.getY() < minY)
+ value.setY(minY);
+ }
+
+ // now the values are ok, we can initialize our graph
+ super.resetData(values);
+ }
+
+ public double getMinY() {
+ return minY;
+ }
+
+ public double getMaxY() {
+ return maxY;
+ }
+}
diff --git a/src/com/jjoe64/graphviewdemos/dataselection/SampleLineGraphView.java b/src/com/jjoe64/graphviewdemos/dataselection/SampleLineGraphView.java
new file mode 100644
index 0000000..df7cdba
--- /dev/null
+++ b/src/com/jjoe64/graphviewdemos/dataselection/SampleLineGraphView.java
@@ -0,0 +1,395 @@
+/*
+ * Copyright (C) 2013 by Garmin Ltd. or its subsidiaries.
+ */
+
+package com.jjoe64.graphviewdemos.dataselection;
+
+import com.jjoe64.graphview.CustomLabelFormatter;
+import com.jjoe64.graphview.LineGraphView;
+import com.jjoe64.graphviewdemos.ColorUtil;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint.Align;
+import android.graphics.RectF;
+import android.os.Handler;
+import android.os.Message;
+
+import java.util.ArrayList;
+
+/**
+ * Garmin Graph Views have some special properties:
+ *
It can display multiple line graphs at the same time.
+ *
It provides the possibility to highlight one of the lines.
+ *
The highlighted item will provide the scale to the other line graphs, so
+ * they will automatically be resized to fit into the highlighted graphs scale.
+ *
The graph itself is updated periodically, and if moves from rigt to
+ * left.
+ *
The graph view is scrollable and on scroll the graph stops moving.
+ *
+ * @author becze
+ */
+public class SampleLineGraphView extends LineGraphView {
+ // ------------------------------------------------------------------------
+ // TYPES
+ // ------------------------------------------------------------------------
+ // Define the Handler that receives messages from the thread and update the
+ // progress
+ private final class UIHandler extends Handler {
+
+ public static final int UPDATE_SERIES_WITH_DATA = 1;
+
+ public void handleMessage(Message msg) {
+
+ switch (msg.what) {
+ case UPDATE_SERIES_WITH_DATA:
+ startGraphUpdate();
+ break;
+
+ default:
+ break;
+ }
+
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // STATIC FIELDS
+ // ------------------------------------------------------------------------
+
+ private static final int HIGHLIGHTED_THICKNESS = 16;
+
+ private static final int HIGHLIGHTED_TRANSPARENCY = 255;
+
+ private static final int DEFAULT_THICKNESS = 8;
+
+ private static final int DEFAULT_TRANSPARENCY = 128;
+
+ private static final int NUMBER_OF_SAMPLE_DATA = 200;
+
+ private static final int VIEWPORT_SIZE = 100;
+
+ // the number of milliseconds between two updates
+ private static final long UPDATE_INTERVAL = 1000;
+
+ /**
+ * The default colors of the graph data
+ */
+ private static int[] COLORS = new int[] {
+ Color.argb(255, 200, 50, 00), Color.argb(255, 100, 150, 00),
+ Color.argb(255, 255, 255, 555), Color.argb(255, 00, 50, 100),
+ Color.argb(255, 00, 50, 200), Color.argb(255, 200, 50, 200),
+ Color.argb(255, 200, 50, 00), Color.argb(255, 100, 150, 00),
+ Color.argb(255, 255, 255, 555), Color.argb(255, 00, 50, 100),
+ Color.argb(255, 00, 50, 200), Color.argb(255, 200, 50, 200)
+ };
+
+ private static UIHandler handler;
+
+ // ------------------------------------------------------------------------
+ // STATIC INITIALIZERS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // STATIC METHODS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // FIELDS
+ // ------------------------------------------------------------------------
+
+ private SampleGraphViewSeries highlightedSeries;
+
+ private ArrayList submittedValues;
+
+ /**
+ * We maintain a local list of series which will help us to have an indexed
+ * order of the series.
+ */
+ private ArrayList seriesList;
+
+ // ------------------------------------------------------------------------
+ // INITIALIZERS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // CONSTRUCTORS
+ // ------------------------------------------------------------------------
+ /**
+ * Just uses passes the context and the title of the graph to the super
+ * constructor
+ */
+ public SampleLineGraphView(Context context, String title) {
+ super(context, title);
+
+ // set the manually bounds. All the graphs' data will be normalized to
+ // be between [0,1]
+ setManualYAxisBounds(1, 0);
+
+ // make a new handler
+ handler = new UIHandler();
+
+ // create a new series
+ seriesList = new ArrayList();
+
+ // initialize the submitted values list
+ submittedValues = new ArrayList();
+
+ // initialize the viewport
+ setViewPort(2, VIEWPORT_SIZE);
+ setScrollable(true);
+
+ // set no horizontal labels
+ setHorizontalLabels(new String[] {
+ ""
+ });
+
+ // no legend is shown
+ setShowLegend(false);
+ setLegendAlign(LegendAlign.TOP);
+ getGraphViewStyle().setLegendWidth(200);
+
+ setSelectionEnabled(true);
+
+ }
+
+ // ------------------------------------------------------------------------
+ // METHODS
+ // ------------------------------------------------------------------------
+
+ /**
+ * Starts to update the graph periodically
+ */
+ public void startGraphUpdate() {
+ updateGraphDataPeriodically();
+ }
+
+ /**
+ * Stop to update the graph periodically
+ */
+ public void stopGraphUpdate() {
+ handler.removeMessages(UIHandler.UPDATE_SERIES_WITH_DATA);
+ }
+
+ /**
+ * @param canvas
+ * @see com.jjoe64.graphview.GraphView#drawGraphView(android.graphics.Canvas)
+ */
+ @Override
+ protected void drawGraphView(Canvas canvas, float height, float width) {
+ super.drawGraphView(canvas, height, width);
+ if (isSelectionEnabled() && lastSelectedDataX != -1) {
+ drawSelectionPanel(canvas, height, width);
+ }
+ }
+
+ /**
+ * Draws a panel with the current values and measurement units
+ *
+ * @param canvas
+ * @param height
+ * @param width
+ */
+ private void drawSelectionPanel(Canvas canvas, float height, float width) {
+
+ ArrayList graphSeries = toListToArray();
+
+ // we check quickly how many series' sample data is available
+ int nrOfSamples = 0;
+ for (int seriesIndex = 0; seriesIndex < graphSeries.size(); seriesIndex++) {
+ SampleGraphViewSeries series = graphSeries.get(seriesIndex);
+ if (series.getHighlightedData() != null)
+ nrOfSamples++;
+ }
+
+ // if no data is avalaible then don't draw anything
+ if (nrOfSamples == 0)
+ return;
+
+ // Draw a same panel as the legend
+ float textSize = paint.getTextSize();
+ int spacing = getGraphViewStyle().getLegendSpacing();
+ int border = getGraphViewStyle().getLegendBorder();
+ int legendWidth = getGraphViewStyle().getLegendWidth();
+ int shapeSize = (int) (textSize * 0.8d);
+
+ /*
+ * We draw the background rectangle
+ */
+ float legendHeight = (shapeSize + spacing) * graphSeries.size() + 2 * border - spacing;
+ float lLeft = lastSelectedDataX - legendHeight / 2;
+ float lRight = lLeft + legendWidth;
+ // if the left bound is negative then shift it to 0
+ if (lLeft < 0) {
+ lRight -= lLeft;
+ lLeft = 0;
+ }
+
+ // if the right bound is out of the screen then we take it back
+ if (lRight > width) {
+ float delta = lRight - width;
+ lLeft -= delta;
+ lRight -= delta;
+ }
+
+ float lTop = 0;
+ float lBottom = legendHeight;
+ paint.setARGB(180, 100, 100, 100);
+ canvas.drawRoundRect(new RectF(lLeft, 0, lRight, lBottom), 8, 8, paint);
+
+ // For each series we generate a colored rectangle and the label
+ for (int seriesIndex = 0; seriesIndex < graphSeries.size(); seriesIndex++) {
+ SampleGraphViewSeries series = graphSeries.get(seriesIndex);
+ // The rectangle will have the same color as the series itself
+ paint.setColor(series.getStyle().color);
+ canvas.drawRect(new RectF(lLeft + border, lTop + border
+ + (seriesIndex * (shapeSize + spacing)), lLeft + border + shapeSize, lTop
+ + border + (seriesIndex * (shapeSize + spacing)) + shapeSize), paint);
+
+ // get the label which will be the value trimmed to two decimals and
+ // the measurement unit
+ paint.setColor(Color.WHITE);
+ paint.setTextAlign(Align.LEFT);
+ String label = "N/A";
+ if (series.getHighlightedData() != null) {
+ label = String.format("%.2f", ((SampleGraphViewData) series.getHighlightedData()).getY());
+ }
+ // draw the label too
+ canvas.drawText(label, lLeft + border + shapeSize + spacing, lTop + border + shapeSize
+ + (seriesIndex * (shapeSize + spacing)), paint);
+ }
+ }
+
+ /**
+ * We add a new series specifying the style of the series too.
+ *
+ * @param series
+ */
+ public void addSeries(SampleGraphViewSeries series) {
+ // add the series to our list
+ seriesList.add(series);
+ // add new submitted value row
+ submittedValues.add(new Double(0));
+
+ // set the default style
+ series.getStyle().color = COLORS[seriesList.size() - 1];
+ series.getStyle().thickness = DEFAULT_THICKNESS;
+
+ // if we just added our first series we highlight it
+ if (seriesList.size() == 1)
+ highlightSeries(series);
+
+ super.addSeries(series);
+
+ }
+
+ /**
+ * Highlights the given series.
+ *
+ * @param seriesIndex
+ */
+ public void highlightSeries(SampleGraphViewSeries highlightedSeries) {
+
+ if (highlightedSeries == null)
+ throw new IllegalArgumentException("The highlighted series must be a non null one.");
+
+ // Reset the style of all the series
+ for (int i = 0; i < seriesList.size(); i++) {
+ seriesList.get(i).getStyle().thickness = DEFAULT_THICKNESS;
+ seriesList.get(i).getStyle().color = ColorUtil.changeColorAlpha(seriesList.get(i)
+ .getStyle().color, DEFAULT_TRANSPARENCY);
+ }
+
+ // change the tickness and transparency of the highlighted graph line
+ highlightedSeries.getStyle().thickness = HIGHLIGHTED_THICKNESS;
+ highlightedSeries.getStyle().color = ColorUtil.changeColorAlpha(highlightedSeries
+ .getStyle().color, HIGHLIGHTED_TRANSPARENCY);
+
+ // save the new series.
+ this.highlightedSeries = highlightedSeries;
+
+ // add to the top the highlighted series, it's very important to call
+ // the super add series
+ removeSeries(highlightedSeries);
+ super.addSeries(highlightedSeries);
+
+ final double maxScaleSize = highlightedSeries.getMaxScaleSize();
+
+ // adding a new custom label formatter.
+ setCustomLabelFormatter(new CustomLabelFormatter() {
+
+ @Override
+ public String formatLabel(double value, boolean isValueX) {
+ // we will not care about the X value. We will always return
+ // empty string
+ // if (isValueX)
+ // return "-";
+ // else {
+ // }
+ return new Double(value * maxScaleSize).toString();
+ }
+ });
+ }
+
+ /**
+ * Highlights the series with the given index.
+ *
+ * @param seriesIndex
+ */
+ public void highlightSeries(int seriesIndex) {
+ highlightSeries(seriesList.get(seriesIndex));
+ }
+
+ /**
+ * If there was a new value submitted then append that value, else just
+ * duplicate the last one.
+ */
+ private void updateGraphDataPeriodically() {
+
+ for (int i = 0; i < seriesList.size(); i++) {
+
+ SampleGraphViewSeries series = seriesList.get(i);
+
+ // if we have a value submitted
+ if (submittedValues.get(i) != null) {
+ series.appendData(new SampleGraphViewData(series, super.getMaxX(true) + 1, Math
+ .random() * series.getMaxY()),
+ false,
+ NUMBER_OF_SAMPLE_DATA);
+ }
+ }
+
+ // enable scrolling if we have enough data
+ handleGraphViewScroll();
+
+ handler.sendEmptyMessageDelayed(UIHandler.UPDATE_SERIES_WITH_DATA, UPDATE_INTERVAL);
+
+ }
+
+ /**
+ * Checks if the graph view is scrollable and should scrol to the end.
+ */
+ private void handleGraphViewScroll() {
+ // check if the graph is scrollable
+ setDisableTouch(super.getMaxX(true) < VIEWPORT_SIZE);
+
+ // allow auto scroll back
+ if (isDisableTouch() || getMaxX(false) + 5 >= super.getMaxX(true)) {
+ // scroll to the end of the graph
+ scrollToEnd();
+ }
+
+ }
+
+
+ /**
+ * Turns the hash map into an array
+ *
+ * @return
+ */
+ private ArrayList toListToArray() {
+ return seriesList;
+ }
+
+}
diff --git a/src/com/jjoe64/graphviewdemos/dataselection/SampleSeriesDemoActivity.java b/src/com/jjoe64/graphviewdemos/dataselection/SampleSeriesDemoActivity.java
new file mode 100644
index 0000000..2bdffa0
--- /dev/null
+++ b/src/com/jjoe64/graphviewdemos/dataselection/SampleSeriesDemoActivity.java
@@ -0,0 +1,175 @@
+
+package com.jjoe64.graphviewdemos.dataselection;
+
+import com.jjoe64.graphview.GraphViewStyle;
+import com.jjoe64.graphviewdemos.R;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.ArrayAdapter;
+import android.widget.LinearLayout;
+import android.widget.Spinner;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SampleSeriesDemoActivity extends Activity implements OnItemSelectedListener {
+
+ // ------------------------------------------------------------------------
+ // TYPES
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // STATIC FIELDS
+ // ------------------------------------------------------------------------
+
+ private static final int NR_OF_GRAPHS = 3;
+
+ private static final int NUMBER_OF_SAMPLE_DATA_PREGENERATED = 150;
+
+ private static final String TAG = SampleSeriesDemoActivity.class.getSimpleName();
+
+ // ------------------------------------------------------------------------
+ // STATIC INITIALIZERS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // STATIC METHODS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // FIELDS
+ // ------------------------------------------------------------------------
+
+ private SampleGraphViewSeries highlightedSeries;
+
+ private Spinner graphSeries;
+
+ private LinearLayout graphLayout;
+
+ private SampleLineGraphView graphView;
+
+ // ------------------------------------------------------------------------
+ // INITIALIZERS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // CONSTRUCTORS
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // METHODS
+ // ------------------------------------------------------------------------
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_garmin_series_demo);
+
+ graphLayout = (LinearLayout) findViewById(R.id.graph1);
+
+ // get the Graph view
+ graphView = new SampleLineGraphView(this, "GraphViewDemo");
+
+ GraphViewStyle style = new GraphViewStyle();
+
+
+ graphView.setGraphViewStyle(style);
+
+
+ // preparing the data to be displayed
+ prepareData();
+ // start the data update
+ graphView.startGraphUpdate();
+
+ graphLayout.addView(graphView);
+
+ }
+
+ /**
+ *
+ * @see android.app.Activity#onDestroy()
+ */
+ @Override
+ protected void onDestroy() {
+ graphView.stopGraphUpdate();
+ super.onDestroy();
+ }
+
+ /**
+ * We prepare NR_OF_GRAPHS series to display a pregenerated data
+ */
+ private void prepareData() {
+
+ // List to hold the spinner data
+ List list = new ArrayList();
+ graphSeries = (Spinner) findViewById(R.id.graphSeries);
+ graphSeries.setOnItemSelectedListener(this);
+
+ // Generate random data for each series
+ for (int i = 0; i < NR_OF_GRAPHS; i++) {
+
+ // Create a new series
+ String seriesName = "data: " + i;
+ double minValue = 0;
+ double maxValue = i * 10 + 1;
+ SampleGraphViewSeries series = new SampleGraphViewSeries(seriesName, minValue, maxValue);
+
+ // reset the series index
+ SampleGraphViewData[] data = new SampleGraphViewData[NUMBER_OF_SAMPLE_DATA_PREGENERATED];
+ for (int j = 0; j < NUMBER_OF_SAMPLE_DATA_PREGENERATED; j++) {
+ // increment the series
+ data[j] = new SampleGraphViewData(series, j, Math.sin(j * 0.05 + i * 5)
+ * series.getMaxScaleSize() / 2);
+
+ }
+
+ // add the data to the series
+ series.initializeData(data);
+ // add the series to the list of the series
+ graphView.addSeries(series);
+ list.add(seriesName);
+ }
+
+ /*
+ * Set up the spinner too
+ */
+ ArrayAdapter dataAdapter = new ArrayAdapter(this,
+ android.R.layout.simple_spinner_item, list);
+ dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ graphSeries.setAdapter(dataAdapter);
+
+ }
+
+
+
+ /**
+ * @param arg0
+ * @param arg1
+ * @param itemIndex
+ * @param arg3
+ * @see android.widget.AdapterView.OnItemSelectedListener#onItemSelected(android.widget.AdapterView,
+ * android.view.View, int, long)
+ */
+ @Override
+ public void onItemSelected(AdapterView> arg0, View arg1, int itemIndex, long arg3) {
+ Log.d(TAG, "Item selected: " + itemIndex);
+
+ // refresh the series
+ graphView.highlightSeries(itemIndex);
+ }
+
+ /**
+ * @param arg0
+ * @see android.widget.AdapterView.OnItemSelectedListener#onNothingSelected(android.widget.AdapterView)
+ */
+ @Override
+ public void onNothingSelected(AdapterView> arg0) {
+ // TODO Auto-generated method stub
+
+ }
+}