From e1af67fd7862b5f0645ac79e55b47f5623ad98a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20FERREIRA=20DE=20SOUSA?= Date: Sun, 29 Nov 2020 18:08:56 +0100 Subject: [PATCH] Update osmdroid to v6.1.8 This commit aims to get Mapnik working for newer Android versions, which is done by upgrading osmdroid to latest. This update implies some porting work : - use Double instead of int argument when calling setMinZoomLevel. - enhance osmdroid configuration : call 'load' to ensure config (github.com/osmdroid/osmdroid/wiki/How-to-use-the-osmdroid-library) and customize user-agent to access tiles following recommendations (github.com/osmdroid/osmdroid/wiki/Important-notes-on-using-osmdroid- in-your-app#set-the-http-user-agent-variable). - replace the discarded OpenCycleMap tile source by HikeBikeMap. --- app/build.gradle | 2 +- .../openbikesharing/app/activities/MapActivity.java | 10 ++++++++-- .../app/activities/StationActivity.java | 9 ++++++++- app/src/main/res/values/strings.xml | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ffc81cf..4ef6f59 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,7 +48,7 @@ android { } dependencies { - compile 'org.osmdroid:osmdroid-android:5.6.4' + compile 'org.osmdroid:osmdroid-android:6.1.8' compile 'com.github.MKergall:osmbonuspack:6.3' compile 'com.android.support:support-v4:23.0.1' } diff --git a/app/src/main/java/be/brunoparmentier/openbikesharing/app/activities/MapActivity.java b/app/src/main/java/be/brunoparmentier/openbikesharing/app/activities/MapActivity.java index 13a7fe7..da90d49 100644 --- a/app/src/main/java/be/brunoparmentier/openbikesharing/app/activities/MapActivity.java +++ b/app/src/main/java/be/brunoparmentier/openbikesharing/app/activities/MapActivity.java @@ -39,6 +39,7 @@ import org.osmdroid.api.IMapController; import org.osmdroid.bonuspack.clustering.GridMarkerClusterer; +import org.osmdroid.config.Configuration; import org.osmdroid.events.MapEventsReceiver; import org.osmdroid.tileprovider.tilesource.TileSourceFactory; import org.osmdroid.util.GeoPoint; @@ -53,6 +54,7 @@ import java.util.ArrayList; import be.brunoparmentier.openbikesharing.app.R; +import be.brunoparmentier.openbikesharing.app.BuildConfig; import be.brunoparmentier.openbikesharing.app.db.StationsDataSource; import be.brunoparmentier.openbikesharing.app.models.Station; import be.brunoparmentier.openbikesharing.app.models.StationStatus; @@ -96,6 +98,10 @@ protected void onCreate(Bundle savedInstanceState) { stationsDataSource = new StationsDataSource(this); ArrayList stations = stationsDataSource.getStations(); + final Context context = getApplicationContext(); + Configuration.getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context)); + Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID); + map = (MapView) findViewById(R.id.mapView); stationMarkerInfoWindow = new StationMarkerInfoWindow(R.layout.bonuspack_bubble, map); @@ -118,7 +124,7 @@ protected void onCreate(Bundle savedInstanceState) { map.setMultiTouchControls(true); map.setBuiltInZoomControls(true); - map.setMinZoomLevel(3); + map.setMinZoomLevel(Double.valueOf(3)); /* map tile source */ String mapLayer = settings.getString(PREF_KEY_MAP_LAYER, ""); @@ -127,7 +133,7 @@ protected void onCreate(Bundle savedInstanceState) { map.setTileSource(TileSourceFactory.MAPNIK); break; case MAP_LAYER_CYCLEMAP: - map.setTileSource(TileSourceFactory.CYCLEMAP); + map.setTileSource(TileSourceFactory.HIKEBIKEMAP); break; case MAP_LAYER_OSMPUBLICTRANSPORT: map.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT); diff --git a/app/src/main/java/be/brunoparmentier/openbikesharing/app/activities/StationActivity.java b/app/src/main/java/be/brunoparmentier/openbikesharing/app/activities/StationActivity.java index 65c35a8..6225427 100644 --- a/app/src/main/java/be/brunoparmentier/openbikesharing/app/activities/StationActivity.java +++ b/app/src/main/java/be/brunoparmentier/openbikesharing/app/activities/StationActivity.java @@ -19,6 +19,7 @@ import android.app.Activity; import android.appwidget.AppWidgetManager; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; @@ -36,6 +37,7 @@ import android.widget.Toast; import org.osmdroid.api.IMapController; +import org.osmdroid.config.Configuration; import org.osmdroid.tileprovider.tilesource.TileSourceFactory; import org.osmdroid.util.GeoPoint; import org.osmdroid.views.MapView; @@ -48,6 +50,7 @@ import java.util.TimeZone; import be.brunoparmentier.openbikesharing.app.R; +import be.brunoparmentier.openbikesharing.app.BuildConfig; import be.brunoparmentier.openbikesharing.app.db.StationsDataSource; import be.brunoparmentier.openbikesharing.app.models.Station; import be.brunoparmentier.openbikesharing.app.models.StationStatus; @@ -79,6 +82,10 @@ protected void onCreate(Bundle savedInstanceState) { station = (Station) getIntent().getSerializableExtra(KEY_STATION); + final Context context = getApplicationContext(); + Configuration.getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context)); + Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID); + map = (MapView) findViewById(R.id.mapView); final GeoPoint stationLocation = new GeoPoint((int) (station.getLatitude() * 1000000), (int) (station.getLongitude() * 1000000)); @@ -93,7 +100,7 @@ protected void onCreate(Bundle savedInstanceState) { map.setTileSource(TileSourceFactory.MAPNIK); break; case MAP_LAYER_CYCLEMAP: - map.setTileSource(TileSourceFactory.CYCLEMAP); + map.setTileSource(TileSourceFactory.HIKEBIKEMAP); break; case MAP_LAYER_OSMPUBLICTRANSPORT: map.setTileSource(TileSourceFactory.PUBLIC_TRANSPORT); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3f86159..0785ad4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -121,7 +121,7 @@ Version Map layer Mapnik - OpenCycleMap + Hike & Bike Map OSMPublicTransport Strip station ID