Skip to content

Commit bd69fec

Browse files
authored
SDK / Tools Updates + More Unit Tests (halfhp#38)
* update target SDK to 25 / update gradle plugin to 2.3.1. also added caching to sdk deps for circle cfg. * added support annotations. added unit tests * more unit test coverage
1 parent b6fbe2f commit bd69fec

23 files changed

Lines changed: 672 additions & 363 deletions

androidplot-core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def gitUrl = 'https://github.com/halfhp/androidplot.git'
5050
dependencies {
5151

5252
compile 'com.halfhp.fig:figlib:1.0.3'
53+
compile 'com.android.support:support-annotations:24.2.0'
5354
testCompile "org.mockito:mockito-core:1.10.19"
5455
testCompile group: 'junit', name: 'junit', version: '4.12'
5556
testCompile "org.robolectric:robolectric:3.1"

androidplot-core/src/main/java/com/androidplot/Plot.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public enum RenderMode {
164164
private final BufferedCanvas pingPong = new BufferedCanvas();
165165

166166
// used to get rid of flickering when drawing offScreenBitmap to the visible Canvas.
167-
private final Object renderSynch = new Object();
167+
private final Object renderSync = new Object();
168168

169169
private HashMap<Class<? extends RendererType>, RendererType> renderers;
170170

@@ -390,13 +390,13 @@ public void run() {
390390
renderOnCanvas(c);
391391
pingPong.swap();
392392
}
393-
synchronized (renderSynch) {
393+
synchronized (renderSync) {
394394
postInvalidate();
395395
// prevent this thread from becoming an orphan
396396
// after the view is destroyed
397397
if (keepRunning) {
398398
try {
399-
renderSynch.wait();
399+
renderSync.wait();
400400
} catch (InterruptedException e) {
401401
keepRunning = false;
402402
}
@@ -712,8 +712,8 @@ public void redraw() {
712712
// if the render thread is idle, so we know that we won't have to wait to
713713
// obtain a lock.
714714
if (isIdle) {
715-
synchronized (renderSynch) {
716-
renderSynch.notify();
715+
synchronized (renderSync) {
716+
renderSync.notify();
717717
}
718718
}
719719
} else if(renderMode == RenderMode.USE_MAIN_THREAD) {
@@ -738,9 +738,9 @@ public synchronized void layout(final DisplayDimensions dims) {
738738
@Override
739739
protected void onDetachedFromWindow() {
740740
super.onDetachedFromWindow();
741-
synchronized(renderSynch) {
741+
synchronized(renderSync) {
742742
keepRunning = false;
743-
renderSynch.notify();
743+
renderSync.notify();
744744
}
745745
}
746746

androidplot-core/src/main/java/com/androidplot/ui/widget/EmptyWidget.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

androidplot-core/src/main/java/com/androidplot/ui/widget/TextLabelWidget.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@
2121
import com.androidplot.util.FontUtils;
2222

2323
public class TextLabelWidget extends Widget {
24-
private static final String TAG = TextLabelWidget.class.getName();
25-
2624
private String text;
2725
private Paint labelPaint;
28-
2926
private TextOrientation orientation;
30-
3127
private boolean autoPackEnabled = true;
3228

3329
{
@@ -67,16 +63,12 @@ public void onPostInit() {
6763
}
6864
}
6965

70-
//protected abstract String getText();
71-
7266
/**
7367
* Sets the dimensions of the widget to exactly contain the text contents
7468
*/
7569
public void pack() {
76-
//Log.d(TAG, "Packing...");
7770
Rect size = FontUtils.getStringDimensions(text, getLabelPaint());
7871
if(size == null) {
79-
//Log.w(TAG, "Attempt to pack empty text.");
8072
return;
8173
}
8274
switch(orientation) {
@@ -103,14 +95,11 @@ public void doOnDraw(Canvas canvas, RectF widgetRect) {
10395
if(text == null || text.length() == 0) {
10496
return;
10597
}
106-
//FontUtils.getStringDimensions(text, labelPaint);
98+
10799
float vOffset = labelPaint.getFontMetrics().descent;
108100
PointF start = getAnchorCoordinates(widgetRect,
109101
Anchor.CENTER);
110102

111-
// BEGIN ROTATION CALCULATION
112-
//int canvasState = canvas.save(Canvas.ALL_SAVE_FLAG);
113-
114103
try {
115104
canvas.save(Canvas.ALL_SAVE_FLAG);
116105
canvas.translate(start.x, start.y);
@@ -129,11 +118,8 @@ public void doOnDraw(Canvas canvas, RectF widgetRect) {
129118
}
130119
canvas.drawText(text, 0, vOffset, labelPaint);
131120
} finally {
132-
//canvas.restoreToCount(canvasState);
133121
canvas.restore();
134122
}
135-
136-
// END ROTATION CALCULATION
137123
}
138124

139125
public Paint getLabelPaint() {
@@ -173,7 +159,6 @@ public void setAutoPackEnabled(boolean autoPackEnabled) {
173159
}
174160

175161
public void setText(String text) {
176-
//Log.d(TAG, "Setting textLabel to: " + text);
177162
this.text = text;
178163
if(autoPackEnabled) {
179164
pack();

androidplot-core/src/main/java/com/androidplot/util/LayerHash.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,28 @@ public synchronized boolean remove(KeyType key) {
153153
return false;
154154
}
155155
}
156+
157+
public ValueType getTop() {
158+
return hash.get(zlist.getLast());
159+
}
160+
161+
public ValueType getBottom() {
162+
return hash.get(zlist.getFirst());
163+
}
164+
165+
public ValueType getAbove(KeyType key) {
166+
final int index = zlist.indexOf(key);
167+
if(index >= 0 && index < size() - 1) {
168+
return hash.get(zlist.get(index + 1));
169+
}
170+
return null;
171+
}
172+
173+
public ValueType getBeneath(KeyType key) {
174+
final int index = zlist.indexOf(key);
175+
if(index > 0) {
176+
return hash.get(zlist.get(index - 1));
177+
}
178+
return null;
179+
}
156180
}

androidplot-core/src/main/java/com/androidplot/util/PlotStatistics.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class PlotStatistics implements PlotListener {
3939
long latencySamples = 0;
4040
long latencySum = 0;
4141
String annotationString = "";
42+
private boolean annotatePlotEnabled;
4243

4344
private Paint paint;
4445
{
@@ -49,11 +50,6 @@ public class PlotStatistics implements PlotListener {
4950
resetCounters();
5051
}
5152

52-
53-
private boolean annotatePlotEnabled;
54-
55-
56-
5753
public PlotStatistics(long updateDelayMs, boolean annotatePlotEnabled) {
5854
this.updateDelayMs = updateDelayMs;
5955
this.annotatePlotEnabled = annotatePlotEnabled;
@@ -109,4 +105,8 @@ public void onAfterDraw(Plot source, Canvas canvas) {
109105
latencySamples++;
110106
annotatePlot(source, canvas);
111107
}
108+
109+
public void setEnabled(boolean isEnabled) {
110+
this.annotatePlotEnabled = isEnabled;
111+
}
112112
}

androidplot-core/src/main/java/com/androidplot/util/SeriesUtils.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ public static RectRegion minMax(XYConstraints constraints, XYSeries... seriesArr
8484
// if this is an advanced xy series then minMax have already been calculated for us:
8585
if(series instanceof FastXYSeries) {
8686
final RectRegion b = ((FastXYSeries) series).minMax();
87+
if(b == null) {
88+
continue;
89+
}
8790
if(constraints == null) {
8891
bounds.union(b);
8992
} else {
@@ -259,26 +262,6 @@ public static Region minMax(List<Number>... lists) {
259262
return minMax(new Region(), lists);
260263
}
261264

262-
public static void main(String[] args) {
263-
264-
// seed the list:
265-
ArrayList<Number> values = new ArrayList<>();
266-
for (int i = 0; i < 1000000; i++) {
267-
values.add(Math.random() * 100);
268-
}
269-
final int numIterations = 20;
270-
long sumTime = 0;
271-
for(int j = 0; j < numIterations; j++) {
272-
final long startTime = System.currentTimeMillis();
273-
Region bounds = minMax(values);
274-
final long thisIteration = System.currentTimeMillis() - startTime;
275-
System.out.println("thisIteration took: " + thisIteration + "ms");
276-
sumTime += thisIteration;
277-
}
278-
279-
System.out.println("Benchmark avg:" + (sumTime / numIterations) + "ms.");
280-
}
281-
282265
/**
283266
* Determine the XVal order of an XYSeries. If series does not implement {@link OrderedXYSeries}
284267
* then {@link com.androidplot.xy.OrderedXYSeries.XOrder#NONE} is assumed.
@@ -287,6 +270,6 @@ public static void main(String[] args) {
287270
*/
288271
public static OrderedXYSeries.XOrder getXYOrder(XYSeries series) {
289272
return series instanceof OrderedXYSeries ?
290-
((OrderedXYSeries) series).getXOrder() : OrderedXYSeries.XOrder.NONE;
273+
((OrderedXYSeries) series).getXOrder() : OrderedXYSeries.XOrder.NONE;
291274
}
292275
}

androidplot-core/src/main/java/com/androidplot/xy/LineAndPointRenderer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ protected ArrayList<PointF> getPointsCache(XYSeries series) {
124124
protected void cullPointsCache() {
125125
for(XYSeries series : pointsCaches.keySet()) {
126126
if(!getPlot().getRegistry().contains(series, LineAndPointFormatter.class)) {
127-
//pointsCaches.put(series, null);
128127
pointsCaches.remove(series);
129128
}
130129
}

androidplot-core/src/main/java/com/androidplot/xy/RectRegion.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -344,39 +344,4 @@ public boolean isFullyDefined() {
344344
public boolean contains(Number x, Number y) {
345345
return getxRegion().contains(x) && getyRegion().contains(y);
346346
}
347-
348-
/**
349-
* Checks to see whether the specified line. Note that this implementation will return
350-
* true even if the line is completely enclosed by this RectRegion.
351-
* WARNING: this implementation has problems. See associated unit test for details.
352-
* @param x1 x-coord of the line beginning
353-
* @param y1 y-coord of the line beginning
354-
* @param x2 x-coord of the line end
355-
* @param y2 y-coord of the line end
356-
* @return True if this RectRegion overlaps any part of the specified line.
357-
*/
358-
public boolean intersectsWithLine(Number x1, Number y1, Number x2, Number y2) {
359-
if(contains(x1, y1) || contains(x2, y2)) {
360-
return true;
361-
}
362-
363-
// if true, it means that these points exist on different sides of the rect's edges
364-
final boolean x1MinRelation = x1.doubleValue() < getMinX().doubleValue();
365-
final boolean x2MinRelation = x2.doubleValue() < getMinX().doubleValue();
366-
final boolean xMinRelation = x1MinRelation &! x2MinRelation;
367-
368-
final boolean x1MaxRelation = x1.doubleValue() < getMaxX().doubleValue();
369-
final boolean x2MaxRelation = x2.doubleValue() < getMaxX().doubleValue();
370-
final boolean xMaxRelation = x1MaxRelation &! x2MaxRelation;
371-
372-
final boolean y1MinRelation = y1.doubleValue() < getMinY().doubleValue();
373-
final boolean y2MinRelation = y2.doubleValue() < getMinY().doubleValue();
374-
final boolean yMinRelation = y1MinRelation &! y2MinRelation;
375-
376-
final boolean y1MaxRelation = y1.doubleValue() < getMaxY().doubleValue();
377-
final boolean y2MaxRelation = y2.doubleValue() < getMaxY().doubleValue();
378-
final boolean yMaxRelation = y1MaxRelation &! y2MaxRelation;
379-
380-
return ((xMinRelation | xMaxRelation) || getxRegion().contains(x1) & (yMinRelation | yMaxRelation) || getyRegion().contains(y1));
381-
}
382347
}

androidplot-core/src/main/java/com/androidplot/xy/StepRenderer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
* Renders a point as a line with the vertices marked. Requires 2 or more points to
2424
* be rendered.
2525
*/
26-
2726
public class StepRenderer extends LineAndPointRenderer<StepFormatter> {
2827

2928
public StepRenderer(XYPlot plot) {

0 commit comments

Comments
 (0)