From 63954f5a155accfd49afbe73a815ade977a1cf8a Mon Sep 17 00:00:00 2001 From: oaamaas Date: Sat, 10 Aug 2019 19:53:14 +0200 Subject: [PATCH 1/7] Updated API key Signed-off-by: oaamaas --- Android/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Android/AndroidManifest.xml b/Android/AndroidManifest.xml index f23c6715ce..52ba7e220d 100644 --- a/Android/AndroidManifest.xml +++ b/Android/AndroidManifest.xml @@ -59,7 +59,7 @@ + android:value="AIzaSyDIqKWHqt4rWiIG_QJZXBAQBKHCbmU-lqI"/> From 553388c32dd57f89453d6bed8f10db5fa63daf5e Mon Sep 17 00:00:00 2001 From: oaamaas Date: Sat, 10 Aug 2019 19:57:21 +0200 Subject: [PATCH 2/7] Commented out leakcanary Signed-off-by: oaamaas --- Android/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Android/build.gradle b/Android/build.gradle index 4e99aba0e6..afadb26f90 100644 --- a/Android/build.gradle +++ b/Android/build.gradle @@ -49,10 +49,10 @@ dependencies { //Charts and graph library compile 'com.github.lecho:hellocharts-library:1.5.5@aar' - //Leak canary (https://github.com/square/leakcanary) + /*Leak canary (https://github.com/square/leakcanary) debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2' releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' - testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' + testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' */ } def versionPrefix = "Tower-v" From bc53c36cb9c35fc1b58cd2a76a977003e53aad78 Mon Sep 17 00:00:00 2001 From: oaamaas Date: Sat, 10 Aug 2019 20:01:32 +0200 Subject: [PATCH 3/7] Commented out initLoggingAndAnalytics(); (leakcanary) Signed-off-by: oaamaas --- Android/src/org/droidplanner/android/DroidPlannerApp.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Android/src/org/droidplanner/android/DroidPlannerApp.java b/Android/src/org/droidplanner/android/DroidPlannerApp.java index 368ce5801b..2c74a04acf 100644 --- a/Android/src/org/droidplanner/android/DroidPlannerApp.java +++ b/Android/src/org/droidplanner/android/DroidPlannerApp.java @@ -162,11 +162,12 @@ public void onCreate() { lbm = LocalBroadcastManager.getInstance(context); soundManager = new SoundManager(context); - initLoggingAndAnalytics(); + /*initLoggingAndAnalytics();*/ initDronekit(); initDatabases(); } + /* private void initLoggingAndAnalytics(){ //Init leak canary LeakCanary.install(this); @@ -195,6 +196,7 @@ public void uncaughtException(Thread thread, Throwable ex) { Fabric.with(context, new Crashlytics()); } } + */ private void initDronekit(){ Context context = getApplicationContext(); From 5daf1b5ab2272296df9e8396b31cecb4d853860f Mon Sep 17 00:00:00 2001 From: oaamaas Date: Sat, 10 Aug 2019 20:31:01 +0200 Subject: [PATCH 4/7] Added mapboxUserId: Required for the following Mapbox API in MapboxUtils.java: https://api.mapbox.com/styles/v1/ Signed-off-by: oaamaas --- Android/res/values/strings.xml | 6 +- Android/res/xml/preferences_google_maps.xml | 8 ++ .../android/maps/GoogleMapFragment.java | 6 +- .../google_map/GoogleMapPrefFragment.kt | 75 ++++++++++++++++++- .../tiles/mapbox/MapboxTileProvider.java | 10 ++- .../mapbox/MapboxTileProviderManager.java | 24 +++--- .../tiles/mapbox/OfflineTileProvider.java | 6 +- 7 files changed, 118 insertions(+), 17 deletions(-) diff --git a/Android/res/values/strings.xml b/Android/res/values/strings.xml index 0c6b21fb68..97c8635e3c 100644 --- a/Android/res/values/strings.xml +++ b/Android/res/values/strings.xml @@ -448,9 +448,12 @@ Mapbox Tile Provider Download Offline Map Click to cache map for use while offline + Mapbox UserId + Mapbox user id + Enter your mapbox user id Mapbox Id Mapbox map id - Enter your mapbox map id + Enter your mapbox styled map id Mapbox Access Token Mapbox access token Enter your mapbox access token @@ -461,6 +464,7 @@ Pan and zoom to adjust the map area to save Tap to save the map Map area saved! + Invalid mapbox user id Invalid mapbox id Invalid mapbox access token Invalid mapbox credentials! Please update your mapbox settings. diff --git a/Android/res/xml/preferences_google_maps.xml b/Android/res/xml/preferences_google_maps.xml index 5023de7f01..5e0e3d206f 100644 --- a/Android/res/xml/preferences_google_maps.xml +++ b/Android/res/xml/preferences_google_maps.xml @@ -76,6 +76,14 @@ android:key="pref_download_menu_option" android:title="@string/pref_title_download_menu_option"/> + + { + if (TextUtils.isEmpty(input)) { + Toast.makeText(context, R.string.label_invalid_mapbox_userid, Toast.LENGTH_LONG) + .show() + } else { + //Save the mapbox user id to preferences + updateMapboxUserId(input?.toString() ?: "", true) + + //Check if the mapbox access token is set enable the mapbox tile + // provider + if (isMapboxAccessTokenSet()) { + enableTileProvider(tileProvidersPref, MAPBOX_TILE_PROVIDER, true) + } + else { + //Check if the mapbox access token is set + accessTokenDialog?.show(fragmentManager, + MAPBOX_ACCESS_TOKEN_DIALOG_TAG) + } + } + } + MAPBOX_ID_DIALOG_TAG -> { if (TextUtils.isEmpty(input)) { Toast.makeText(context, R.string.label_invalid_mapbox_id, Toast.LENGTH_LONG) @@ -360,6 +399,23 @@ class GoogleMapPrefFragment : MapProviderPreferences(), EditInputDialog.Listener downloadMenuPref.isChecked = sharedPref.getBoolean(PREF_DOWNLOAD_MENU_OPTION, DEFAULT_DOWNLOAD_MENU_OPTION) } + //Setup mapbox user id + val mapboxUserIdPref = findPreference(PREF_MAPBOX_USERID) + if(mapboxUserIdPref != null) { + val mapboxUserId = sharedPref.getString(PREF_MAPBOX_USERID, null) + mapboxUserId?.let { mapboxUserIdPref.summary = mapboxUserId } + mapboxUserIdPref.setOnPreferenceChangeListener { preference, newValue -> + val newMapboxUserId = newValue.toString() + if(TextUtils.isEmpty(newMapboxUserId)){ + Toast.makeText(context,"invalid_mapbox user id", Toast.LENGTH_LONG) + .show() + } + + updateMapboxUserId(newMapboxUserId, false) + true + } + } + //Setup mapbox map id val mapboxIdPref = findPreference(PREF_MAPBOX_ID) if(mapboxIdPref != null) { @@ -402,6 +458,23 @@ class GoogleMapPrefFragment : MapProviderPreferences(), EditInputDialog.Listener } } + private fun updateMapboxUserId(id: String, persist: Boolean){ + val mapboxUserIdPref = findPreference(PREF_MAPBOX_USERID) + mapboxUserIdPref?.let { + val summary = if (TextUtils.isEmpty(id)) { + enableTileProvider(GOOGLE_TILE_PROVIDER, true) + getString(R.string.pref_hint_mapbox_Userid) + } else { + id + } + + mapboxUserIdPref.summary = summary + } + + if(persist) + setMapboxUserId(getContext(), id) + } + private fun updateMapboxId(id: String, persist: Boolean){ val mapboxIdPref = findPreference(PREF_MAPBOX_ID) mapboxIdPref?.let { diff --git a/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxTileProvider.java b/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxTileProvider.java index 2eeaf0c61e..3d13fe1368 100644 --- a/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxTileProvider.java +++ b/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxTileProvider.java @@ -14,12 +14,14 @@ public class MapboxTileProvider extends UrlTileProvider { private final static String TAG = MapboxTileProvider.class.getSimpleName(); + private final String mapboxUserId; private final String mapboxId; private final String mapboxAccessToken; private final int maxZoomLevel; - public MapboxTileProvider(String mapboxId, String mapboxAccessToken, int maxZoomLevel) { + public MapboxTileProvider(String mapboxUserId, String mapboxId, String mapboxAccessToken, int maxZoomLevel) { super(MapboxUtils.TILE_WIDTH, MapboxUtils.TILE_HEIGHT); + this.mapboxUserId = mapboxUserId; this.mapboxId = mapboxId; this.mapboxAccessToken = mapboxAccessToken; this.maxZoomLevel = maxZoomLevel; @@ -28,7 +30,7 @@ public MapboxTileProvider(String mapboxId, String mapboxAccessToken, int maxZoom @Override public URL getTileUrl(int x, int y, int zoom) { if (zoom <= maxZoomLevel) { - final String tileUrl = MapboxUtils.getMapTileURL(mapboxId, mapboxAccessToken, zoom, x, y); + final String tileUrl = MapboxUtils.getMapTileURL(mapboxUserId, mapboxId, mapboxAccessToken, zoom, x, y); try { return new URL(tileUrl); } catch (MalformedURLException e) { @@ -45,4 +47,8 @@ public String getMapboxAccessToken() { public String getMapboxId() { return mapboxId; } + + public String getMapboxUserId() { + return mapboxUserId; + } } diff --git a/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxTileProviderManager.java b/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxTileProviderManager.java index a0e3dd245f..45aa6735af 100644 --- a/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxTileProviderManager.java +++ b/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxTileProviderManager.java @@ -37,18 +37,24 @@ public class MapboxTileProviderManager extends TileProviderManager { private final Handler handler = new Handler(); private final Context context; + private final String mapboxUserId; private final String mapboxId; private final String mapboxAccessToken; - public MapboxTileProviderManager(Context context, String mapboxId, String mapboxAccessToken, int maxZoomLevel) { - super(new MapboxTileProvider(mapboxId, mapboxAccessToken, maxZoomLevel), - new OfflineTileProvider(context, mapboxId, mapboxAccessToken, maxZoomLevel)); + public MapboxTileProviderManager(Context context, String mapboxUserId, String mapboxId, String mapboxAccessToken, int maxZoomLevel) { + super(new MapboxTileProvider(mapboxUserId, mapboxId, mapboxAccessToken, maxZoomLevel), + new OfflineTileProvider(context, mapboxUserId, mapboxId, mapboxAccessToken, maxZoomLevel)); this.context = context; + this.mapboxUserId = mapboxUserId; this.mapboxId = mapboxId; this.mapboxAccessToken = mapboxAccessToken; } + public String getMapboxUserId() { + return mapboxUserId; + } + public String getMapboxAccessToken() { return mapboxAccessToken; } @@ -60,15 +66,15 @@ public String getMapboxId() { @Override public void downloadMapTiles(MapDownloader mapDownloader, DPMap.VisibleMapArea mapRegion, int minimumZ, int maximumZ) { - beginDownloadingMapID(mapDownloader, this.mapboxId, this.mapboxAccessToken, mapRegion, minimumZ, maximumZ); + beginDownloadingMapID(mapDownloader, this.mapboxUserId, this.mapboxId, this.mapboxAccessToken, mapRegion, minimumZ, maximumZ); } - private void beginDownloadingMapID(final MapDownloader mapDownloader, final String mapId, final String accessToken, DPMap.VisibleMapArea mapRegion, int + private void beginDownloadingMapID(final MapDownloader mapDownloader, final String userId, final String mapId, final String accessToken, DPMap.VisibleMapArea mapRegion, int minimumZ, int maximumZ) { - beginDownloadingMapID(mapDownloader, mapId, accessToken, mapRegion, minimumZ, maximumZ, true, true); + beginDownloadingMapID(mapDownloader, userId, mapId, accessToken, mapRegion, minimumZ, maximumZ, true, true); } - private void beginDownloadingMapID(final MapDownloader mapDownloader, final String mapId, final String accessToken, DPMap.VisibleMapArea mapRegion, int + private void beginDownloadingMapID(final MapDownloader mapDownloader, final String userId, final String mapId, final String accessToken, DPMap.VisibleMapArea mapRegion, int minimumZ, int maximumZ, boolean includeMetadata, boolean includeMarkers) { @@ -76,11 +82,11 @@ private void beginDownloadingMapID(final MapDownloader mapDownloader, final Stri String dataName = "features.json"; // Only using API V4 for now // Include URLs for the metadata and markers json if applicable - if (includeMetadata) { + if (false) { urls.add(String.format(Locale.US, MapboxUtils.MAPBOX_BASE_URL_V4 + "%s.json?secure&access_token=%s", mapId, accessToken)); } - if (includeMarkers) { + if (false) { urls.add(String.format(Locale.US, MapboxUtils.MAPBOX_BASE_URL_V4 + "%s/%s?access_token=%s", mapId, dataName, accessToken)); } diff --git a/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/OfflineTileProvider.java b/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/OfflineTileProvider.java index 31e9ed4ca2..abb9e304a2 100644 --- a/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/OfflineTileProvider.java +++ b/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/OfflineTileProvider.java @@ -15,12 +15,14 @@ public class OfflineTileProvider implements TileProvider { private static final String TAG = OfflineTileProvider.class.getSimpleName(); private final Context context; + private final String mapboxUserId; private final String mapboxId; private final String mapboxAccessToken; private final int maxZoomLevel; - public OfflineTileProvider(Context context, String mapboxId, String mapboxAccessToken, int maxZoomLevel) { + public OfflineTileProvider(Context context, String mapboxUserId, String mapboxId, String mapboxAccessToken, int maxZoomLevel) { this.context = context; + this.mapboxUserId = mapboxUserId; this.mapboxId = mapboxId; this.mapboxAccessToken = mapboxAccessToken; this.maxZoomLevel = maxZoomLevel; @@ -32,7 +34,7 @@ public Tile getTile(int x, int y, int zoom) { return TileProvider.NO_TILE; } - final String tileUri = MapboxUtils.getMapTileURL(mapboxId, mapboxAccessToken, zoom, x, y); + final String tileUri = MapboxUtils.getMapTileURL(mapboxUserId, mapboxId, mapboxAccessToken, zoom, x, y); byte[] data = DatabaseState.getOfflineDatabaseHandlerForMapId(context, mapboxId).dataForURL(tileUri); if (data == null || data.length == 0) return TileProvider.NO_TILE; From 9963cdae7d1d1c8fe04ab637099af441dd68ed33 Mon Sep 17 00:00:00 2001 From: oaamaas Date: Sat, 10 Aug 2019 20:45:07 +0200 Subject: [PATCH 5/7] Introducing the following Mapbox API, replaces the original: https://api.mapbox.com/styles/v1/ Original API was depending in the phased out approach with Mapbox projects, and the use of the retured Mapbox Classic app. The API introduced utilizes the current Mapbox Studio's abilities to create styles, and to modify these styles with tilesets and other customizations The API requires: - The Mapbox Account name: As introduced in multiple file as mapboxUserId - The Style ID: Re-used the mapId for this purpose since the old API is phased out anyway - The Mapbox token, already present in previous versions of Tower Solution fully working, but has a flaw when user selects "flight data screen" (no flaw in screens for editor and history: - Tower loads normal maps from Google, but does not overlay the styled tiles - Workaround: Change orientation of device, and the styled tiles are overlaid The flaw is caused by logic in DroneMap.java, the following IF concludes wether or not tiles should be overlaid: if (mMapFragment == null || mMapFragment.getProvider() != mapProvider) (line 294) Should be corrected, but Mapbox in Tower is now fully functional with the workaround. Signed-off-by: oaamaas --- .../maps/providers/google_map/tiles/mapbox/MapboxUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxUtils.java b/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxUtils.java index cbe2d7d192..e05a3102c7 100644 --- a/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxUtils.java +++ b/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxUtils.java @@ -25,9 +25,9 @@ private MapboxUtils(){} public static final String MAPBOX_BASE_URL_V4 = "https://a.tiles.mapbox.com/v4/"; - public static String getMapTileURL(String mapID, String accessToken, int zoom, int x, int y) { - return String.format(Locale.US, "https://a.tiles.mapbox.com/v4/%s/%d/%d/%d%s.%s?access_token=%s", - mapID, zoom, x, y, "@2x", "png", accessToken); + public static String getMapTileURL(String userId, String mapID, String accessToken, int zoom, int x, int y) { + return String.format(Locale.US, "https://api.mapbox.com/styles/v1/%s/%s/tiles/%d/%d/%d%s?access_token=%s", + userId, mapID, zoom, x, y, "@2x", accessToken); } public static int fetchReferenceTileUrl(Context context, String mapId, String accessToken){ From 63e78ab80c80027e4e432ad26bda19b50432b3ec Mon Sep 17 00:00:00 2001 From: oaamaas Date: Sat, 10 Aug 2019 20:56:13 +0200 Subject: [PATCH 6/7] Introduced mapboxUserId to support API Removed import of disabled leakcanary in DroidPlannerApp Signed-off-by: oaamaas --- Android/src/org/droidplanner/android/DroidPlannerApp.java | 1 - .../google_map/tiles/mapbox/MapboxTileProviderManager.java | 2 +- .../maps/providers/google_map/tiles/mapbox/MapboxUtils.java | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Android/src/org/droidplanner/android/DroidPlannerApp.java b/Android/src/org/droidplanner/android/DroidPlannerApp.java index 2c74a04acf..e64e7e523d 100644 --- a/Android/src/org/droidplanner/android/DroidPlannerApp.java +++ b/Android/src/org/droidplanner/android/DroidPlannerApp.java @@ -26,7 +26,6 @@ import com.o3dr.services.android.lib.drone.connection.ConnectionType; import com.o3dr.services.android.lib.gcs.link.LinkConnectionStatus; import com.o3dr.services.android.lib.model.AbstractCommandListener; -import com.squareup.leakcanary.LeakCanary; import org.droidplanner.android.activities.helpers.BluetoothDevicesActivity; import org.droidplanner.android.droneshare.UploaderService; diff --git a/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxTileProviderManager.java b/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxTileProviderManager.java index 45aa6735af..be3950ee3e 100644 --- a/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxTileProviderManager.java +++ b/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxTileProviderManager.java @@ -123,7 +123,7 @@ private void beginDownloadingMapID(final MapDownloader mapDownloader, final Stri maxY = Double.valueOf(Math.floor((1.0 - (Math.log(Math.tan(minLat * Math.PI / 180.0) + 1.0 / Math.cos(minLat * Math.PI / 180.0)) / Math.PI)) / 2.0 * tilesPerSide)).intValue(); for (int x = minX; x <= maxX; x++) { for (int y = minY; y <= maxY; y++) { - urls.add(MapboxUtils.getMapTileURL(mapId, accessToken, zoom, x, y)); + urls.add(MapboxUtils.getMapTileURL(userId, mapId, accessToken, zoom, x, y)); } } } diff --git a/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxUtils.java b/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxUtils.java index e05a3102c7..3459930d4d 100644 --- a/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxUtils.java +++ b/Android/src/org/droidplanner/android/maps/providers/google_map/tiles/mapbox/MapboxUtils.java @@ -30,13 +30,13 @@ public static String getMapTileURL(String userId, String mapID, String accessTok userId, mapID, zoom, x, y, "@2x", accessToken); } - public static int fetchReferenceTileUrl(Context context, String mapId, String accessToken){ + public static int fetchReferenceTileUrl(Context context, String userId, String mapId, String accessToken){ if(!NetworkUtils.isNetworkAvailable(context)){ Timber.d("Network is not available. Aborting reference tile fetching."); return -1; } - final String referenceUrl = getMapTileURL(mapId, accessToken, 0, 0, 0); + final String referenceUrl = getMapTileURL(userId, mapId, accessToken, 0, 0, 0); HttpURLConnection conn = null; try{ From 30df490556440ff76ffff2a8c6e4be6bd6421c6c Mon Sep 17 00:00:00 2001 From: OlavAa <46791541+OlavAa@users.noreply.github.com> Date: Sun, 11 Aug 2019 01:52:36 +0200 Subject: [PATCH 7/7] Update AndroidManifest.xml --- Android/AndroidManifest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Android/AndroidManifest.xml b/Android/AndroidManifest.xml index 52ba7e220d..64ac741a0f 100644 --- a/Android/AndroidManifest.xml +++ b/Android/AndroidManifest.xml @@ -59,7 +59,7 @@ + android:value="AddYourOwnKeyFromGoogleCloudPlatformHere"/> @@ -173,4 +173,4 @@ - \ No newline at end of file +