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

Commit

Permalink
test / debug downstream mapbox/mapbox-navigation-android#1895 in gl-n…
Browse files Browse the repository at this point in the history
…ative
  • Loading branch information
Guardiola31337 committed Jun 17, 2019
1 parent 304207c commit 0f4a864
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public void onStatusChanged(final OfflineRegionStatus status) {
@Override
public void run() {
if (observer != null) {
System.out.println("DEBUG " + status.getCompletedResourceCount() + "/" + status.getRequiredResourceCount() + " resources; " + status.getCompletedResourceSize() + " bytes downloaded.");
observer.onStatusChanged(status);
}
}
Expand All @@ -281,6 +282,7 @@ public void onError(final OfflineRegionError error) {
@Override
public void run() {
if (observer != null) {
System.out.println("DEBUG onError " + error);
observer.onError(error);
}
}
Expand All @@ -295,6 +297,7 @@ public void mapboxTileCountLimitExceeded(final long limit) {
@Override
public void run() {
if (observer != null) {
System.out.println("DEBUG mapboxTileCountLimitExceeded");
observer.mapboxTileCountLimitExceeded(limit);
}
}
Expand Down
4 changes: 3 additions & 1 deletion platform/android/MapboxGLDownstreamTestApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ android {

dependencies {
api(project(':MapboxGLAndroidSDK'))
implementation("com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.34.0") {
implementation("com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.37.0-20190424.152733-3") {
exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-sdk'
exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-navigation'
}
implementation "com.mapbox.mapboxsdk:mapbox-android-navigation:0.37.0-20190424.152701-3"

// Butter Knife
implementation "com.jakewharton:butterknife:8.8.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mapbox.mapboxsdk.downstream.testapp">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.SharedPreferences;
import android.location.Location;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand All @@ -26,6 +27,7 @@
import com.mapbox.api.directions.v5.models.DirectionsResponse;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.core.constants.Constants;
import com.mapbox.core.utils.TextUtils;
import com.mapbox.geojson.LineString;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.Mapbox;
Expand All @@ -49,6 +51,7 @@
import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute;
import com.mapbox.services.android.navigation.v5.utils.LocaleUtils;

import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -61,6 +64,8 @@
import retrofit2.Response;
import timber.log.Timber;

import static android.os.Environment.getExternalStoragePublicDirectory;

public class NavigationLauncherActivity extends AppCompatActivity implements OnMapReadyCallback,
MapboxMap.OnMapLongClickListener, OnRouteSelectionChangeListener {

Expand Down Expand Up @@ -264,6 +269,7 @@ private void fetchRoute() {
.getRoute(new SimplifiedCallback() {
@Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
System.out.println("PGS url " + call.request().url().toString());
if (validRouteResponse(response)) {
hideLoading();
route = response.body().routes().get(0);
Expand Down Expand Up @@ -320,6 +326,16 @@ private String getRouteProfileFromSharedPreferences() {
);
}

private String obtainOfflinePath() {
File offline = getExternalStoragePublicDirectory("Offline");
return offline.getAbsolutePath();
}

private String retrieveOfflineVersionFromPreferences() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
return sharedPreferences.getString(getString(R.string.offline_version_key), "");
}

private void launchNavigationWithRoute() {
if (route == null) {
Snackbar.make(mapView, R.string.error_route_not_available, Snackbar.LENGTH_SHORT).show();
Expand All @@ -334,6 +350,18 @@ private void launchNavigationWithRoute() {
.build();
optionsBuilder.initialMapCameraPosition(initialPosition);
optionsBuilder.directionsRoute(route);
String offlinePath = obtainOfflinePath();
if (!TextUtils.isEmpty(offlinePath)) {
optionsBuilder.offlineRoutingTilesPath(offlinePath);
}
String offlineVersion = retrieveOfflineVersionFromPreferences();
if (!offlineVersion.isEmpty()) {
optionsBuilder.offlineRoutingTilesVersion(offlineVersion);
}
// TODO Testing merging previously sideloaded region
optionsBuilder.offlineMapDatabasePath(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + "kingfarm_to_rockville.db");
// TODO Testing merging previously downloaded region
// optionsBuilder.offlineMapDatabasePath(getFilesDir().getPath() + "/" + "mbgl-offline.db");
NavigationLauncher.startNavigation(this, optionsBuilder.build());
}

Expand Down
1 change: 1 addition & 0 deletions platform/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ buildscript {

allprojects {
repositories {
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
mavenCentral()
google()
jcenter()
Expand Down

0 comments on commit 0f4a864

Please sign in to comment.