aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorcampbeb <bpcampbell@gmail.com>2012-06-02 18:21:19 +0900
committercampbeb <bpcampbell@gmail.com>2012-06-08 18:13:36 +0900
commitbbc713d01b655870ffdd35941bdd0b3395e09210 (patch)
tree76935eb9787d9a8d72bfe16f63c71f99e313dda8 /main
parent550eb54d1c76dd2788c43ae9b67d43e57b90bf26 (diff)
downloadcgeo-bbc713d01b655870ffdd35941bdd0b3395e09210.zip
cgeo-bbc713d01b655870ffdd35941bdd0b3395e09210.tar.gz
cgeo-bbc713d01b655870ffdd35941bdd0b3395e09210.tar.bz2
Display cache and waypoint information on compass
For caches: displays difficulty, terrain, and size. For waypoints: displays waypoint type. For direct navigation: displays nothing. Also includes some refactoring in the code used do display information about caches and waypoints.
Diffstat (limited to 'main')
-rw-r--r--main/res/layout/navigate.xml71
-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
7 files changed, 148 insertions, 85 deletions
diff --git a/main/res/layout/navigate.xml b/main/res/layout/navigate.xml
index 8e98136..94ed7bc 100644
--- a/main/res/layout/navigate.xml
+++ b/main/res/layout/navigate.xml
@@ -17,36 +17,47 @@
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
- <TextView android:id="@+id/destination"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
- android:layout_gravity="center"
- android:textSize="14dip"
- android:textColor="?text_color"/>
- <TextView android:id="@+id/heading"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="16dip"
- android:layout_marginLeft="3dip"
- android:layout_alignParentTop="true"
- android:layout_alignParentLeft="true"
- android:layout_gravity="left"
- android:textSize="26dip"
- android:textColor="?text_color"
- android:text="@null" />
- <TextView android:id="@+id/distance"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="16dip"
- android:layout_marginRight="3dip"
- android:layout_alignParentTop="true"
- android:layout_alignParentRight="true"
- android:layout_gravity="right"
- android:textSize="26dip"
- android:textColor="?text_color"
- android:text="@null" />
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+ <TextView android:id="@+id/destination"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_gravity="center"
+ android:textSize="14dip"
+ android:textColor="?text_color"/>
+ <TextView android:id="@+id/cacheinfo"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_gravity="center"
+ android:textSize="14dip"
+ android:textColor="?text_color"/>
+ <RelativeLayout
+ android:layout_width="fill_parent"
+ android:layout_height="30dip" >
+ <TextView android:id="@+id/heading"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="3dip"
+ android:layout_alignParentLeft="true"
+ android:layout_gravity="left"
+ android:textSize="26dip"
+ android:textColor="?text_color"
+ android:text="@null" />
+ <TextView android:id="@+id/distance"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginRight="3dip"
+ android:layout_alignParentRight="true"
+ android:layout_gravity="right"
+ android:textSize="26dip"
+ android:textColor="?text_color"
+ android:text="@null" />
+ </RelativeLayout>
+ </LinearLayout>
<view class="cgeo.geocaching.ui.CompassView"
android:id="@+id/rose"
android:layout_width="fill_parent"
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index bf80e5a..3740c55 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.HumanDistance;
import cgeo.geocaching.geopoint.IConversion;
@@ -2317,23 +2316,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 567ae74..dd6e09b 100644
--- a/main/src/cgeo/geocaching/cgeonavigate.java
+++ b/main/src/cgeo/geocaching/cgeonavigate.java
@@ -18,6 +18,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;
@@ -29,6 +30,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;
@@ -37,6 +39,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;
@@ -65,6 +68,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)) {
@@ -86,6 +90,7 @@ public class cgeonavigate extends AbstractActivity {
// set header
setTitle();
setDestCoords();
+ setCacheInfo();
// get textviews once
compassView = (CompassView) findViewById(R.id.rose);
@@ -179,6 +184,7 @@ public class cgeonavigate extends AbstractActivity {
dstCoords = coordinate.getCoords();
setTitle();
setDestCoords();
+ setCacheInfo();
updateDistanceInfo(app.currentGeo());
Log.d("destination set: " + title + " (" + dstCoords + ")");
@@ -204,6 +210,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;
@@ -290,7 +306,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);
@@ -302,6 +319,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 c6d3404..9fa54eb 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;
@@ -492,37 +490,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);
+ }
}