aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/ui')
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListAdapter.java20
-rw-r--r--main/src/cgeo/geocaching/ui/CompassMiniView.java3
-rw-r--r--main/src/cgeo/geocaching/ui/CompassView.java40
-rw-r--r--main/src/cgeo/geocaching/ui/Formatter.java23
4 files changed, 52 insertions, 34 deletions
diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
index bcfdde7..c6d3404 100644
--- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
@@ -14,6 +14,7 @@ import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.sorting.CacheComparator;
import cgeo.geocaching.sorting.DistanceComparator;
import cgeo.geocaching.sorting.VisitComparator;
+import cgeo.geocaching.utils.AngleUtils;
import cgeo.geocaching.utils.Log;
import org.apache.commons.collections.CollectionUtils;
@@ -263,19 +264,15 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
notifyDataSetChanged();
}
- public void setActualCoordinates(final Geopoint coordsIn) {
- if (coordsIn == null) {
- return;
- }
-
- coords = coordsIn;
+ public void setActualCoordinates(final Geopoint coords) {
+ this.coords = coords;
updateSortByDistance();
for (final DistanceView distance : distances) {
- distance.update(coordsIn);
+ distance.update(coords);
}
for (final CompassMiniView compass : compasses) {
- compass.updateCurrentCoords(coordsIn);
+ compass.updateCurrentCoords(coords);
}
}
@@ -304,13 +301,12 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
return cacheComparator == null || cacheComparator instanceof DistanceComparator;
}
- public void setActualHeading(Float directionNow) {
- if (directionNow == null) {
+ public void setActualHeading(final float direction) {
+ if (Math.abs(AngleUtils.difference(azimuth, direction)) < 10) {
return;
}
- azimuth = directionNow;
-
+ azimuth = direction;
for (final CompassMiniView compass : compasses) {
compass.updateAzimuth(azimuth);
}
diff --git a/main/src/cgeo/geocaching/ui/CompassMiniView.java b/main/src/cgeo/geocaching/ui/CompassMiniView.java
index 1c96a09..44fb8e2 100644
--- a/main/src/cgeo/geocaching/ui/CompassMiniView.java
+++ b/main/src/cgeo/geocaching/ui/CompassMiniView.java
@@ -3,6 +3,7 @@ package cgeo.geocaching.ui;
import cgeo.geocaching.R;
import cgeo.geocaching.Settings;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.utils.AngleUtils;
import android.content.Context;
import android.graphics.Bitmap;
@@ -159,7 +160,7 @@ final public class CompassMiniView extends View {
}
private float calculateAzimuthRelative() {
- return (azimuth - heading + 360) % 360;
+ return AngleUtils.normalize(azimuth - heading);
}
@Override
diff --git a/main/src/cgeo/geocaching/ui/CompassView.java b/main/src/cgeo/geocaching/ui/CompassView.java
index 703f96f..b328527 100644
--- a/main/src/cgeo/geocaching/ui/CompassView.java
+++ b/main/src/cgeo/geocaching/ui/CompassView.java
@@ -1,7 +1,7 @@
package cgeo.geocaching.ui;
-import cgeo.geocaching.DirectionProvider;
import cgeo.geocaching.R;
+import cgeo.geocaching.utils.AngleUtils;
import cgeo.geocaching.utils.PeriodicHandler;
import android.content.Context;
@@ -23,19 +23,19 @@ public class CompassView extends View {
/**
* North direction currently SHOWN on compass (not measured)
*/
- private double azimuthShown = 0.0;
+ private float azimuthShown = 0;
/**
* cache direction currently SHOWN on compass (not measured)
*/
- private double cacheHeadingShown = 0.0;
+ private float cacheHeadingShown = 0;
/**
* cache direction measured from device, or 0.0
*/
- private double cacheHeadingMeasured = 0.0;
+ private float cacheHeadingMeasured = 0;
/**
* North direction measured from device, or 0.0
*/
- private double northMeasured = 0.0;
+ private float northMeasured = 0;
private PaintFlagsDrawFilter setfil = null;
private PaintFlagsDrawFilter remfil = null;
private int compassUnderlayWidth = 0;
@@ -103,7 +103,7 @@ public class CompassView extends View {
}
}
- public synchronized void updateNorth(double northHeadingIn, double cacheHeadingIn) {
+ public synchronized void updateNorth(float northHeadingIn, float cacheHeadingIn) {
if (initialDisplay) {
// We will force the compass to move brutally if this is the first
// update since it is visible.
@@ -128,20 +128,20 @@ public class CompassView extends View {
* the actual value
* @return the new value
*/
- static protected double smoothUpdate(double goal, double actual) {
- final double diff = DirectionProvider.difference(actual, goal);
+ static protected float smoothUpdate(float goal, float actual) {
+ final float diff = AngleUtils.difference(actual, goal);
- double offset = 0.0;
+ float offset = 0;
// If the difference is smaller than 1 degree, do nothing as it
// causes the arrow to vibrate. Round away from 0.
if (diff > 1.0) {
- offset = Math.ceil(diff / 10.0); // for larger angles, rotate faster
+ offset = (float) Math.ceil(diff / 10.0); // for larger angles, rotate faster
} else if (diff < 1.0) {
- offset = Math.floor(diff / 10.0);
+ offset = (float) Math.floor(diff / 10.0);
}
- return (actual + offset + 360) % 360;
+ return AngleUtils.normalize(actual + offset);
}
private class RedrawHandler extends PeriodicHandler {
@@ -152,10 +152,10 @@ public class CompassView extends View {
@Override
public void act() {
- final double newAzimuthShown = smoothUpdate(northMeasured, azimuthShown);
- final double newCacheHeadingShown = smoothUpdate(cacheHeadingMeasured, cacheHeadingShown);
- if (Math.abs(DirectionProvider.difference(azimuthShown, newAzimuthShown)) >= 2 ||
- Math.abs(DirectionProvider.difference(cacheHeadingShown, newCacheHeadingShown)) >= 2) {
+ final float newAzimuthShown = smoothUpdate(northMeasured, azimuthShown);
+ final float newCacheHeadingShown = smoothUpdate(cacheHeadingMeasured, cacheHeadingShown);
+ if (Math.abs(AngleUtils.difference(azimuthShown, newAzimuthShown)) >= 2 ||
+ Math.abs(AngleUtils.difference(cacheHeadingShown, newCacheHeadingShown)) >= 2) {
synchronized(CompassView.this) {
azimuthShown = newAzimuthShown;
cacheHeadingShown = newCacheHeadingShown;
@@ -169,16 +169,16 @@ public class CompassView extends View {
@Override
protected void onDraw(Canvas canvas) {
// use local synchronized variables to avoid them being changed from the device during drawing
- double azimuthDrawn;
- double headingDrawn;
+ float azimuthDrawn;
+ float headingDrawn;
synchronized (this) {
azimuthDrawn = azimuthShown;
headingDrawn = cacheHeadingShown;
}
- double azimuthTemp = azimuthDrawn;
- final double azimuthRelative = (azimuthTemp - headingDrawn + 360) % 360;
+ float azimuthTemp = azimuthDrawn;
+ final float azimuthRelative = AngleUtils.normalize(azimuthTemp - headingDrawn);
// compass margins
int canvasCenterX = (compassRoseWidth / 2) + ((getWidth() - compassRoseWidth) / 2);
diff --git a/main/src/cgeo/geocaching/ui/Formatter.java b/main/src/cgeo/geocaching/ui/Formatter.java
index 6ee1a65..33793c1 100644
--- a/main/src/cgeo/geocaching/ui/Formatter.java
+++ b/main/src/cgeo/geocaching/ui/Formatter.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.ui;
+import cgeo.geocaching.R;
import cgeo.geocaching.cgeoapplication;
import android.content.Context;
@@ -64,9 +65,29 @@ public abstract class Formatter {
}
/**
+ * Generate a numeric date string according to system-wide settings (locale, date format)
+ * such as "10/20/2010". Today and yesterday will be presented as strings "today" and "yesterday".
+ *
+ * @param date
+ * milliseconds since the epoch
+ * @return the formatted string
+ */
+ public static String formatShortDateVerbally(long date) {
+ int diff = cgeo.geocaching.utils.DateUtils.daysSince(date);
+ switch (diff) {
+ case 0:
+ return cgeoapplication.getInstance().getString(R.string.log_today);
+ case 1:
+ return cgeoapplication.getInstance().getString(R.string.log_yesterday);
+ default:
+ return formatShortDate(date);
+ }
+ }
+
+ /**
* Generate a numeric date and time string according to system-wide settings (locale,
* date format) such as "7 sept. at 12:35".
- *
+ *
* @param context
* a Context
* @param date