mirror of
https://gitlab.com/oeffi/oeffi.git
synced 2025-07-07 06:08:51 +00:00
Move LocationView.addressToLocation() to GeocoderThread.
This commit is contained in:
parent
653c5afad1
commit
68f6908b40
4 changed files with 32 additions and 28 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue