Open sandyscoffable opened 3 years ago
Hey @sandyscoffable thanks for reaching out and report your issue.
Could you add some more information around your test setup? Could you also share your request setup / RouteOptions
you're adding and the DirectionsRoute
that you get / use when you have a chance?
If there is any sample or pseudo code you can provide, that would be really helpful and it'll give us better insight into your implementation and what could be causing your problem.
Hi, I'm running a physical device (Samsung Galaxy SM-A715F, Android SDK 30) using Android 11. The app I'm using to mock locations on device is "Mock Locations (fake GPS path)" ru.gavrikov.mocklocations
v 1.70 ... it's a bit shonky but does the job.
It's tricky as I can't reliably trigger it. I am switching between apps a lot, so perhaps it has something to do with the containing app not running in the foreground?
That setup is totally fine.
It's tricky as I can't reliably trigger it. I am switching between apps a lot, so perhaps it has something to do with the containing app not running in the foreground?
What do you mean by that?
Could you provide more details? We use often that setup and not running into reroute issues 🤔
As mentioned, it'd be great if you could provide a small project or code snippet reproducing the issue.
I don't think I'll have spare time to properly narrow this issue down (as I'll need to do it in the emulator [which has issues in v2 navigation apparently], find a route and the exact reproduction scenario, and then move the relevant bits of code from the app I've got in development to an example - this would likely take days not hours).
However, I think the stack trace is reasonably helpful ... perhaps this will only ever be seen in development, and I guess that's what you're trying to do, triage the bug and work out how important it is to fix is.
I managed to demo a full route with waypoints with rerouting and it worked fine yesterday (so 👍). Maybe first run luck. I guess if I see this in our live testing or on consumer devices I'll spend more time on it.
It just seemed to me like some sort of array indexing type problem, and perhaps some defensive coding might help out there.
To give you a bit more of a picture on the app architecture:
I hit this again today with 2.0.0-beta.5
:
2021-04-15 13:42:47.572 787-787/com.XXX.YYY.debug E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.XXX.YYY.debug, PID: 787
java.lang.IllegalArgumentException: Requested element count -1 is less than zero.
at kotlin.collections.CollectionsKt___CollectionsKt.drop(_Collections.kt:650)
at com.mapbox.navigation.core.routeoptions.MapboxRouteOptionsUpdater.update(MapboxRouteOptionsUpdater.kt:66)
at com.mapbox.navigation.core.reroute.MapboxRerouteController.reroute(MapboxRerouteController.kt:62)
at com.mapbox.navigation.core.MapboxNavigation.reroute(MapboxNavigation.kt:813)
at com.mapbox.navigation.core.MapboxNavigation.access$reroute(MapboxNavigation.kt:149)
at com.mapbox.navigation.core.MapboxNavigation$createInternalOffRouteObserver$1.onOffRouteStateChanged(MapboxNavigation.kt:807)
at com.mapbox.navigation.core.trip.session.MapboxTripSession.setOffRoute(MapboxTripSession.kt:141)
at com.mapbox.navigation.core.trip.session.MapboxTripSession.access$setOffRoute$p(MapboxTripSession.kt:55)
at com.mapbox.navigation.core.trip.session.MapboxTripSession$updateDataFromNavigatorStatus$updateNavigatorStatusDataJob$1.invokeSuspend(MapboxTripSession.kt:528)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8506)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
@kmadsen could you take a look into this when you have a chance? 🙏
Hey @sandyscoffable thanks for reaching out and report your issue.
Could you share your requests setup / RouteOptions
you're adding and the DirectionsRoute
s that you get / use when you have a chance?
cc @RingerJK
@sandyscoffable I'm unable to trace the issue looking at our logic without a reproducible case, but here' a PR that prints more debug data in case this happens again in the future - https://github.com/mapbox/mapbox-navigation-android/pull/4384.
If it does happen again, it would be great if we could get our hands on logs with tags MbxRerouteController
and MbxRouteOptionsProvider
that would precede the crash.
Meanwhile, @mapbox/navnative would you be able to briefly walk through your codebase and check whether there could be an issue where returned remainingWaypoints
integer is bigger than the current route's coordinates size? This is what causes the crash here.
I wouldn't want to resort to the defensive coding yet, especially as long as we're in a beta phase, because a failure to parse the coordinates here would result in a failed reroute request making the navigation session needing a hard restart anyway. Hopefully we'll be able to get to the bottom of this before v2 becomes stable.
Closing as stale or potentially resolved already but please let us know if this is still reproducible @sandyscoffable!
👍 .. I'm not working on this mapping related project at the moment, but I'll hopefully get back to it in the next 6 months..
@LukasPaczos @Guardiola31337
I submitted a support ticket to support@mapbox regarding this from our enterprise acct @ Fri 12/3/2021 10:39 AM
We are seeing this issue as well on a very regular basis, our developer has reached out to support for assistance, we are willing to do the necessary debugging to assist mapbox is closing this ticket.
We are running the Nav and Maps SDK for android...
Fatal Exception: java.lang.IllegalArgumentException Requested element count -1 is less than zero. Fatal Exception: java.lang.IllegalArgumentException: Requested element count -1 is less than zero. at kotlin.collections.CollectionsKt___CollectionsKt.drop(_Collections.kt:650) at com.mapbox.navigation.core.routeoptions.MapboxRouteOptionsUpdater.update(MapboxRouteOptionsUpdater.kt:51) at com.mapbox.navigation.core.reroute.MapboxRerouteController.reroute(MapboxRerouteController.kt:50) at com.mapbox.navigation.core.MapboxNavigation.reroute(MapboxNavigation.kt:746) at com.mapbox.navigation.core.MapboxNavigation.access$reroute(MapboxNavigation.kt:131) at com.mapbox.navigation.core.MapboxNavigation$createInternalOffRouteObserver$1.onOffRouteStateChanged(MapboxNavigation.kt:740) at com.mapbox.navigation.core.trip.session.MapboxTripSession.setOffRoute(MapboxTripSession.kt:123) at com.mapbox.navigation.core.trip.session.MapboxTripSession.access$setOffRoute$p(MapboxTripSession.kt:48) at com.mapbox.navigation.core.trip.session.MapboxTripSession$updateDataFromNavigatorStatus$updateNavigatorStatusDataJob$1.invokeSuspend(MapboxTripSession.kt:514) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7432) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:520) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
We are using the following mapbox dependencies in our app.
implementation 'com.mapbox.navigation:ui:1.4.0' implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-places-v8:0.9.0' implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.1'
Here is my below mapbox navigation request.
mapboxNavigation.requestRoutes( RouteOptions.builder() .accessToken(getString(R.string.access_token)) .requestUuid(uuid.toString()) .coordinates(list) .baseUrl(Constants.BASE_API_URL) .profile(getRouteProfileFromSharedPreferences()) .user(Constants.MAPBOX_USER) .voiceUnits(DirectionsCriteria.METRIC) .voiceInstructions(true) .bannerInstructions(true) .continueStraight(true) .alternatives(true) .annotations("congestion") .language("en") .roundaboutExits(true) .overview("full") .exclude(DirectionsCriteria.EXCLUDE_TOLL) .steps(true) .build(), routesCallback );
@LukasPaczos @Guardiola31337 @RingerJK
I've asked our mobile android developer to follow up on this thread today, and provide any additional code snippets / tracing / stack info that will assist the mapbox team in diagnosing and resolving this issue we face daily in our fleet of courier and transport drivers.
This seems to be gaining traction amongst our drivers.
Email received from @harikhalsa with support ticket #116014 referenced.. updated here for record keeping.
Adding logcat stack from crash.
12-06 11:56:59.689 4960 4960 E AndroidRuntime: FATAL EXCEPTION: main
12-06 11:56:59.689 4960 4960 E AndroidRuntime: Process: app.abcourier.ccmobile, PID: 4960
12-06 11:56:59.689 4960 4960 E AndroidRuntime: java.lang.IllegalArgumentException: Requested element count -1 is less than zero.
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at kotlin.collections.CollectionsKt_CollectionsKt.drop(_Collections.kt:650)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at com.mapbox.navigation.core.routeoptions.MapboxRouteOptionsUpdater.update(MapboxRouteOptionsUpdater.kt:51)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at com.mapbox.navigation.core.reroute.MapboxRerouteController.reroute(MapboxRerouteController.kt:50)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at com.mapbox.navigation.core.MapboxNavigation.reroute(MapboxNavigation.kt:746)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at com.mapbox.navigation.core.MapboxNavigation.access$reroute(MapboxNavigation.kt:131)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at com.mapbox.navigation.core.MapboxNavigation$createInternalOffRouteObserver$1.onOffRouteStateChanged(MapboxNavigation.kt:740)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at com.mapbox.navigation.core.trip.session.MapboxTripSession.setOffRoute(MapboxTripSession.kt:123)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at com.mapbox.navigation.core.trip.session.MapboxTripSession.access$setOffRoute$p(MapboxTripSession.kt:48)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at com.mapbox.navigation.core.trip.session.MapboxTripSession$updateDataFromNavigatorStatus$updateNavigatorStatusDataJob$1.invokeSuspend(MapboxTripSession.kt:514)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:883)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:100)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at android.os.Looper.loop(Looper.java:214)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7432)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:520)
12-06 11:56:59.689 4960 4960 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
12-06 17:16:01.533 20595 20595 F libc : /usr/local/google/buildbot/src/android/ndk-release-r21/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:72: abort_message: assertion "terminating with uncaught exception of type jni::PendingJavaException" failed
12-06 17:16:01.539 20595 20595 F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 20595 (ourier.ccmobile), pid 20595 (ourier.ccmobile)
12-06 17:16:02.039 21066 21066 F DEBUG :
12-06 17:16:02.040 21066 21066 F DEBUG : Build fingerprint: 'Sonim/XP8832/XP8800:10/8A.0.7-12-10.0.0-11.19.00/18:user/release-keys'
12-06 17:16:02.040 21066 21066 F DEBUG : Revision: '0'
12-06 17:16:02.040 21066 21066 F DEBUG : ABI: 'arm'
12-06 17:16:02.070 21066 21066 F DEBUG : Timestamp: 2021-12-06 17:16:02-0500
12-06 17:16:02.070 21066 21066 F DEBUG : pid: 20595, tid: 20595, name: ourier.ccmobile >>> app.abcourier.ccmobile <<<
12-06 17:16:02.070 21066 21066 F DEBUG : uid: 10121
12-06 17:16:02.070 21066 21066 F DEBUG : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
12-06 17:16:02.070 21066 21066 F DEBUG : Abort message: '/usr/local/google/buildbot/src/android/ndk-release-r21/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:72: abort_message: assertion "terminating with uncaught exception of type jni::PendingJavaException" failed'
12-06 17:16:02.070 21066 21066 F DEBUG : r0 00000000 r1 00005073 r2 00000006 r3 ff923c08
12-06 17:16:02.070 21066 21066 F DEBUG : r4 ff923c1c r5 ff923c00 r6 00005073 r7 0000016b
12-06 17:16:02.070 21066 21066 F DEBUG : r8 ff923c18 r9 ff923c08 r10 ff923c38 r11 ff923c28
12-06 17:16:02.070 21066 21066 F DEBUG : ip 00005073 sp ff923bd8 lr e60a84ab pc e60a84be
12-06 17:16:02.603 21066 21066 F DEBUG :
12-06 17:16:02.603 21066 21066 F DEBUG : backtrace:
12-06 17:16:02.603 21066 21066 F DEBUG : #00 pc 000604be /apex/com.android.runtime/lib/bionic/libc.so (abort+166) (BuildId: ff2749049c33375235540d96bc589a7a)
12-06 17:16:02.603 21066 21066 F DEBUG : #01 pc 00060747 /apex/com.android.runtime/lib/bionic/libc.so (assert2+22) (BuildId: ff2749049c33375235540d96bc589a7a)
12-06 17:16:02.603 21066 21066 F DEBUG : #02 pc 0028abc3 /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.603 21066 21066 F DEBUG : #03 pc 0028ace3 /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.603 21066 21066 F DEBUG : #04 pc 00289415 /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.603 21066 21066 F DEBUG : #05 pc 00288cc3 /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #06 pc 00288c8b /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (cxa_throw+74) (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #07 pc 0005461d /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #08 pc 0006b771 /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #09 pc 000c22fd /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #10 pc 0014fba1 /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #11 pc 0014f753 /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #12 pc 00151679 /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #13 pc 0019a245 /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #14 pc 000add17 /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #15 pc 0019512b /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #16 pc 00194b91 /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #17 pc 00194c1f /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #18 pc 001940fb /data/app/app.abcourier.ccmobile-BWyOX_EN6Q3j6p5E2Y2AzQ==/lib/arm/libmapbox-gl.so (BuildId: f97e0b40d4f1a81499746c3e5528d8d1b15d08af)
12-06 17:16:02.604 21066 21066 F DEBUG : #19 pc 00010a75 /system/lib/libutils.so (android::Looper::pollInner(int)+672) (BuildId: 7b5529a9d829b64e623a42ae4c1dde66)
12-06 17:16:02.604 21066 21066 F DEBUG : #20 pc 0001075b /system/lib/libutils.so (android::Looper::pollOnce(int, int, int, void*)+30) (BuildId: 7b5529a9d829b64e623a42ae4c1dde66)
12-06 17:16:02.605 21066 21066 F DEBUG : #21 pc 000d33c7 /system/lib/libandroid_runtime.so (android::android_os_MessageQueue_nativePollOnce(_JNIEnv, _jobject, long long, int)+24) (BuildId: 60b826e670bea0dec3e2f7eb854b0860)
12-06 17:16:02.605 21066 21066 F DEBUG : #22 pc 0029a43d /system/framework/arm/boot-framework.oat (art_jni_trampoline+92) (BuildId: 1d35fa745fa7b292a0ae6ad8ca52a749a8816077)
12-06 17:16:02.605 21066 21066 F DEBUG : #23 pc 006326c3 /system/framework/arm/boot-framework.oat (android.os.MessageQueue.next+202) (BuildId: 1d35fa745fa7b292a0ae6ad8ca52a749a8816077)
12-06 17:16:02.605 21066 21066 F DEBUG : #24 pc 0062fe0d /system/framework/arm/boot-framework.oat (android.os.Looper.loop+580) (BuildId: 1d35fa745fa7b292a0ae6ad8ca52a749a8816077)
12-06 17:16:02.605 21066 21066 F DEBUG : #25 pc 004535bd /system/framework/arm/boot-framework.oat (android.app.ActivityThread.main+756) (BuildId: 1d35fa745fa7b292a0ae6ad8ca52a749a8816077)
12-06 17:16:02.605 21066 21066 F DEBUG : #26 pc 000d7bc5 /apex/com.android.runtime/lib/libart.so (art_quick_invoke_stub_internal+68) (BuildId: bf06ac57a1e7242585f433264a46d200)
12-06 17:16:02.605 21066 21066 F DEBUG : #27 pc 00436269 /apex/com.android.runtime/lib/libart.so (art_quick_invoke_static_stub+248) (BuildId: bf06ac57a1e7242585f433264a46d200)
12-06 17:16:02.605 21066 21066 F DEBUG : #28 pc 000dffff /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread, unsigned int, unsigned int, art::JValue, char const)+198) (BuildId: bf06ac57a1e7242585f433264a46d200)
12-06 17:16:02.605 21066 21066 F DEBUG : #29 pc 0037723b /apex/com.android.runtime/lib/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod, art::(anonymous namespace)::ArgArray, art::JValue, char const)+54) (BuildId: bf06ac57a1e7242585f433264a46d200)
12-06 17:16:02.605 21066 21066 F DEBUG : #30 pc 00378755 /apex/com.android.runtime/lib/libart.so (art::InvokeMethod(art::ScopedObjectAccessAlreadyRunnable const&, _jobject, _jobject, _jobject, unsigned int)+932) (BuildId: bf06ac57a1e7242585f433264a46d200)
12-06 17:16:02.605 21066 21066 F DEBUG : #31 pc 0032409b /apex/com.android.runtime/lib/libart.so (art::Method_invoke(_JNIEnv, _jobject, _jobject, _jobjectArray)+30) (BuildId: bf06ac57a1e7242585f433264a46d200)
12-06 17:16:02.606 21066 21066 F DEBUG : #32 pc 000bb82f /system/framework/arm/boot.oat (art_jni_trampoline+110) (BuildId: cf3eda66f563693f5494ea4f4f88cf2eeb2519c5)
12-06 17:16:02.606 21066 21066 F DEBUG : #33 pc 00824cc3 /system/framework/arm/boot-framework.oat (com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run+114) (BuildId: 1d35fa745fa7b292a0ae6ad8ca52a749a8816077)
12-06 17:16:02.606 21066 21066 F DEBUG : #34 pc 0082b267 /system/framework/arm/boot-framework.oat (com.android.internal.os.ZygoteInit.main+1758) (BuildId: 1d35fa745fa7b292a0ae6ad8ca52a749a8816077)
12-06 17:16:02.606 21066 21066 F DEBUG : #35 pc 000d7bc5 /apex/com.android.runtime/lib/libart.so (art_quick_invoke_stub_internal+68) (BuildId: bf06ac57a1e7242585f433264a46d200)
12-06 17:16:02.606 21066 21066 F DEBUG : #36 pc 00436269 /apex/com.android.runtime/lib/libart.so (art_quick_invoke_static_stub+248) (BuildId: bf06ac57a1e7242585f433264a46d200)
12-06 17:16:02.606 21066 21066 F DEBUG : #37 pc 000dffff /apex/com.android.runtime/lib/libart.so (art::ArtMethod::Invoke(art::Thread, unsigned int, unsigned int, art::JValue, char const)+198) (BuildId: bf06ac57a1e7242585f433264a46d200)
12-06 17:16:02.606 21066 21066 F DEBUG : #38 pc 0037723b /apex/com.android.runtime/lib/libart.so (art::(anonymous namespace)::InvokeWithArgArray(art::ScopedObjectAccessAlreadyRunnable const&, art::ArtMethod, art::(anonymous namespace)::ArgArray, art::JValue, char const)+54) (BuildId: bf06ac57a1e7242585f433264a46d200)
12-06 17:16:02.606 21066 21066 F DEBUG : #39 pc 00376ff1 /apex/com.android.runtime/lib/libart.so (art::InvokeWithVarArgs(art::ScopedObjectAccessAlreadyRunnable const&, _jobject, _jmethodID, std::va_list)+292) (BuildId: bf06ac57a1e7242585f433264a46d200)
12-06 17:16:02.606 21066 21066 F DEBUG : #40 pc 002c0da9 /apex/com.android.runtime/lib/libart.so (art::JNI::CallStaticVoidMethodV(_JNIEnv, _jclass, _jmethodID*, std::va_list)+460) (BuildId: bf06ac57a1e7242585f433264a46d200)
12-06 17:16:02.606 21066 21066 F DEBUG : #41 pc 0007e649 /system/lib/libandroid_runtime.so (_JNIEnv::CallStaticVoidMethod(_jclass, _jmethodID, ...)+28) (BuildId: 60b826e670bea0dec3e2f7eb854b0860)
12-06 17:16:02.606 21066 21066 F DEBUG : #42 pc 00080c31 /system/lib/libandroid_runtime.so (android::AndroidRuntime::start(char const*, android::Vector
FYI: Devices: SonimTech XP8 Mobile Android Devices, running 8.10 or 10.0 for an OS.
NAV SDK 1.4.0 Maps sdk 9.6.1 Processor - AArch64 Processor rev 4(aarh64), CPU Architecture - 42.21GHz, 41.84GHz, Supported ABIs : arm64-v8a, armeabi-v7a, armeabi, CPU type -64 bit. targetSdkVersion-28
the SDK drops first X
coordinates based on the remaining waypoints, that provided by NN (SDK v.1.4.0 consumes NN version 28.0.0
). The issue there is that the remaining waypoint size is greater than the number of coordinates. @SiarheiFedartsou Could you have a look
For your information, I have added the below code to reproduce the issue. I have not written RerouteController in my code. Once the offroute gets detected then the mapbox sdk is rerouting by default. So I have tested that and it was working fine. So I did not add code for rerouting.
public class NavigationActivity extends AppCompatActivity implements OnMapReadyCallback, NavigationListener, PermissionsListener, MapboxMap.OnMapLongClickListener, OnWayNameChangedListener, FeedbackBottomSheetListener, RerouteController.RerouteStateObserver, OnRouteSelectionChangeListener {
private LocationComponent locationComponent;
private PermissionsManager permissionsManager;
private NavigationMapboxMap navigationMapboxMap;
Camera camera;
private WayNameView wayNameView;
private TextView speedTxt;
private static final String TAG = "NavigationActivity";
private ImageButton routeOverviewButton;
private RecenterButton recenterBtn;
private AppCompatButton order_details_btn;
private void enableLocationComponent(@NonNull Style loadedMapStyle) {
// Check if permissions are enabled and if not request
if (checkLocationPermission(NavigationActivity.this)) {
if (PermissionsManager.areLocationPermissionsGranted(this)) {
// Activate the MapboxMap LocationComponent to show user location
// Adding in LocationComponentOptions is also an optional parameter
locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(this, loadedMapStyle);
locationComponent.setLocationComponentEnabled(true);
// Set the component's camera mode
locationComponent.setCameraMode(CameraMode.TRACKING);
locationComponent.setRenderMode(RenderMode.COMPASS);
} else {
permissionsManager = new PermissionsManager(NavigationActivity.this);
permissionsManager.requestLocationPermissions(this);
}
}
}
@Override
public void onExplanationNeeded(List<String> permissionsToExplain) {
}
@Override
public void onPermissionResult(boolean granted) {
if (granted)
enableLocationComponent(mapboxMap.getStyle());
}
@Override
public boolean onMapLongClick(@NonNull @NotNull LatLng point) {
return false;
}
private CameraPosition getCameraPosition() {
CameraPosition position = new CameraPosition.Builder()
.zoom(13)
.tilt(10)
.target(new LatLng(origin_lat, origin_lon))
.build();
return position;
}
private void updateCameraOnNavigationStateChange(boolean navigationStarted) {
if (navigationStarted) {
if (navigationMapboxMap != null) {
navigationMapboxMap.updateCameraTrackingMode(NavigationCamera.NAVIGATION_TRACKING_MODE_GPS);
navigationMapboxMap.updateLocationLayerRenderMode(RenderMode.GPS);
}
}
}
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
if (bannerInstructionObserver != null && mapboxNavigation != null) {
mapboxNavigation.registerBannerInstructionsObserver(bannerInstructionObserver);
mapboxNavigation.registerArrivalObserver(arrivalObserver);
mapboxNavigation.registerRouteProgressObserver(routeProgressObserver);
mapboxNavigation.registerVoiceInstructionsObserver(voiceInstructionsObserver);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mapboxNavigation.registerOffRouteObserver(offRouteObserver);
}
}, 5000);
}
}
private OffRouteObserver offRouteObserver = new OffRouteObserver() {
@Override
public void onOffRouteStateChanged(boolean offRoute) {
Log.e(TAG, "OFFROUTE_DETECTED" + offRoute);
}
};
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
speechPlayer.onDestroy();
mapboxNavigation.stopTripSession();
mapboxNavigation.unregisterLocationObserver(locationObserver);
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onStop() {
super.onStop();
mapView.onStop();
mapboxNavigation.unregisterBannerInstructionsObserver(bannerInstructionObserver);
mapboxNavigation.unregisterArrivalObserver(arrivalObserver);
mapboxNavigation.unregisterRouteProgressObserver(routeProgressObserver);
mapboxNavigation.unregisterVoiceInstructionsObserver(voiceInstructionsObserver);
mapboxNavigation.unregisterOffRouteObserver(offRouteObserver);
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
mapboxNavigation.stopTripSession();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
private ArrivalObserver arrivalObserver = new ArrivalObserver() {
@Override
public void onNextRouteLegStart(@NotNull RouteLegProgress routeLegProgress) {
}
@Override
public void onFinalDestinationArrival(@NotNull RouteProgress routeProgress) {
}
};
private BannerInstructionsObserver bannerInstructionObserver = new BannerInstructionsObserver() {
@Override
public void onNewBannerInstructions(@NotNull BannerInstructions bannerInstructions) {
instructionView.updateBannerInstructionsWith(bannerInstructions);
}
};
private RouteProgressObserver routeProgressObserver = new RouteProgressObserver() {
@Override
public void onRouteProgressChanged(@NotNull RouteProgress routeProgress) {
instructionView.updateDistanceWith(routeProgress);
summaryBottomSheet.update(routeProgress);
}
};
private VoiceInstructionsObserver voiceInstructionsObserver = new VoiceInstructionsObserver() {
@Override
public void onNewVoiceInstructions(@NotNull VoiceInstructions voiceInstructions) {
speechPlayer.play(voiceInstructions);
}
};
@Override
public void onMapReady(@NonNull @NotNull MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
mapboxMap.getUiSettings().setAttributionEnabled(false);
mapboxMap.getUiSettings().setLogoEnabled(false);
mapboxMap.setCameraPosition(getCameraPosition());
camera = new DynamicCamera(mapboxMap);
mapboxMap.setStyle(new Style.Builder().fromUri("mapbox://styles/abcourier/cknrlcjm80vd817qo4dj7axf5"), new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
enableLocationComponent(style);
navigationMapboxMap = new NavigationMapboxMap.Builder(mapView, mapboxMap, NavigationActivity.this)
.useSpecializedLocationLayer(true)
.vanishRouteLineEnabled(true)
.build();
updateCameraOnNavigationStateChange(true);
Point origin;
origin = Point.fromLngLat(origin_lon,
origin_lat);
Point destination = Point.fromLngLat(destin_lon, destin_lat);
if (mapboxNavigation != null)
fetchRoute(origin, destination);
}
});
}
private void fetchRoute(Point origin, Point destination) {
List<Point> list = new ArrayList<>();
UUID uuid = UUID.randomUUID();
list.add(origin);
list.add(destination);
mapboxNavigation.requestRoutes(
RouteOptions.builder()
.accessToken(getString(R.string.access_token))
.requestUuid(uuid.toString())
.coordinates(list)
.baseUrl(Constants.BASE_API_URL)
.profile(getRouteProfileFromSharedPreferences())
.user(Constants.MAPBOX_USER)
.voiceUnits(DirectionsCriteria.METRIC)
.voiceInstructions(true)
.bannerInstructions(true)
.continueStraight(true)
.alternatives(true)
.annotations("congestion")
.language("en")
.roundaboutExits(true)
.overview("full")
.exclude(DirectionsCriteria.EXCLUDE_TOLL)
.steps(true)
.build(), routesCallback
);
}
private final RoutesRequestCallback routesCallback = new RoutesRequestCallback() {
@Override
public void onRoutesRequestFailure(@NotNull Throwable throwable, @NotNull RouteOptions routeOptions) {
}
@Override
public void onRoutesRequestCanceled(@NotNull RouteOptions routeOptions) {
}
@Override
public void onRoutesReady(@NotNull List<? extends DirectionsRoute> list) {
if (checkLocationPermission(NavigationActivity.this)) {
navigationMapboxMap.addProgressChangeListener(mapboxNavigation);
navigationMapboxMap.addOnCameraTrackingChangedListener(cameraTrackingChangedListener);
navigationMapboxMap.startCamera(list.get(0));
mapboxNavigation.startTripSession();
mapboxNavigation
.getNavigationOptions()
.getLocationEngine()
.getLastLocation(locationListenerCallback);
}
}
};
private OnCameraTrackingChangedListener cameraTrackingChangedListener = new OnCameraTrackingChangedListener() {
@Override
public void onCameraTrackingDismissed() {
}
@Override
public void onCameraTrackingChanged(int currentMode) {
if (mapboxNavigation.getTripSessionState() == TripSessionState.STARTED) {
hideWayNameView();
}
}
};
private void hideWayNameView() {
wayNameView.updateVisibility(false);
}
private Boolean checkLocationPermission(Context context) {
String permission = Manifest.permission.ACCESS_FINE_LOCATION;
String permission1 = Manifest.permission.ACCESS_COARSE_LOCATION;
int res = context.checkCallingOrSelfPermission(permission);
int res1 = context.checkCallingOrSelfPermission(permission1);
if (res == 0 && res1 == 0)
return res == PackageManager.PERMISSION_GRANTED;
else
return false;
}
private class MyLocationEngineCallback implements LocationEngineCallback<LocationEngineResult> {
private WeakReference activityRef;
public MyLocationEngineCallback(NavigationActivity directionsActivity) {
activityRef = new WeakReference(directionsActivity);
}
@Override
public void onSuccess(LocationEngineResult result) {
if (navigationMapboxMap != null)
navigationMapboxMap.updateLocation(result.getLastLocation());
}
@Override
public void onFailure(@NonNull Exception exception) {
}
}
private MyLocationEngineCallback locationListenerCallback = new MyLocationEngineCallback(NavigationActivity.this);
private String getRouteProfileFromSharedPreferences() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
return sharedPreferences.getString(
getString(R.string.route_profile_key), DirectionsCriteria.PROFILE_DRIVING_TRAFFIC
);
}
@Override
public void onRerouteStateChanged(@NotNull RerouteState rerouteState) {
}
@Override
public void onFeedbackSelected(FeedbackItem feedbackItem) {
}
@Override
public void onFeedbackDismissed() {
}
@Override
public void onCancelNavigation() {
mapboxNavigation.stopTripSession();
finish();
}
@Override
public void onNavigationFinished() {
}
@Override
public void onNavigationRunning() {
}
@Override
public void onWayNameChanged(@NonNull @NotNull String wayName) {
wayNameView.updateWayNameText(wayName);
if (summaryBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
hideWayNameView();
} else {
showWayNameView();
}
}
@Override
public void onNewPrimaryRouteSelected(DirectionsRoute directionsRoute) {
}
private LocationObserver locationObserver = new LocationObserver() {
@Override
public void onRawLocationChanged(@NotNull Location location) {
}
@Override
public void onEnhancedLocationChanged(@NotNull Location location, @NotNull List<? extends Location> list) {
speedTxt.setText("" + (int) Math.round(location.getSpeed() * 3.6) + " \n" + "KPH");
}
};
private boolean shouldSimulateRoute() {
return PreferenceManager.getDefaultSharedPreferences(NavigationActivity.this)
.getBoolean(this.getString(R.string.simulate_route_key), false);
}
private LocationEngine getLocationEngine() {
if (shouldSimulateRoute()) {
return new ReplayLocationEngine(mapboxReplayer);
} else {
return LocationEngineProvider.getBestLocationEngine(NavigationActivity.this);
}
}
private void initializeSpeechPlayer() {
Cache cache =
new Cache(
new File(
NavigationActivity.this.getCacheDir(),
"voice-instruction-cache"
),
10 * 1024 * 1024
);
VoiceInstructionLoader voiceInstructionLoader = new
VoiceInstructionLoader(NavigationActivity.this, Mapbox.getAccessToken(), cache);
SpeechPlayerProvider speechPlayerProvider =
new SpeechPlayerProvider(
NavigationActivity.this,
Locale.US.getLanguage(),
true,
voiceInstructionLoader
);
speechPlayer = new NavigationSpeechPlayer(speechPlayerProvider);
}
private Location getLastKnownLocation(LocationManager mLocationManager) {
mLocationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
List<String> providers = mLocationManager.getProviders(true);
Location bestLocation = null;
if (ContextCompat.checkSelfPermission(NavigationActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
ActivityCompat.requestPermissions(NavigationActivity.this,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
101);
}
for (String provider : providers) {
Location l = mLocationManager.getLastKnownLocation(provider);
if (l == null) {
continue;
}
if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) {
// Found best last known location: %s", l);
bestLocation = l;
}
}
return bestLocation;
}
private double origin_lat;
private double origin_lon;
private double destin_lon;
private double destin_lat;
private MapView mapView;
private MapboxMap mapboxMap;
private InstructionView instructionView;
private SummaryBottomSheet summaryBottomSheet;
NavigationOptions mapOptions;
private NavigationSpeechPlayer speechPlayer;
private MapboxNavigation mapboxNavigation;
private MapboxReplayer mapboxReplayer = new MapboxReplayer();
private AppCompatImageButton cancelBtn;
private BottomSheetBehavior<SummaryBottomSheet> summaryBehavior;
private final ReplayRouteMapper replayRouteMapper = new ReplayRouteMapper();
@Override
protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mapview);
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
instructionView = findViewById(R.id.instructionView);
speedTxt = findViewById(R.id.speed);
wayNameView = findViewById(R.id.wayNameView);
instructionView.setVisibility(View.VISIBLE);
cancelBtn = findViewById(R.id.cancelBtn);
order_details_btn = findViewById(R.id.order_details_btn);
routeOverviewButton = findViewById(R.id.routeOverviewBtn);
recenterBtn = findViewById(R.id.recenterBtn);
recenterBtn.show();
summaryBottomSheet = findViewById(R.id.summaryBottomSheet);
summaryBehavior = BottomSheetBehavior.from(summaryBottomSheet);
summaryBehavior.setBottomSheetCallback(bottomSheetCallback);
summaryBehavior.setHideable(false);
wayNameView = findViewById(R.id.wayNameView);
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapboxNavigation.stopTripSession();
finish();
}
});
routeOverviewButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
summaryBehavior.setHideable(true);
if (navigationMapboxMap != null)
navigationMapboxMap.showRouteOverview(buildRouteOverviewPadding());
recenterBtn.show();
}
});
recenterBtn.addOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
summaryBehavior.setHideable(false);
summaryBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
showWayNameView();
if (navigationMapboxMap != null) {
navigationMapboxMap.resetPadding();
navigationMapboxMap.resetCameraPositionWith(NavigationCamera.NAVIGATION_TRACKING_MODE_GPS);
}
}
});
order_details_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent();
setResult(602, i);
stopNavigation();
}
});
mapOptions = MapboxNavigation.defaultNavigationOptionsBuilder(NavigationActivity.this, getString(R.string.access_token))
.locationEngine(getLocationEngine())
.isDebugLoggingEnabled(true)
.build();
mapboxNavigation = new MapboxNavigation(mapOptions);
mapboxNavigation.registerRouteProgressObserver(new ReplayProgressObserver(mapboxReplayer));
mapboxReplayer.pushRealLocation(NavigationActivity.this, 0.0);
mapboxReplayer.play();
mapboxNavigation.registerLocationObserver(locationObserver);
destin_lat = getIntent().getDoubleExtra("destin_lat", 0.0);
destin_lon = getIntent().getDoubleExtra("destin_long", 0.0);
origin_lat = getIntent().getDoubleExtra("origin_lat", 0.0);
origin_lon = getIntent().getDoubleExtra("origin_lon", 0.0);
initializeSpeechPlayer();
}
private BottomSheetBehavior.BottomSheetCallback bottomSheetCallback = new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (summaryBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
recenterBtn.show();
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
};
private int[] buildRouteOverviewPadding() {
int leftRightPadding =
(int) getResources()
.getDimension(
com.mapbox.navigation.ui.R.dimen.mapbox_route_overview_left_right_padding
);
int paddingBuffer =
(int) getResources()
.getDimension(
com.mapbox.navigation.ui.R.dimen.mapbox_route_overview_buffer_padding
);
int instructionHeight = (int) (getResources()
.getDimension(
com.mapbox.navigation.ui.R.dimen.mapbox_instruction_content_height
) +
paddingBuffer);
int summaryHeight =
(int) getResources()
.getDimension(com.mapbox.navigation.ui.R.dimen.mapbox_summary_bottom_sheet_height);
return new int[]{leftRightPadding, instructionHeight, leftRightPadding, summaryHeight};
}
private void showWayNameView() {
wayNameView.updateVisibility(!wayNameView.retrieveWayNameText().isEmpty());
}
private void stopNavigation() {
mapboxNavigation.stopTripSession();
finish();
}
}
@Sridhar261990 could you also provide the layout and unwrap all hidden values from shared preference? Also, could you provide coordinates of route (now they are provided outside via Intent)
Hi Yuri,
The issue is happening for a lot of drivers and I don't have exact coordinates value. Please check the attached layout , preferences and class file for more information.
FYI , I have given the sample class for replicating the issue in the previous comment section and now I have added the all inner logics and API call code everything. I have just removed some unused stuffs to avoid confusions. Please check it and let me know if you need any clarification.
Please let me know if you want any additional information.
Thanks and Regards, Sridhar
On Fri, Dec 10, 2021 at 12:21 AM Yury Kanetski @.***> wrote:
@Sridhar261990 https://github.com/Sridhar261990 could you also provide the layout and unwrap all hidden values from shared preference? Also, could you provide coordinates of route (now they are provided outside via Intent)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mapbox/mapbox-navigation-android/issues/4179#issuecomment-990128784, or unsubscribe https://github.com/notifications/unsubscribe-auth/AW2UJUMTEMC2SAEWEOY4PILUQD3DPANCNFSM4ZZGUGDA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
package app.abcourier.ccmobile.activity.mapbox;
import android.Manifest;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.provider.Settings;
import android.text.InputType;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatImageButton;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.livefront.bridge.Bridge;
import com.mapbox.android.core.location.LocationEngine;
import com.mapbox.android.core.location.LocationEngineCallback;
import com.mapbox.android.core.location.LocationEngineProvider;
import com.mapbox.android.core.location.LocationEngineResult;
import com.mapbox.android.core.permissions.PermissionsListener;
import com.mapbox.android.core.permissions.PermissionsManager;
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.RouteOptions;
import com.mapbox.api.directions.v5.models.VoiceInstructions;
import com.mapbox.core.constants.Constants;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener;
import com.mapbox.mapboxsdk.location.modes.CameraMode;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.navigation.base.options.NavigationOptions;
import com.mapbox.navigation.base.trip.model.RouteLegProgress;
import com.mapbox.navigation.base.trip.model.RouteProgress;
import com.mapbox.navigation.base.trip.model.RouteProgressState;
import com.mapbox.navigation.core.MapboxNavigation;
import com.mapbox.navigation.core.arrival.ArrivalObserver;
import com.mapbox.navigation.core.directions.session.RoutesRequestCallback;
import com.mapbox.navigation.core.replay.MapboxReplayer;
import com.mapbox.navigation.core.replay.ReplayLocationEngine;
import com.mapbox.navigation.core.replay.route.ReplayProgressObserver;
import com.mapbox.navigation.core.replay.route.ReplayRouteMapper;
import com.mapbox.navigation.core.reroute.RerouteController;
import com.mapbox.navigation.core.reroute.RerouteState;
import com.mapbox.navigation.core.trip.session.BannerInstructionsObserver;
import com.mapbox.navigation.core.trip.session.LocationObserver;
import com.mapbox.navigation.core.trip.session.OffRouteObserver;
import com.mapbox.navigation.core.trip.session.RouteProgressObserver;
import com.mapbox.navigation.core.trip.session.TripSessionState;
import com.mapbox.navigation.core.trip.session.TripSessionStateObserver;
import com.mapbox.navigation.core.trip.session.VoiceInstructionsObserver;
import com.mapbox.navigation.ui.FeedbackButton;
import com.mapbox.navigation.ui.NavigationButton;
import com.mapbox.navigation.ui.RecenterButton;
import com.mapbox.navigation.ui.SoundButton;
import com.mapbox.navigation.ui.camera.Camera;
import com.mapbox.navigation.ui.camera.DynamicCamera;
import com.mapbox.navigation.ui.camera.NavigationCamera;
import com.mapbox.navigation.ui.camera.RouteInformation;
import com.mapbox.navigation.ui.feedback.FeedbackBottomSheet;
import com.mapbox.navigation.ui.feedback.FeedbackBottomSheetListener;
import com.mapbox.navigation.ui.feedback.FeedbackItem;
import com.mapbox.navigation.ui.instruction.InstructionView;
import com.mapbox.navigation.ui.internal.utils.ViewUtils;
import com.mapbox.navigation.ui.listeners.NavigationListener;
import com.mapbox.navigation.ui.map.NavigationMapboxMap;
import com.mapbox.navigation.ui.map.OnWayNameChangedListener;
import com.mapbox.navigation.ui.map.WayNameView;
import com.mapbox.navigation.ui.map.building.BuildingFootprintHighlightLayer;
import com.mapbox.navigation.ui.route.OnRouteSelectionChangeListener;
import com.mapbox.navigation.ui.summary.SummaryBottomSheet;
import com.mapbox.navigation.ui.voice.NavigationSpeechPlayer;
import com.mapbox.navigation.ui.voice.SpeechPlayerProvider;
import com.mapbox.navigation.ui.voice.VoiceInstructionLoader;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.lang.ref.WeakReference;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import app.abcourier.ccmobile.ABCourier;
import app.abcourier.ccmobile.R;
import app.abcourier.ccmobile.common.Utils;
import app.abcourier.ccmobile.database.dbHelper;
import app.abcourier.ccmobile.fragment.homeFragment.datamodel.PackageDetails;
import app.abcourier.ccmobile.sharedPreference.PrefUtil;
import app.abcourier.ccmobile.utils.LogUtils;
import okhttp3.Cache;
import timber.log.Timber;
import static app.abcourier.ccmobile.common.AppConstants.ABCourier_BACKOFF_MULT;
import static app.abcourier.ccmobile.common.AppConstants.ABCourier_MAX_RETRIES;
import static app.abcourier.ccmobile.common.AppConstants.ABCourier_TIMEOUT;
import static com.mapbox.navigation.core.telemetry.events.FeedbackEvent.UI;
import static com.mapbox.navigation.core.trip.session.TripSessionState.STARTED;
import static com.mapbox.navigation.core.trip.session.TripSessionState.STOPPED;
public class NavigationActivity extends AppCompatActivity implements OnMapReadyCallback, NavigationListener, PermissionsListener,
MapboxMap.OnMapLongClickListener, OnWayNameChangedListener, FeedbackBottomSheetListener, RerouteController.RerouteStateObserver,
OnRouteSelectionChangeListener {
private static final String TAG = "NavigationActivity";
private MapView mapView;
private MapboxMap mapboxMap;
private AppCompatButton order_details_btn;
private AppCompatButton complete_trip;
NavigationOptions mapOptions;
private NavigationSpeechPlayer speechPlayer;
private MapboxNavigation mapboxNavigation;
static boolean isOffRoute = false;
private NavigationSpeechPlayer navigationSpeechPlayer;
private ImageButton routeOverviewButton;
private RecenterButton recenterBtn;
private BottomSheetBehavior<SummaryBottomSheet> summaryBehavior;
private WayNameView wayNameView;
private AppCompatImageButton cancelBtn;
private InstructionView instructionView;
private FeedbackButton feedbackButton;
private TextView stepSecondaryText, stepPrimaryText;
Handler spinWheelTimer;
Dialog spinWheelDialog;
public static final int SPINWHEEL_LIFE_TIME = 2000;
private String addressWithColor;
private SummaryBottomSheet summaryBottomSheet;
private NavigationButton instructionSoundButton;
private double origin_lat;
private double origin_lon;
private double buildingLat;
private double buildingLong;
private String buildLat, buildLong;
private boolean isGroup;
private List<String> groupOrders;
private String btnValue;
private String driverNo;
private double latitude;
private double bearing;
private double longitude;
private double altitude;
private double accuracy;
private String address;
private String indexVal;
private String partialAddress;
private float speedVal;
private double progressLatitude = 0.0;
private double progressLongitude;
private TextView speedTxt;
private int sameaddress;
private Bundle mapInstanceState;
private NavigationMapboxMap navigationMapboxMap;
private DirectionsRoute directionRoute;
private double destin_lon = 0.0;
private double destin_lat = 0.0;
private LogUtils logUtils;
private RequestQueue requestQueue;
private LatLng highlightQueryLatLng;
private boolean higlightedFootprintAlreadyShown = false;
private String prevOrderNo;
private boolean IsDirectGo;
private void initializeSpeechPlayer() {
Cache cache =
new Cache(
new File(
NavigationActivity.this.getCacheDir(),
"voice-instruction-cache"
),
10 * 1024 * 1024
);
VoiceInstructionLoader voiceInstructionLoader = new
VoiceInstructionLoader(NavigationActivity.this, Mapbox.getAccessToken(), cache);
SpeechPlayerProvider speechPlayerProvider =
new SpeechPlayerProvider(
NavigationActivity.this,
Locale.US.getLanguage(),
true,
voiceInstructionLoader
);
speechPlayerProvider.setIsFallbackAlwaysEnabled(false);
speechPlayer = new NavigationSpeechPlayer(speechPlayerProvider);
}
@Override
public void onBackPressed() {
super.onBackPressed();
PrefUtil.setIsGroupReturn(NavigationActivity.this, false);
PrefUtil.setParkingStarted(NavigationActivity.this, "ENDED");
Intent i = new Intent();
setResult(103, i);
finish();
}
private FeedbackItem feedbackItem;
private String feedbackEncodedScreenShot;
private void showFeedbackBottomSheet(View view) {
feedbackItem = null;
feedbackEncodedScreenShot = null;
FeedbackBottomSheet feedbackBottomSheet = FeedbackBottomSheet.newInstance(
(FeedbackBottomSheetListener) NavigationActivity.this,
30000L
);
feedbackBottomSheet.show(getSupportFragmentManager(), FeedbackBottomSheet.TAG);
}
private void sendFeedback() {
if (feedbackItem != null && feedbackItem.getFeedbackType() != null) {
FeedbackItem feedback = feedbackItem;
String screenShot = feedbackEncodedScreenShot;
JSONObject jsonObject = new JSONObject();
List<PackageDetails> packageDetailsList = dbHelper.getInstance(NavigationActivity.this).getOrderNoLatLong(prevOrderNo);
String insertValidateUrl = Utils.frameURLs(NavigationActivity.this) + "/api/MobileOrder/ReportNavigationIssue";
try {
jsonObject.put("DriverNumber", PrefUtil.getABCourierDriverNumberPreference(NavigationActivity.this));
jsonObject.put("OrderNo", prevOrderNo);
if (packageDetailsList != null && packageDetailsList.size() > 0) {
if (packageDetailsList.get(0).getStatusID().equals("4"))
jsonObject.put("OrderStatus", "Delivery");
else jsonObject.put("OrderStatus", "PickedUp");
}
jsonObject.put("Latitude", latitude);
jsonObject.put("Longitude", longitude);
jsonObject.put("Comments", feedback.getFeedbackType());
jsonObject.put("ReportedTime", Utils.getCurrentDate());
Log.e(TAG, jsonObject.toString());
logUtils.writeToLogFile(TAG + "- ReportNavigationIssue REPORT URL -" + insertValidateUrl);
logUtils.writeToLogFile(TAG + "- ReportNavigationIssue REPORT Params -" + jsonObject.toString());
} catch (Exception e) {
logUtils.writeToLogFile(TAG + "-sendFeedback-" + e.getMessage());
e.printStackTrace();
}
startSpinwheel(false, false);
if (requestQueue == null)
requestQueue = ABCourier.getInstance().getRequestQueue();
// Initialize a new JsonArrayRequest instance
JsonObjectRequest jsonArrayRequest = new JsonObjectRequest(
com.android.volley.Request.Method.POST,
insertValidateUrl,
jsonObject,
new com.android.volley.Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e(TAG, response.toString());
logUtils.writeToLogFile(TAG + "- ReportNavigationIssue REPORT RESPONE -" + response.toString());
}
},
new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
stopSpinWheel();
if (error != null && error.getMessage() != null) {
Log.e(TAG, error.getMessage());
logUtils.writeToLogFile(TAG + "- ReportNavigationIssue REPORT RESPONE Error-" + error.getMessage());
}
}
}
);
// Add JsonArrayRequest to the RequestQueue
jsonArrayRequest.setRetryPolicy((new DefaultRetryPolicy(
ABCourier_TIMEOUT,
ABCourier_MAX_RETRIES,
ABCourier_BACKOFF_MULT)));
requestQueue.add(jsonArrayRequest);
if (feedback != null && !TextUtils.isEmpty(screenShot)) {
mapboxNavigation.postUserFeedback(feedback.getFeedbackType(),
feedback.getDescription(),
UI,
screenShot,
new String[]{Arrays.toString(new Set[]{feedback.getFeedbackSubType()})}, null);
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initView(savedInstanceState);
try {
mapOptions = MapboxNavigation.defaultNavigationOptionsBuilder(NavigationActivity.this, getString(R.string.access_token))
.locationEngine(getLocationEngine())
.isDebugLoggingEnabled(true)
.build();
mapboxNavigation = new MapboxNavigation(mapOptions);
mapboxReplayer.pushRealLocation(NavigationActivity.this, 0.0);
mapboxReplayer.play();
mapboxNavigation.registerLocationObserver(locationObserver);
} catch (Exception e) {
logUtils.writeToLogFile(TAG + "-" + e.getMessage());
e.printStackTrace();
}
initializeSpeechPlayer();
updateNightMode();
feedbackButton.addOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showFeedbackBottomSheet(v);
}
});
instructionSoundButton.addOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NavigationButton soundButton = instructionSoundButton;
if (soundButton instanceof SoundButton) {
speechPlayer.setMuted(((SoundButton) soundButton).toggleMute());
}
}
});
routeOverviewButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
summaryBehavior.setHideable(true);
if (navigationMapboxMap != null)
navigationMapboxMap.showRouteOverview(buildRouteOverviewPadding());
recenterBtn.show();
}
});
complete_trip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PrefUtil.setParkingStarted(NavigationActivity.this, "ENDED");
PrefUtil.setIsGroupReturn(NavigationActivity.this, false);
if (dbHelper.getInstance(NavigationActivity.this).checkIfUpcomingDataAvailable(prevOrderNo))
dbHelper.getInstance(NavigationActivity.this).deleteUpcomingParking(prevOrderNo);
Intent i = new Intent();
i.putExtra("screen", btnValue);
i.putExtra("trip", "completed");
if (sameaddress == 0)
setResult(602, i);
else
setResult(608, i);
stopNavigation();
}
});
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PrefUtil.setIsGroupReturn(NavigationActivity.this, false);
PrefUtil.setParkingStarted(NavigationActivity.this, "ENDED");
mapboxNavigation.stopTripSession();
finish();
}
});
order_details_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent();
i.putExtra("screen", btnValue);
i.putExtra("indexVal", indexVal);
if (sameaddress == 0)
setResult(602, i);
else
setResult(608, i);
stopNavigation();
}
});
recenterBtn.addOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
summaryBehavior.setHideable(false);
summaryBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
showWayNameView();
if (navigationMapboxMap != null) {
navigationMapboxMap.resetPadding();
navigationMapboxMap.resetCameraPositionWith(NavigationCamera.NAVIGATION_TRACKING_MODE_GPS);
}
}
});
if (!TextUtils.isEmpty(prevOrderNo)) {
List<PackageDetails> packageDetailsList = dbHelper.getInstance(NavigationActivity.this).getOrderNoLatLong(prevOrderNo);
if (packageDetailsList != null && packageDetailsList.size() > 0) {
String orderStatus = packageDetailsList.get(0).getStatusID();
if (!orderStatus.equals("4")) {
buildLat = packageDetailsList.get(0).getPuBLat();
buildLong = packageDetailsList.get(0).getPuBLong();
destin_lat = Double.valueOf(packageDetailsList.get(0).getPuLat());
destin_lon = Double.valueOf(packageDetailsList.get(0).getPuLon());
} else {
buildLat = packageDetailsList.get(0).getDelLat();
buildLong = packageDetailsList.get(0).getDelBLong();
destin_lat = Double.valueOf(packageDetailsList.get(0).getDelLat());
destin_lon = Double.valueOf(packageDetailsList.get(0).getDelLon());
}
}
}
IsDirectGo = getIntent().getBooleanExtra("direct_go", false);
prevOrderNo = getIntent().getStringExtra("orderNo");
if (destin_lon == 0.0) {
destin_lat = getIntent().getDoubleExtra("destin_lat", 0.0);
destin_lon = getIntent().getDoubleExtra("destin_long", 0.0);
}
origin_lat = getIntent().getDoubleExtra("origin_lat", 0.0);
origin_lon = getIntent().getDoubleExtra("origin_lon", 0.0);
if (!TextUtils.isEmpty(buildLat)) {
buildingLat = Double.valueOf(buildLat);
buildingLong = Double.valueOf(buildLong);
logUtils.writeToLogFile(TAG + "--building_coordinates" + buildingLat + "--" + buildingLong);
Log.e(TAG, "building_color" + buildingLat + "--" + buildingLong);
}
sameaddress = getIntent().getIntExtra("sameaddress", 0);
isGroup = getIntent().getBooleanExtra("isGroup", false);
groupOrders = getIntent().getStringArrayListExtra("groupOrders");
btnValue = getIntent().getStringExtra("screen");
if (!TextUtils.isEmpty(btnValue))
complete_trip.setText(btnValue);
driverNo = PrefUtil.getABCourierDriverNumberPreference(NavigationActivity.this);
if (!TextUtils.isEmpty(address)) {
Log.e(TAG, address);
logUtils.writeToLogFile(TAG + "-turnby-turn-navigation-address" + "--" + address);
}
partialAddress = getIntent().getStringExtra("partialAddress");
indexVal = getIntent().getStringExtra("indexVal");
if (!TextUtils.isEmpty(address)) {
complete_trip.setVisibility(View.VISIBLE);
}
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setCostAllowed(false);
String provider = locationManager.getBestProvider(criteria, false);
Location location = null;
MyLocationListener mylistener = new MyLocationListener();
if (getLastKnownLocation(locationManager) != null) {
// add location to the location listener for location changes
mylistener.onLocationChanged(getLastKnownLocation(locationManager));
} else {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
if (checkLocationPermission(NavigationActivity.this))
locationManager.requestLocationUpdates(provider, 500, 1, mylistener);
}
private void initView(Bundle savedInstanceState) {
Bridge.restoreInstanceState(NavigationActivity.this, savedInstanceState);
logUtils = new LogUtils();
address = getIntent().getStringExtra("address");
if (!TextUtils.isEmpty(address))
setContentView(R.layout.activity_mapview);
else setContentView(R.layout.activity_gps_mapview);
logUtils.writeToLogFile(TAG + "-onCreate");
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
instructionView = findViewById(R.id.instructionView);
order_details_btn = findViewById(R.id.order_details_btn);
order_details_btn.setEnabled(false);
order_details_btn.setBackground(getResources().getDrawable(R.drawable.inactivebutton));
complete_trip = findViewById(R.id.complete_trip);
instructionSoundButton = instructionView.retrieveSoundButton();
instructionView.setVisibility(View.VISIBLE);
summaryBottomSheet = findViewById(R.id.summaryBottomSheet);
feedbackButton = instructionView.findViewById(R.id.feedbackLayout);
speedTxt = findViewById(R.id.speed);
routeOverviewButton = findViewById(R.id.routeOverviewBtn);
recenterBtn = findViewById(R.id.recenterBtn);
cancelBtn = findViewById(R.id.cancelBtn);
summaryBehavior = BottomSheetBehavior.from(summaryBottomSheet);
summaryBehavior.setBottomSheetCallback(bottomSheetCallback);
summaryBehavior.setHideable(false);
wayNameView = findViewById(R.id.wayNameView);
recenterBtn.show();
stepSecondaryText = instructionView.findViewById(R.id.stepSecondaryText);
stepPrimaryText = instructionView.findViewById(R.id.stepPrimaryText);
stepPrimaryText.setTextSize(23);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
stepPrimaryText.setElegantTextHeight(true);
}
stepPrimaryText.setSingleLine(true);
stepSecondaryText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
stepSecondaryText.setMaxLines(7);
stepSecondaryText.setTextSize(15);
stepSecondaryText.setSingleLine(false);
stepSecondaryText.setVisibility(View.VISIBLE);
}
private LocationEngine getLocationEngine() {
if (shouldSimulateRoute()) {
return new ReplayLocationEngine(mapboxReplayer);
} else {
return LocationEngineProvider.getBestLocationEngine(NavigationActivity.this);
}
}
private boolean shouldSimulateRoute() {
return PreferenceManager.getDefaultSharedPreferences(NavigationActivity.this)
.getBoolean(this.getString(R.string.simulate_route_key), false);
}
private void stopNavigation() {
mapboxNavigation.stopTripSession();
finish();
}
private Location getLastKnownLocation(LocationManager mLocationManager) {
mLocationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
List<String> providers = mLocationManager.getProviders(true);
Location bestLocation = null;
if (ContextCompat.checkSelfPermission(NavigationActivity.this, Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
ActivityCompat.requestPermissions(NavigationActivity.this,
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
101);
}
for (String provider : providers) {
Location l = mLocationManager.getLastKnownLocation(provider);
if (l == null) {
continue;
}
if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) {
// Found best last known location: %s", l);
bestLocation = l;
}
}
return bestLocation;
}
@Override
public void onFeedbackSelected(FeedbackItem feedbackItem) {
this.feedbackItem = feedbackItem;
sendFeedback();
}
@Override
public void onFeedbackDismissed() {
}
@Override
public void onRerouteStateChanged(@NotNull RerouteState rerouteState) {
}
@Override
public void onNewPrimaryRouteSelected(DirectionsRoute directionsRoute) {
Log.e(TAG, "onNewPrimaryRouteSelected");
}
private class MyLocationListener implements LocationListener {
@Override
public void onLocationChanged(Location location) {
// Do something with the location
latitude = location.getLatitude();
longitude = location.getLongitude();
altitude = location.getAltitude();
accuracy = location.getAccuracy();
bearing = location.getBearing();
Log.e("CURRENT_LOCATION", latitude + "--" + longitude);
Log.e("LOCATION-SPEED", (int) Math.round(location.getSpeed() * 3.6) + " \n" + "KPH" + "");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// Log.i("onStatusChanged: ", "Do something with the status: " + status);
}
@Override
public void onProviderEnabled(String provider) {
// Log.i("onProviderEnabled: ", "Do something with the provider-> " + provider);
}
@Override
public void onProviderDisabled(String provider) {
// Log.i("onProviderDisabled:", "Do something with the provider-> " + provider);
}
}
private void updateNightMode() {
if (wasNavigationStopped()) {
updateWasNavigationStopped(false);
// AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
recreate();
}
}
private void setIsOffroute(boolean isOffRoute) {
this.isOffRoute = isOffRoute;
}
private boolean getIsOffroute() {
return this.isOffRoute;
}
private boolean wasNavigationStopped() {
Context context = NavigationActivity.this;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
return preferences.getBoolean(getString(R.string.was_navigation_stopped), false);
}
public void updateWasNavigationStopped(boolean wasNavigationStopped) {
Context context = NavigationActivity.this;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(getString(R.string.was_navigation_stopped), wasNavigationStopped);
editor.apply();
}
private void showWayNameView() {
wayNameView.updateVisibility(!wayNameView.retrieveWayNameText().isEmpty());
}
private BottomSheetBehavior.BottomSheetCallback bottomSheetCallback = new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (summaryBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
recenterBtn.show();
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
};
private int[] buildRouteOverviewPadding() {
int leftRightPadding =
(int) getResources()
.getDimension(
com.mapbox.navigation.ui.R.dimen.mapbox_route_overview_left_right_padding
);
int paddingBuffer =
(int) getResources()
.getDimension(
com.mapbox.navigation.ui.R.dimen.mapbox_route_overview_buffer_padding
);
int instructionHeight = (int) (getResources()
.getDimension(
com.mapbox.navigation.ui.R.dimen.mapbox_instruction_content_height
) +
paddingBuffer);
int summaryHeight =
(int) getResources()
.getDimension(com.mapbox.navigation.ui.R.dimen.mapbox_summary_bottom_sheet_height);
return new int[]{leftRightPadding, instructionHeight, leftRightPadding, summaryHeight};
}
Handler handlerOffRoute = new Handler(Looper.myLooper());
private OffRouteObserver offRouteObserver = new OffRouteObserver() {
@Override
public void onOffRouteStateChanged(boolean offRoute) {
Log.e(TAG, "OFFROUTE_DETECTED" + offRoute);
logUtils.writeToLogFile(TAG + "-OFFROUTE_DETECTED--" + offRoute);
//Do something after 100ms
setIsOffroute(offRoute);
if (offRoute) {
if (handlerOffRoute == null) {
handlerOffRoute = new Handler(Looper.myLooper());
}
Runnable runnable = new Runnable() {
@Override
public void run() {
if (getIsOffroute()) {
isOnRoute = false;
callOffRouteAPI(directionRoute.geometry(), getIsOffroute(), durationRemainingOnProgress);
setIsOffroute(false);
}
}
};
handlerOffRoute.postDelayed(runnable, 2000);
}
}
};
@Override
public void onResume() {
super.onResume();
logUtils.writeToLogFile(TAG + "-onResume");
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("navigation_update");
mapView.onResume();
}
@Override
protected void onStart() {
super.onStart();
mapView.onStart();
logUtils.writeToLogFile(TAG + "-onStart");
if (bannerInstructionObserver != null && mapboxNavigation != null) {
mapboxNavigation.registerBannerInstructionsObserver(bannerInstructionObserver);
mapboxNavigation.registerArrivalObserver(arrivalObserver);
mapboxNavigation.registerTripSessionStateObserver(tripSessionStateObserver);
mapboxNavigation.registerRouteProgressObserver(routeProgressObserver);
mapboxNavigation.registerVoiceInstructionsObserver(voiceInstructionsObserver);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
mapboxNavigation.registerOffRouteObserver(offRouteObserver);
}
}, 5000);
}
}
@Override
protected void onStop() {
super.onStop();
mapView.onStop();
logUtils.writeToLogFile(TAG + "-onStop");
mapboxNavigation.unregisterBannerInstructionsObserver(bannerInstructionObserver);
mapboxNavigation.unregisterArrivalObserver(arrivalObserver);
mapboxNavigation.unregisterTripSessionStateObserver(tripSessionStateObserver);
mapboxNavigation.unregisterRouteProgressObserver(routeProgressObserver);
mapboxNavigation.unregisterVoiceInstructionsObserver(voiceInstructionsObserver);
mapboxNavigation.unregisterOffRouteObserver(offRouteObserver);
}
@Override
public void onPause() {
super.onPause();
logUtils.writeToLogFile(TAG + "-onPause");
mapView.onPause();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (outState != null && mapView != null)
mapView.onSaveInstanceState(outState);
if (directionRoute != null)
outState.putString(PRIMARY_ROUTE_BUNDLE_KEY, directionRoute.toJson());
if (navigationMapboxMap != null)
navigationMapboxMap.saveStateWith(outState);
Bridge.saveInstanceState(this, outState);
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
speechPlayer.onDestroy();
mapboxNavigation.stopTripSession();
mapboxNavigation.unregisterLocationObserver(locationObserver);
logUtils.writeToLogFile(TAG + "-onDestroy");
Bridge.clear(this);
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
private static final String PRIMARY_ROUTE_BUNDLE_KEY = "myPrimaryRouteBundleKey";
@Override
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mapInstanceState = savedInstanceState;
if (savedInstanceState != null && navigationMapboxMap != null) {
navigationMapboxMap.restoreStateFrom(savedInstanceState);
directionRoute = getRouteFromBundle(savedInstanceState);
}
}
public static DirectionsRoute getRouteFromBundle(Bundle bundle) {
try {
if (bundle.containsKey(PRIMARY_ROUTE_BUNDLE_KEY)) {
String routeAsJson = bundle.getString(PRIMARY_ROUTE_BUNDLE_KEY);
return DirectionsRoute.fromJson(routeAsJson);
}
} catch (Exception ex) {
Timber.i(ex);
}
return null;
}
private CameraPosition getCameraPosition() {
CameraPosition position = new CameraPosition.Builder()
.zoom(16.5)
.tilt(20)
.target(new LatLng(origin_lat, origin_lon))
.build();
return position;
}
@Override
public void onMapReady(@NonNull MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
mapboxMap.getUiSettings().setAttributionEnabled(false);
mapboxMap.getUiSettings().setLogoEnabled(false);
mapboxMap.setCameraPosition(getCameraPosition());
mapboxMap.setStyle(new Style.Builder().fromUri("mapbox://styles/abcourier/cknrlcjm80vd817qo4dj7axf5"), new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
enableLocationComponent(style);
navigationMapboxMap = new NavigationMapboxMap.Builder(mapView, mapboxMap, NavigationActivity.this)
.useSpecializedLocationLayer(true)
.vanishRouteLineEnabled(true)
.build();
if (mapInstanceState != null) {
logUtils.writeToLogFile(TAG + "-" + "Restore method called");
navigationMapboxMap.restoreStateFrom(mapInstanceState);
restoreNavigation();
}
updateCameraOnNavigationStateChange(true);
Point origin;
if (progressLatitude != 0.0)
origin = Point.fromLngLat(progressLongitude,
progressLatitude);
else origin = Point.fromLngLat(origin_lon,
origin_lat);
Point destination = Point.fromLngLat(destin_lon, destin_lat);
logUtils.writeToLogFile(TAG + "-starting navigation-coordinates-origin-" + origin.latitude() + "-" + origin.longitude());
logUtils.writeToLogFile(TAG + "-starting navigation-coordinates-destination-" + destin_lat + "-" + destin_lon);
PrefUtil.setParkingStarted(NavigationActivity.this, "DIRECT");
if (mapboxNavigation != null)
fetchRoute(origin, destination);
Log.e(TAG, "LOCATION-" + origin.latitude() + "," + origin.longitude() + ";" + destination.latitude() + "," + destination.longitude());
}
});
}
private void restoreNavigation() {
if (navigationMapboxMap != null) {
if (!TextUtils.isEmpty(indexVal)) {
if (mapboxNavigation != null && mapboxNavigation.getRoutes() != null) {
if (mapboxNavigation.getRoutes().size() <= Integer.parseInt(indexVal))
navigationMapboxMap.startCamera(mapboxNavigation.getRoutes().get(Integer.parseInt(indexVal)));
else navigationMapboxMap.startCamera(mapboxNavigation.getRoutes().get(0));
}
} else {
if (mapboxNavigation != null && mapboxNavigation.getRoutes() != null)
navigationMapboxMap.startCamera(mapboxNavigation.getRoutes().get(0));
}
updateCameraOnNavigationStateChange(true);
}
if (checkLocationPermission(NavigationActivity.this)) {
mapboxNavigation.startTripSession();
}
}
private ArrivalObserver arrivalObserver = new ArrivalObserver() {
@Override
public void onNextRouteLegStart(@NotNull RouteLegProgress routeLegProgress) {
}
@Override
public void onFinalDestinationArrival(@NotNull RouteProgress routeProgress) {
Log.e(TAG, "onFinalDestinationArrival" + "-" + partialAddress);
PrefUtil.setParkingStarted(NavigationActivity.this, "ENDED");
addressWithColor = partialAddress;
stepSecondaryText.setVisibility(View.VISIBLE);
if (!TextUtils.isEmpty(addressWithColor)) {
Spannable wordToSpan = new SpannableString(addressWithColor);
wordToSpan.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.addressyellow)), 0, addressWithColor.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stepSecondaryText.setText(wordToSpan);
}
if (dbHelper.getInstance(NavigationActivity.this).checkIfUpcomingDataAvailable(prevOrderNo))
dbHelper.getInstance(NavigationActivity.this).deleteUpcomingParking(prevOrderNo);
PrefUtil.setIsGroupReturn(NavigationActivity.this, false);
}
};
private LocationObserver locationObserver = new LocationObserver() {
@Override
public void onRawLocationChanged(@NotNull Location location) {
}
@Override
public void onEnhancedLocationChanged(@NotNull Location location, @NotNull List<? extends Location> list) {
speedTxt.setText("" + (int) Math.round(location.getSpeed() * 3.6) + " \n" + "KPH");
speedVal = (int) Math.round(location.getSpeed() * 3.6);
progressLatitude = location.getLatitude();
progressLongitude = location.getLongitude();
}
};
private TripSessionStateObserver tripSessionStateObserver = new TripSessionStateObserver() {
@Override
public void onSessionStateChanged(@NotNull TripSessionState tripSessionState) {
switch (tripSessionState) {
case STARTED:
updateViews(STARTED);
if (navigationMapboxMap != null) {
navigationMapboxMap.addOnWayNameChangedListener(NavigationActivity.this);
navigationMapboxMap.updateWaynameQueryMap(true);
}
break;
case STOPPED:
updateViews(STOPPED);
if (navigationMapboxMap != null) {
if (!mapboxNavigation.getRoutes().isEmpty()) {
navigationMapboxMap.hideRoute();
}
navigationMapboxMap.removeOnWayNameChangedListener(NavigationActivity.this);
navigationMapboxMap.updateWaynameQueryMap(false);
updateCameraOnNavigationStateChange(false);
}
break;
default:
break;
}
}
};
private double durationRemainingOnProgress = 0.0;
private double zoomVal = 0.0;
String routeGeometry = "";
private void updateViews(TripSessionState tripSessionState) {
switch (tripSessionState) {
case STARTED:
summaryBottomSheet.setVisibility(View.VISIBLE);
instructionView.setVisibility(View.VISIBLE);
feedbackButton.show();
instructionSoundButton.show();
break;
case STOPPED:
summaryBottomSheet.setVisibility(View.GONE);
hideWayNameView();
instructionView.setVisibility(View.GONE);
feedbackButton.hide();
instructionSoundButton.hide();
break;
}
}
private void hideWayNameView() {
wayNameView.updateVisibility(false);
}
private RouteProgressObserver routeProgressObserver = new RouteProgressObserver() {
@Override
public void onRouteProgressChanged(@NotNull RouteProgress routeProgress) {
Log.e(TAG, "onRouteProgressChanged");
instructionView.updateDistanceWith(routeProgress);
summaryBottomSheet.update(routeProgress);
zoomVal = mapboxMap.getCameraPosition().zoom;
routeGeometry = routeProgress.getRoute().geometry();
logUtils.writeToLogFile(TAG + "-ROUTE RESPONSE--" + routeProgress.getRoute());
List<Point> points = routeProgress.getRoute().routeOptions().coordinates();
logUtils.writeToLogFile(TAG + "-onRouteProgress origin:::" + points.get(0).coordinates().get(0) + "," + points.get(0).coordinates().get(1));
logUtils.writeToLogFile(TAG + "-onRouteProgress destination:::" + points.get(1).coordinates().get(0) + "," + points.get(1).coordinates().get(1));
logUtils.writeToLogFile(TAG + "-onRouteProgress bannerInstructions:::" + routeProgress.getBannerInstructions());
Log.e(TAG, "-onRouteProgress origin:::" + points.get(0).coordinates().get(0) + "," + points.get(0).coordinates().get(1));
Log.e(TAG, "-onRouteProgress destination:::" + points.get(1).coordinates().get(0) + "," + points.get(1).coordinates().get(1));
Log.e(TAG, zoomVal + "");
if (!instructionView.isShowingInstructionList())
speedTxt.setVisibility(View.VISIBLE);
if (routeProgress.getCurrentState().name().equals("OFF_ROUTE"))
logUtils.writeToLogFile(TAG + "-Current_state-" + routeProgress.getCurrentState().name());
durationRemainingOnProgress = routeProgress.getDurationRemaining();
addressWithColor = partialAddress;
if (!TextUtils.isEmpty(addressWithColor)) {
Spannable wordToSpan = new SpannableString(addressWithColor);
wordToSpan.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.addressyellow)), 0, addressWithColor.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stepSecondaryText.setVisibility(View.VISIBLE);
stepSecondaryText.setText(wordToSpan);
} else {
stepSecondaryText.setText("");
}
if (!higlightedFootprintAlreadyShown) {
Log.e(TAG, "building_color");
mapboxMap.getStyle(new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded(@NonNull Style style) {
BuildingFootprintHighlightLayer buildingFootprintHighlightLayer = new BuildingFootprintHighlightLayer(mapboxMap);
highlightQueryLatLng = new LatLng(buildingLat, buildingLong);
buildingFootprintHighlightLayer.setQueryLatLng(highlightQueryLatLng);
buildingFootprintHighlightLayer.updateVisibility(true);
logUtils.writeToLogFile(TAG + "--building_color highlighted" + buildingLat + "--" + buildingLong);
Log.e(TAG, "building_color highlighted");
higlightedFootprintAlreadyShown = true;
}
});
}
}
};
private BannerInstructionsObserver bannerInstructionObserver = new BannerInstructionsObserver() {
@Override
public void onNewBannerInstructions(@NotNull BannerInstructions bannerInstructions) {
Log.e(TAG, bannerInstructions.primary().text());
logUtils.writeToLogFile(TAG + "-bannerInstructions.primary()--" + bannerInstructions.toString());
instructionView.updateBannerInstructionsWith(bannerInstructions);
}
};
private VoiceInstructionsObserver voiceInstructionsObserver = new VoiceInstructionsObserver() {
@Override
public void onNewVoiceInstructions(@NotNull VoiceInstructions voiceInstructions) {
if (voiceInstructions.announcement() != null)
logUtils.writeToLogFile(TAG + "-voiceInstructions-- announcement" + voiceInstructions.announcement());
speechPlayer.play(voiceInstructions);
stepSecondaryText.setVisibility(View.VISIBLE);
if (!TextUtils.isEmpty(addressWithColor)) {
Spannable wordToSpan = new SpannableString(addressWithColor);
wordToSpan.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.addressyellow)), 0, addressWithColor.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
stepSecondaryText.setText(wordToSpan);
} else stepSecondaryText.setText(voiceInstructions.announcement());
}
};
private LocationComponent locationComponent;
private PermissionsManager permissionsManager;
private void enableLocationComponent(@NonNull Style loadedMapStyle) {
// Check if permissions are enabled and if not request
if (PermissionsManager.areLocationPermissionsGranted(this)) {
// Activate the MapboxMap LocationComponent to show user location
// Adding in LocationComponentOptions is also an optional parameter
locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(this, loadedMapStyle);
if (checkLocationPermission(NavigationActivity.this))
locationComponent.setLocationComponentEnabled(true);
// Set the component's camera mode
locationComponent.setCameraMode(CameraMode.TRACKING);
locationComponent.setRenderMode(RenderMode.COMPASS);
} else {
permissionsManager = new PermissionsManager(NavigationActivity.this);
permissionsManager.requestLocationPermissions(this);
}
}
private String getRouteProfileFromSharedPreferences() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
return sharedPreferences.getString(
getString(R.string.route_profile_key), DirectionsCriteria.PROFILE_DRIVING_TRAFFIC
);
}
private void fetchRoute(Point origin, Point destination) {
List<Point> list = new ArrayList<>();
UUID uuid = UUID.randomUUID();
list.add(origin);
list.add(destination);
mapboxNavigation.requestRoutes(
RouteOptions.builder()
.accessToken(!IsDirectGo ? getString(R.string.access_token) : getString(R.string.secondary_access_token))
.requestUuid(uuid.toString())
.coordinates(list)
.baseUrl(Constants.BASE_API_URL)
.profile(getRouteProfileFromSharedPreferences())
.user(Constants.MAPBOX_USER)
.voiceUnits(DirectionsCriteria.METRIC)
.voiceInstructions(true)
.bannerInstructions(true)
.continueStraight(true)
.alternatives(true)
.annotations("congestion")
.language("en")
.roundaboutExits(true)
.overview("full")
.exclude(DirectionsCriteria.EXCLUDE_TOLL)
.steps(true)
.build(), routesCallback
);
}
private OnCameraTrackingChangedListener cameraTrackingChangedListener = new OnCameraTrackingChangedListener() {
@Override
public void onCameraTrackingDismissed() {
}
@Override
public void onCameraTrackingChanged(int currentMode) {
if (mapboxNavigation.getTripSessionState() == TripSessionState.STARTED) {
hideWayNameView();
}
}
};
List<String> geometryList;
List<Double> timedurationList;
private RoutesRequestCallback routesCallback = new RoutesRequestCallback() {
@Override
public void onRoutesReady(@NotNull List<? extends DirectionsRoute> list) {
geometryList = new ArrayList<>();
timedurationList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
geometryList.add(list.get(i).geometry());
timedurationList.add(list.get(i).duration());
}
if (Utils.isNetworkAvailable(NavigationActivity.this))
sendGeometryData(geometryList, true, indexVal, timedurationList);
if (navigationMapboxMap != null) {
navigationMapboxMap.addProgressChangeListener(mapboxNavigation);
navigationMapboxMap.addOnCameraTrackingChangedListener(cameraTrackingChangedListener);
if (!TextUtils.isEmpty(indexVal)) {
for (int i = 0; i < list.size(); i++) {
if (Integer.parseInt(indexVal) == i)
directionRoute = list.get(Integer.parseInt(indexVal));
else list.remove(i);
}
} else directionRoute = list.get(0);
if (mapboxNavigation != null)
mapboxNavigation.setRoutes(list);
if (directionRoute != null && navigationMapboxMap != null)
navigationMapboxMap.startCamera(directionRoute);
}
startNavigation();
}
@Override
public void onRoutesRequestFailure(@NotNull Throwable throwable, @NotNull RouteOptions routeOptions) {
Log.e(TAG, "onRoutesRequestFailure");
}
@Override
public void onRoutesRequestCanceled(@NotNull RouteOptions routeOptions) {
Log.e(TAG, "onRoutesRequestCanceled");
}
};
private void startNavigation() {
if (checkLocationPermission(NavigationActivity.this)) {
mapboxNavigation
.getNavigationOptions()
.getLocationEngine()
.getLastLocation(locationListenerCallback);
mapboxNavigation.startTripSession();
}
}
private Boolean checkLocationPermission(Context context) {
String permission = Manifest.permission.ACCESS_FINE_LOCATION;
String permission1 = Manifest.permission.ACCESS_COARSE_LOCATION;
int res = context.checkCallingOrSelfPermission(permission);
int res1 = context.checkCallingOrSelfPermission(permission1);
if (res == 0 && res1 == 0)
return res == PackageManager.PERMISSION_GRANTED;
else
return false;
}
private MapboxReplayer mapboxReplayer = new MapboxReplayer();
private final ReplayRouteMapper replayRouteMapper = new ReplayRouteMapper();
boolean isOnRoute = false;
private NavigationActivity.MyLocationEngineCallback locationListenerCallback = new NavigationActivity.MyLocationEngineCallback(NavigationActivity.this);
int count;
private void callOffRouteAPI(String geometry, boolean isOffroute, double durationRemaining) {
startSpinwheel(false, false);
String url = Utils.frameURLs(NavigationActivity.this) + "/api/DriverOffRouteDetect/DriverOffRouteDetector";
Log.e("OffRouteAPI", url);
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject();
jsonObject.put("DriverNumber", Integer.parseInt(PrefUtil.getABCourierDriverNumberPreference(NavigationActivity.this)));
jsonObject.put("OrderNumber", prevOrderNo);
if (isOffroute) {
jsonObject.put("IsOffRoute", 1);
jsonObject.put("IsOnRoute", 0);
} else {
jsonObject.put("IsOffRoute", 0);
jsonObject.put("IsOnRoute", 1);
}
jsonObject.put("Latitude", latitude);
jsonObject.put("Longitude", longitude);
jsonObject.put("Bearing", bearing);
jsonObject.put("Speed", speedVal);
jsonObject.put("AltRouteGenerated", geometry);
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = df.format(c.getTime());
jsonObject.put("DetectedDateTime", formattedDate);
String hms = String.format("%02d:%02d:%02d", TimeUnit.SECONDS.toHours((long) durationRemaining),
TimeUnit.SECONDS.toMinutes((long) durationRemaining) - TimeUnit.HOURS.toMinutes(TimeUnit.SECONDS.toHours((long) durationRemaining)),
TimeUnit.SECONDS.toSeconds((long) durationRemaining) - TimeUnit.MINUTES.toSeconds(TimeUnit.SECONDS.toMinutes((long) durationRemaining)));
Log.e("eta_duration", hms);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
String currentDateandTime = sdf.format(new Date());
String timeArr[] = hms.split(":");
Date date = null;
try {
date = sdf.parse(currentDateandTime);
} catch (ParseException e) {
logUtils.writeToLogFile(TAG + "-callOffRouteAPI-" + e.getMessage());
e.printStackTrace();
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR, Integer.parseInt(timeArr[0]));
calendar.add(Calendar.MINUTE, Integer.parseInt(timeArr[1]));
calendar.add(Calendar.SECOND, Integer.parseInt(timeArr[2]));
Log.e("Desired Time here ", sdf.format(calendar.getTime()));
jsonObject.put("ETADateTime", sdf.format(calendar.getTime()));
} catch (JSONException e) {
logUtils.writeToLogFile(TAG + "-callOffRouteAPI-" + e.getMessage());
e.printStackTrace();
}
logUtils.writeToLogFile("OffRoute detection url - " + url);
logUtils.writeToLogFile("OffRoute detection params - " + jsonObject.toString());
if (requestQueue == null)
requestQueue = ABCourier.getInstance().getRequestQueue();
// Initialize a new JsonArrayRequest instance
JsonObjectRequest jsonArrayRequest = new JsonObjectRequest(
com.android.volley.Request.Method.POST,
url,
jsonObject,
new com.android.volley.Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
stopSpinWheel();
if (response != null) {
logUtils.writeToLogFile("OffRoute detection response - " + response.toString());
logUtils.writeToLogFile("OffRoute detection response destination - " + destin_lat + "--" + destin_lon);
}
if (!isOnRoute) {
if (!getIsOffroute()) {
if (!TextUtils.isEmpty(directionRoute.geometry())) {
if (durationRemainingOnProgress != 0.0)
callOffRouteAPI(routeGeometry, false, durationRemainingOnProgress);
else
callOffRouteAPI(routeGeometry, false, durationRemaining);
}
}
isOnRoute = true;
}
}
},
new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
stopSpinWheel();
if (error != null && error.getMessage() != null) {
Log.e("OffRoute_Exception", error.getMessage());
logUtils.writeToLogFile("OffRoute exception::" + error.getMessage());
Toast.makeText(NavigationActivity.this, error.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
);
// Add JsonArrayRequest to the RequestQueue
jsonArrayRequest.setRetryPolicy((new DefaultRetryPolicy(
ABCourier_TIMEOUT,
ABCourier_MAX_RETRIES,
ABCourier_BACKOFF_MULT)));
requestQueue.add(jsonArrayRequest);
}
private void sendGeometryData(List<String> geometryList, boolean IsDriverSelected, String indexVal, List<Double> timedurationList) {
startSpinwheel(false, false);
String url = Utils.frameURLs(NavigationActivity.this) + "/api/DriverRouteGeometry/Insert";
// Initialize a new RequestQueue instance
JSONObject jsonObject = new JSONObject();
try {
byte[] bytes = new byte[0];
for (int i = 0; i < geometryList.size(); i++) {
try {
bytes = geometryList.get(i).getBytes("UTF-8");
} catch (Exception e) {
logUtils.writeToLogFile(TAG + "-sendGeometryData-" + e.getMessage());
e.printStackTrace();
}
break;
}
long millis = (new Double(timedurationList.get(0))).longValue(); //129
String hms = String.format("%02d:%02d:%02d", TimeUnit.SECONDS.toHours(millis),
TimeUnit.SECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.SECONDS.toHours(millis)),
TimeUnit.SECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.SECONDS.toMinutes(millis)));
Log.e("timeDuration_current", hms);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
String currentDateandTime = sdf.format(new Date());
String timeArr[] = hms.split(":");
Date date = null;
try {
date = sdf.parse(currentDateandTime);
} catch (ParseException e) {
logUtils.writeToLogFile(TAG + "-sendGeometryData-" + e.getMessage());
e.printStackTrace();
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR, Integer.parseInt(timeArr[0]));
calendar.add(Calendar.MINUTE, Integer.parseInt(timeArr[1]));
calendar.add(Calendar.SECOND, Integer.parseInt(timeArr[2]));
Log.e("Desired Time here ", sdf.format(calendar.getTime()));
if (!TextUtils.isEmpty(indexVal)) {
if (count == Integer.parseInt(indexVal))
jsonObject.put("IsDriverSelected", true);
else jsonObject.put("IsDriverSelected", false);
} else jsonObject.put("IsDriverSelected", true);
count++;
String convertedData = Base64.encodeToString(bytes, Base64.DEFAULT);
jsonObject.put("DriverNumber", Integer.parseInt(PrefUtil.getABCourierDriverNumberPreference(NavigationActivity.this)));
JSONArray orderArr = new JSONArray();
if (!isGroup) {
if (!TextUtils.isEmpty(prevOrderNo)) {
orderArr.put(Integer.parseInt(prevOrderNo));
jsonObject.put("OrderNumber", orderArr);
} else {
orderArr.put(0);
jsonObject.put("OrderNumber", orderArr);
}
} else {
if (groupOrders != null) {
for (int i = 0; i < groupOrders.size(); i++) {
orderArr.put(Integer.parseInt(groupOrders.get(i)));
}
if (orderArr != null) {
jsonObject.put("OrderNumber", orderArr);
} else {
orderArr.put(0);
jsonObject.put("OrderNumber", orderArr);
}
} else {
orderArr.put(0);
jsonObject.put("OrderNumber", orderArr);
}
}
if (btnValue != null && btnValue.equals("Arrived at PickUp Location"))
jsonObject.put("StopType", 1);
else
jsonObject.put("StopType", 2);
jsonObject.put("ETA", sdf.format(calendar.getTime()));
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = df.format(c.getTime());
jsonObject.put("DirectionRequestedTime", formattedDate);
jsonObject.put("Polyline6", convertedData);
} catch (JSONException e) {
logUtils.writeToLogFile(TAG + "-sendGeometryData-" + e.getMessage());
e.printStackTrace();
}
Log.e("Geometry_params", jsonObject.toString());
logUtils.writeToLogFile("Geometry_params - " + jsonObject.toString());
logUtils.writeToLogFile("Geometry_slot_url - " + url);
if (requestQueue == null)
requestQueue = ABCourier.getInstance().getRequestQueue();
// Initialize a new JsonArrayRequest instance
JsonObjectRequest jsonArrayRequest = new JsonObjectRequest(
com.android.volley.Request.Method.POST,
url,
jsonObject,
new com.android.volley.Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
stopSpinWheel();
Log.e("Geometry", geometryList.size() + "--");
if (geometryList != null && geometryList.size() > 0)
geometryList.remove(geometryList.get(0));
if (timedurationList != null && timedurationList.size() > 0)
timedurationList.remove(timedurationList.get(0));
Log.e("Geometry", response.toString());
logUtils.writeToLogFile("Geometryresponse - " + response.toString());
if (geometryList != null && geometryList.size() > 0) {
if (indexVal != null) {
if (Utils.isNetworkAvailable(NavigationActivity.this))
sendGeometryData(geometryList, false, indexVal, timedurationList);
}
}
}
},
new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
stopSpinWheel();
if (error != null && error.getMessage() != null) {
Log.e("Geometry Exception", error.getMessage());
logUtils.writeToLogFile("Geometry exception::" + error.getMessage());
}
}
}
);
// Add JsonArrayRequest to the RequestQueue
jsonArrayRequest.setRetryPolicy((new DefaultRetryPolicy(
ABCourier_TIMEOUT,
ABCourier_MAX_RETRIES,
ABCourier_BACKOFF_MULT)));
requestQueue.add(jsonArrayRequest);
}
@Override
public void onWayNameChanged(@NonNull String wayName) {
wayNameView.updateWayNameText(wayName);
if (summaryBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN) {
hideWayNameView();
} else {
showWayNameView();
}
}
private class MyLocationEngineCallback implements LocationEngineCallback<LocationEngineResult> {
private WeakReference activityRef;
public MyLocationEngineCallback(NavigationActivity NavigationActivity) {
activityRef = new WeakReference(NavigationActivity);
}
@Override
public void onSuccess(LocationEngineResult result) {
if (navigationMapboxMap != null)
navigationMapboxMap.updateLocation(result.getLastLocation());
}
@Override
public void onFailure(@NonNull Exception exception) {
}
}
private void updateCameraOnNavigationStateChange(boolean navigationStarted) {
if (navigationStarted) {
if (navigationMapboxMap != null) {
navigationMapboxMap.updateCameraTrackingMode(NavigationCamera.NAVIGATION_TRACKING_MODE_GPS);
navigationMapboxMap.updateLocationLayerRenderMode(RenderMode.GPS);
}
}
}
@Override
public void onCancelNavigation() {
mapboxNavigation.stopTripSession();
finish();
}
@Override
public void onNavigationFinished() {
}
@Override
public void onNavigationRunning() {
}
@Override
public void onExplanationNeeded(List<String> permissionsToExplain) {
}
@Override
public void onPermissionResult(boolean granted) {
if (granted)
enableLocationComponent(mapboxMap.getStyle());
}
@Override
public boolean onMapLongClick(@NonNull LatLng point) {
return true;
}
public void startSpinwheel(boolean setDefaultLifetime, boolean isCancelable) {
if (NavigationActivity.this.isDestroyed())
return;
if (spinWheelDialog != null && spinWheelDialog.isShowing())
return;
spinWheelDialog = new Dialog(NavigationActivity.this, R.style.wait_spinner_style);
ProgressBar progressBar = new ProgressBar(NavigationActivity.this);
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
spinWheelDialog.addContentView(progressBar, layoutParams);
spinWheelDialog.setCancelable(isCancelable);
spinWheelDialog.show();
// start timer for SPINWHEEL_LIFE_TIME
if (spinWheelTimer == null)
spinWheelTimer = new Handler();
spinWheelTimer.removeCallbacks(dismissSpinner);
if (setDefaultLifetime) // If requested for default dismiss time.
spinWheelTimer.postAtTime(dismissSpinner, SystemClock.uptimeMillis() + SPINWHEEL_LIFE_TIME);
spinWheelDialog.setCanceledOnTouchOutside(false);
}
/*
* Dismiss the spin wheel
*/
Runnable dismissSpinner = new Runnable() {
@Override
public void run() {
stopSpinWheel();
}
};
/*
* Closes the spin wheel dialog
*/
public void stopSpinWheel() {
if (NavigationActivity.this.isDestroyed())
return;
if (spinWheelDialog != null)
spinWheelDialog.dismiss();
spinWheelDialog = null;
}
}
activity_gps_mapview
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigationLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="75dp"
app:mapbox_uiCompass="false" />
<ImageView
android:id="@+id/screenshotView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:ignore="ContentDescription" />
<com.mapbox.navigation.ui.summary.SummaryBottomSheet
android:id="@+id/summaryBottomSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />
<com.mapbox.navigation.ui.map.WayNameView
android:id="@+id/wayNameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:visibility="invisible"
/>
<TextView
android:id="@+id/alertsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/mapbox_alert_view_background"
android:gravity="center_vertical"
android:layout_gravity="bottom"
android:padding="10dp"
android:layout_marginBottom="65dp"
android:textColor="@color/mapboxWhite"
android:textStyle="bold"
android:visibility="gone"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="300dp"
android:layout_marginRight="15dp"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:background="@drawable/square_speed_background"
android:elevation="15dp"
android:layout_marginTop="60dp"
android:gravity="center_horizontal"
android:padding="10dp"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="visible" />
<com.mapbox.navigation.ui.RecenterButton
android:id="@+id/recenterBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/speed"
android:layout_gravity="bottom"
android:paddingBottom="@dimen/mapbox_dimen_8dp"
app:layout_anchorGravity="bottom"
android:visibility="invisible"
/>
</LinearLayout>
</LinearLayout>
<com.mapbox.navigation.ui.instruction.InstructionView
android:id="@+id/instructionView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_above="@+id/linaear"
tools:visibility="visible" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:layout_gravity="bottom"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/order_details_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:background="@xml/custom_button"
android:text="Order Details"
android:textColor="@android:color/white"
android:visibility="gone" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.3"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/complete_trip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:background="@xml/custom_button"
android:text="Arrived at Pick Up Location"
android:textColor="@android:color/white"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
activity_mapview
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigationLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_anchor="@id/summaryBottomSheet"
app:layout_anchorGravity="top"
android:layout_marginBottom="125dp"
app:mapbox_uiCompass="false" />
<ImageView
android:id="@+id/screenshotView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:ignore="ContentDescription" />
<com.mapbox.navigation.ui.summary.SummaryBottomSheet
android:id="@+id/summaryBottomSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_anchor="@id/complete_trip"
app:layout_anchorGravity="top"
android:layout_marginBottom="49dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior" />
<com.mapbox.navigation.ui.map.WayNameView
android:id="@+id/wayNameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:visibility="invisible"
app:layout_anchor="@id/summaryBottomSheet"
app:layout_anchorGravity="center|top" />
<TextView
android:id="@+id/alertsText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"
android:visibility="gone"
android:text="fdsfsdffds"
android:padding="10dp"
android:textColor="@color/mapboxWhite"
android:background="@color/mapbox_alert_view_progress_bar_background"
app:layout_anchor="@id/summaryBottomSheet"
app:layout_anchorGravity="center|top" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="300dp"
android:layout_marginRight="15dp"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:background="@drawable/square_speed_background"
android:elevation="15dp"
android:layout_marginTop="60dp"
android:gravity="center_horizontal"
android:padding="10dp"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="visible" />
<com.mapbox.navigation.ui.RecenterButton
android:id="@+id/recenterBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/speed"
android:layout_gravity="bottom"
android:paddingBottom="@dimen/mapbox_dimen_8dp"
app:layout_anchorGravity="bottom"
android:visibility="invisible"
/>
</LinearLayout>
</LinearLayout>
<com.mapbox.navigation.ui.instruction.InstructionView
android:id="@+id/instructionView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_above="@+id/linaear"
tools:visibility="visible" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:layout_gravity="bottom"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/order_details_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:background="@xml/custom_button"
android:text="Order Details"
android:textColor="@android:color/white"
android:visibility="visible" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.3"
android:orientation="horizontal">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/complete_trip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:background="@xml/custom_button"
android:text="Arrived at Pick Up Location"
android:textColor="@android:color/white"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
<!-- Adding bottom sheet after main content -->
</androidx.coordinatorlayout.widget.CoordinatorLayout>
SharedPreference.xml
<map>
<string name="parking">false</string>
<string name="date">2021-12-10 02:42:00 AM</string>
<string name="scandit_device_id">-------------------------</string>
<string name="orderno">8394286</string>
<string name="morning">10-12-2021</string>
<string name="afternoon">08-12-2021</string>
<string name="odaometer">28175</string>
<string name="order_status">4</string>
<string name="notification">end</string>
<string name="acceptdate">08-12-2021</string>
<string name="eta">14:49 PM</string>
<string name="printer_serial_no">-----------</string>
<string name="evening">06-12-2021</string>
<string name="day">2021-12-10</string>
</map>
Hey @Sridhar261990 could you attach history file for us to debug that case?
Hey @wanfranck , May I know which history file you need?
@Sridhar261990 the one written with the help of HistoryRecorder, it contains all events triggered during the ride.
I have not written HistoryRecorder in my code. Please let me know if you need any other information.
Is that by any chance it will be enabled by default? I am not sure. Just asking you.
@wanfranck I will enable the HistoryRecorder and capture some events for your debugging. Can you please provide me a example for that? I will try to give you the history file by today end of the day.
@Sridhar261990 for now it's won't be really helpful, thank you! Since it's crash history won't really help to debug it. I'll take a look into the problem and reach out to you later.
Hi @wanfranck, Do you have any update on this issue?
@Sridhar261990 I think we found a problem, will keep you updated when a fix be available
@RingerJK Thank you sir.
@RingerJK Thanks Yury! We are eager to deploy a fix to our production fleet as this would greatly improve the driver experience issue we face as a result of this crash.
Thanks again to everyone working to resolve this!
@EricGeiler , right now the issue is fixed for version 2.x. Although the crash on 1.4.0 looks very similar to the crash on 2.x the cause could be different.
It's hard to say for sure what is the cause of the cash on 1.4.0 because there are no steps to reproduce. Right now we have a few different assumptions.
I prepared a special version of 1.4.0 which logs more - 1.4.0-reroute-troubleshooting-SNAPSHOT
. You can see more details about the snapshot in #5286. Can you try to update Android Navigation SDK to the 1.4.0-reroute-troubleshooting-SNAPSHOT
and deploy it to your users? With the snapshot, you will get more info in the crashlytics which helps us identify the cause of the crash. Here you can learn how to use snapshots.
@VysotskiVadim thanks for the snapshot, i've tagged out android developer on this, and will we act accordingly to get the required logs from this snapshot.
@Sridhar261990 Lets discuss this on our daily call pls.
Hi @VysotskiVadim, I have tried updating "com.mapbox.navigation:ui:1.4.0-reroute-troubleshooting-SNAPSHOT". I got too many errors and I cannot use most of the UI components. It seems that it requires code level changes and it is not a simple change. This link shows 1.2.0 snapshot which you provided in the email. Can you please tell me whether I can follow the same example from the link provided? In Case if it requires any code level changes.
Hello @Sridhar261990. What version of the Mapbox Navigation SDK do you use right now? 1.4.0?
I don't want you to change any code. If you use some different version, i.e. not 1.4.0, please tell me the version number and I will create snapshot for you with exactly the same version but with more logs.
@VysotskiVadim I am using 1.4.0 version only. implementation "com.mapbox.navigation:ui:1.4.0".
@Sridhar261990, just to make sure:
maven {
url 'https://api.mapbox.com/downloads/v2/snapshots/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
username = "mapbox"
password = System.getenv("SDK_REGISTRY_TOKEN") // use your download token here
}
}
implementation 'com.mapbox.navigation:ui:1.4.0-reroute-troubleshooting-SNAPSHOT'
And now you're getting build errors with the snapshot, right?
Build successful. I am getting the package errors. I have added the sna
import com.mapbox.navigation.base.options.NavigationOptions; import com.mapbox.navigation.base.trip.model.RouteLegProgress; import com.mapbox.navigation.base.trip.model.RouteProgress; import com.mapbox.navigation.core.MapboxNavigation; import com.mapbox.navigation.core.arrival.ArrivalObserver; import com.mapbox.navigation.core.directions.session.RoutesRequestCallback; import com.mapbox.navigation.core.replay.MapboxReplayer; import com.mapbox.navigation.core.replay.ReplayLocationEngine; import com.mapbox.navigation.core.reroute.RerouteController; import com.mapbox.navigation.core.reroute.RerouteState; import com.mapbox.navigation.core.trip.session.BannerInstructionsObserver; import com.mapbox.navigation.core.trip.session.LocationObserver; import com.mapbox.navigation.core.trip.session.OffRouteObserver; import com.mapbox.navigation.core.trip.session.RouteProgressObserver; import com.mapbox.navigation.core.trip.session.TripSessionState; import com.mapbox.navigation.core.trip.session.TripSessionStateObserver; import com.mapbox.navigation.core.trip.session.VoiceInstructionsObserver; import com.mapbox.navigation.ui.FeedbackButton; import com.mapbox.navigation.ui.NavigationButton; import com.mapbox.navigation.ui.RecenterButton; import com.mapbox.navigation.ui.SoundButton; import com.mapbox.navigation.ui.camera.NavigationCamera; import com.mapbox.navigation.ui.feedback.FeedbackBottomSheet; import com.mapbox.navigation.ui.feedback.FeedbackBottomSheetListener; import com.mapbox.navigation.ui.feedback.FeedbackItem; import com.mapbox.navigation.ui.instruction.InstructionView; import com.mapbox.navigation.ui.listeners.NavigationListener; import com.mapbox.navigation.ui.map.NavigationMapboxMap; import com.mapbox.navigation.ui.map.OnWayNameChangedListener; import com.mapbox.navigation.ui.map.WayNameView; import com.mapbox.navigation.ui.map.building.BuildingFootprintHighlightLayer; import com.mapbox.navigation.ui.route.OnRouteSelectionChangeListener; import com.mapbox.navigation.ui.summary.SummaryBottomSheet; import com.mapbox.navigation.ui.voice.NavigationSpeechPlayer; import com.mapbox.navigation.ui.voice.SpeechPlayerProvider; import com.mapbox.navigation.ui.voice.VoiceInstructionLoader;
@Sridhar261990 ,
Build successful
Does it mean that you're able to build and run your app with the snapshot?
Hi @VysotskiVadim, Sorry. I just forget to modify url 'https://api.mapbox.com/downloads/v2/snapshots/maven' instead of url 'https://api.mapbox.com/downloads/v2/releases/maven'. It is working fine. But I am getting errors in Mapsdk import statements. I am using map sdk version - implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.1' . Should I change the version? I am getting errors in the following import statements. I am using MapView in my app and I am also using all the navigation sdk ui components. There is no error in navigation ui sdk import statements. But I am getting errors only in map sdk.
import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.location.LocationComponent; import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener; import com.mapbox.mapboxsdk.location.modes.CameraMode; import com.mapbox.mapboxsdk.location.modes.RenderMode; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.maps.Style; import com.mapbox.mapboxsdk.offline.CacheAreaDefinition; import com.mapbox.mapboxsdk.offline.OfflineManager;
@Sridhar261990 you need both repos:
your build.gradle setup should look like:
// for releases dependencies
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
username = "mapbox"
password = System.getenv("SDK_REGISTRY_TOKEN") // use your download token here
}
}
// for shapshot dependencies
maven {
url 'https://api.mapbox.com/downloads/v2/snapshots/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
username = "mapbox"
password = System.getenv("SDK_REGISTRY_TOKEN") // use your download token here
}
}
Thank you @RingerJK . I got it.
@Sridhar261990 , nice to hear that the snapshot works. We will be waiting for you to come back with new data related to crash.
@VysotskiVadim We are expecting to roll SNAPSHOT out to our fleet once we finish our current bug fix sprint, we are currently waiting on Rafa Gutierrez @ Mapbox to finish his investigation on Support Ticket #116238
Once we have this pending issue resolved, we will be a position to deploy the SNAPSHOT to our fleet to capture the logging you need via Firebase.
Android API: 30 Mapbox Navigation SDK version: 2.0.0-beta2
Steps to trigger behavior
Expected behavior
Reroute should be successful
Actual behavior
App crashes while trying to reroute
Stacktraces (this has happened a couple of times this morning)