Skip to content

Commit

Permalink
cursor mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Gehring committed Feb 23, 2017
1 parent 940d6e5 commit 3ae8a21
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.new-version.md
Expand Up @@ -25,7 +25,7 @@ and/or here as ascii

hardcode user/pwd of nexus account in maven_push.gradle

run gradle task uploadArchives
success gradle task uploadArchives
- ./gradlew --rerun-tasks uploadArchives
- enter gpg info (id:D8C3B041 / path: /Users/jonas/.gnupg/secring.gpg / PWD)

Expand All @@ -47,6 +47,6 @@ Wait some days

How to create a new .jar file
--------------------------------
run this gradle task
success this gradle task
- ./gradlew --rerun-tasks clearJar makeJar
- cp build/outputs/myCompiledLibrary.jar public/GraphView-4.2.0.jar
41 changes: 41 additions & 0 deletions src/main/java/com/jjoe64/graphview/CursorMode.java
@@ -0,0 +1,41 @@
package com.jjoe64.graphview;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.v4.view.ViewCompat;
import android.util.Log;
import android.view.MotionEvent;

/**
* Created by jonas on 22/02/2017.
*/

public class CursorMode {
protected final Paint mPaintLine;
protected final GraphView mGraphView;
protected float mPosX;
protected boolean mVisible;

public CursorMode(GraphView graphView) {
mGraphView = graphView;
mPaintLine = new Paint();
mPaintLine.setColor(Color.argb(128, 180, 180, 180));
mPaintLine.setStrokeWidth(10f);
}

public void onDown(MotionEvent e) {
mPosX = e.getX();
mVisible = true;
mGraphView.invalidate();
}

public void onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
}

public void draw(Canvas canvas) {
if (!mVisible) return;

canvas.drawLine(mPosX, 0, mPosX, canvas.getHeight(), mPaintLine);
}
}
31 changes: 29 additions & 2 deletions src/main/java/com/jjoe64/graphview/GraphView.java
Expand Up @@ -22,7 +22,6 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PointF;
import android.net.Uri;
import android.provider.MediaStore;
Expand Down Expand Up @@ -156,11 +155,15 @@ public boolean onTouchEvent(MotionEvent event) {
*/
private Paint mPaintTitle;

private boolean mIsCursorMode;

/**
* paint for the preview (in the SDK)
*/
private Paint mPreviewPaint;

private CursorMode mCursorMode;

/**
* Initialize the GraphView view
* @param context
Expand Down Expand Up @@ -309,6 +312,11 @@ protected void drawGraphElements(Canvas canvas) {
s.draw(this, canvas, true);
}
}

if (mCursorMode != null) {
mCursorMode.draw(canvas);
}

mViewport.draw(canvas);
mLegendRenderer.draw(canvas);
}
Expand Down Expand Up @@ -568,7 +576,7 @@ public void removeAllSeries() {

/**
* Remove a specific series of the graph.
* This will also re-render the graph, but
* This will also re-draw the graph, but
* without recalculating the viewport and
* label sizes.
* If you want this, you have to call {@link #onDataChanged(boolean, boolean)}
Expand Down Expand Up @@ -617,4 +625,23 @@ public void takeSnapshotAndShare(Context context, String imageName, String title
ex.printStackTrace();
}
}

public void setCursorMode(boolean b) {
mIsCursorMode = b;
if (mIsCursorMode) {
if (mCursorMode == null) {
mCursorMode = new CursorMode(this);
}
} else {
mCursorMode = null;
}
}

public CursorMode getCursorMode() {
return mCursorMode;
}

public boolean isCursorMode() {
return mIsCursorMode;
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/jjoe64/graphview/Viewport.java
Expand Up @@ -258,6 +258,11 @@ public boolean onScale(ScaleGestureDetector detector) {
*/
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
// cursor mode
if (mGraphView.isCursorMode()) {
return false;
}

if (mIsScalable) {
mScalingActive = true;
return true;
Expand Down Expand Up @@ -292,6 +297,12 @@ public void onScaleEnd(ScaleGestureDetector detector) {
= new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
// cursor mode
if (mGraphView.isCursorMode()) {
mGraphView.getCursorMode().onDown(e);
return true;
}

if (!mIsScrollable || mScalingActive) return false;

// Initiates the decay phase of any active edge effects.
Expand All @@ -304,6 +315,11 @@ public boolean onDown(MotionEvent e) {

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
// cursor mode
if (mGraphView.isCursorMode()) {
mGraphView.getCursorMode().onScroll(e1, e2, distanceX, distanceY);
return true;
}
if (!mIsScrollable || mScalingActive) return false;

// Scrolling uses math based on the viewport (as opposed to math using pixels).
Expand Down
Expand Up @@ -501,7 +501,7 @@ public void setCustomPaint(Paint mCustomPaint) {
}

/**
* render the series with an animation
* draw the series with an animation
*
* @param animated animation activated or not
*/
Expand Down
Expand Up @@ -395,7 +395,7 @@ public void draw(GraphView graphView, Canvas canvas, boolean isSecondScale) {
if (mDrawAsPath) {
mPath.lineTo(endXAnimated, endY);
} else {
// render vertical lines that were skipped
// draw vertical lines that were skipped
if (sameXSkip) {
sameXSkip = false;
renderLine(canvas, new float[] {lastRenderedX, minYOnSameX, lastRenderedX, maxYOnSameX}, paint);
Expand All @@ -405,7 +405,7 @@ public void draw(GraphView graphView, Canvas canvas, boolean isSecondScale) {
lastRenderedX = endX;
} else {
// rendering on same x position
// save min+max y position and render it as line
// save min+max y position and draw it as line
if (sameXSkip) {
minYOnSameX = Math.min(minYOnSameX, endY);
maxYOnSameX = Math.max(maxYOnSameX, endY);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/jjoe64/graphview/series/PointsGraphSeries.java
Expand Up @@ -41,7 +41,7 @@ public class PointsGraphSeries<E extends DataPointInterface> extends BaseSeries<
public static interface CustomShape {
/**
* called when drawing a single data point.
* use the x and y coordinates to render your
* use the x and y coordinates to draw your
* drawing at this point.
*
* @param canvas canvas to draw on
Expand All @@ -55,9 +55,9 @@ public static interface CustomShape {
}

/**
* choose a predefined shape to render for
* choose a predefined shape to draw for
* each data point.
* You can also render a custom drawing via {@link com.jjoe64.graphview.series.PointsGraphSeries.CustomShape}
* You can also draw a custom drawing via {@link com.jjoe64.graphview.series.PointsGraphSeries.CustomShape}
*/
public enum Shape {
/**
Expand Down Expand Up @@ -240,7 +240,7 @@ public void draw(GraphView graphView, Canvas canvas, boolean isSecondScale) {
}

/**
* helper to render triangle
* helper to draw triangle
*
* @param point array with 3 coordinates
* @param canvas canvas to draw on
Expand Down Expand Up @@ -302,7 +302,7 @@ public void setShape(Shape s) {
}

/**
* Use a custom handler to render your own
* Use a custom handler to draw your own
* drawing for each data point.
*
* @param shape handler to use a custom drawing
Expand Down

0 comments on commit 3ae8a21

Please sign in to comment.