-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dan-snap-check
- Loading branch information
Showing
12 changed files
with
219 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
...rc/main/java/com/mapbox/services/android/navigation/ui/v5/WaypointNavigationActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package com.mapbox.services.android.navigation.ui.v5; | ||
|
||
import android.content.DialogInterface; | ||
import android.location.Location; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AlertDialog; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import com.mapbox.geojson.Point; | ||
import com.mapbox.services.android.navigation.ui.v5.listeners.NavigationListener; | ||
import com.mapbox.services.android.navigation.v5.routeprogress.ProgressChangeListener; | ||
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress; | ||
import com.mapbox.services.android.navigation.v5.utils.RouteUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class WaypointNavigationActivity extends AppCompatActivity implements OnNavigationReadyCallback, | ||
NavigationListener, ProgressChangeListener { | ||
|
||
private NavigationView navigationView; | ||
private boolean dropoffDialogShown; | ||
private Location lastKnownLocation; | ||
|
||
private List<Point> points = new ArrayList<>(); | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
setTheme(R.style.Theme_AppCompat_NoActionBar); | ||
super.onCreate(savedInstanceState); | ||
points.add(Point.fromLngLat(-77.04012393951416, 38.9111117447887)); | ||
points.add(Point.fromLngLat(-77.03847169876099, 38.91113678979344)); | ||
points.add(Point.fromLngLat(-77.03848242759705, 38.91040213277608)); | ||
points.add(Point.fromLngLat(-77.03850388526917, 38.909650771013034)); | ||
points.add(Point.fromLngLat(-77.03651905059814, 38.90894949285854)); | ||
setContentView(R.layout.activity_navigation); | ||
navigationView = findViewById(R.id.navigationView); | ||
navigationView.onCreate(savedInstanceState); | ||
navigationView.getNavigationAsync(this); | ||
} | ||
|
||
@Override | ||
public void onLowMemory() { | ||
super.onLowMemory(); | ||
navigationView.onLowMemory(); | ||
} | ||
|
||
@Override | ||
public void onBackPressed() { | ||
// If the navigation view didn't need to do anything, call super | ||
if (!navigationView.onBackPressed()) { | ||
super.onBackPressed(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
navigationView.onDestroy(); | ||
} | ||
|
||
@Override | ||
protected void onSaveInstanceState(Bundle outState) { | ||
navigationView.onSaveInstanceState(outState); | ||
super.onSaveInstanceState(outState); | ||
} | ||
|
||
@Override | ||
protected void onRestoreInstanceState(Bundle savedInstanceState) { | ||
super.onRestoreInstanceState(savedInstanceState); | ||
navigationView.onRestoreInstanceState(savedInstanceState); | ||
} | ||
|
||
@Override | ||
public void onNavigationReady() { | ||
navigationView.startNavigation(setupOptions(points.remove(0))); | ||
} | ||
|
||
private NavigationViewOptions setupOptions(Point origin) { | ||
dropoffDialogShown = false; | ||
|
||
NavigationViewOptions.Builder options = NavigationViewOptions.builder(); | ||
options.navigationListener(this); | ||
options.progressChangeListener(this); | ||
options.origin(origin); | ||
options.destination(points.remove(0)); | ||
options.shouldSimulateRoute(true); | ||
return options.build(); | ||
} | ||
|
||
@Override | ||
public void onCancelNavigation() { | ||
// Navigation canceled, finish the activity | ||
finish(); | ||
} | ||
|
||
@Override | ||
public void onNavigationFinished() { | ||
// Intentionally empty | ||
} | ||
|
||
@Override | ||
public void onNavigationRunning() { | ||
// Intentionally empty | ||
} | ||
|
||
@Override | ||
public void onProgressChange(Location location, RouteProgress routeProgress) { | ||
if (RouteUtils.isArrivalEvent(routeProgress)) { | ||
lastKnownLocation = location; // Accounts for driver moving after dialog was triggered | ||
if (!dropoffDialogShown && !points.isEmpty()) { | ||
showDropoffDialog(); | ||
dropoffDialogShown = true; // Accounts for multiple arrival events | ||
} | ||
} | ||
} | ||
|
||
private void showDropoffDialog() { | ||
AlertDialog alertDialog = new AlertDialog.Builder(this).create(); | ||
alertDialog.setMessage(getString(R.string.dropoff_dialog_text)); | ||
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.dropoff_dialog_positive_text), | ||
new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialogInterface, int in) { | ||
navigationView.startNavigation( | ||
setupOptions(Point.fromLngLat(lastKnownLocation.getLongitude(), lastKnownLocation.getLatitude()))); | ||
} | ||
}); | ||
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.dropoff_dialog_negative_text), | ||
new DialogInterface.OnClickListener() { | ||
@Override | ||
public void onClick(DialogInterface dialogInterface, int in) { | ||
// Do nothing | ||
} | ||
}); | ||
|
||
alertDialog.show(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.