diff options
Diffstat (limited to 'main/src/cgeo/geocaching/Waypoint.java')
| -rw-r--r-- | main/src/cgeo/geocaching/Waypoint.java | 49 |
1 files changed, 12 insertions, 37 deletions
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(); + } + }; } |
