From 5873e26d4654c5305ead298101113d93963f02fe Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Thu, 15 Nov 2018 23:03:35 +0100 Subject: [PATCH] Adapt to: Point: Store coordinate as pair of double, rather than 1E6 ints. --- .../src/de/schildbach/oeffi/OeffiMapView.java | 2 +- .../oeffi/directions/DirectionsActivity.java | 22 +++--- .../DirectionsShortcutActivity.java | 3 +- .../oeffi/directions/LocationTextView.java | 2 +- .../directions/QueryHistoryProvider.java | 16 ++-- .../oeffi/directions/TripDetailsActivity.java | 16 ++-- .../directions/list/QueryHistoryAdapter.java | 6 +- .../oeffi/network/NetworkPickerActivity.java | 12 +-- .../schildbach/oeffi/plans/PlanActivity.java | 8 +- .../oeffi/plans/PlanContentProvider.java | 6 +- .../oeffi/plans/ScrollImageView.java | 4 +- .../stations/FavoriteStationsProvider.java | 6 +- .../oeffi/stations/FavoriteUtils.java | 4 +- .../NearestFavoriteStationWidgetService.java | 6 +- .../oeffi/stations/StationContextMenu.java | 22 +++--- .../stations/StationDetailsActivity.java | 9 ++- .../oeffi/stations/StationsActivity.java | 20 ++--- .../oeffi/util/LocationUriParser.java | 2 +- .../oeffi/util/LocationUriParserTest.java | 76 +++++++++---------- 19 files changed, 128 insertions(+), 114 deletions(-) diff --git a/oeffi/src/de/schildbach/oeffi/OeffiMapView.java b/oeffi/src/de/schildbach/oeffi/OeffiMapView.java index f5c4ab0..b6969c3 100644 --- a/oeffi/src/de/schildbach/oeffi/OeffiMapView.java +++ b/oeffi/src/de/schildbach/oeffi/OeffiMapView.java @@ -317,7 +317,7 @@ public class OeffiMapView extends MapView { Station selectedStation = null; for (final Station station : stations) { - if (station.location.hasLocation()) { + if (station.location.hasCoord()) { projection.toPixels(new GeoPoint(station.location.getLatAsDouble(), station.location.getLonAsDouble()), point); diff --git a/oeffi/src/de/schildbach/oeffi/directions/DirectionsActivity.java b/oeffi/src/de/schildbach/oeffi/directions/DirectionsActivity.java index 5eb4a63..44054fb 100644 --- a/oeffi/src/de/schildbach/oeffi/directions/DirectionsActivity.java +++ b/oeffi/src/de/schildbach/oeffi/directions/DirectionsActivity.java @@ -788,23 +788,23 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom mapView.setFromViaToAware(new FromViaToAware() { public Point getFrom() { final Location from = viewFromLocation.getLocation(); - if (from == null || !from.hasLocation()) + if (from == null || !from.hasCoord()) return null; - return new Point(from.lat, from.lon); + return from.coord; } public Point getVia() { final Location via = viewViaLocation.getLocation(); - if (via == null || !via.hasLocation() || viewViaLocation.getVisibility() != View.VISIBLE) + if (via == null || !via.hasCoord() || viewViaLocation.getVisibility() != View.VISIBLE) return null; - return new Point(via.lat, via.lon); + return via.coord; } public Point getTo() { final Location to = viewToLocation.getLocation(); - if (to == null || !to.hasLocation()) + if (to == null || !to.hasCoord()) return null; - return new Point(to.lat, to.lon); + return to.coord; } }); mapView.zoomToAll(); @@ -933,7 +933,7 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom return false; if (location.type == LocationType.ANY && location.name == null) return false; - if (!allowIncompleteAddress && location.type == LocationType.ADDRESS && !location.hasLocation() + if (!allowIncompleteAddress && location.type == LocationType.ADDRESS && !location.hasCoord() && location.name == null) return false; @@ -1301,8 +1301,9 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom .contains(constraintStr.toLowerCase(Constants.DEFAULT_LOCALE))) { final Location location = new Location( QueryHistoryProvider.convert(cursor.getInt(fromTypeC)), - cursor.getString(fromIdC), cursor.getInt(fromLatC), - cursor.getInt(fromLonC), cursor.getString(fromPlaceC), fromName); + cursor.getString(fromIdC), + Point.from1E6(cursor.getInt(fromLatC), cursor.getInt(fromLonC)), + cursor.getString(fromPlaceC), fromName); if (!results.contains(location)) results.add(location); } @@ -1311,7 +1312,8 @@ public class DirectionsActivity extends OeffiMainActivity implements ActivityCom .contains(constraintStr.toLowerCase(Constants.DEFAULT_LOCALE))) { final Location location = new Location( QueryHistoryProvider.convert(cursor.getInt(toTypeC)), - cursor.getString(toIdC), cursor.getInt(toLatC), cursor.getInt(toLonC), + cursor.getString(toIdC), + Point.from1E6(cursor.getInt(toLatC), cursor.getInt(toLonC)), cursor.getString(toPlaceC), toName); if (!results.contains(location)) results.add(location); diff --git a/oeffi/src/de/schildbach/oeffi/directions/DirectionsShortcutActivity.java b/oeffi/src/de/schildbach/oeffi/directions/DirectionsShortcutActivity.java index c816967..f7db755 100644 --- a/oeffi/src/de/schildbach/oeffi/directions/DirectionsShortcutActivity.java +++ b/oeffi/src/de/schildbach/oeffi/directions/DirectionsShortcutActivity.java @@ -214,7 +214,8 @@ public class DirectionsShortcutActivity extends OeffiActivity final String id = getLocationIdExtra(intent); final int lat = intent.getIntExtra(INTENT_EXTRA_LAT, 0); final int lon = intent.getIntExtra(INTENT_EXTRA_LON, 0); - final Location to = new Location(type, id, lat, lon, null, id != null ? name : name + "!"); + final Point coord = lat != 0 || lon != 0 ? Point.from1E6(lat, lon) : null; + final Location to = new Location(type, id, coord, null, id != null ? name : name + "!"); if (networkProvider != null) { final Optimize optimize = prefs.contains(Constants.PREFS_KEY_OPTIMIZE_TRIP) diff --git a/oeffi/src/de/schildbach/oeffi/directions/LocationTextView.java b/oeffi/src/de/schildbach/oeffi/directions/LocationTextView.java index d6bf7ac..e27e950 100644 --- a/oeffi/src/de/schildbach/oeffi/directions/LocationTextView.java +++ b/oeffi/src/de/schildbach/oeffi/directions/LocationTextView.java @@ -69,7 +69,7 @@ public class LocationTextView extends TextView { text.append(location.place).append(",
"); if (location.name != null) text.append("").append(location.name).append(""); - if (text.length() == 0 && location.hasLocation()) + if (text.length() == 0 && location.hasCoord()) text.append(getContext().getString(R.string.directions_location_view_coordinate)).append(":
") .append(String.format(Locale.ENGLISH, "%1$.6f, %2$.6f", location.getLatAsDouble(), location.getLonAsDouble())); diff --git a/oeffi/src/de/schildbach/oeffi/directions/QueryHistoryProvider.java b/oeffi/src/de/schildbach/oeffi/directions/QueryHistoryProvider.java index 1b344a1..386e164 100644 --- a/oeffi/src/de/schildbach/oeffi/directions/QueryHistoryProvider.java +++ b/oeffi/src/de/schildbach/oeffi/directions/QueryHistoryProvider.java @@ -96,8 +96,8 @@ public class QueryHistoryProvider extends ContentProvider { if (cursor.getInt(cursor.getColumnIndexOrThrow(QueryHistoryProvider.KEY_FROM_LAT)) == 0 && cursor.getInt(cursor.getColumnIndexOrThrow(QueryHistoryProvider.KEY_FROM_LON)) == 0) { - values.put(QueryHistoryProvider.KEY_FROM_LAT, from.lat); - values.put(QueryHistoryProvider.KEY_FROM_LON, from.lon); + values.put(QueryHistoryProvider.KEY_FROM_LAT, from.getLatAs1E6()); + values.put(QueryHistoryProvider.KEY_FROM_LON, from.getLonAs1E6()); } if (cursor.getInt(cursor.getColumnIndexOrThrow(QueryHistoryProvider.KEY_TO_ID)) == 0) @@ -105,8 +105,8 @@ public class QueryHistoryProvider extends ContentProvider { if (cursor.getInt(cursor.getColumnIndexOrThrow(QueryHistoryProvider.KEY_TO_LAT)) == 0 && cursor.getInt(cursor.getColumnIndexOrThrow(QueryHistoryProvider.KEY_TO_LON)) == 0) { - values.put(QueryHistoryProvider.KEY_TO_LAT, to.lat); - values.put(QueryHistoryProvider.KEY_TO_LON, to.lon); + values.put(QueryHistoryProvider.KEY_TO_LAT, to.getLatAs1E6()); + values.put(QueryHistoryProvider.KEY_TO_LON, to.getLonAs1E6()); } if (favorite != null) @@ -125,14 +125,14 @@ public class QueryHistoryProvider extends ContentProvider { final ContentValues values = new ContentValues(); values.put(QueryHistoryProvider.KEY_FROM_TYPE, QueryHistoryProvider.convert(from.type)); values.put(QueryHistoryProvider.KEY_FROM_ID, from.id); - values.put(QueryHistoryProvider.KEY_FROM_LAT, from.lat); - values.put(QueryHistoryProvider.KEY_FROM_LON, from.lon); + values.put(QueryHistoryProvider.KEY_FROM_LAT, from.getLatAs1E6()); + values.put(QueryHistoryProvider.KEY_FROM_LON, from.getLonAs1E6()); values.put(QueryHistoryProvider.KEY_FROM_PLACE, from.place); values.put(QueryHistoryProvider.KEY_FROM_NAME, from.name); values.put(QueryHistoryProvider.KEY_TO_TYPE, QueryHistoryProvider.convert(to.type)); values.put(QueryHistoryProvider.KEY_TO_ID, to.id); - values.put(QueryHistoryProvider.KEY_TO_LAT, to.lat); - values.put(QueryHistoryProvider.KEY_TO_LON, to.lon); + values.put(QueryHistoryProvider.KEY_TO_LAT, to.getLatAs1E6()); + values.put(QueryHistoryProvider.KEY_TO_LON, to.getLonAs1E6()); values.put(QueryHistoryProvider.KEY_TO_PLACE, to.place); values.put(QueryHistoryProvider.KEY_TO_NAME, to.name); diff --git a/oeffi/src/de/schildbach/oeffi/directions/TripDetailsActivity.java b/oeffi/src/de/schildbach/oeffi/directions/TripDetailsActivity.java index d09a958..0eab8b7 100644 --- a/oeffi/src/de/schildbach/oeffi/directions/TripDetailsActivity.java +++ b/oeffi/src/de/schildbach/oeffi/directions/TripDetailsActivity.java @@ -494,7 +494,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen if (leg instanceof Trip.Public) { final Trip.Public publicLeg = (Trip.Public) leg; - if (publicLeg.departure.hasLocation()) { + if (publicLeg.departure.hasCoord()) { android.location.Location.distanceBetween(publicLeg.departure.getLatAsDouble(), publicLeg.departure.getLonAsDouble(), location.getLatAsDouble(), location.getLonAsDouble(), distanceBetweenResults); @@ -508,7 +508,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen final List intermediateStops = publicLeg.intermediateStops; if (intermediateStops != null) { for (final Stop stop : intermediateStops) { - if (stop.location.hasLocation()) { + if (stop.location.hasCoord()) { android.location.Location.distanceBetween(stop.location.getLatAsDouble(), stop.location.getLonAsDouble(), location.getLatAsDouble(), location.getLonAsDouble(), distanceBetweenResults); @@ -521,7 +521,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen } } - if (publicLeg.arrival.hasLocation()) { + if (publicLeg.arrival.hasCoord()) { android.location.Location.distanceBetween(publicLeg.arrival.getLatAsDouble(), publicLeg.arrival.getLonAsDouble(), location.getLatAsDouble(), location.getLonAsDouble(), distanceBetweenResults); @@ -705,7 +705,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen final ImageButton mapView = (ImageButton) row.findViewById(R.id.directions_trip_details_individual_entry_map); mapView.setVisibility(View.GONE); mapView.setOnClickListener(null); - if (leg.arrival.hasLocation()) { + if (leg.arrival.hasCoord()) { mapView.setVisibility(View.VISIBLE); mapView.setOnClickListener(new MapClickListener(leg.arrival)); } else if (leg.arrival.hasId()) { @@ -970,7 +970,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen if (cursor.moveToFirst()) { final int latColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LAT); final int lonColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LON); - point = new Point(cursor.getInt(latColumnIndex), cursor.getInt(lonColumnIndex)); + point = Point.from1E6(cursor.getInt(latColumnIndex), cursor.getInt(lonColumnIndex)); } else { point = null; } @@ -994,7 +994,7 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen if (cursor.moveToFirst()) { final int latColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LAT); final int lonColumnIndex = cursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LON); - point = new Point(cursor.getInt(latColumnIndex), cursor.getInt(lonColumnIndex)); + point = Point.from1E6(cursor.getInt(latColumnIndex), cursor.getInt(lonColumnIndex)); } else { point = null; } @@ -1127,8 +1127,8 @@ public class TripDetailsActivity extends OeffiActivity implements LocationListen } private Point pointFromLocation(final Location location) { - if (location.hasLocation()) - return new Point(location.lat, location.lon); + if (location.hasCoord()) + return location.coord; if (location.hasId()) { final Point point = pointFromStationDb(location.id); diff --git a/oeffi/src/de/schildbach/oeffi/directions/list/QueryHistoryAdapter.java b/oeffi/src/de/schildbach/oeffi/directions/list/QueryHistoryAdapter.java index 8d9d3b5..ad36504 100644 --- a/oeffi/src/de/schildbach/oeffi/directions/list/QueryHistoryAdapter.java +++ b/oeffi/src/de/schildbach/oeffi/directions/list/QueryHistoryAdapter.java @@ -22,6 +22,7 @@ import de.schildbach.oeffi.directions.QueryHistoryProvider; import de.schildbach.oeffi.stations.FavoriteStationsProvider; import de.schildbach.pte.NetworkId; import de.schildbach.pte.dto.Location; +import de.schildbach.pte.dto.Point; import android.content.ContentResolver; import android.content.ContentValues; @@ -184,10 +185,11 @@ public class QueryHistoryAdapter extends RecyclerView.Adapter= lon || vertex2.lon < lon && vertex1.lon >= lon) { - if ((double) (vertex1.lat + (lon - vertex1.lon)) / (vertex2.lon - vertex1.lon) - * (vertex2.lat - vertex1.lat) < lat) + if (vertex1.getLonAsDouble() < lon && vertex2.getLonAsDouble() >= lon + || vertex2.getLonAsDouble() < lon && vertex1.getLonAsDouble() >= lon) { + if ((vertex1.getLatAsDouble() + (lon - vertex1.getLonAsDouble())) + / (vertex2.getLonAsDouble() - vertex1.getLonAsDouble()) + * (vertex2.getLatAsDouble() - vertex1.getLatAsDouble()) < lat) inArea = !inArea; } diff --git a/oeffi/src/de/schildbach/oeffi/plans/PlanActivity.java b/oeffi/src/de/schildbach/oeffi/plans/PlanActivity.java index 64b132d..33eabb2 100644 --- a/oeffi/src/de/schildbach/oeffi/plans/PlanActivity.java +++ b/oeffi/src/de/schildbach/oeffi/plans/PlanActivity.java @@ -58,6 +58,7 @@ import de.schildbach.pte.dto.Line; import de.schildbach.pte.dto.LineDestination; import de.schildbach.pte.dto.Location; import de.schildbach.pte.dto.LocationType; +import de.schildbach.pte.dto.Point; import de.schildbach.pte.dto.QueryDeparturesResult; import de.schildbach.pte.dto.StationDepartures; @@ -215,7 +216,8 @@ public class PlanActivity extends Activity { final String label = stationsCursor.getString(labelColumn); final int x = stationsCursor.getInt(xColumn); final int y = stationsCursor.getInt(yColumn); - stations.add(new Station(network, new Location(LocationType.STATION, localId, y, x, null, label))); + final Point point = Point.from1E6(y, x); + stations.add(new Station(network, new Location(LocationType.STATION, localId, point, null, label))); } stationsCursor.close(); } @@ -283,7 +285,7 @@ public class PlanActivity extends Activity { private void selectStation(final Station selection) { this.selection = selection; - plan.animatePlanIntoView(selection.location.lon, selection.location.lat); + plan.animatePlanIntoView(selection.location.getLonAs1E6(), selection.location.getLatAs1E6()); bubble.setVisibility(View.VISIBLE); bubbleName.setText(selection.location.name); @@ -331,7 +333,7 @@ public class PlanActivity extends Activity { private void updateBubble() { final Station selection = this.selection; if (selection != null) { - final int[] coords = new int[] { selection.location.lon, selection.location.lat }; + final int[] coords = new int[] { selection.location.getLonAs1E6(), selection.location.getLatAs1E6() }; plan.translateToViewCoordinates(coords); final BubbleLayout.LayoutParams layoutParams = (BubbleLayout.LayoutParams) bubble.getLayoutParams(); layoutParams.x = coords[0]; diff --git a/oeffi/src/de/schildbach/oeffi/plans/PlanContentProvider.java b/oeffi/src/de/schildbach/oeffi/plans/PlanContentProvider.java index 1f56303..03d3034 100644 --- a/oeffi/src/de/schildbach/oeffi/plans/PlanContentProvider.java +++ b/oeffi/src/de/schildbach/oeffi/plans/PlanContentProvider.java @@ -234,7 +234,7 @@ public class PlanContentProvider extends ContentProvider { filterMatch = false; if (filterMatch) { - cursor.newRow().add(rowId).add(planId).add(planName).add(p.lat).add(p.lon) + cursor.newRow().add(rowId).add(planId).add(planName).add(p.getLatAs1E6()).add(p.getLonAs1E6()) .add(planValidFrom != null ? planValidFrom.getTime() : 0).add(planDisclaimer).add(planUrl) .add(planNetworkLogo); } @@ -373,13 +373,13 @@ public class PlanContentProvider extends ContentProvider { public int compare(final Integer index1, final Integer index2) { cursor.moveToPosition(index1); - final Point p1 = new Point(cursor.getInt(latColumn), cursor.getInt(lonColumn)); + final Point p1 = Point.from1E6(cursor.getInt(latColumn), cursor.getInt(lonColumn)); android.location.Location.distanceBetween(lat, lon, p1.getLatAsDouble(), p1.getLonAsDouble(), distanceBetweenResults); final float dist1 = distanceBetweenResults[0]; cursor.moveToPosition(index2); - final Point p2 = new Point(cursor.getInt(latColumn), cursor.getInt(lonColumn)); + final Point p2 = Point.from1E6(cursor.getInt(latColumn), cursor.getInt(lonColumn)); android.location.Location.distanceBetween(lat, lon, p2.getLatAsDouble(), p2.getLonAsDouble(), distanceBetweenResults); final float dist2 = distanceBetweenResults[0]; diff --git a/oeffi/src/de/schildbach/oeffi/plans/ScrollImageView.java b/oeffi/src/de/schildbach/oeffi/plans/ScrollImageView.java index 25f6b7b..3d74675 100644 --- a/oeffi/src/de/schildbach/oeffi/plans/ScrollImageView.java +++ b/oeffi/src/de/schildbach/oeffi/plans/ScrollImageView.java @@ -351,8 +351,8 @@ public class ScrollImageView extends ImageView implements Runnable { double tappedDistance = 0; for (final Station station : stations) { - coords[0] = station.location.lon; - coords[1] = station.location.lat; + coords[0] = station.location.getLonAs1E6(); + coords[1] = station.location.getLatAs1E6(); translateToViewCoordinates(coords); final double distance = Math .sqrt(Math.pow(e.getX() - coords[0], 2) + Math.pow(e.getY() - coords[1], 2)); diff --git a/oeffi/src/de/schildbach/oeffi/stations/FavoriteStationsProvider.java b/oeffi/src/de/schildbach/oeffi/stations/FavoriteStationsProvider.java index 655f9df..375e741 100644 --- a/oeffi/src/de/schildbach/oeffi/stations/FavoriteStationsProvider.java +++ b/oeffi/src/de/schildbach/oeffi/stations/FavoriteStationsProvider.java @@ -25,6 +25,7 @@ import de.schildbach.oeffi.Application; import de.schildbach.pte.NetworkId; import de.schildbach.pte.dto.Location; import de.schildbach.pte.dto.LocationType; +import de.schildbach.pte.dto.Point; import android.content.ContentProvider; import android.content.ContentResolver; @@ -130,8 +131,9 @@ public class FavoriteStationsProvider extends ContentProvider { final int nameIndex = cursor.getColumnIndexOrThrow(FavoriteStationsProvider.KEY_STATION_NAME); final int latIndex = cursor.getColumnIndexOrThrow(FavoriteStationsProvider.KEY_STATION_LAT); final int lonIndex = cursor.getColumnIndexOrThrow(FavoriteStationsProvider.KEY_STATION_LON); - return new Location(LocationType.STATION, cursor.getString(idIndex), cursor.getInt(latIndex), - cursor.getInt(lonIndex), cursor.getString(placeIndex), cursor.getString(nameIndex)); + return new Location(LocationType.STATION, cursor.getString(idIndex), + Point.from1E6(cursor.getInt(latIndex), cursor.getInt(lonIndex)), cursor.getString(placeIndex), + cursor.getString(nameIndex)); } public static Integer favState(final ContentResolver contentResolver, final NetworkId network, diff --git a/oeffi/src/de/schildbach/oeffi/stations/FavoriteUtils.java b/oeffi/src/de/schildbach/oeffi/stations/FavoriteUtils.java index b01f037..db1ff04 100644 --- a/oeffi/src/de/schildbach/oeffi/stations/FavoriteUtils.java +++ b/oeffi/src/de/schildbach/oeffi/stations/FavoriteUtils.java @@ -41,8 +41,8 @@ public class FavoriteUtils { values.put(FavoriteStationsProvider.KEY_STATION_ID, station.id); values.put(FavoriteStationsProvider.KEY_STATION_PLACE, station.place); values.put(FavoriteStationsProvider.KEY_STATION_NAME, station.name); - values.put(FavoriteStationsProvider.KEY_STATION_LAT, station.lat); - values.put(FavoriteStationsProvider.KEY_STATION_LON, station.lon); + values.put(FavoriteStationsProvider.KEY_STATION_LAT, station.getLatAs1E6()); + values.put(FavoriteStationsProvider.KEY_STATION_LON, station.getLonAs1E6()); final Uri rowUri = contentResolver.insert(FavoriteStationsProvider.CONTENT_URI, values); diff --git a/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationWidgetService.java b/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationWidgetService.java index 713d8ef..bce0781 100644 --- a/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationWidgetService.java +++ b/oeffi/src/de/schildbach/oeffi/stations/NearestFavoriteStationWidgetService.java @@ -195,7 +195,7 @@ public class NearestFavoriteStationWidgetService extends JobIntentService { final String stationId = favCursor.getString(stationIdCol); String stationPlace = favCursor.getString(stationPlaceCol); String stationName = favCursor.getString(stationNameCol); - Point stationPoint = new Point(favCursor.getInt(stationLatCol), favCursor.getInt(stationLonCol)); + Point stationPoint = Point.from1E6(favCursor.getInt(stationLatCol), favCursor.getInt(stationLonCol)); try { final NetworkId networkId = NetworkId.valueOf(network); @@ -214,13 +214,13 @@ public class NearestFavoriteStationWidgetService extends JobIntentService { if (placeCol != -1) stationPlace = stationCursor.getString(placeCol); stationName = stationCursor.getString(nameCol); - stationPoint = new Point(stationCursor.getInt(latCol), stationCursor.getInt(lonCol)); + stationPoint = Point.from1E6(stationCursor.getInt(latCol), stationCursor.getInt(lonCol)); } stationCursor.close(); } - if (stationPoint.lat > 0 || stationPoint.lon > 0) { + if (stationPoint.getLatAsDouble() > 0 || stationPoint.getLonAsDouble() > 0) { final float[] distanceBetweenResults = new float[1]; android.location.Location.distanceBetween(here.getLatitude(), here.getLongitude(), stationPoint.getLatAsDouble(), stationPoint.getLonAsDouble(), distanceBetweenResults); diff --git a/oeffi/src/de/schildbach/oeffi/stations/StationContextMenu.java b/oeffi/src/de/schildbach/oeffi/stations/StationContextMenu.java index 8c13777..ade38ff 100644 --- a/oeffi/src/de/schildbach/oeffi/stations/StationContextMenu.java +++ b/oeffi/src/de/schildbach/oeffi/stations/StationContextMenu.java @@ -64,7 +64,7 @@ public class StationContextMenu extends PopupMenu { menu.findItem(R.id.station_context_add_ignore).setVisible(showIgnore && !isIgnored); menu.findItem(R.id.station_context_remove_ignore).setVisible(showIgnore && isIgnored); final MenuItem mapItem = menu.findItem(R.id.station_context_map); - if (showMap && station.hasLocation()) + if (showMap && station.hasCoord()) prepareMapMenu(context, mapItem.getSubMenu(), network, station); else mapItem.setVisible(false); @@ -96,9 +96,11 @@ public class StationContextMenu extends PopupMenu { if (location.type == LocationType.STATION && (networkId != NetworkId.BVG || Integer.parseInt(location.id) >= 1000000)) shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_ID, location.id); - if (location.hasLocation()) { - shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_LAT, location.lat); - shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_LON, location.lon); + if (location.hasCoord()) { + shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_LAT, + location.getLatAs1E6()); + shortcutIntent.putExtra(DirectionsShortcutActivity.INTENT_EXTRA_LON, + location.getLonAs1E6()); } ShortcutManagerCompat.requestPinShortcut(context, @@ -132,7 +134,7 @@ public class StationContextMenu extends PopupMenu { name != null ? '(' + URLEncoder.encode(name.replaceAll("[()]", "")) + ')' : ""))); googleMapsIntent.setComponent( new ComponentName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity")); - googleMapsItem.setVisible(location.hasLocation() && pm.resolveActivity(googleMapsIntent, 0) != null); + googleMapsItem.setVisible(location.hasCoord() && pm.resolveActivity(googleMapsIntent, 0) != null); googleMapsItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(final MenuItem item) { context.startActivity(googleMapsIntent); @@ -146,7 +148,7 @@ public class StationContextMenu extends PopupMenu { name != null ? '(' + URLEncoder.encode(name.replaceAll("[()]", "")) + ')' : ""))); amazonMapsIntent.setComponent( new ComponentName("com.amazon.geo.client.maps", "com.amazon.geo.client.renderer.MapsAppActivityDuke")); - amazonMapsItem.setVisible(location.hasLocation() && pm.resolveActivity(amazonMapsIntent, 0) != null); + amazonMapsItem.setVisible(location.hasCoord() && pm.resolveActivity(amazonMapsIntent, 0) != null); amazonMapsItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(final MenuItem item) { context.startActivity(amazonMapsIntent); @@ -158,7 +160,7 @@ public class StationContextMenu extends PopupMenu { final Intent openStreetMapsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(Locale.ENGLISH, "osmand.geo:%.6f,%.6f?q=%.6f,%.6f%s", lat, lon, lat, lon, name != null ? '(' + URLEncoder.encode(name.replaceAll("[()]", "")) + ')' : ""))); - openStreetMapsItem.setVisible(location.hasLocation() && pm.resolveActivity(openStreetMapsIntent, 0) != null); + openStreetMapsItem.setVisible(location.hasCoord() && pm.resolveActivity(openStreetMapsIntent, 0) != null); openStreetMapsItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(final MenuItem item) { context.startActivity(openStreetMapsIntent); @@ -171,8 +173,7 @@ public class StationContextMenu extends PopupMenu { Uri.parse(String.format(Locale.ENGLISH, "google.streetview:cbll=%.6f,%.6f", lat, lon))); googleStreetViewIntent .setComponent(new ComponentName("com.google.android.street", "com.google.android.street.Street")); - googleStreetViewItem - .setVisible(location.hasLocation() && pm.resolveActivity(googleStreetViewIntent, 0) != null); + googleStreetViewItem.setVisible(location.hasCoord() && pm.resolveActivity(googleStreetViewIntent, 0) != null); googleStreetViewItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(final MenuItem item) { context.startActivity(googleStreetViewIntent); @@ -186,8 +187,7 @@ public class StationContextMenu extends PopupMenu { name != null ? URLEncoder.encode(name) : ""))); googleNavigationIntent.setComponent(new ComponentName("com.google.android.apps.maps", "com.google.android.maps.driveabout.app.NavigationActivity")); - googleNavigationItem - .setVisible(location.hasLocation() && pm.resolveActivity(googleNavigationIntent, 0) != null); + googleNavigationItem.setVisible(location.hasCoord() && pm.resolveActivity(googleNavigationIntent, 0) != null); googleNavigationItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(final MenuItem item) { context.startActivity(googleNavigationIntent); diff --git a/oeffi/src/de/schildbach/oeffi/stations/StationDetailsActivity.java b/oeffi/src/de/schildbach/oeffi/stations/StationDetailsActivity.java index e6ebf1a..9c8facc 100644 --- a/oeffi/src/de/schildbach/oeffi/stations/StationDetailsActivity.java +++ b/oeffi/src/de/schildbach/oeffi/stations/StationDetailsActivity.java @@ -57,6 +57,7 @@ import de.schildbach.pte.dto.Line; import de.schildbach.pte.dto.LineDestination; import de.schildbach.pte.dto.Location; import de.schildbach.pte.dto.LocationType; +import de.schildbach.pte.dto.Point; import de.schildbach.pte.dto.Product; import de.schildbach.pte.dto.QueryDeparturesResult; import de.schildbach.pte.dto.StationDepartures; @@ -410,7 +411,7 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa .getColumnIndexOrThrow(NetworkContentProvider.KEY_LINES); location = new Location(LocationType.STATION, location.id, - cursor.getInt(latCol), cursor.getInt(lonCol), + Point.from1E6(cursor.getInt(latCol), cursor.getInt(lonCol)), placeCol != -1 ? cursor.getString(placeCol) : selectedStation.place, cursor.getString(nameCol)); @@ -520,8 +521,8 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa final int lonCol = stationCursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LON); final int linesCol = stationCursor.getColumnIndexOrThrow(NetworkContentProvider.KEY_LINES); - selectedStation = new Location(LocationType.STATION, selectedStation.id, stationCursor.getInt(latCol), - stationCursor.getInt(lonCol), + selectedStation = new Location(LocationType.STATION, selectedStation.id, + Point.from1E6(stationCursor.getInt(latCol), stationCursor.getInt(lonCol)), placeCol != -1 ? stationCursor.getString(placeCol) : selectedStation.place, stationCursor.getString(nameCol)); @@ -551,7 +552,7 @@ public class StationDetailsActivity extends OeffiActivity implements StationsAwa selectedFavState = FavoriteStationsProvider.favState(getContentResolver(), selectedNetwork, selectedStation); - if (selectedStation.hasLocation()) + if (selectedStation.hasCoord()) mapView.getController() .animateTo(new GeoPoint(selectedStation.getLatAsDouble(), selectedStation.getLonAsDouble())); diff --git a/oeffi/src/de/schildbach/oeffi/stations/StationsActivity.java b/oeffi/src/de/schildbach/oeffi/stations/StationsActivity.java index 0a141f1..7a179ff 100644 --- a/oeffi/src/de/schildbach/oeffi/stations/StationsActivity.java +++ b/oeffi/src/de/schildbach/oeffi/stations/StationsActivity.java @@ -612,7 +612,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware if (favState == null || favState != FavoriteStationsProvider.TYPE_FAVORITE) { i.remove(); stationsMap.remove(station.location.id); - } else if (station.location.hasLocation()) { + } else if (station.location.hasCoord()) { android.location.Location.distanceBetween(deviceLocation.getLatAsDouble(), deviceLocation.getLonAsDouble(), station.location.getLatAsDouble(), station.location.getLonAsDouble(), distanceBetweenResults); @@ -839,8 +839,8 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware final Builder uriBuilder = NetworkContentProvider.CONTENT_URI.buildUpon(); uriBuilder.appendPath(network.name()); - uriBuilder.appendQueryParameter("lat", Integer.toString(referenceLocation.lat)); - uriBuilder.appendQueryParameter("lon", Integer.toString(referenceLocation.lon)); + uriBuilder.appendQueryParameter("lat", Integer.toString(referenceLocation.getLatAs1E6())); + uriBuilder.appendQueryParameter("lon", Integer.toString(referenceLocation.getLonAs1E6())); uriBuilder.appendQueryParameter("ids", favoriteIds.toString()); final Cursor cursor = getContentResolver().query(uriBuilder.build(), null, null, null, null); @@ -877,7 +877,8 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware : cursor.getString(nativeIdColumnIndex); final String place = placeColumnIndex != -1 ? cursor.getString(placeColumnIndex) : null; final String name = cursor.getString(nameColumnIndex); - final Point p = new Point(cursor.getInt(latColumnIndex), cursor.getInt(lonColumnIndex)); + final Point p = Point.from1E6(cursor.getInt(latColumnIndex), + cursor.getInt(lonColumnIndex)); final Station station = new Station(network, new de.schildbach.pte.dto.Location(LocationType.STATION, id, p, place, name), lineDestinations); @@ -923,7 +924,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware if (favType == FavoriteStationsProvider.TYPE_FAVORITE) { final Station station = new Station(network, location, null); - if (deviceLocation != null && location.hasLocation()) { + if (deviceLocation != null && location.hasCoord()) { android.location.Location.distanceBetween(deviceLocation.getLatAsDouble(), deviceLocation.getLonAsDouble(), location.getLatAsDouble(), location.getLonAsDouble(), distanceBetweenResults); @@ -950,7 +951,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware final float[] distanceBetweenResults = new float[2]; for (final Station freshStation : freshStations) { - if (freshStation.location.hasLocation()) { + if (freshStation.location.hasCoord()) { android.location.Location.distanceBetween(referenceLat, referenceLon, freshStation.location.getLatAsDouble(), freshStation.location.getLonAsDouble(), distanceBetweenResults); @@ -1316,7 +1317,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware } // scroll map - if (station != null && station.location.hasLocation()) + if (station != null && station.location.hasCoord()) mapView.zoomToStations(Arrays.asList(station)); else if (!stations.isEmpty()) mapView.zoomToStations(stations); @@ -1494,7 +1495,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware final float[] distanceBetweenResults = new float[2]; for (final Station station : stations) { - if (station.location.hasLocation()) { + if (station.location.hasCoord()) { android.location.Location.distanceBetween(hereLat, hereLon, station.location.getLatAsDouble(), station.location.getLonAsDouble(), distanceBetweenResults); station.setDistanceAndBearing(distanceBetweenResults[0], distanceBetweenResults[1]); @@ -1616,6 +1617,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware || mQuery.reset(name).find()) { final int lat = cursor.getInt(latColumnIndex); final int lon = cursor.getInt(lonColumnIndex); + final Point coord = Point.from1E6(lat, lon); final List lineDestinations = new LinkedList<>(); for (final String lineStr : cursor.getString(linesColumnIndex).split(",")) { if (!lineStr.isEmpty()) { @@ -1626,7 +1628,7 @@ public class StationsActivity extends OeffiMainActivity implements StationsAware .add(new LineDestination(new Line(null, null, product, label, style), null)); } } - final Location location = new Location(LocationType.STATION, id, lat, lon, place, name); + final Location location = new Location(LocationType.STATION, id, coord, place, name); stations.add(new Station(network, location, lineDestinations)); } } diff --git a/oeffi/src/de/schildbach/oeffi/util/LocationUriParser.java b/oeffi/src/de/schildbach/oeffi/util/LocationUriParser.java index eeca4a6..ffb1210 100644 --- a/oeffi/src/de/schildbach/oeffi/util/LocationUriParser.java +++ b/oeffi/src/de/schildbach/oeffi/util/LocationUriParser.java @@ -118,7 +118,7 @@ public class LocationUriParser { final Point coord; if (m.matches()) { final Point c = Point.fromDouble(Double.parseDouble(m.group(1)), Double.parseDouble(m.group(2))); - if (c.lat != 0 || c.lon != 0) + if (c.getLatAs1E6() != 0 || c.getLonAs1E6() != 0) coord = c; else coord = null; diff --git a/oeffi/test/de/schildbach/oeffi/util/LocationUriParserTest.java b/oeffi/test/de/schildbach/oeffi/util/LocationUriParserTest.java index 6c9ce39..4639c6f 100644 --- a/oeffi/test/de/schildbach/oeffi/util/LocationUriParserTest.java +++ b/oeffi/test/de/schildbach/oeffi/util/LocationUriParserTest.java @@ -34,13 +34,13 @@ public class LocationUriParserTest { final Location toLocation = results[1]; Assert.assertEquals(LocationType.ADDRESS, fromLocation.type); - Assert.assertEquals(9905079, fromLocation.lon); - Assert.assertEquals(53587885, fromLocation.lat); + Assert.assertEquals(9905079, fromLocation.getLonAs1E6()); + Assert.assertEquals(53587885, fromLocation.getLatAs1E6()); Assert.assertNull(fromLocation.name); Assert.assertEquals(LocationType.ADDRESS, toLocation.type); - Assert.assertEquals(9719720, toLocation.lon); - Assert.assertEquals(52368950, toLocation.lat); + Assert.assertEquals(9719720, toLocation.getLonAs1E6()); + Assert.assertEquals(52368950, toLocation.getLatAs1E6()); Assert.assertEquals("home", toLocation.name); } @@ -54,13 +54,13 @@ public class LocationUriParserTest { final Location toLocation = results[1]; Assert.assertEquals(LocationType.COORD, fromLocation.type); - Assert.assertEquals(13426309, fromLocation.lon); - Assert.assertEquals(52536088, fromLocation.lat); + Assert.assertEquals(13426309, fromLocation.getLonAs1E6()); + Assert.assertEquals(52536088, fromLocation.getLatAs1E6()); Assert.assertNull(fromLocation.name); Assert.assertEquals(LocationType.ADDRESS, toLocation.type); - Assert.assertEquals(13374129, toLocation.lon); - Assert.assertEquals(52525681, toLocation.lat); + Assert.assertEquals(13374129, toLocation.getLonAs1E6()); + Assert.assertEquals(52525681, toLocation.getLatAs1E6()); Assert.assertEquals("Work", toLocation.name); } @@ -74,13 +74,13 @@ public class LocationUriParserTest { final Location toLocation = results[1]; Assert.assertEquals(LocationType.COORD, fromLocation.type); - Assert.assertEquals(13344510, fromLocation.lon); - Assert.assertEquals(52547400, fromLocation.lat); + Assert.assertEquals(13344510, fromLocation.getLonAs1E6()); + Assert.assertEquals(52547400, fromLocation.getLatAs1E6()); Assert.assertNull(fromLocation.name); Assert.assertEquals(LocationType.COORD, toLocation.type); - Assert.assertEquals(13353884, toLocation.lon); - Assert.assertEquals(52505719, toLocation.lat); + Assert.assertEquals(13353884, toLocation.getLonAs1E6()); + Assert.assertEquals(52505719, toLocation.getLatAs1E6()); Assert.assertNull(toLocation.name); } @@ -95,8 +95,8 @@ public class LocationUriParserTest { final Location location = results[0]; Assert.assertEquals(LocationType.ADDRESS, location.type); - Assert.assertEquals(13413215, location.lon); - Assert.assertEquals(52521918, location.lat); + Assert.assertEquals(13413215, location.getLonAs1E6()); + Assert.assertEquals(52521918, location.getLatAs1E6()); Assert.assertEquals("Alexanderplatz, 10178 Berlin", location.name); } @@ -109,8 +109,8 @@ public class LocationUriParserTest { final Location location = results[0]; Assert.assertEquals(LocationType.ADDRESS, location.type); - Assert.assertEquals(13420671, location.lon); - Assert.assertEquals(52512845, location.lat); + Assert.assertEquals(13420671, location.getLonAs1E6()); + Assert.assertEquals(52512845, location.getLatAs1E6()); Assert.assertEquals("c-base", location.name); } @@ -123,8 +123,8 @@ public class LocationUriParserTest { final Location location = results[0]; Assert.assertEquals(LocationType.ADDRESS, location.type); - Assert.assertEquals(9634707, location.lon); - Assert.assertEquals(47460045, location.lat); + Assert.assertEquals(9634707, location.getLonAs1E6()); + Assert.assertEquals(47460045, location.getLatAs1E6()); Assert.assertEquals("Work", location.name); } @@ -136,8 +136,8 @@ public class LocationUriParserTest { final Location location = results[0]; Assert.assertEquals(LocationType.ANY, location.type); - Assert.assertEquals(0, location.lon); - Assert.assertEquals(0, location.lat); + Assert.assertEquals(0, location.getLonAs1E6()); + Assert.assertEquals(0, location.getLatAs1E6()); Assert.assertEquals("gleimstr.", location.name); } @@ -150,8 +150,8 @@ public class LocationUriParserTest { final Location location = results[0]; Assert.assertEquals(LocationType.ADDRESS, location.type); - Assert.assertEquals(13401525, location.lon); - Assert.assertEquals(52535836, location.lat); + Assert.assertEquals(13401525, location.getLonAs1E6()); + Assert.assertEquals(52535836, location.getLatAs1E6()); Assert.assertEquals("Zionskirchstraße 7, 10119 Berlin, Germany", location.name); } @@ -164,8 +164,8 @@ public class LocationUriParserTest { final Location location = results[0]; Assert.assertEquals(LocationType.ADDRESS, location.type); - Assert.assertEquals(13420106, location.lon); - Assert.assertEquals(52513064, location.lat); + Assert.assertEquals(13420106, location.getLonAs1E6()); + Assert.assertEquals(52513064, location.getLatAs1E6()); Assert.assertEquals("C-Base, Rungestraße, Berlin, Germany", location.name); } @@ -177,8 +177,8 @@ public class LocationUriParserTest { final Location location = results[0]; Assert.assertEquals(LocationType.ANY, location.type); - Assert.assertEquals(0, location.lat); - Assert.assertEquals(0, location.lon); + Assert.assertEquals(0, location.getLatAs1E6()); + Assert.assertEquals(0, location.getLonAs1E6()); Assert.assertEquals("Karl-Marx-Allee 84, Berlin", location.name); } @@ -190,8 +190,8 @@ public class LocationUriParserTest { final Location locationNewline = resultsNewline[0]; Assert.assertEquals(LocationType.ANY, locationNewline.type); - Assert.assertEquals(0, locationNewline.lat); - Assert.assertEquals(0, locationNewline.lon); + Assert.assertEquals(0, locationNewline.getLatAs1E6()); + Assert.assertEquals(0, locationNewline.getLonAs1E6()); Assert.assertEquals("Karl-Marx-Allee 84, Berlin", locationNewline.name); final Location[] resultsEncodedNewline = LocationUriParser @@ -201,8 +201,8 @@ public class LocationUriParserTest { final Location locationEncodedNewline = resultsEncodedNewline[0]; Assert.assertEquals(LocationType.ANY, locationEncodedNewline.type); - Assert.assertEquals(0, locationEncodedNewline.lat); - Assert.assertEquals(0, locationEncodedNewline.lon); + Assert.assertEquals(0, locationEncodedNewline.getLatAs1E6()); + Assert.assertEquals(0, locationEncodedNewline.getLonAs1E6()); Assert.assertEquals("Karl-Marx-Allee 84, Berlin", locationEncodedNewline.name); final Location[] resultsComma = LocationUriParser.parseLocations("geo:0,0?q=Karl-Marx-Allee+84,%0aBerlin"); @@ -211,8 +211,8 @@ public class LocationUriParserTest { final Location locationComma = resultsComma[0]; Assert.assertEquals(LocationType.ANY, locationComma.type); - Assert.assertEquals(0, locationComma.lat); - Assert.assertEquals(0, locationComma.lon); + Assert.assertEquals(0, locationComma.getLatAs1E6()); + Assert.assertEquals(0, locationComma.getLonAs1E6()); Assert.assertEquals("Karl-Marx-Allee 84, Berlin", locationComma.name); } @@ -224,8 +224,8 @@ public class LocationUriParserTest { final Location location = results[0]; Assert.assertEquals(LocationType.ANY, location.type); - Assert.assertEquals(0, location.lat); - Assert.assertEquals(0, location.lon); + Assert.assertEquals(0, location.getLatAs1E6()); + Assert.assertEquals(0, location.getLonAs1E6()); Assert.assertEquals("Prinzenstraße 85, Berlin", location.name); } @@ -238,8 +238,8 @@ public class LocationUriParserTest { final Location location = results[0]; Assert.assertEquals(LocationType.ADDRESS, location.type); - Assert.assertEquals(52503520, location.lat); - Assert.assertEquals(13409188, location.lon); + Assert.assertEquals(52503520, location.getLatAs1E6()); + Assert.assertEquals(13409188, location.getLonAs1E6()); Assert.assertEquals( "motion*s Tanz- und Bewegungsstudio - Stella Caric GmbH, Prinzenstraße 85, Aufgang B1 - Zugang von der Oranienstraße, 10969 Berlin, Germany", location.name); @@ -253,8 +253,8 @@ public class LocationUriParserTest { final Location location = results[0]; Assert.assertEquals(LocationType.COORD, location.type); - Assert.assertEquals(52133331, location.lat); - Assert.assertEquals(11600000, location.lon); + Assert.assertEquals(52133331, location.getLatAs1E6()); + Assert.assertEquals(11600000, location.getLonAs1E6()); Assert.assertNull(location.name); }