From c8a245d0319f080ae6b490032f94a244b2950b8c Mon Sep 17 00:00:00 2001 From: Andrew Davie Date: Tue, 29 Mar 2016 04:57:52 +1100 Subject: [PATCH] Honoured isCancelled() for the async renderer, and return correct status This should speed up things a bit by killing background tasks earlier --- .../plus/views/AsynchronousResampler.java | 153 ++++++++---------- .../src/net/osmand/plus/views/Renderable.java | 2 +- 2 files changed, 67 insertions(+), 88 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/AsynchronousResampler.java b/OsmAnd/src/net/osmand/plus/views/AsynchronousResampler.java index 15bf2fc5f1..8f8cf9089f 100644 --- a/OsmAnd/src/net/osmand/plus/views/AsynchronousResampler.java +++ b/OsmAnd/src/net/osmand/plus/views/AsynchronousResampler.java @@ -1,10 +1,8 @@ package net.osmand.plus.views; -import android.graphics.Color; import android.os.AsyncTask; import net.osmand.plus.GPXUtilities; -import net.osmand.plus.views.OsmandMapTileView; import net.osmand.util.MapUtils; import java.util.ArrayList; @@ -26,48 +24,22 @@ public abstract class AsynchronousResampler extends AsyncTask 0) + for (GPXUtilities.WptPt pt : culled) + pt.colourARGB = getRainbowColour((pt.ele - min) / elevationRange); } - Double elevationRange = max-min; - if (elevationRange > 0) - for (GPXUtilities.WptPt pt : culled) - pt.colourARGB = getColor2((pt.ele - min)/elevationRange); - - return "OK"; + return isCancelled() ? "" : "OK"; } } @@ -176,37 +154,38 @@ public abstract class AsynchronousResampler extends AsyncTask points = rs.getPoints(); culled = resampleTrack(points, segmentSize); + if (!isCancelled()) { - GPXUtilities.WptPt lastPt = points.get(0); - lastPt.speed = 0; + GPXUtilities.WptPt lastPt = points.get(0); + lastPt.speed = 0; - // calculate speeds using time:distance for each segment - for (int i=1; i0) - pt.speed = MapUtils.getDistance(pt.getLatitude(),pt.getLongitude(), - lastPt.getLatitude(),lastPt.getLongitude())/delta; - else - pt.speed = 0; // GPX doesn't have time - this is OK, colour will be mid-range for whole track - lastPt = pt; + // calculate speeds using time:distance for each segment + for (int i = 1; i < points.size(); i++) { + GPXUtilities.WptPt pt = points.get(i); + double delta = pt.time - lastPt.time; + if (delta > 0) + pt.speed = MapUtils.getDistance(pt.getLatitude(), pt.getLongitude(), + lastPt.getLatitude(), lastPt.getLongitude()) / delta; + else + pt.speed = 0; // GPX doesn't have time - this is OK, colour will be mid-range for whole track + lastPt = pt; + } + + // Calculate the absolutes of the speed variations + Double max = Double.NEGATIVE_INFINITY; + Double min = Double.POSITIVE_INFINITY; + for (GPXUtilities.WptPt pt : points) { + max = Math.max(max, pt.speed); + min = Math.min(min, pt.speed); + pt.colourARGB = getRainbowColour(0.5); + } + Double range = max - min; + if (range > 0) + for (GPXUtilities.WptPt pt : points) + pt.colourARGB = getRainbowColour((pt.speed - min) / range); } - // Calculate the absolutes of the speed variations - Double max = Double.NEGATIVE_INFINITY; - Double min = Double.POSITIVE_INFINITY; - for (GPXUtilities.WptPt pt : points) { - max = Math.max(max, pt.speed); - min = Math.min(min, pt.speed); - pt.colourARGB = getColor2(0.5); - } - Double range = max-min; - if (range > 0) - for (GPXUtilities.WptPt pt : points) - pt.colourARGB = getColor2((pt.speed - min) / range); - - - return "OK"; + return isCancelled() ? "" : "OK"; } } @@ -223,7 +202,7 @@ public abstract class AsynchronousResampler extends AsyncTask(); int nsize = points.size(); - survivor = new boolean[nsize]; if (nsize > 0) { + survivor = new boolean[nsize]; cullRamerDouglasPeucer(0, nsize - 1); - survivor[0] = true; + if (!isCancelled()) { + survivor[0] = true; + for (int i = 0; i < survivor.length; i++) + if (survivor[i]) + culled.add(points.get(i)); + } } - - culled = new ArrayList<>(); - for (int i = 0; i < survivor.length; i++) - if (survivor[i]) - culled.add(points.get(i)); - - return "OK"; + return isCancelled() ? "" : "OK"; } private void cullRamerDouglasPeucer(int start, int end) { diff --git a/OsmAnd/src/net/osmand/plus/views/Renderable.java b/OsmAnd/src/net/osmand/plus/views/Renderable.java index 81dea8cf26..8291ad9ce4 100644 --- a/OsmAnd/src/net/osmand/plus/views/Renderable.java +++ b/OsmAnd/src/net/osmand/plus/views/Renderable.java @@ -254,7 +254,7 @@ public class Renderable { this.segmentSize = segmentSize; this.alpha = alpha; alphaPaint = new Paint(); - alphaPaint.setStrokeCap(Paint.Cap.ROUND); + alphaPaint.setStrokeCap(Paint.Cap.BUTT); colorBandWidth = 3.0f; }