diff options
| author | Bananeweizen <Bananeweizen@gmx.de> | 2012-05-18 16:45:54 +0200 |
|---|---|---|
| committer | Bananeweizen <Bananeweizen@gmx.de> | 2012-05-18 16:45:54 +0200 |
| commit | ce0a294df6744ba44215997e0779d786cd93151d (patch) | |
| tree | 1b64fe780b5985420311b2f016156f1b2f99331c /main/src | |
| parent | 74b24b2823f61d69c4e47f174945828c121f7534 (diff) | |
| download | cgeo-ce0a294df6744ba44215997e0779d786cd93151d.zip cgeo-ce0a294df6744ba44215997e0779d786cd93151d.tar.gz cgeo-ce0a294df6744ba44215997e0779d786cd93151d.tar.bz2 | |
#1518: avoid repainting mini compass for changes less than 5 degrees
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/cgeocaches.java | 42 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ui/CompassMiniView.java | 37 |
2 files changed, 48 insertions, 31 deletions
diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index 94d554c..c4d72d3 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -152,28 +152,28 @@ public class cgeocaches extends AbstractListActivity { private final GeoDirHandler geoDirHandler = new GeoDirHandler() { @Override - public void updateGeoData(final IGeoData geo) { - if (adapter == null) { - return; - } + public void updateGeoData(final IGeoData geo) { + if (adapter == null) { + return; + } - try { - if (geo.getCoords() != null) { - adapter.setActualCoordinates(geo.getCoords()); - } - - if (!Settings.isUseCompass() || geo.getSpeed() > 5) { // use GPS when speed is higher than 18 km/h - if (!Settings.isUseCompass()) { - adapter.setActualHeading(geo.getBearing()); - } - if (northHeading != null) { - adapter.setActualHeading(northHeading); - } - } - } catch (Exception e) { - Log.w("Failed to UpdateLocation location."); - } - } + try { + if (geo.getCoords() != null) { + adapter.setActualCoordinates(geo.getCoords()); + } + + if (!Settings.isUseCompass() || geo.getSpeed() > 5) { // use GPS when speed is higher than 18 km/h + if (!Settings.isUseCompass()) { + adapter.setActualHeading(geo.getBearing()); + } + if (northHeading != null) { + adapter.setActualHeading(northHeading); + } + } + } catch (Exception e) { + Log.w("Failed to UpdateLocation location."); + } + } @Override public void updateDirection(final float direction) { diff --git a/main/src/cgeo/geocaching/ui/CompassMiniView.java b/main/src/cgeo/geocaching/ui/CompassMiniView.java index a0aaeaf..a60afa6 100644 --- a/main/src/cgeo/geocaching/ui/CompassMiniView.java +++ b/main/src/cgeo/geocaching/ui/CompassMiniView.java @@ -17,6 +17,10 @@ final public class CompassMiniView extends View { private Geopoint targetCoords = null; private float azimuth = 0; private float heading = 0; + /** + * remember the last state of drawing so we can avoid repainting for very small changes + */ + private float lastDrawingAzimuth; /** * lazy initialized bitmap resource depending on selected skin @@ -45,6 +49,7 @@ final public class CompassMiniView extends View { private static final int ARROW_BITMAP_SIZE = 21; private static final PaintFlagsDrawFilter FILTER_SET = new PaintFlagsDrawFilter(0, Paint.FILTER_BITMAP_FLAG); private static final PaintFlagsDrawFilter FILTER_REMOVE = new PaintFlagsDrawFilter(Paint.FILTER_BITMAP_FLAG, 0); + private static final float MINIMUM_ROTATION_DEGREES_FOR_REPAINT = 5; public CompassMiniView(Context context) { super(context); @@ -115,8 +120,15 @@ final public class CompassMiniView extends View { return; } - // compass margins + float azimuthRelative = calculateAzimuthRelative(); + + // avoid updates on very small changes, which are not visible to the user + float change = Math.abs(azimuthRelative - lastDrawingAzimuth); + if (change < MINIMUM_ROTATION_DEGREES_FOR_REPAINT) { + return; + } + // compass margins final int marginLeft = (getWidth() - compassArrowWidth) / 2; final int marginTop = (getHeight() - compassArrowHeight) / 2; @@ -127,19 +139,14 @@ final public class CompassMiniView extends View { protected void onDraw(Canvas canvas) { super.onDraw(canvas); - float azimuthRelative = azimuth - heading; - if (azimuthRelative < 0) { - azimuthRelative += 360; - } else if (azimuthRelative >= 360) { - azimuthRelative -= 360; - } + float azimuthRelative = calculateAzimuthRelative(); + lastDrawingAzimuth = azimuthRelative; // compass margins canvas.setDrawFilter(FILTER_SET); - - final int canvasCenterX = (compassArrowWidth / 2) + ((getWidth() - compassArrowWidth) / 2); - final int canvasCenterY = (compassArrowHeight / 2) + ((getHeight() - compassArrowHeight) / 2); + final int canvasCenterX = getWidth() / 2; + final int canvasCenterY = getHeight() / 2; final int marginLeft = (getWidth() - compassArrowWidth) / 2; final int marginTop = (getHeight() - compassArrowHeight) / 2; @@ -151,6 +158,16 @@ final public class CompassMiniView extends View { canvas.setDrawFilter(FILTER_REMOVE); } + private float calculateAzimuthRelative() { + float azimuthRelative = azimuth - heading; + if (azimuthRelative < 0) { + azimuthRelative += 360; + } else if (azimuthRelative >= 360) { + azimuthRelative -= 360; + } + return azimuthRelative; + } + @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec)); |
