From de01258b0c1a6df3e35b36ea41173c1aa9616a50 Mon Sep 17 00:00:00 2001 From: Vahid Date: Wed, 8 Mar 2017 14:22:23 -0500 Subject: [PATCH] #484: Add support for modifying the sensitivity of onTap() method invocation in BaseSeries class In BaseSeries.java: Adds mTapTriggerDistanceThreshold field that stores the threshold distance value that will trigger the onTap method of the series. Defines TapSensitivity enum class to represent the sensitivity of the tap events. LOW(150), NORMAL(120), MEDIUM(90), HIGH(60), EXTREME(30) Lets the user modify the tap sensitivity by calling the public method setTapThreshold that accepts TapSensitivity enum values. Removes duplicate entries in .gitignore. Removes the gradle.properties that should have been ignored from the repo. --- .gitignore | 13 +--- .../jjoe64/graphview/series/BaseSeries.java | 71 +++++++++++++------ 2 files changed, 51 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 77cbeee5a..72eb78243 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ tmp/**/* *.bak *.swp *~.nib +# Local configuration file (sdk path, etc) local.properties .classpath .settings/ @@ -52,12 +53,6 @@ local.properties bin/ gen/ -# Local configuration file (sdk path, etc) -local.properties - -# Eclipse project files -.classpath -.project # Proguard folder generated by Eclipse proguard/ @@ -65,12 +60,6 @@ proguard/ # Proguard folder generated by Intellij proguard_logs/ -# Intellij project files -*.iml -*.ipr -*.iws -.idea/ - adt-bundle-windows-x86_64/ ### Windows ### diff --git a/src/main/java/com/jjoe64/graphview/series/BaseSeries.java b/src/main/java/com/jjoe64/graphview/series/BaseSeries.java index f996fbfa8..6eb3e1364 100644 --- a/src/main/java/com/jjoe64/graphview/series/BaseSeries.java +++ b/src/main/java/com/jjoe64/graphview/series/BaseSeries.java @@ -79,10 +79,16 @@ public abstract class BaseSeries implements Series private double mLowestYCache = Double.NaN; /** - * cahce for highest y value + * cache for highest y value */ private double mHighestYCache = Double.NaN; + /** + * stores the threshold distance value will + * trigger the onTap method of the series. + */ + private double mTapTriggerDistanceThreshold = 120; + /** * listener to handle tap events on a data point */ @@ -105,8 +111,8 @@ public BaseSeries() { /** * creates series with data * - * @param data data points - * important: array has to be sorted from lowest x-value to the highest + * @param data data points + * important: array has to be sorted from lowest x-value to the highest */ public BaseSeries(E[] data) { mGraphViews = new ArrayList(); @@ -129,7 +135,7 @@ public double getLowestValueX() { */ public double getHighestValueX() { if (mData.isEmpty()) return 0d; - return mData.get(mData.size()-1).getX(); + return mData.get(mData.size() - 1).getX(); } /** @@ -174,7 +180,7 @@ public double getHighestValueY() { * If it is only a part of the data, the range is returned plus one datapoint * before and after to get a nice scrolling. * - * @param from minimal x-value + * @param from minimal x-value * @param until maximal x-value * @return data for the range +/- 1 datapoint */ @@ -327,14 +333,14 @@ protected E findDataPoint(float x, float y) { float x2 = x; float y2 = y; - float distance = (float) Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); + float distance = (float) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); if (shortest == null || distance < shortestDistance) { shortestDistance = distance; shortest = entry.getValue(); } } if (shortest != null) { - if (shortestDistance < 120) { + if (shortestDistance < mTapTriggerDistanceThreshold) { return shortest; } } @@ -365,8 +371,8 @@ public E findDataPointAtX(float x) { /** * register the datapoint to find it at a tap * - * @param x pixel - * @param y pixel + * @param x pixel + * @param y pixel * @param dp the data point to save */ protected void registerDataPoint(float x, float y, E dp) { @@ -430,17 +436,17 @@ public void onGraphViewAttached(GraphView graphView) { /** * - * @param dataPoint values the values must be in the correct order! - * x-value has to be ASC. First the lowest x value and at least the highest x value. - * @param scrollToEnd true => graphview will scroll to the end (maxX) + * @param dataPoint values the values must be in the correct order! + * x-value has to be ASC. First the lowest x value and at least the highest x value. + * @param scrollToEnd true => graphview will scroll to the end (maxX) * @param maxDataPoints if max data count is reached, the oldest data * value will be lost to avoid memory leaks - * @param silent set true to avoid rerender the graph + * @param silent set true to avoid rerender the graph */ public void appendData(E dataPoint, boolean scrollToEnd, int maxDataPoints, boolean silent) { checkValueOrder(dataPoint); - if (!mData.isEmpty() && dataPoint.getX() < mData.get(mData.size()-1).getX()) { + if (!mData.isEmpty() && dataPoint.getX() < mData.get(mData.size() - 1).getX()) { throw new IllegalArgumentException("new x-value must be greater then the last value. x-values has to be ordered in ASC."); } synchronized (mData) { @@ -487,9 +493,9 @@ public void appendData(E dataPoint, boolean scrollToEnd, int maxDataPoints, bool /** * - * @param dataPoint values the values must be in the correct order! - * x-value has to be ASC. First the lowest x value and at least the highest x value. - * @param scrollToEnd true => graphview will scroll to the end (maxX) + * @param dataPoint values the values must be in the correct order! + * x-value has to be ASC. First the lowest x value and at least the highest x value. + * @param scrollToEnd true => graphview will scroll to the end (maxX) * @param maxDataPoints if max data count is reached, the oldest data * value will be lost to avoid memory leaks */ @@ -508,14 +514,14 @@ public boolean isEmpty() { /** * checks that the data is in the correct order * - * @param onlyLast if not null, it will only check that this - * datapoint is after the last point. + * @param onlyLast if not null, it will only check that this + * datapoint is after the last point. */ protected void checkValueOrder(DataPointInterface onlyLast) { - if (mData.size()>1) { + if (mData.size() > 1) { if (onlyLast != null) { // only check last - if (onlyLast.getX() < mData.get(mData.size()-1).getX()) { + if (onlyLast.getX() < mData.get(mData.size() - 1).getX()) { throw new IllegalArgumentException("new x-value must be greater then the last value. x-values has to be ordered in ASC."); } } else { @@ -538,4 +544,27 @@ protected void checkValueOrder(DataPointInterface onlyLast) { public void clearCursorModeCache() { mIsCursorModeCache = null; } + + /** + * An enum class to represent the sensitivity of the tap events. + * Each enum value maps an amount to itself. + */ + public enum TapSensitivity { + LOW(150), NORMAL(120), MEDIUM(90), HIGH(60), EXTREME(30); + private final double tapThreshold; + + TapSensitivity(final double tapThreshold) { + this.tapThreshold = tapThreshold; + } + } + + /** + * sets the tap sensitivity threshold. + * + * @param tapSensitivity the sensitivity level of tap + */ + public void setTapThreshold(final TapSensitivity tapSensitivity) { + this.mTapTriggerDistanceThreshold = tapSensitivity.tapThreshold; + + } }