diff options
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/AbstractDialogFragment.java | 3 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 11 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/ox/OXGPXParser.java | 8 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 17 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/utils/MapUtils.java | 54 |
5 files changed, 61 insertions, 32 deletions
diff --git a/main/src/cgeo/geocaching/AbstractDialogFragment.java b/main/src/cgeo/geocaching/AbstractDialogFragment.java index 4025347..9277d8c 100644 --- a/main/src/cgeo/geocaching/AbstractDialogFragment.java +++ b/main/src/cgeo/geocaching/AbstractDialogFragment.java @@ -4,7 +4,6 @@ import butterknife.ButterKnife; import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.activity.ActivityMixin; -import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.LoadFlags; import cgeo.geocaching.gcvote.GCVote; import cgeo.geocaching.gcvote.GCVoteRating; @@ -211,7 +210,7 @@ public abstract class AbstractDialogFragment extends DialogFragment implements C assert cache != null; // cache type final String cacheType = cache.getType().getL10n(); - final String cacheSize = cache.getSize() != CacheSize.UNKNOWN ? " (" + cache.getSize().getL10n() + ")" : ""; + final String cacheSize = cache.showSize() ? " (" + cache.getSize().getL10n() + ")" : ""; details.add(R.string.cache_type, cacheType + cacheSize); details.add(R.string.cache_geocode, cache.getGeocode()); diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index f134812..0976b35 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -1947,7 +1947,16 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc @Override public boolean onActionItemClicked(final ActionMode actionMode, final MenuItem menuItem) { - return onClipboardItemSelected(actionMode, menuItem, clickedItemText); + switch (menuItem.getItemId()) { + // detail fields + case R.id.menu_calendar: + CalendarAddon.addToCalendarWithIntent(CacheDetailActivity.this, cache); + actionMode.finish(); + return true; + // handle clipboard actions in base + default: + return onClipboardItemSelected(actionMode, menuItem, clickedItemText); + } } }); return true; diff --git a/main/src/cgeo/geocaching/connector/ox/OXGPXParser.java b/main/src/cgeo/geocaching/connector/ox/OXGPXParser.java index 5f11a11..7896826 100644 --- a/main/src/cgeo/geocaching/connector/ox/OXGPXParser.java +++ b/main/src/cgeo/geocaching/connector/ox/OXGPXParser.java @@ -10,13 +10,13 @@ public class OXGPXParser extends GPX10Parser { private final boolean isDetailed; - public OXGPXParser(int listIdIn, boolean isDetailed) { + public OXGPXParser(final int listIdIn, final boolean isDetailed) { super(listIdIn); this.isDetailed = isDetailed; } @Override - protected void afterParsing(Geocache cache) { + protected void afterParsing(final Geocache cache) { cache.setUpdated(System.currentTimeMillis()); if (isDetailed) { cache.setDetailedUpdate(cache.getUpdated()); @@ -27,11 +27,11 @@ public class OXGPXParser extends GPX10Parser { /** * The short description of OX caches contains "title by owner, type(T/D/Awesomeness)". That is a lot of - * duplication. + * duplication. Additionally a space between type and (T/D/Awesomeness) is introduced. * * @param cache */ private static void removeTitleFromShortDescription(final @NonNull Geocache cache) { - cache.setShortDescription(StringUtils.trim(StringUtils.substringAfterLast(cache.getShortDescription(), ","))); + cache.setShortDescription(StringUtils.replace(StringUtils.trim(StringUtils.substringAfterLast(cache.getShortDescription(), ",")), "(", " (")); } } diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 8aae0cc..9bbf7af 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -60,8 +60,6 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.LayerDrawable; import android.location.Location; import android.os.Build; import android.os.Bundle; @@ -1657,24 +1655,13 @@ public class CGeoMap extends AbstractMap implements ViewFactory { private CachesOverlayItemImpl getCacheItem(final Geocache cache) { final CachesOverlayItemImpl item = mapItemFactory.getCachesOverlayItem(cache, cache.applyDistanceRule()); - item.setMarker(MapUtils.getCacheItem(getResources(), cache)); + item.setMarker(MapUtils.getCacheMarker(getResources(), cache)); return item; } private CachesOverlayItemImpl getWaypointItem(final Waypoint waypoint) { final CachesOverlayItemImpl item = mapItemFactory.getCachesOverlayItem(waypoint, waypoint.getWaypointType().applyDistanceRule()); - final Drawable marker = getResources().getDrawable(!waypoint.isVisited() ? R.drawable.marker : R.drawable.marker_transparent); - final Drawable[] layers = new Drawable[] { - marker, - getResources().getDrawable(waypoint.getWaypointType().markerId) - }; - final LayerDrawable ld = new LayerDrawable(layers); - if (layers[0].getIntrinsicWidth() > 40) { - ld.setLayerInset(1, 9, 12, 10, 13); - } else { - ld.setLayerInset(1, 9, 12, 8, 12); - } - item.setMarker(ld); + item.setMarker(MapUtils.getWaypointMarker(getResources(), waypoint)); return item; } diff --git a/main/src/cgeo/geocaching/utils/MapUtils.java b/main/src/cgeo/geocaching/utils/MapUtils.java index 948df77..5120ca5 100644 --- a/main/src/cgeo/geocaching/utils/MapUtils.java +++ b/main/src/cgeo/geocaching/utils/MapUtils.java @@ -2,6 +2,7 @@ package cgeo.geocaching.utils; import cgeo.geocaching.Geocache; import cgeo.geocaching.R; +import cgeo.geocaching.Waypoint; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -15,12 +16,12 @@ import java.util.ArrayList; public final class MapUtils { // data for overlays - private static final int[][] INSET_RELIABLE = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; // center, 33x40 / 45x51 / 60x68 - private static final int[][] INSET_TYPE = { { 5, 8, 6, 10 }, { 4, 4, 5, 11 }, { 4, 4, 5, 11 } }; // center, 22x22 / 36x36 - private static final int[][] INSET_OWN = { { 21, 0, 0, 26 }, { 25, 0, 0, 35 }, { 40, 0, 0, 48 } }; // top right, 12x12 / 16x16 / 20x20 - private static final int[][] INSET_FOUND = { { 0, 0, 21, 28 }, { 0, 0, 25, 35 }, { 0, 0, 40, 48 } }; // top left, 12x12 / 16x16 / 20x20 - private static final int[][] INSET_USERMODIFIEDCOORDS = { { 21, 28, 0, 0 }, { 19, 25, 0, 0 }, { 25, 33, 0, 0 } }; // bottom right, 12x12 / 26x26 / 35x35 - private static final int[][] INSET_PERSONALNOTE = { { 0, 28, 21, 0 }, { 0, 25, 19, 0 }, { 0, 33, 25, 0 } }; // bottom left, 12x12 / 26x26 / 35x35 + private static final int[][] INSET_RELIABLE = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; // center, 33x40 / 45x51 / 60x68 / 90x102 / 120x136 + private static final int[][] INSET_TYPE = { { 5, 8, 6, 10 }, { 4, 4, 4, 11 }, { 6, 6, 6, 14 }, { 9, 9, 9, 21 }, { 12, 12, 12, 28 } }; // center, 22x22 / 36x36 + private static final int[][] INSET_OWN = { { 21, 0, 0, 28 }, { 29, 0, 0, 35 }, { 40, 0, 0, 48 }, { 58, 0, 0, 70 }, { 80, 0, 0, 96 } }; // top right, 12x12 / 16x16 / 20x20 / 32x32 / 40x40 + private static final int[][] INSET_FOUND = { { 0, 0, 21, 28 }, { 0, 0, 29, 35 }, { 0, 0, 40, 48 }, { 0, 0, 58, 70 }, { 0, 0, 80, 96 } }; // top left, 12x12 / 16x16 / 20x20 / 32x32 / 40x40 + private static final int[][] INSET_USERMODIFIEDCOORDS = { { 21, 28, 0, 0 }, { 19, 25, 0, 0 }, { 25, 33, 0, 0 }, { 38, 50, 0, 0 }, { 50, 66, 0, 0 } }; // bottom right, 12x12 / 26x26 / 35x35 / 52x52 / 70x70 + private static final int[][] INSET_PERSONALNOTE = { { 0, 28, 21, 0 }, { 0, 25, 19, 0 }, { 0, 33, 25, 0 }, { 0, 50, 38, 0 }, { 0, 66, 50, 0 } }; // bottom left, 12x12 / 26x26 / 35x35 / 52x52 / 70x70 private static final SparseArray<LayerDrawable> overlaysCache = new SparseArray<>(); @@ -35,7 +36,7 @@ public final class MapUtils { * @param cache the cache to build the drawable for * @return a drawable representing the current cache status */ - public static LayerDrawable getCacheItem(final Resources res, final Geocache cache) { + public static LayerDrawable getCacheMarker(final Resources res, final Geocache cache) { final int hashcode = new HashCodeBuilder() .append(cache.isReliableLatLon()) .append(cache.getType().id) @@ -52,13 +53,41 @@ public final class MapUtils { synchronized (overlaysCache) { LayerDrawable drawable = overlaysCache.get(hashcode); if (drawable == null) { - drawable = MapUtils.createCacheItem(res, cache); + drawable = createCacheMarker(res, cache); overlaysCache.put(hashcode, drawable); } return drawable; } } + public static LayerDrawable getWaypointMarker(final Resources res, final Waypoint waypoint) { + final int hashcode = new HashCodeBuilder() + .append(waypoint.isVisited()) + .append(waypoint.getWaypointType().id) + .toHashCode(); + + synchronized (overlaysCache) { + LayerDrawable drawable = overlaysCache.get(hashcode); + if (drawable == null) { + drawable = createWaypointMarker(res, waypoint); + overlaysCache.put(hashcode, drawable); + } + return drawable; + } + } + + private static LayerDrawable createWaypointMarker(final Resources res, final Waypoint waypoint) { + final Drawable marker = res.getDrawable(!waypoint.isVisited() ? R.drawable.marker : R.drawable.marker_transparent); + final Drawable[] layers = new Drawable[] { + marker, + res.getDrawable(waypoint.getWaypointType().markerId) + }; + final LayerDrawable drawable = new LayerDrawable(layers); + final int resolution = calculateResolution(marker); + drawable.setLayerInset(1, INSET_TYPE[resolution][0], INSET_TYPE[resolution][1], INSET_TYPE[resolution][2], INSET_TYPE[resolution][3]); + return drawable; + } + /** * Clear the cache of drawable items. */ @@ -68,7 +97,7 @@ public final class MapUtils { } } - private static LayerDrawable createCacheItem(final Resources res, final Geocache cache) { + private static LayerDrawable createCacheMarker(final Resources res, final Geocache cache) { // Set initial capacities to the maximum of layers and insets to avoid dynamic reallocation final ArrayList<Drawable> layers = new ArrayList<>(9); final ArrayList<int[]> insets = new ArrayList<>(8); @@ -76,7 +105,7 @@ public final class MapUtils { // background: disabled or not final Drawable marker = res.getDrawable(cache.getMapMarkerId()); layers.add(marker); - final int resolution = marker.getIntrinsicWidth() > 40 ? (marker.getIntrinsicWidth() > 50 ? 2 : 1) : 0; + final int resolution = calculateResolution(marker); // reliable or not if (!cache.isReliableLatLon()) { insets.add(INSET_RELIABLE[resolution]); @@ -123,4 +152,9 @@ public final class MapUtils { return ld; } + + private static int calculateResolution(final Drawable marker) { + final int resolution = marker.getIntrinsicWidth() > 40 ? (marker.getIntrinsicWidth() > 50 ? (marker.getIntrinsicWidth() > 70 ? (marker.getIntrinsicWidth() > 100 ? 4 : 3) : 2) : 1) : 0; + return resolution; + } } |
