diff --git a/oeffi/src/de/schildbach/oeffi/directions/DirectionsActivity.java b/oeffi/src/de/schildbach/oeffi/directions/DirectionsActivity.java index 188995a..7762bcc 100644 --- a/oeffi/src/de/schildbach/oeffi/directions/DirectionsActivity.java +++ b/oeffi/src/de/schildbach/oeffi/directions/DirectionsActivity.java @@ -486,7 +486,7 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom new GeocoderThread(DirectionsActivity.this, p.getLatitude(), p.getLongitude(), new GeocoderThread.Callback() { public void onGeocoderResult(final Address address) { - pinLocation = LocationView.addressToLocation(address); + pinLocation = GeocoderThread.addressToLocation(address); locationView.setLocation(pinLocation); locationView.setShowLocationType(false); } diff --git a/oeffi/src/de/schildbach/oeffi/directions/DirectionsShortcutActivity.java b/oeffi/src/de/schildbach/oeffi/directions/DirectionsShortcutActivity.java index 239fe29..44b9701 100644 --- a/oeffi/src/de/schildbach/oeffi/directions/DirectionsShortcutActivity.java +++ b/oeffi/src/de/schildbach/oeffi/directions/DirectionsShortcutActivity.java @@ -168,7 +168,7 @@ public class DirectionsShortcutActivity extends OeffiActivity public void onLocation(final Point here) { new GeocoderThread(DirectionsShortcutActivity.this, here, new GeocoderThread.Callback() { public void onGeocoderResult(final Address address) { - final Location location = LocationView.addressToLocation(address); + final Location location = GeocoderThread.addressToLocation(address); query(location); } diff --git a/oeffi/src/de/schildbach/oeffi/directions/LocationView.java b/oeffi/src/de/schildbach/oeffi/directions/LocationView.java index 67f8da7..a601831 100644 --- a/oeffi/src/de/schildbach/oeffi/directions/LocationView.java +++ b/oeffi/src/de/schildbach/oeffi/directions/LocationView.java @@ -19,7 +19,6 @@ package de.schildbach.oeffi.directions; import java.util.Locale; -import com.google.common.base.Joiner; import com.google.common.base.Strings; import de.schildbach.oeffi.Constants; @@ -340,7 +339,7 @@ public class LocationView extends FrameLayout implements LocationHelper.Callback new GeocoderThread(getContext(), coord, new GeocoderThread.Callback() { public void onGeocoderResult(final Address address) { if (locationType == LocationType.COORD) { - setLocation(addressToLocation(address)); + setLocation(GeocoderThread.addressToLocation(address)); hint = null; } } @@ -446,30 +445,6 @@ public class LocationView extends FrameLayout implements LocationHelper.Callback other.fireChanged(); } - public static Location addressToLocation(final Address address) { - final Point coord; - if (address.hasLatitude() && address.hasLongitude()) - coord = Point.fromDouble(address.getLatitude(), address.getLongitude()); - else - coord = null; - - final Location location; - final int maxAddressLineIndex = address.getMaxAddressLineIndex(); - if (maxAddressLineIndex >= 2 && Strings.emptyToNull(address.getAddressLine(2)) != null) { - location = new Location(LocationType.ADDRESS, null, coord, address.getAddressLine(1), - address.getAddressLine(0)); - } else if (address.getThoroughfare() != null) { - final Joiner joiner = Joiner.on(' ').skipNulls(); - location = new Location(LocationType.ADDRESS, null, coord, - joiner.join(address.getPostalCode(), address.getLocality()), - joiner.join(address.getThoroughfare(), address.getFeatureName())); - } else { - location = new Location(LocationType.ADDRESS, null, coord); - } - - return location; - } - private void fireChanged() { if (listener != null) listener.changed(); diff --git a/oeffi/src/de/schildbach/oeffi/util/GeocoderThread.java b/oeffi/src/de/schildbach/oeffi/util/GeocoderThread.java index 627f90e..0049210 100644 --- a/oeffi/src/de/schildbach/oeffi/util/GeocoderThread.java +++ b/oeffi/src/de/schildbach/oeffi/util/GeocoderThread.java @@ -27,6 +27,11 @@ import java.util.Locale; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.base.Joiner; +import com.google.common.base.Strings; + +import de.schildbach.pte.dto.Location; +import de.schildbach.pte.dto.LocationType; import de.schildbach.pte.dto.Point; import android.content.Context; @@ -109,4 +114,28 @@ public class GeocoderThread extends Thread { } }); } + + public static Location addressToLocation(final Address address) { + final Point coord; + if (address.hasLatitude() && address.hasLongitude()) + coord = Point.fromDouble(address.getLatitude(), address.getLongitude()); + else + coord = null; + + final Location location; + final int maxAddressLineIndex = address.getMaxAddressLineIndex(); + if (maxAddressLineIndex >= 2 && Strings.emptyToNull(address.getAddressLine(2)) != null) { + location = new Location(LocationType.ADDRESS, null, coord, address.getAddressLine(1), + address.getAddressLine(0)); + } else if (address.getThoroughfare() != null) { + final Joiner joiner = Joiner.on(' ').skipNulls(); + location = new Location(LocationType.ADDRESS, null, coord, + joiner.join(address.getPostalCode(), address.getLocality()), + joiner.join(address.getThoroughfare(), address.getFeatureName())); + } else { + location = new Location(LocationType.ADDRESS, null, coord); + } + + return location; + } }