diff options
| -rw-r--r-- | main/res/values/strings_not_translatable.xml | 1 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 37 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/CgeoApplication.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/Waypoint.java | 49 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/WaypointTest.java | 38 |
5 files changed, 66 insertions, 61 deletions
diff --git a/main/res/values/strings_not_translatable.xml b/main/res/values/strings_not_translatable.xml index e8d4e27..e5db27c 100644 --- a/main/res/values/strings_not_translatable.xml +++ b/main/res/values/strings_not_translatable.xml @@ -61,6 +61,7 @@ · <a href="http://www.jaytech.cz/">Jan Žatecký</a> (graphic)\n · <a href="http://joachim-wilke.de/">JoWi24</a> (code)\n · <a href="http://github.com/koem">Karsten Priegnitz</a> (code, artwork computation)\n + · <a href="http://www.geocaching.com/profile/?guid=231070d8-b6f4-4d14-8d5a-b8bdcb19b78e">KiwiStone</a> (code, localization DE)\n · <a href="http://www.geocaching.com/email/?guid=d11a3e3d-7db0-4d43-87f2-7893238844a6">Lineflyer</a> (tester, support, localization DE)\n · Ludovic Valente (localization FR)\n · marco-jacob (code, loc. DE)\n diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index f92245c..d0273c5 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -68,6 +68,7 @@ import android.graphics.Bitmap; import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; +import android.graphics.drawable.LayerDrawable; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -1814,6 +1815,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc } private class WaypointsViewCreator extends AbstractCachingPageViewCreator<ListView> { + private final int VISITED_INSET = (int) (6.6f * CgeoApplication.getInstance().getResources().getDisplayMetrics().density + 0.5f); @Override public ListView getDispatchedView() { @@ -1824,7 +1826,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc // sort waypoints: PP, Sx, FI, OWN final List<Waypoint> sortedWaypoints = new ArrayList<Waypoint>(cache.getWaypoints()); - Collections.sort(sortedWaypoints); + Collections.sort(sortedWaypoints, Waypoint.WAYPOINT_COMPARATOR); view = (ListView) getLayoutInflater().inflate(R.layout.cachedetail_waypoints_page, null); view.setClickable(true); @@ -1864,20 +1866,26 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc protected void fillViewHolder(View rowView, final WaypointViewHolder holder, final Waypoint wpt) { // coordinates + final TextView coordinatesView = holder.coordinatesView; if (null != wpt.getCoords()) { - final TextView coordinatesView = holder.coordinatesView; coordinatesView.setOnClickListener(new CoordinatesFormatSwitcher(wpt.getCoords())); coordinatesView.setText(wpt.getCoords().toString()); coordinatesView.setVisibility(View.VISIBLE); } + else { + coordinatesView.setVisibility(View.GONE); + } // info final String waypointInfo = Formatter.formatWaypointInfo(wpt); + final TextView infoView = holder.infoView; if (StringUtils.isNotBlank(waypointInfo)) { - final TextView infoView = holder.infoView; infoView.setText(waypointInfo); infoView.setVisibility(View.VISIBLE); } + else { + infoView.setVisibility(View.GONE); + } // title final TextView nameView = holder.nameView; @@ -1888,7 +1896,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc } else { nameView.setText(res.getString(R.string.waypoint)); } - wpt.setIcon(res, nameView); + setWaypointIcon(res, nameView, wpt); // visited if (wpt.isVisited()) { @@ -1901,8 +1909,8 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc } // note + final TextView noteView = holder.noteView; if (StringUtils.isNotBlank(wpt.getNote())) { - final TextView noteView = holder.noteView; noteView.setVisibility(View.VISIBLE); if (TextUtils.containsHtml(wpt.getNote())) { noteView.setText(Html.fromHtml(wpt.getNote()), TextView.BufferType.SPANNABLE); @@ -1911,6 +1919,9 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc noteView.setText(wpt.getNote()); } } + else { + noteView.setVisibility(View.GONE); + } final View wpNavView = holder.wpNavView; wpNavView.setOnClickListener(new View.OnClickListener() { @@ -1946,6 +1957,22 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc } }); } + + private void setWaypointIcon(final Resources res, final TextView nameView, final Waypoint wpt) { + final WaypointType waypointType = wpt.getWaypointType(); + final Drawable icon; + if (wpt.isVisited()) { + LayerDrawable ld = new LayerDrawable(new Drawable[] { + res.getDrawable(waypointType.markerId), + res.getDrawable(R.drawable.tick) }); + ld.setLayerInset(0, 0, 0, VISITED_INSET, VISITED_INSET); + ld.setLayerInset(1, VISITED_INSET, VISITED_INSET, 0, 0); + icon = ld; + } else { + icon = res.getDrawable(waypointType.markerId); + } + nameView.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); + } } private class InventoryViewCreator extends AbstractCachingPageViewCreator<ListView> { diff --git a/main/src/cgeo/geocaching/CgeoApplication.java b/main/src/cgeo/geocaching/CgeoApplication.java index 2c419cf..0af8117 100644 --- a/main/src/cgeo/geocaching/CgeoApplication.java +++ b/main/src/cgeo/geocaching/CgeoApplication.java @@ -37,8 +37,6 @@ public class CgeoApplication extends Application { @Override public void onCreate() { new Thread(statusUpdater).start(); - // Initialize densitiy related waypoint data - Waypoint.initializeScale(); } @Override diff --git a/main/src/cgeo/geocaching/Waypoint.java b/main/src/cgeo/geocaching/Waypoint.java index b204bdd..e1a8b2f 100644 --- a/main/src/cgeo/geocaching/Waypoint.java +++ b/main/src/cgeo/geocaching/Waypoint.java @@ -5,19 +5,12 @@ import cgeo.geocaching.geopoint.Geopoint; import org.apache.commons.lang3.StringUtils; -import android.content.res.Resources; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.LayerDrawable; -import android.widget.TextView; - +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; -/** - * Note: this class has a natural ordering that is inconsistent with equals. - */ -public class Waypoint implements IWaypoint, Comparable<Waypoint> { +public class Waypoint implements IWaypoint { public static final String PREFIX_OWN = "OWN"; private static final int ORDER_UNDEFINED = -2; @@ -33,13 +26,6 @@ public class Waypoint implements IWaypoint, Comparable<Waypoint> { private int cachedOrder = ORDER_UNDEFINED; private boolean own = false; private boolean visited = false; - // preliminary default for mdpi screens - private static int VISITED_INSET = 7; - - public static void initializeScale() { - // Calculate visited inset based on screen density - VISITED_INSET = (int) (6.6f * CgeoApplication.getInstance().getResources().getDisplayMetrics().density + 0.5f); - } /** * require name and type for every waypoint @@ -64,22 +50,6 @@ public class Waypoint implements IWaypoint, Comparable<Waypoint> { id = -1; } - public void setIcon(final Resources res, final TextView nameView) { - Drawable icon; - if (visited) { - LayerDrawable ld = new LayerDrawable(new Drawable[] { - res.getDrawable(waypointType.markerId), - res.getDrawable(R.drawable.tick) }); - ld.setLayerInset(0, 0, 0, VISITED_INSET, VISITED_INSET); - ld.setLayerInset(1, VISITED_INSET, VISITED_INSET, 0, 0); - icon = ld; - } else { - icon = res.getDrawable(waypointType.markerId); - } - final Drawable fIcon = icon; - nameView.setCompoundDrawablesWithIntrinsicBounds(fIcon, null, null, null); - } - public void merge(final Waypoint old) { if (StringUtils.isBlank(prefix)) { setPrefix(old.prefix); @@ -163,11 +133,6 @@ public class Waypoint implements IWaypoint, Comparable<Waypoint> { return cachedOrder; } - @Override - public int compareTo(Waypoint other) { - return order() - other.order(); - } - public String getPrefix() { return prefix; } @@ -282,4 +247,14 @@ public class Waypoint implements IWaypoint, Comparable<Waypoint> { return (int) hash; } + /** + * Sort waypoints by their probable order (e.g. parking first, final last). + */ + public static final Comparator<? super Waypoint> WAYPOINT_COMPARATOR = new Comparator<Waypoint>() { + + @Override + public int compare(Waypoint left, Waypoint right) { + return left.order() - right.order(); + } + }; } diff --git a/tests/src/cgeo/geocaching/WaypointTest.java b/tests/src/cgeo/geocaching/WaypointTest.java index dc2853a..3ddc32c 100644 --- a/tests/src/cgeo/geocaching/WaypointTest.java +++ b/tests/src/cgeo/geocaching/WaypointTest.java @@ -14,23 +14,27 @@ public class WaypointTest extends AndroidTestCase { final Waypoint own = new Waypoint("own", WaypointType.OWN, true); final Waypoint parking = new Waypoint("parking", WaypointType.PARKING, false); - assertTrue(trailhead.compareTo(puzzle) < 0); - assertTrue(trailhead.compareTo(stage) < 0); - assertTrue(trailhead.compareTo(cache) < 0); - - assertTrue(stage.compareTo(cache) < 0); - assertTrue(puzzle.compareTo(cache) < 0); - - assertTrue(trailhead.compareTo(own) < 0); - assertTrue(puzzle.compareTo(own) < 0); - assertTrue(stage.compareTo(own) < 0); - assertTrue(cache.compareTo(own) < 0); - - assertTrue(parking.compareTo(puzzle) < 0); - assertTrue(parking.compareTo(stage) < 0); - assertTrue(parking.compareTo(cache) < 0); - assertTrue(parking.compareTo(own) < 0); - assertTrue(parking.compareTo(trailhead) < 0); + assertOrdered(trailhead, puzzle); + assertOrdered(trailhead, stage); + assertOrdered(trailhead, cache); + + assertOrdered(stage, cache); + assertOrdered(puzzle, cache); + + assertOrdered(trailhead, own); + assertOrdered(puzzle, own); + assertOrdered(stage, own); + assertOrdered(cache, own); + + assertOrdered(parking, puzzle); + assertOrdered(parking, stage); + assertOrdered(parking, cache); + assertOrdered(parking, own); + assertOrdered(parking, trailhead); + } + + private static void assertOrdered(Waypoint first, Waypoint second) { + assertTrue(Waypoint.WAYPOINT_COMPARATOR.compare(first, second) < 0); } public static void testGeocode() { |
