diff options
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCBase.java | 33 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/IconDecoder.java | 14 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 37 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java | 56 |
4 files changed, 101 insertions, 39 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/GCBase.java b/main/src/cgeo/geocaching/connector/gc/GCBase.java index 127b773..650435a 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCBase.java +++ b/main/src/cgeo/geocaching/connector/gc/GCBase.java @@ -9,8 +9,10 @@ import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LiveMapStrategy.Strategy; import cgeo.geocaching.enumerations.LiveMapStrategy.StrategyFlag; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.geopoint.IConversion; import cgeo.geocaching.geopoint.Viewport; import cgeo.geocaching.network.Network; +import cgeo.geocaching.ui.Formatter; import cgeo.geocaching.utils.BaseUtils; import cgeo.geocaching.utils.LeastRecentlyUsedCache; @@ -60,7 +62,21 @@ public class GCBase { float speedNow = cgeoapplication.getInstance().getSpeedFromGeo(); strategy = speedNow >= 8 ? Strategy.FASTEST : Strategy.DETAILED; // 8 m/s = 30 km/h } - return searchByViewport(viewport, tokens, strategy); + // return searchByViewport(viewport, tokens, strategy); + + // testing purpose + { + SearchResult result = searchByViewport(viewport, tokens, strategy); + String text = Formatter.SEPARATOR + strategy.getL10n() + Formatter.SEPARATOR; + int speed = (int) cgeoapplication.getInstance().getSpeedFromGeo(); + if (Settings.isUseMetricUnits()) { + text += speed + " km/h"; + } else { + text += speed / IConversion.MILES_TO_KILOMETER + " mph"; + } + result.setUrl(result.getUrl() + text); + return result; + } } /** @@ -88,6 +104,12 @@ public class GCBase { final Set<Tile> tiles = getTilesForViewport(viewport); for (Tile tile : tiles) { + + // testing purpose + { + searchResult.setUrl("Zoom=" + tile.getZoomlevel()); + } + StringBuilder url = new StringBuilder(); url.append("?x=").append(tile.getX()) // x tile .append("&y=").append(tile.getY()) // y tile @@ -242,12 +264,9 @@ public class GCBase { cache.setName(nameCache.get(id)); cache.setZoomlevel(tile.getZoomlevel()); cache.setCoords(tile.getCoord(xy)); - if (strategy.flags.contains(StrategyFlag.PARSE_TILES)) { - if (tile.getZoomlevel() >= 14) { - IconDecoder.parseMapPNG14(cache, bitmap, xy); - } else { - IconDecoder.parseMapPNG13(cache, bitmap, xy); - } + if (strategy.flags.contains(StrategyFlag.PARSE_TILES) && positions.size() < 64) { + // don't parse if there are too many caches. The decoding would return too much wrong results + IconDecoder.parseMapPNG(cache, bitmap, xy, tile.getZoomlevel()); } else { cache.setType(CacheType.UNKNOWN); } diff --git a/main/src/cgeo/geocaching/connector/gc/IconDecoder.java b/main/src/cgeo/geocaching/connector/gc/IconDecoder.java index 2935ef0..43ca2ce 100644 --- a/main/src/cgeo/geocaching/connector/gc/IconDecoder.java +++ b/main/src/cgeo/geocaching/connector/gc/IconDecoder.java @@ -7,10 +7,18 @@ import android.graphics.Bitmap; /** * icon decoder for cache icons - * + * */ public abstract class IconDecoder { + public static void parseMapPNG(final cgCache cache, Bitmap bitmap, UTFGridPosition xy, int zoomlevel) { + if (zoomlevel >= 14) { + parseMapPNG14(cache, bitmap, xy); + } else { + parseMapPNG13(cache, bitmap, xy); + } + } + private static final int[] OFFSET_X = new int[] { 0, -1, -1, 0, 1, 1, 1, 0, -1, -2, -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2 }; private static final int[] OFFSET_Y = new int[] { 0, 0, 1, 1, 1, 0, -1, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2 }; @@ -22,7 +30,7 @@ public abstract class IconDecoder { * @param bitmap * @param xy */ - public static void parseMapPNG13(final cgCache cache, Bitmap bitmap, UTFGridPosition xy) { + private static void parseMapPNG13(final cgCache cache, Bitmap bitmap, UTFGridPosition xy) { final int xCenter = xy.getX() * 4 + 2; final int yCenter = xy.getY() * 4 + 2; final int bitmapWidth = bitmap.getWidth(); @@ -111,7 +119,7 @@ public abstract class IconDecoder { * @param bitmap * @param xy */ - public static void parseMapPNG14(cgCache cache, Bitmap bitmap, UTFGridPosition xy) { + private static void parseMapPNG14(cgCache cache, Bitmap bitmap, UTFGridPosition xy) { int x = xy.getX() * 4 + 2; int y = xy.getY() * 4 + 2; diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 65cc69c..e96c5dc 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -210,6 +210,12 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } title.append(']'); } + // testing purpose + { + if (search != null && StringUtils.isNotBlank(search.getUrl())) { + title.append("[" + search.getUrl() + "]"); + } + } ActivityMixin.setTitle(activity, title.toString()); break; @@ -1364,7 +1370,6 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } final Viewport viewport = new Viewport(new Geopoint(latMin, lonMin), new Geopoint(latMax, lonMax)); - // search = cgBase.searchByViewport(token, viewport); search = ConnectorFactory.searchByViewport(viewport, tokens); if (search != null) { downloaded = true; @@ -1429,50 +1434,50 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto } // display caches - final List<cgCache> cachesProtected = new ArrayList<cgCache>(caches); - final List<CachesOverlayItemImpl> items = new ArrayList<CachesOverlayItemImpl>(); + final List<cgCache> cachesToDisplay = new ArrayList<cgCache>(caches); + final List<CachesOverlayItemImpl> itemsToDisplay = new ArrayList<CachesOverlayItemImpl>(); - if (!cachesProtected.isEmpty()) { - for (cgCache cacheOne : cachesProtected) { + if (!cachesToDisplay.isEmpty()) { + for (cgCache cache : cachesToDisplay) { if (stop) { throw new ThreadDeath(); } - if (cacheOne.getCoords() == null) { + if (cache.getCoords() == null) { continue; } // display cache waypoints - if (cacheOne.hasWaypoints() + if (cache.hasWaypoints() // Only show waypoints for single view or setting // when less than showWaypointsthreshold Caches shown - && (cachesProtected.size() == 1 || (cachesProtected.size() < Settings.getWayPointsThreshold()))) { - for (cgWaypoint oneWaypoint : cacheOne.getWaypoints()) { - if (oneWaypoint.getCoords() == null) { + && (cachesToDisplay.size() == 1 || (cachesToDisplay.size() < Settings.getWayPointsThreshold()))) { + for (cgWaypoint waypoint : cache.getWaypoints()) { + if (waypoint.getCoords() == null) { continue; } - items.add(getItem(new cgCoord(oneWaypoint), null, oneWaypoint)); + itemsToDisplay.add(getItem(new cgCoord(waypoint), null, waypoint)); } } - items.add(getItem(new cgCoord(cacheOne), cacheOne, null)); + itemsToDisplay.add(getItem(new cgCoord(cache), cache, null)); } - overlayCaches.updateItems(items); + overlayCaches.updateItems(itemsToDisplay); displayHandler.sendEmptyMessage(INVALIDATE_MAP); - cachesCnt = cachesProtected.size(); + cachesCnt = cachesToDisplay.size(); if (stop) { throw new ThreadDeath(); } } else { - overlayCaches.updateItems(items); + overlayCaches.updateItems(itemsToDisplay); displayHandler.sendEmptyMessage(INVALIDATE_MAP); } - cachesProtected.clear(); + cachesToDisplay.clear(); displayHandler.sendEmptyMessage(UPDATE_TITLE); } catch (ThreadDeath e) { diff --git a/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java b/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java index db6dc44..74704b3 100644 --- a/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java +++ b/tests/src/cgeo/geocaching/connector/gc/IconDecoderTest.java @@ -16,10 +16,10 @@ public class IconDecoderTest extends AbstractResourceInstrumentationTestCase { final Bitmap bitmap = getBitmap(R.raw.tile14); Log.d(Settings.tag, "Bitmap=" + bitmap.getWidth() + "x" + bitmap.getHeight()); - assertEquals(CacheType.TRADITIONAL, parse14(bitmap, 97 / 4, 136 / 4).getType()); - assertEquals(CacheType.MYSTERY, parse14(bitmap, 226 / 4, 104 / 4).getType()); - assertEquals(CacheType.MULTI, parse14(bitmap, 54 / 4, 97 / 4).getType()); - assertTrue(parse14(bitmap, 119 / 4, 108 / 4).isFound()); + assertEquals(CacheType.TRADITIONAL, parseMapPNG(bitmap, 97, 136, 14).getType()); + assertEquals(CacheType.MYSTERY, parseMapPNG(bitmap, 226, 104, 14).getType()); + assertEquals(CacheType.MULTI, parseMapPNG(bitmap, 54, 97, 14).getType()); + assertTrue(parseMapPNG(bitmap, 119, 108, 14).isFound()); } private Bitmap getBitmap(int resourceId) { @@ -30,23 +30,53 @@ public class IconDecoderTest extends AbstractResourceInstrumentationTestCase { return bitmap; } - private static cgCache parse14(Bitmap bitmap, int x, int y) { + private static cgCache parseMapPNG(Bitmap bitmap, int x, int y, int zoomlevel) { final cgCache cache = new cgCache(); - IconDecoder.parseMapPNG14(cache, bitmap, new UTFGridPosition(x, y)); + IconDecoder.parseMapPNG(cache, bitmap, new UTFGridPosition(x / 4, y / 4), zoomlevel); return cache; } public void testParseMap13() { final Bitmap bitmap = getBitmap(R.raw.tile13); - assertEquals(CacheType.TRADITIONAL, parse13(bitmap, 146 / 4, 225 / 4).getType()); - assertEquals(CacheType.MYSTERY, parse13(bitmap, 181 / 4, 116 / 4).getType()); - assertEquals(CacheType.MULTI, parse13(bitmap, 118 / 4, 230 / 4).getType()); + assertEquals(CacheType.TRADITIONAL, parseMapPNG(bitmap, 146, 225, 13).getType()); + assertEquals(CacheType.MYSTERY, parseMapPNG(bitmap, 181, 116, 13).getType()); + assertEquals(CacheType.MULTI, parseMapPNG(bitmap, 118, 230, 13).getType()); } - private static cgCache parse13(Bitmap bitmap, int x, int y) { - final cgCache cache = new cgCache(); - IconDecoder.parseMapPNG13(cache, bitmap, new UTFGridPosition(x, y)); - return cache; + public void testParseMap12() { + final Bitmap bitmap = getBitmap(R.raw.tile12); + + int multi = 0; + multi = parseMapPNG(bitmap, 130, 92, 12).getType() == CacheType.MULTI ? multi + 1 : multi; + multi = parseMapPNG(bitmap, 93, 222, 12).getType() == CacheType.MULTI ? multi + 1 : multi; + multi = parseMapPNG(bitmap, 129, 227, 12).getType() == CacheType.MULTI ? multi + 1 : multi; + multi = parseMapPNG(bitmap, 234, 170, 12).getType() == CacheType.MULTI ? multi + 1 : multi; + multi = parseMapPNG(bitmap, 195, 113, 12).getType() == CacheType.MULTI ? multi + 1 : multi; + multi = parseMapPNG(bitmap, 195, 124, 12).getType() == CacheType.MULTI ? multi + 1 : multi; + multi = parseMapPNG(bitmap, 111, 74, 12).getType() == CacheType.MULTI ? multi + 1 : multi; + + int mystery = 0; + mystery = parseMapPNG(bitmap, 37, 25, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery; + mystery = parseMapPNG(bitmap, 49, 183, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery; + mystery = parseMapPNG(bitmap, 183, 181, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery; + mystery = parseMapPNG(bitmap, 176, 94, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery; + mystery = parseMapPNG(bitmap, 161, 124, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery; + mystery = parseMapPNG(bitmap, 168, 118, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery; + mystery = parseMapPNG(bitmap, 231, 114, 12).getType() == CacheType.MYSTERY ? mystery + 1 : mystery; + + int tradi = 0; + tradi = parseMapPNG(bitmap, 179, 27, 12).getType() == CacheType.TRADITIONAL ? tradi + 1 : tradi; + tradi = parseMapPNG(bitmap, 106, 93, 12).getType() == CacheType.TRADITIONAL ? tradi + 1 : tradi; + tradi = parseMapPNG(bitmap, 145, 147, 12).getType() == CacheType.TRADITIONAL ? tradi + 1 : tradi; + tradi = parseMapPNG(bitmap, 204, 163, 12).getType() == CacheType.TRADITIONAL ? tradi + 1 : tradi; + tradi = parseMapPNG(bitmap, 9, 146, 12).getType() == CacheType.TRADITIONAL ? tradi + 1 : tradi; + tradi = parseMapPNG(bitmap, 117, 225, 12).getType() == CacheType.TRADITIONAL ? tradi + 1 : tradi; + tradi = parseMapPNG(bitmap, 90, 107, 12).getType() == CacheType.TRADITIONAL ? tradi + 1 : tradi; + + assertEquals(7, multi); + assertEquals(7, mystery); + assertEquals(7, tradi); + } } |
