Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Upgrade osmdroid #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -96,6 +98,10 @@ protected void onCreate(Bundle savedInstanceState) {
stationsDataSource = new StationsDataSource(this);
ArrayList<Station> stations = stationsDataSource.getStations();

final Context context = getApplicationContext();
Configuration.getInstance().load(context, PreferenceManager.getDefaultSharedPreferences(context));
Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we really need the versionCode in the UserAgent + I'd use BuildConfig.APPLICATION_ID which identifies the app, instead of context.getPackageName() (the package name can be different from the application ID).

So I'd replace the whole block with:

Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID)

(as suggested in https://github.com/osmdroid/osmdroid/wiki/Important-notes-on-using-osmdroid-in-your-app#set-the-http-user-agent-variable)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, yeah it's true that the osmdroid does not officially recommend to go as far as this. Actually, as stated in my commit message I relied on the osmdroid github thread that pointed the issue, and more precisely a comment of an OSM sysadmin called Firefishy.
My understanding of the whole bug is that, at some point of the time when there was a single user-agent for every osmdroid client, it has been banned by the OSM Foundation because of overloading problems in which it was involved. Now the new osmdroid requires the customization of the user-agent so OSM could ban only the ending client that overloads its servers. In this context using the APPLICATION_ID would be enough. That said, the recommendation of Firefishy was to use a different user-agent for each app version to prevent the whole package to be banned forever if a specific version behaves badly for some reason.

map = (MapView) findViewById(R.id.mapView);
stationMarkerInfoWindow = new StationMarkerInfoWindow(R.layout.bonuspack_bubble, map);

Expand All @@ -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, "");
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
<string name="pref_title_version">Version</string>
<string name="pref_map_layer_title">Map layer</string>
<string name="pref_map_layer_mapnik" translatable="false">Mapnik</string>
<string name="pref_map_layer_cyclemap" translatable="false">OpenCycleMap</string>
<string name="pref_map_layer_cyclemap" translatable="false">Hike &amp; Bike Map</string>
<string name="pref_map_layer_osmpublictransport" translatable="false">OSMPublicTransport</string>
<string name="pref_title_strip_station_id">Strip station ID</string>
<string name="pref_title_strip_station_id_summary">
Expand Down