aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/res/values/strings_not_translatable.xml1
-rw-r--r--main/src/cgeo/geocaching/StaticMapsProvider.java31
-rw-r--r--main/src/cgeo/geocaching/Waypoint.java2
-rw-r--r--main/src/cgeo/geocaching/compatibility/AndroidLevel8.java24
-rw-r--r--main/src/cgeo/geocaching/compatibility/AndroidLevel8Emulation.java5
-rw-r--r--main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java3
-rw-r--r--tests/src/cgeo/geocaching/StaticMapsProviderTest.java76
7 files changed, 98 insertions, 44 deletions
diff --git a/main/res/values/strings_not_translatable.xml b/main/res/values/strings_not_translatable.xml
index 83f0e9f..4c56fba 100644
--- a/main/res/values/strings_not_translatable.xml
+++ b/main/res/values/strings_not_translatable.xml
@@ -106,6 +106,7 @@
· Active cache detail page now remembered when rotating device\n
· Replaced the term \"GC-Code\" by \"Geocode\"\n
· Improvements for light theme\n
+ · Share function uses short URL again\n
\n
<a href="https://github.com/cgeo/c-geo-opensource/issues?milestone=9&amp;state=closed">Detailed list of all changes</a>\n
\n
diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java
index 8e853d6..cd88071 100644
--- a/main/src/cgeo/geocaching/StaticMapsProvider.java
+++ b/main/src/cgeo/geocaching/StaticMapsProvider.java
@@ -142,7 +142,7 @@ public class StaticMapsProvider {
String wpMarkerUrl = getWpMarkerUrl(waypoint);
if (!hasAllStaticMapsForWaypoint(geocode, waypoint)) {
// download map images in separate background thread for higher performance
- downloadMaps(geocode, wpMarkerUrl, WAYPOINT_PREFIX + waypoint.getId() + '_' + waypoint.calculateStaticMapsHashcode() + "_", wpLatlonMap, edge, null, waitForResult);
+ downloadMaps(geocode, wpMarkerUrl, WAYPOINT_PREFIX + waypoint.getId() + '_' + waypoint.getStaticMapsHashcode() + "_", wpLatlonMap, edge, null, waitForResult);
}
}
@@ -233,7 +233,7 @@ public class StaticMapsProvider {
return;
}
int waypointId = waypoint.getId();
- int waypointMapHash = waypoint.calculateStaticMapsHashcode();
+ int waypointMapHash = waypoint.getStaticMapsHashcode();
for (int level = 1; level <= 5; level++) {
try {
StaticMapsProvider.getMapFile(geocode, WAYPOINT_PREFIX + waypointId + "_" + waypointMapHash + '_' + level, false).delete();
@@ -245,9 +245,9 @@ public class StaticMapsProvider {
/**
* Check if at least one map file exists for the given cache.
- *
+ *
* @param cache
- * @return <code>true</code> if at least one mapfile exists; <code>false</code> otherwise
+ * @return <code>true</code> if at least one map file exists; <code>false</code> otherwise
*/
public static boolean hasStaticMap(final Geocache cache) {
if (cache == null) {
@@ -259,7 +259,7 @@ public class StaticMapsProvider {
}
for (int level = 1; level <= 5; level++) {
File mapFile = StaticMapsProvider.getMapFile(geocode, String.valueOf(level), false);
- if (mapFile != null && mapFile.exists()) {
+ if (mapFile.exists()) {
return true;
}
}
@@ -268,17 +268,17 @@ public class StaticMapsProvider {
/**
* Checks if at least one map file exists for the given geocode and waypoint ID.
- *
+ *
* @param geocode
* @param waypoint
- * @return <code>true</code> if at least one mapfile exists; <code>false</code> otherwise
+ * @return <code>true</code> if at least one map file exists; <code>false</code> otherwise
*/
public static boolean hasStaticMapForWaypoint(String geocode, Waypoint waypoint) {
int waypointId = waypoint.getId();
- int waypointMapHash = waypoint.calculateStaticMapsHashcode();
+ int waypointMapHash = waypoint.getStaticMapsHashcode();
for (int level = 1; level <= 5; level++) {
File mapFile = StaticMapsProvider.getMapFile(geocode, WAYPOINT_PREFIX + waypointId + "_" + waypointMapHash + "_" + level, false);
- if (mapFile != null && mapFile.exists()) {
+ if (mapFile.exists()) {
return true;
}
}
@@ -286,20 +286,17 @@ public class StaticMapsProvider {
}
/**
- * Checks if at least one map file exists for the given geocode and waypoint ID.
- *
+ * Checks if all map files exist for the given geocode and waypoint ID.
+ *
* @param geocode
* @param waypoint
- * @return <code>true</code> if at least one mapfile exists; <code>false</code> otherwise
+ * @return <code>true</code> if all map files exist; <code>false</code> otherwise
*/
public static boolean hasAllStaticMapsForWaypoint(String geocode, Waypoint waypoint) {
int waypointId = waypoint.getId();
- int waypointMapHash = waypoint.calculateStaticMapsHashcode();
+ int waypointMapHash = waypoint.getStaticMapsHashcode();
for (int level = 1; level <= 5; level++) {
File mapFile = StaticMapsProvider.getMapFile(geocode, WAYPOINT_PREFIX + waypointId + "_" + waypointMapHash + "_" + level, false);
- if (mapFile == null) {
- return false;
- }
boolean mapExists = mapFile.exists();
if (!mapExists) {
return false;
@@ -314,7 +311,7 @@ public class StaticMapsProvider {
public static Bitmap getWaypointMap(final String geocode, Waypoint waypoint, int level) {
int waypointId = waypoint.getId();
- int waypointMapHash = waypoint.calculateStaticMapsHashcode();
+ int waypointMapHash = waypoint.getStaticMapsHashcode();
return decodeFile(StaticMapsProvider.getMapFile(geocode, WAYPOINT_PREFIX + waypointId + "_" + waypointMapHash + "_" + level, false));
}
diff --git a/main/src/cgeo/geocaching/Waypoint.java b/main/src/cgeo/geocaching/Waypoint.java
index 53160e5..48c9bc5 100644
--- a/main/src/cgeo/geocaching/Waypoint.java
+++ b/main/src/cgeo/geocaching/Waypoint.java
@@ -270,7 +270,7 @@ public class Waypoint implements IWaypoint, Comparable<Waypoint> {
return visited;
}
- public int calculateStaticMapsHashcode() {
+ public int getStaticMapsHashcode() {
long hash = 0;
if (coords != null) {
hash = coords.hashCode();
diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java
index e250934..1189ff5 100644
--- a/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java
+++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java
@@ -6,7 +6,6 @@ import android.annotation.TargetApi;
import android.app.Activity;
import android.app.backup.BackupManager;
import android.os.Environment;
-import android.view.Display;
import android.view.Surface;
import java.io.File;
@@ -15,12 +14,6 @@ import java.io.File;
public class AndroidLevel8 implements AndroidLevel8Interface {
@Override
- public int getRotation(final Activity activity) {
- Display display = activity.getWindowManager().getDefaultDisplay();
- return display.getRotation();
- }
-
- @Override
public void dataChanged(final String name) {
Log.i("Requesting settings backup with settings manager");
BackupManager.dataChanged(name);
@@ -28,21 +21,16 @@ public class AndroidLevel8 implements AndroidLevel8Interface {
@Override
public int getRotationOffset(final Activity activity) {
- try {
- final int rotation = getRotation(activity);
- if (rotation == Surface.ROTATION_90) {
+ switch (activity.getWindowManager().getDefaultDisplay().getRotation()) {
+ case Surface.ROTATION_90:
return 90;
- } else if (rotation == Surface.ROTATION_180) {
+ case Surface.ROTATION_180:
return 180;
- } else if (rotation == Surface.ROTATION_270) {
+ case Surface.ROTATION_270:
return 270;
- }
- } catch (final Exception e) {
- // This should never happen: IllegalArgumentException, IllegalAccessException or InvocationTargetException
- Log.e("Cannot call getRotation()", e);
+ default:
+ return 0;
}
-
- return 0;
}
@Override
diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel8Emulation.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel8Emulation.java
index 996c527..a60b48d 100644
--- a/main/src/cgeo/geocaching/compatibility/AndroidLevel8Emulation.java
+++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel8Emulation.java
@@ -12,11 +12,6 @@ import java.io.File;
public class AndroidLevel8Emulation implements AndroidLevel8Interface {
@Override
- public int getRotation(final Activity activity) {
- return 0;
- }
-
- @Override
public void dataChanged(final String name) {
// do nothing
}
diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java
index 75998aa..2ba3708 100644
--- a/main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java
+++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel8Interface.java
@@ -5,10 +5,7 @@ import android.app.Activity;
import java.io.File;
public interface AndroidLevel8Interface {
- public int getRotation(final Activity activity);
public void dataChanged(final String name);
-
public int getRotationOffset(final Activity activity);
-
public File getExternalPictureDir();
} \ No newline at end of file
diff --git a/tests/src/cgeo/geocaching/StaticMapsProviderTest.java b/tests/src/cgeo/geocaching/StaticMapsProviderTest.java
new file mode 100644
index 0000000..cbace10
--- /dev/null
+++ b/tests/src/cgeo/geocaching/StaticMapsProviderTest.java
@@ -0,0 +1,76 @@
+package cgeo.geocaching;
+
+import cgeo.geocaching.enumerations.WaypointType;
+import cgeo.geocaching.files.LocalStorage;
+import cgeo.geocaching.geopoint.Geopoint;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+public class StaticMapsProviderTest extends TestCase {
+
+ public static void testDownloadStaticMaps() {
+ final double lat = 52.354176d;
+ final double lon = 9.745685d;
+ String geocode = "GCTEST1";
+
+ boolean backupStore = Settings.isStoreOfflineMaps();
+ boolean backupStoreWP = Settings.isStoreOfflineWpMaps();
+ Settings.setStoreOfflineMaps(true);
+ Settings.setStoreOfflineWpMaps(true);
+ try {
+ Geopoint gp = new Geopoint(lat + 0.25d, lon + 0.25d);
+ Geocache cache = new Geocache();
+ cache.setGeocode(geocode);
+ cache.setCoords(gp);
+ cache.setCacheId(String.valueOf(1));
+
+ Waypoint theFinal = new Waypoint("Final", WaypointType.FINAL, false);
+ Geopoint finalGp = new Geopoint(lat + 0.25d + 1, lon + 0.25d + 1);
+ theFinal.setCoords(finalGp);
+ theFinal.setId(1);
+ cache.addOrChangeWaypoint(theFinal, false);
+
+ Waypoint trailhead = new Waypoint("Trail head", WaypointType.TRAILHEAD, false);
+ Geopoint trailheadGp = new Geopoint(lat + 0.25d + 2, lon + 0.25d + 2);
+ trailhead.setCoords(trailheadGp);
+ trailhead.setId(2);
+ cache.addOrChangeWaypoint(trailhead, false);
+
+ // make sure we don't have stale downloads
+ deleteCacheDirectory(geocode);
+ assertFalse(StaticMapsProvider.hasStaticMap(cache));
+ assertFalse(StaticMapsProvider.hasStaticMapForWaypoint(geocode, theFinal));
+ assertFalse(StaticMapsProvider.hasStaticMapForWaypoint(geocode, trailhead));
+
+ // download
+ StaticMapsProvider.downloadMaps(cache);
+
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ fail();
+ }
+
+ // check download
+ assertTrue(StaticMapsProvider.hasStaticMap(cache));
+ assertTrue(StaticMapsProvider.hasStaticMapForWaypoint(geocode, theFinal));
+ assertTrue(StaticMapsProvider.hasStaticMapForWaypoint(geocode, trailhead));
+
+ // waypoint static maps hashcode dependent
+ trailhead.setCoords(new Geopoint(lat + 0.24d + 2, lon + 0.25d + 2));
+ assertFalse(StaticMapsProvider.hasStaticMapForWaypoint(geocode, trailhead));
+ } finally {
+ Settings.setStoreOfflineWpMaps(backupStoreWP);
+ Settings.setStoreOfflineMaps(backupStore);
+ deleteCacheDirectory(geocode);
+ }
+ }
+
+ private static void deleteCacheDirectory(String geocode) {
+ File cacheDir = LocalStorage.getStorageDir(geocode);
+ LocalStorage.deleteDirectory(cacheDir);
+ }
+
+}