diff --git a/app/src/main/java/amos/corridornavigation/MainActivity.java b/app/src/main/java/amos/corridornavigation/MainActivity.java index 93e3719..7204ce0 100644 --- a/app/src/main/java/amos/corridornavigation/MainActivity.java +++ b/app/src/main/java/amos/corridornavigation/MainActivity.java @@ -3,6 +3,7 @@ import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; +import android.util.Log; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.ArrayAdapter; @@ -10,6 +11,12 @@ import android.widget.EditText; import android.widget.Toast; +import com.mapbox.api.directions.v5.DirectionsCriteria; +import com.mapbox.api.directions.v5.models.BannerInstructions; +import com.mapbox.api.directions.v5.models.DirectionsRoute; +import com.mapbox.api.directions.v5.models.LegStep; +import com.mapbox.api.directions.v5.models.RouteLeg; +import com.mapbox.api.directions.v5.models.StepManeuver; import com.mapbox.api.geocoding.v5.MapboxGeocoding; import com.mapbox.api.geocoding.v5.models.CarmenFeature; import com.mapbox.api.geocoding.v5.models.GeocodingResponse; @@ -19,7 +26,13 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.services.android.navigation.ui.v5.NavigationLauncher; +import com.mapbox.services.android.navigation.ui.v5.NavigationLauncherOptions; +import com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation; +import com.mapbox.services.android.navigation.v5.navigation.MapboxNavigationOptions; +import com.mapbox.services.android.navigation.v5.navigation.NavigationRoute; +import java.util.ArrayList; import java.util.List; import retrofit2.Call; @@ -29,8 +42,7 @@ // classes needed to add location layer -public class MainActivity extends MapContext -{ +public class MainActivity extends MapContext { public static String[] countries; @Override @@ -63,11 +75,9 @@ public void afterTextChanged(Editable s) { } public void actionButtonPressed(View view) { - if(super.originLocation != null) { + if (super.originLocation != null) { this.setCameraPosition(super.originLocation); - } - else - { + } else { Toast.makeText(this, R.string.user_location_not_available, Toast.LENGTH_LONG).show(); } } @@ -76,37 +86,37 @@ public void onSearchStart(CharSequence s) { String addressPart = s.toString(); String[] dropdownSuggestions = getSuggestions(addressPart); AutoCompleteTextView autoCompleteTextView = findViewById(R.id.main_searchbar_input); - ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, dropdownSuggestions); + ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, dropdownSuggestions); autoCompleteTextView.setAdapter(adapter); } // TOTO-make getSuggestion return list of suggested addresses, now it just returns // hardcoded list of countries for demoing and testing. private String[] getSuggestions(String addressPart) { - return new String[] {"Afghanistan","Albania","Algeria","Andorra","Angola","Anguilla","Antigua; Barbuda", - "Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh", - "Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bosnia & Herzegovina", - "Botswana","Brazil","British Virgin Islands","Brunei","Bulgaria","Burkina Faso","Burundi","Cambodia", - "Cameroon","Cape Verde","Cayman Islands","Chad","Chile","China","Colombia","Congo","Cook Islands", - "Costa Rica","Cote D Ivoire","Croatia","Cruise Ship","Cuba","Cyprus","Czech Republic","Denmark", - "Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea", - "Estonia","Ethiopia","Falkland Islands","Faroe Islands","Fiji","Finland","France","French Polynesia", - "French West Indies","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland", - "Grenada","Guam","Guatemala","Guernsey","Guinea","Guinea Bissau","Guyana","Haiti","Honduras", - "Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Isle of Man","Israel", - "Italy","Jamaica","Japan","Jersey","Jordan","Kazakhstan","Kenya","Kuwait","Kyrgyz Republic","Laos", - "Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macau", - "Macedonia","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Mauritania","Mauritius", - "Mexico","Moldova","Monaco","Mongolia","Montenegro","Montserrat","Morocco","Mozambique","Namibia", - "Nepal","Netherlands","Netherlands Antilles","New Caledonia","New Zealand","Nicaragua","Niger", - "Nigeria","Norway","Oman","Pakistan","Palestine","Panama","Papua New Guinea","Paraguay","Peru", - "Philippines","Poland","Portugal","Puerto Rico","Qatar","Reunion","Romania","Russia","Rwanda", - "Saint Pierre & Miquelon","Samoa","San Marino","Satellite","Saudi Arabia","Senegal","Serbia", - "Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","South Africa","South Korea","Spain", - "Sri Lanka","St Kitts & Nevis","St Lucia","St Vincent","St. Lucia","Sudan","Suriname","Swaziland", - "Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor L'Este","Togo","Tonga", - "Trinidad & Tobago","Tunisia","Turkey","Turkmenistan","Turks & Caicos","Uganda","Ukraine", - "United Arab Emirates","United Kingdom","Uruguay","Uzbekistan","Venezuela","Vietnam","Virgin Islands (US)","Yemen","Zambia","Zimbabwe"}; + return new String[]{"Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Anguilla", "Antigua; Barbuda", + "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", + "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia & Herzegovina", + "Botswana", "Brazil", "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", + "Cameroon", "Cape Verde", "Cayman Islands", "Chad", "Chile", "China", "Colombia", "Congo", "Cook Islands", + "Costa Rica", "Cote D Ivoire", "Croatia", "Cruise Ship", "Cuba", "Cyprus", "Czech Republic", "Denmark", + "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", + "Estonia", "Ethiopia", "Falkland Islands", "Faroe Islands", "Fiji", "Finland", "France", "French Polynesia", + "French West Indies", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", + "Grenada", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea Bissau", "Guyana", "Haiti", "Honduras", + "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel", + "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kuwait", "Kyrgyz Republic", "Laos", + "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", + "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Mauritania", "Mauritius", + "Mexico", "Moldova", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Namibia", + "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", + "Nigeria", "Norway", "Oman", "Pakistan", "Palestine", "Panama", "Papua New Guinea", "Paraguay", "Peru", + "Philippines", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russia", "Rwanda", + "Saint Pierre & Miquelon", "Samoa", "San Marino", "Satellite", "Saudi Arabia", "Senegal", "Serbia", + "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "South Africa", "South Korea", "Spain", + "Sri Lanka", "St Kitts & Nevis", "St Lucia", "St Vincent", "St. Lucia", "Sudan", "Suriname", "Swaziland", + "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Timor L'Este", "Togo", "Tonga", + "Trinidad & Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks & Caicos", "Uganda", "Ukraine", + "United Arab Emirates", "United Kingdom", "Uruguay", "Uzbekistan", "Venezuela", "Vietnam", "Virgin Islands (US)", "Yemen", "Zambia", "Zimbabwe"}; } public void onSearchButtonClicked(View view) { @@ -121,15 +131,13 @@ public void onSearchButtonClicked(View view) { String address = editText.getText().toString(); MapboxGeocoding client; try { - if(super.originLocation != null) { + if (super.originLocation != null) { client = MapboxGeocoding.builder() .accessToken(getString(R.string.access_token)) .proximity(Point.fromLngLat(super.originLocation.getLongitude(), super.originLocation.getLatitude())) .query(address) .build(); - } - else - { + } else { client = MapboxGeocoding.builder() .accessToken(getString(R.string.access_token)) .query(address) @@ -140,14 +148,13 @@ public void onSearchButtonClicked(View view) { public void onResponse(Call call, Response response) { List results = response.body().features(); - if(results.size() > 1) - { + if (results.size() > 1) { LatLng latLng = new LatLng(); latLng.setLatitude(results.get(0).center().latitude()); latLng.setLongitude(results.get(0).center().longitude()); onMapClick(latLng); - mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,13.0)); // mapboxMap came from MapContext + mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 13.0)); // mapboxMap came from MapContext } } @@ -163,4 +170,28 @@ public void onFailure(Call call, Throwable throwable) { } } + + public void onNavigateButtonClicked(View view) { + + try { + boolean simulateRoute = true; + NavigationLauncherOptions options = NavigationLauncherOptions.builder() + .directionsRoute(super.locationMarker.currentRoute) + .shouldSimulateRoute(simulateRoute) + .build(); + + + int max=options.directionsRoute().legs().get(0).steps().size(); + for(int i = 0; i + +