aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <Bananeweizen@gmx.de>2012-01-29 19:46:23 +0100
committerBananeweizen <Bananeweizen@gmx.de>2012-01-29 19:46:23 +0100
commit56f2474379db581abdfb2e74d70c6827c0c4b297 (patch)
tree932348ff11f501a655a4ee589b23179317593864
parent94319286c9e37ce757f172b4a9fe4ac4d2530158 (diff)
downloadcgeo-56f2474379db581abdfb2e74d70c6827c0c4b297.zip
cgeo-56f2474379db581abdfb2e74d70c6827c0c4b297.tar.gz
cgeo-56f2474379db581abdfb2e74d70c6827c0c4b297.tar.bz2
#1065: add distance to search results for search by address
-rw-r--r--main/src/cgeo/geocaching/cgeoaddresses.java35
1 files changed, 20 insertions, 15 deletions
diff --git a/main/src/cgeo/geocaching/cgeoaddresses.java b/main/src/cgeo/geocaching/cgeoaddresses.java
index 769e84d..27a3110 100644
--- a/main/src/cgeo/geocaching/cgeoaddresses.java
+++ b/main/src/cgeo/geocaching/cgeoaddresses.java
@@ -1,8 +1,10 @@
package cgeo.geocaching;
import cgeo.geocaching.activity.AbstractActivity;
+import cgeo.geocaching.geopoint.Geopoint;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
import android.app.ProgressDialog;
import android.location.Address;
@@ -15,6 +17,7 @@ import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
+import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -79,32 +82,34 @@ public class cgeoaddresses extends AbstractActivity {
return;
} else {
LinearLayout oneAddPre = null;
+ final Geopoint lastLoc = cgeoapplication.getInstance().getLastCoords();
for (Address address : addresses) {
oneAddPre = (LinearLayout) inflater.inflate(R.layout.address_button, null);
Button oneAdd = (Button) oneAddPre.findViewById(R.id.button);
- int index = 0;
- StringBuilder allAdd = new StringBuilder();
- StringBuilder allAddLine = new StringBuilder();
- while (address.getAddressLine(index) != null) {
- if (allAdd.length() > 0) {
- allAdd.append('\n');
- }
- if (allAddLine.length() > 0) {
- allAddLine.append("; ");
+ final int maxIndex = address.getMaxAddressLineIndex();
+ final ArrayList<String> lines = new ArrayList<String>();
+ for (int i = 0; i <= maxIndex; i++) {
+ String line = address.getAddressLine(i);
+ if (StringUtils.isNotBlank(line)) {
+ lines.add(line);
}
+ }
- allAdd.append(address.getAddressLine(index));
- allAddLine.append(address.getAddressLine(index));
+ final String listTitle = StringUtils.join(lines, "; ");
- index++;
+ if (lastLoc != null) {
+ if (address.hasLatitude() && address.hasLongitude()) {
+ lines.add(cgBase.getHumanDistance(lastLoc.distanceTo(new Geopoint(address.getLatitude(), address.getLongitude()))));
+ }
}
- oneAdd.setText(allAdd.toString());
- oneAdd.setLines(allAdd.toString().split("\n").length);
+ oneAdd.setText(StringUtils.join(lines, "\n"));
+ oneAdd.setLines(lines.size());
oneAdd.setClickable(true);
- oneAdd.setOnClickListener(new buttonListener(address.getLatitude(), address.getLongitude(), allAddLine.toString()));
+
+ oneAdd.setOnClickListener(new buttonListener(address.getLatitude(), address.getLongitude(), listTitle));
addList.addView(oneAddPre);
}
}