aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2012-06-11 11:29:22 +0200
committerSamuel Tardieu <sam@rfc1149.net>2012-06-11 11:29:22 +0200
commit0dd4bd74af1b1e2a871616ffd8b9416960656a46 (patch)
tree0ea6583af57afb4c6d809ba891ba79f50269aaef /main/src/cgeo/geocaching
parent4e64657dc74e9a10d8264b5f26f1e21c0101a85f (diff)
parentbbc713d01b655870ffdd35941bdd0b3395e09210 (diff)
downloadcgeo-0dd4bd74af1b1e2a871616ffd8b9416960656a46.zip
cgeo-0dd4bd74af1b1e2a871616ffd8b9416960656a46.tar.gz
cgeo-0dd4bd74af1b1e2a871616ffd8b9416960656a46.tar.bz2
Merge remote-tracking branch 'campbeb/fix315' into upstream
Diffstat (limited to 'main/src/cgeo/geocaching')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java20
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/CompassApp.java7
-rw-r--r--main/src/cgeo/geocaching/cgWaypoint.java2
-rw-r--r--main/src/cgeo/geocaching/cgeonavigate.java25
-rw-r--r--main/src/cgeo/geocaching/ui/CacheListAdapter.java34
-rw-r--r--main/src/cgeo/geocaching/ui/Formatter.java74
6 files changed, 107 insertions, 55 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 23c02c6..a3b78e2 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -12,7 +12,6 @@ import cgeo.geocaching.enumerations.CacheAttribute;
import cgeo.geocaching.enumerations.LoadFlags;
import cgeo.geocaching.enumerations.LoadFlags.SaveFlag;
import cgeo.geocaching.enumerations.LogType;
-import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.geopoint.GeopointFormatter;
import cgeo.geocaching.geopoint.Units;
import cgeo.geocaching.network.HtmlImage;
@@ -2314,23 +2313,10 @@ public class CacheDetailActivity extends AbstractActivity {
}
// info
- final List<String> infoTextList = new ArrayList<String>(3);
- if (WaypointType.ALL_TYPES_EXCEPT_OWN.contains(wpt.getWaypointType())) {
- infoTextList.add(wpt.getWaypointType().getL10n());
- }
- if (cgWaypoint.PREFIX_OWN.equalsIgnoreCase(wpt.getPrefix())) {
- infoTextList.add(res.getString(R.string.waypoint_custom));
- } else {
- if (StringUtils.isNotBlank(wpt.getPrefix())) {
- infoTextList.add(wpt.getPrefix());
- }
- if (StringUtils.isNotBlank(wpt.getLookup())) {
- infoTextList.add(wpt.getLookup());
- }
- }
- if (CollectionUtils.isNotEmpty(infoTextList)) {
+ final String waypointInfo = Formatter.formatWaypointInfo(wpt);
+ if (StringUtils.isNotBlank(waypointInfo)) {
final TextView infoView = (TextView) waypointView.findViewById(R.id.info);
- infoView.setText(StringUtils.join(infoTextList, Formatter.SEPARATOR));
+ infoView.setText(waypointInfo);
infoView.setVisibility(View.VISIBLE);
}
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/CompassApp.java b/main/src/cgeo/geocaching/apps/cache/navi/CompassApp.java
index da3d5f9..5275d53 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/CompassApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/CompassApp.java
@@ -6,6 +6,7 @@ import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.cgeonavigate;
import cgeo.geocaching.apps.AbstractApp;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.ui.Formatter;
import android.app.Activity;
@@ -27,7 +28,8 @@ class CompassApp extends AbstractApp implements CacheNavigationApp, WaypointNavi
@Override
public void navigate(Activity activity, cgWaypoint waypoint) {
- cgeonavigate.startActivity(activity, waypoint.getPrefix() + "/" + waypoint.getLookup(), waypoint.getName(), waypoint.getCoords(), null);
+ cgeonavigate.startActivity(activity, waypoint.getPrefix() + "/" + waypoint.getLookup(), waypoint.getName(), waypoint.getCoords(), null,
+ waypoint.getWaypointType().getL10n());
}
@Override
@@ -37,7 +39,8 @@ class CompassApp extends AbstractApp implements CacheNavigationApp, WaypointNavi
@Override
public void navigate(Activity activity, cgCache cache) {
- cgeonavigate.startActivity(activity, cache.getGeocode(), cache.getName(), cache.getCoords(), null);
+ cgeonavigate.startActivity(activity, cache.getGeocode(), cache.getName(), cache.getCoords(), null,
+ Formatter.formatCacheInfoShort(cache));
}
@Override
diff --git a/main/src/cgeo/geocaching/cgWaypoint.java b/main/src/cgeo/geocaching/cgWaypoint.java
index c847b24..af6bab5 100644
--- a/main/src/cgeo/geocaching/cgWaypoint.java
+++ b/main/src/cgeo/geocaching/cgWaypoint.java
@@ -12,7 +12,7 @@ import java.util.List;
public class cgWaypoint implements IWaypoint, Comparable<cgWaypoint> {
- static final String PREFIX_OWN = "OWN";
+ public static final String PREFIX_OWN = "OWN";
private static final int ORDER_UNDEFINED = -2;
private int id = 0;
private String geocode = "geocode";
diff --git a/main/src/cgeo/geocaching/cgeonavigate.java b/main/src/cgeo/geocaching/cgeonavigate.java
index 6062a14..53470b3 100644
--- a/main/src/cgeo/geocaching/cgeonavigate.java
+++ b/main/src/cgeo/geocaching/cgeonavigate.java
@@ -17,6 +17,7 @@ import android.os.PowerManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
+import android.view.View;
import android.widget.TextView;
import java.util.ArrayList;
@@ -28,6 +29,7 @@ public class cgeonavigate extends AbstractActivity {
private static final String EXTRAS_COORDS = "coords";
private static final String EXTRAS_NAME = "name";
private static final String EXTRAS_GEOCODE = "geocode";
+ private static final String EXTRAS_CACHE_INFO = "cacheinfo";
private static final List<IWaypoint> coordinates = new ArrayList<IWaypoint>();
private static final int MENU_MAP = 0;
private static final int MENU_SWITCH_COMPASS_GPS = 1;
@@ -36,6 +38,7 @@ public class cgeonavigate extends AbstractActivity {
private float cacheHeading = 0;
private String title = null;
private String name = null;
+ private String info = null;
private TextView navType = null;
private TextView navAccuracy = null;
private TextView navSatellites = null;
@@ -64,6 +67,7 @@ public class cgeonavigate extends AbstractActivity {
title = geocode;
name = extras.getString(EXTRAS_NAME);
dstCoords = (Geopoint) extras.getParcelable(EXTRAS_COORDS);
+ info = extras.getString(EXTRAS_CACHE_INFO);
if (StringUtils.isNotBlank(name)) {
if (StringUtils.isNotBlank(title)) {
@@ -85,6 +89,7 @@ public class cgeonavigate extends AbstractActivity {
// set header
setTitle();
setDestCoords();
+ setCacheInfo();
// get textviews once
compassView = (CompassView) findViewById(R.id.rose);
@@ -178,6 +183,7 @@ public class cgeonavigate extends AbstractActivity {
dstCoords = coordinate.getCoords();
setTitle();
setDestCoords();
+ setCacheInfo();
updateDistanceInfo(app.currentGeo());
Log.d("destination set: " + title + " (" + dstCoords + ")");
@@ -203,6 +209,16 @@ public class cgeonavigate extends AbstractActivity {
((TextView) findViewById(R.id.destination)).setText(dstCoords.toString());
}
+ private void setCacheInfo() {
+ final TextView cacheInfoView = (TextView) findViewById(R.id.cacheinfo);
+ if (info == null) {
+ cacheInfoView.setVisibility(View.GONE);
+ return;
+ }
+ cacheInfoView.setVisibility(View.VISIBLE);
+ cacheInfoView.setText(info);
+ }
+
private void updateDistanceInfo(final IGeoData geo) {
if (geo.getCoords() == null || dstCoords == null) {
return;
@@ -282,7 +298,8 @@ public class cgeonavigate extends AbstractActivity {
}
}
- public static void startActivity(final Context context, final String geocode, final String displayedName, final Geopoint coords, final Collection<IWaypoint> coordinatesWithType) {
+ public static void startActivity(final Context context, final String geocode, final String displayedName, final Geopoint coords, final Collection<IWaypoint> coordinatesWithType,
+ final String info) {
coordinates.clear();
if (coordinatesWithType != null) { // avoid possible NPE
coordinates.addAll(coordinatesWithType);
@@ -294,6 +311,12 @@ public class cgeonavigate extends AbstractActivity {
if (null != displayedName) {
navigateIntent.putExtra(EXTRAS_NAME, displayedName);
}
+ navigateIntent.putExtra(EXTRAS_CACHE_INFO, info);
context.startActivity(navigateIntent);
}
+
+ public static void startActivity(final Context context, final String geocode, final String displayedName, final Geopoint coords, final Collection<IWaypoint> coordinatesWithType) {
+ cgeonavigate.startActivity(context, geocode, displayedName, coords, coordinatesWithType, null);
+ }
+
}
diff --git a/main/src/cgeo/geocaching/ui/CacheListAdapter.java b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
index 976abec..65d3fbc 100644
--- a/main/src/cgeo/geocaching/ui/CacheListAdapter.java
+++ b/main/src/cgeo/geocaching/ui/CacheListAdapter.java
@@ -7,7 +7,6 @@ import cgeo.geocaching.Settings;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.enumerations.CacheListType;
-import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.filter.IFilter;
import cgeo.geocaching.geopoint.Geopoint;
@@ -18,7 +17,6 @@ import cgeo.geocaching.utils.AngleUtils;
import cgeo.geocaching.utils.Log;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import android.app.Activity;
@@ -502,37 +500,9 @@ public class CacheListAdapter extends ArrayAdapter<cgCache> {
holder.favourite.setBackgroundResource(favoriteBack);
if (cacheListType == CacheListType.HISTORY && cache.getVisitedDate() > 0) {
- final ArrayList<String> infos = new ArrayList<String>();
- infos.add(StringUtils.upperCase(cache.getGeocode()));
- infos.add(Formatter.formatDate(cache.getVisitedDate()));
- infos.add(Formatter.formatTime(cache.getVisitedDate()));
- holder.info.setText(StringUtils.join(infos, Formatter.SEPARATOR));
+ holder.info.setText(Formatter.formatCacheInfoHistory(cache));
} else {
- final ArrayList<String> infos = new ArrayList<String>();
- if (StringUtils.isNotBlank(cache.getGeocode())) {
- infos.add(cache.getGeocode());
- }
- if (cache.hasDifficulty()) {
- infos.add("D " + String.format("%.1f", cache.getDifficulty()));
- }
- if (cache.hasTerrain()) {
- infos.add("T " + String.format("%.1f", cache.getTerrain()));
- }
-
- // don't show "not chosen" for events and virtuals, that should be the normal case
- if (cache.getSize() != CacheSize.UNKNOWN && cache.showSize()) {
- infos.add(cache.getSize().getL10n());
- } else if (cache.isEventCache() && cache.getHiddenDate() != null) {
- infos.add(Formatter.formatShortDate(cache.getHiddenDate().getTime()));
- }
-
- if (cache.isPremiumMembersOnly()) {
- infos.add(res.getString(R.string.cache_premium));
- }
- if (cacheListType != CacheListType.OFFLINE && cacheListType != CacheListType.HISTORY && cache.getListId() > 0) {
- infos.add(res.getString(R.string.cache_offline));
- }
- holder.info.setText(StringUtils.join(infos, Formatter.SEPARATOR));
+ holder.info.setText(Formatter.formatCacheInfoLong(cache, cacheListType));
}
return v;
diff --git a/main/src/cgeo/geocaching/ui/Formatter.java b/main/src/cgeo/geocaching/ui/Formatter.java
index 33793c1..53a7276 100644
--- a/main/src/cgeo/geocaching/ui/Formatter.java
+++ b/main/src/cgeo/geocaching/ui/Formatter.java
@@ -1,11 +1,21 @@
package cgeo.geocaching.ui;
import cgeo.geocaching.R;
+import cgeo.geocaching.cgCache;
+import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.enumerations.CacheListType;
+import cgeo.geocaching.enumerations.CacheSize;
+import cgeo.geocaching.enumerations.WaypointType;
+
+import org.apache.commons.lang3.StringUtils;
import android.content.Context;
import android.text.format.DateUtils;
+import java.util.ArrayList;
+import java.util.List;
+
public abstract class Formatter {
/** Text separator used for formatting texts */
@@ -67,7 +77,7 @@ public abstract class Formatter {
/**
* Generate a numeric date string according to system-wide settings (locale, date format)
* such as "10/20/2010". Today and yesterday will be presented as strings "today" and "yesterday".
- *
+ *
* @param date
* milliseconds since the epoch
* @return the formatted string
@@ -87,7 +97,7 @@ public abstract class Formatter {
/**
* Generate a numeric date and time string according to system-wide settings (locale,
* date format) such as "7 sept. at 12:35".
- *
+ *
* @param context
* a Context
* @param date
@@ -98,4 +108,64 @@ public abstract class Formatter {
return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL);
}
+ public static String formatCacheInfoLong(cgCache cache, CacheListType cacheListType) {
+ final ArrayList<String> infos = new ArrayList<String>();
+ if (StringUtils.isNotBlank(cache.getGeocode())) {
+ infos.add(cache.getGeocode());
+ }
+
+ infos.add(Formatter.formatCacheInfoShort(cache));
+
+ if (cache.isPremiumMembersOnly()) {
+ infos.add(cgeoapplication.getInstance().getString(R.string.cache_premium));
+ }
+ if (cacheListType != CacheListType.OFFLINE && cacheListType != CacheListType.HISTORY && cache.getListId() > 0) {
+ infos.add(cgeoapplication.getInstance().getString(R.string.cache_offline));
+ }
+ return StringUtils.join(infos, Formatter.SEPARATOR);
+ }
+
+ public static String formatCacheInfoShort(cgCache cache) {
+ final ArrayList<String> infos = new ArrayList<String>();
+ if (cache.hasDifficulty()) {
+ infos.add("D " + String.format("%.1f", cache.getDifficulty()));
+ }
+ if (cache.hasTerrain()) {
+ infos.add("T " + String.format("%.1f", cache.getTerrain()));
+ }
+
+ // don't show "not chosen" for events and virtuals, that should be the normal case
+ if (cache.getSize() != CacheSize.UNKNOWN && cache.showSize()) {
+ infos.add(cache.getSize().getL10n());
+ } else if (cache.isEventCache() && cache.getHiddenDate() != null) {
+ infos.add(Formatter.formatShortDate(cache.getHiddenDate().getTime()));
+ }
+ return StringUtils.join(infos, Formatter.SEPARATOR);
+ }
+
+ public static String formatCacheInfoHistory(cgCache cache) {
+ final ArrayList<String> infos = new ArrayList<String>(3);
+ infos.add(StringUtils.upperCase(cache.getGeocode()));
+ infos.add(Formatter.formatDate(cache.getVisitedDate()));
+ infos.add(Formatter.formatTime(cache.getVisitedDate()));
+ return StringUtils.join(infos, Formatter.SEPARATOR);
+ }
+
+ public static String formatWaypointInfo(cgWaypoint waypoint) {
+ final List<String> infos = new ArrayList<String>(3);
+ if (WaypointType.ALL_TYPES_EXCEPT_OWN.contains(waypoint.getWaypointType())) {
+ infos.add(waypoint.getWaypointType().getL10n());
+ }
+ if (cgWaypoint.PREFIX_OWN.equalsIgnoreCase(waypoint.getPrefix())) {
+ infos.add(cgeoapplication.getInstance().getString(R.string.waypoint_custom));
+ } else {
+ if (StringUtils.isNotBlank(waypoint.getPrefix())) {
+ infos.add(waypoint.getPrefix());
+ }
+ if (StringUtils.isNotBlank(waypoint.getLookup())) {
+ infos.add(waypoint.getLookup());
+ }
+ }
+ return StringUtils.join(infos, Formatter.SEPARATOR);
+ }
}