1package com.navigine.examples
3import com.navigine.idl.java.*
6 * NavigineSDK usage example for Kotlin
7 * Demonstrates SDK initialization and access to various managers
9class NavigineSdkExample {
11 private var sdk: NavigineSdk? = null
12 private var locationManager: LocationManager? = null
13 private var navigationManager: NavigationManager? = null
14 private var zoneManager: ZoneManager? = null
15 private var routeManager: RouteManager? = null
16 private var asyncRouteManager: AsyncRouteManager? = null
17 private var notificationManager: NotificationManager? = null
18 private var measurementManager: MeasurementManager? = null
19 private var locationListManager: LocationListManager? = null
20 private var storageManager: StorageManager? = null
21 private var mqttSession: MqttSession? = null
22 private var locationWindow: LocationWindow? = null
23 private var routeLayer: RouteLayer? = null
24 private var guidanceCamera: GuidanceCamera? = null
31 * SDK initialization and basic parameter setup
33 private fun initializeSdk() {
35 // [kotlin_NavigineSdk_getInstance]
37 sdk = NavigineSdk.getInstance()
38 // [kotlin_NavigineSdk_getInstance]
40 // [kotlin_NavigineSdk_getVersion]
42 println("Navigine SDK Version: ${NavigineSdk.getVersion()}")
43 // [kotlin_NavigineSdk_getVersion]
45 // [kotlin_NavigineSdk_getDeviceId]
47 println("Device ID: ${NavigineSdk.getDeviceId()}")
48 // [kotlin_NavigineSdk_getDeviceId]
50 // [kotlin_NavigineSdk_getRelativeTime]
52 println("Relative Time: ${NavigineSdk.getRelativeTime()}")
53 // [kotlin_NavigineSdk_getRelativeTime]
55 // [kotlin_NavigineSdk_setUserHash]
56 // Set user hash (authorization token)
57 sdk?.setUserHash("XXXX-XXXX-XXXX-XXXX")
58 // [kotlin_NavigineSdk_setUserHash]
61 // [kotlin_NavigineSdk_getUserAgent]
62 println("User-Agent: ${NavigineSdk.getUserAgent()}")
63 // [kotlin_NavigineSdk_getUserAgent]
65 // [kotlin_NavigineSdk_reset]
67 println("SDK reset to initial state")
68 // [kotlin_NavigineSdk_reset]
70 // [kotlin_NavigineSdk_setServer]
71 // Set server URL (optional)
72 sdk?.setServer("https://custom.navigine.com")
73 // [kotlin_NavigineSdk_setServer]
75 // Initialize managers
78 } catch (e: Exception) {
79 System.err.println("SDK initialization error: ${e.message}")
84 * Initialize all SDK managers
86 private fun initializeManagers() {
87 sdk?.let { sdkInstance ->
88 // [kotlin_NavigineSdk_getLocationManager]
89 // Get LocationManager for working with locations
90 locationManager = sdkInstance.locationManager
91 locationManager?.let {
92 println("LocationManager successfully initialized")
94 // [kotlin_NavigineSdk_getLocationManager]
96 // [kotlin_NavigineSdk_getNavigationManager]
97 // Get NavigationManager for navigation
98 locationManager?.let { locationManager ->
99 navigationManager = sdkInstance.getNavigationManager(locationManager)
100 navigationManager?.let {
101 println("NavigationManager successfully initialized")
104 // [kotlin_NavigineSdk_getNavigationManager]
106 // [kotlin_NavigineSdk_getZoneManager]
107 // Get ZoneManager for working with zones
108 navigationManager?.let { navigationManager ->
109 zoneManager = sdkInstance.getZoneManager(navigationManager)
111 println("ZoneManager successfully initialized")
114 // [kotlin_NavigineSdk_getZoneManager]
116 // [kotlin_NavigineSdk_getRouteManager]
117 // Get RouteManager for building routes
118 locationManager?.let { locationManager ->
119 navigationManager?.let { navigationManager ->
120 routeManager = sdkInstance.getRouteManager(locationManager, navigationManager)
122 println("RouteManager successfully initialized")
126 // [kotlin_NavigineSdk_getRouteManager]
128 // [kotlin_NavigineSdk_getAsyncRouteManager]
129 // Get AsyncRouteManager for async route operations
130 locationManager?.let { locationManager ->
131 navigationManager?.let { navigationManager ->
132 asyncRouteManager = sdkInstance.getAsyncRouteManager(locationManager, navigationManager)
133 asyncRouteManager?.let {
134 println("AsyncRouteManager successfully initialized")
138 // [kotlin_NavigineSdk_getAsyncRouteManager]
140 // [kotlin_NavigineSdk_getNotificationManager]
141 // Get NotificationManager for notifications
142 locationManager?.let { locationManager ->
143 notificationManager = sdkInstance.getNotificationManager(locationManager)
144 notificationManager?.let {
145 println("NotificationManager successfully initialized")
148 // [kotlin_NavigineSdk_getNotificationManager]
150 // [kotlin_NavigineSdk_getMeasurementManager]
151 // Get MeasurementManager for measurements
152 locationManager?.let { locationManager ->
153 measurementManager = sdkInstance.getMeasurementManager(locationManager)
154 measurementManager?.let {
155 println("MeasurementManager successfully initialized")
158 // [kotlin_NavigineSdk_getMeasurementManager]
160 // [kotlin_NavigineSdk_getLocationListManager]
161 // Get LocationListManager for location list operations
162 locationListManager = sdkInstance.locationListManager
163 locationListManager?.let {
164 println("LocationListManager successfully initialized")
166 // [kotlin_NavigineSdk_getLocationListManager]
168 // [kotlin_NavigineSdk_getStorageManager]
169 // Get StorageManager for working with storages
170 storageManager = sdkInstance.storageManager
171 storageManager?.let {
172 println("StorageManager successfully initialized")
174 // [kotlin_NavigineSdk_getStorageManager]
176 // [kotlin_NavigineSdk_getRouteLayer]
177 // Create RouteLayer for building and drawing routes on the map
178 if (locationWindow != null) {
179 routeLayer = sdkInstance.getRouteLayer(locationWindow!!)
181 println("RouteLayer successfully initialized")
184 // [kotlin_NavigineSdk_getRouteLayer]
186 // [kotlin_NavigineSdk_getGuidanceCamera]
187 if (locationWindow != null && routeLayer != null) {
188 guidanceCamera = sdkInstance.getGuidanceCamera(locationWindow!!, routeLayer!!)
189 // [kotlin_GuidanceCamera_setMode]
190 guidanceCamera?.setMode(GuidanceCameraMode.FOLLOWING)
191 // [kotlin_GuidanceCamera_setMode]
192 // [kotlin_GuidanceCamera_set2DMode]
193 guidanceCamera?.set2DMode(false)
194 // [kotlin_GuidanceCamera_set2DMode]
195 // [kotlin_GuidanceCamera_mode]
196 println("Guidance mode: ${guidanceCamera?.mode}")
197 // [kotlin_GuidanceCamera_mode]
198 // [kotlin_GuidanceCamera_instruction]
199 val next = guidanceCamera?.instruction
200 println("Next instruction: ${next?.title} ${next?.distance} m")
201 // [kotlin_GuidanceCamera_instruction]
202 // [kotlin_GuidanceCamera_addListener]
203 guidanceCamera?.addListener(object : GuidanceListener() {
204 override fun onCameraModeChanged(mode: GuidanceCameraMode) {
205 println("Guidance camera mode: $mode")
208 override fun onInstructionChanged(instruction: RouteInstruction?) {
209 println("Next: ${instruction?.title} ${instruction?.distance} m")
212 // [kotlin_GuidanceCamera_addListener]
214 // [kotlin_NavigineSdk_getGuidanceCamera]
216 // [kotlin_NavigineSdk_getRouteSimulator]
217 if (locationWindow != null) {
218 val routeSimulator = sdkInstance.getRouteSimulator(locationWindow!!)
219 // [kotlin_RouteSimulator_setGeometry]
220 val walk = LocationPolyline(
221 listOf(GlobalPoint(55.751, 37.618), GlobalPoint(55.752, 37.618)),
224 routeSimulator.setGeometry(listOf(walk))
225 // [kotlin_RouteSimulator_setGeometry]
226 // [kotlin_RouteSimulator_setSpeed]
227 routeSimulator.setSpeed(1.4f)
228 // [kotlin_RouteSimulator_setSpeed]
229 // [kotlin_RouteSimulator_start]
230 val started = routeSimulator.start()
231 println("Route walk started: $started")
232 // [kotlin_RouteSimulator_start]
233 // [kotlin_RouteSimulator_sample]
234 val sample = routeSimulator.sample
235 println("Walk advance: ${sample?.advance} m")
236 // [kotlin_RouteSimulator_sample]
238 // [kotlin_NavigineSdk_getRouteSimulator]
240 // [kotlin_NavigineSdk_getMqttSession]
241 // Get MqttSession for publishing position data via MQTT
242 navigationManager?.let { navigationManager ->
243 mqttSession = sdkInstance.getMqttSession(navigationManager)
245 println("MqttSession successfully initialized")
248 // [kotlin_NavigineSdk_getMqttSession]
253 * Get information about current SDK state
256 println("=== Navigine SDK Information ===")
257 println("SDK Version: ${NavigineSdk.getVersion()}")
258 println("Device ID: ${NavigineSdk.getDeviceId()}")
259 println("Relative Time: ${NavigineSdk.getRelativeTime()}")
260 println("LocationManager: ${if (locationManager != null) "available" else "unavailable"}")
261 println("NavigationManager: ${if (navigationManager != null) "available" else "unavailable"}")
262 println("ZoneManager: ${if (zoneManager != null) "available" else "unavailable"}")
263 println("RouteManager: ${if (routeManager != null) "available" else "unavailable"}")
264 println("AsyncRouteManager: ${if (asyncRouteManager != null) "available" else "unavailable"}")
265 println("NotificationManager: ${if (notificationManager != null) "available" else "unavailable"}")
266 println("MeasurementManager: ${if (measurementManager != null) "available" else "unavailable"}")
267 println("LocationListManager: ${if (locationListManager != null) "available" else "unavailable"}")
268 println("StorageManager: ${if (storageManager != null) "available" else "unavailable"}")
269 println("MqttSession: ${if (mqttSession != null) "available" else "unavailable"}")
273 * Demonstrate usage of all managers
275 fun demonstrateManagersUsage() {
276 println("=== Manager Usage Demonstration ===")
278 // LocationManager usage example
279 locationManager?.let {
280 println("LocationManager ready for location operations")
281 // Add code here for loading locations, working with them, etc.
284 // NavigationManager usage example
285 navigationManager?.let {
286 println("NavigationManager ready for positioning")
287 // Add code here for getting position, setting up listeners, etc.
290 // ZoneManager usage example
292 println("ZoneManager ready for zone operations")
293 // Add code here for setting up zones, handling enter/exit events, etc.
296 // RouteManager usage example
298 println("RouteManager ready for route building")
299 // Add code here for building routes, setting destination points, etc.
302 // AsyncRouteManager usage example
303 asyncRouteManager?.let {
304 println("AsyncRouteManager ready for async route operations")
305 // Add code here for creating routing sessions, etc.
308 // NotificationManager usage example
309 notificationManager?.let {
310 println("NotificationManager ready for notifications")
311 // Add code here for setting up beacon notifications, etc.
314 // MeasurementManager usage example
315 measurementManager?.let {
316 println("MeasurementManager ready for measurements")
317 // Add code here for managing measurement generators, etc.
320 // LocationListManager usage example
321 locationListManager?.let {
322 println("LocationListManager ready for location list operations")
323 // Add code here for getting available locations list, etc.
326 // StorageManager usage example
327 storageManager?.let {
328 println("StorageManager ready for storage operations")
329 // Add code here for creating storages, managing data, etc.
332 // MqttSession usage example
334 println("MqttSession ready for publishing position data via MQTT")
335 // Add code here for connecting to MQTT broker, publishing positions, etc.
340 * Demonstrate Kotlin features usage
342 fun demonstrateKotlinFeatures() {
343 println("=== Kotlin Features Demonstration ===")
345 // Using let for safe calls
346 sdk?.let { sdkInstance ->
347 sdkInstance.setUserHash("YYYY-YYYY-YYYY-YYYY")
348 println("User hash updated")
351 // Using run for code block execution
354 "version" to NavigineSdk.getVersion(),
355 "deviceId" to NavigineSdk.getDeviceId(),
356 "relativeTime" to NavigineSdk.getRelativeTime()
359 println("SDK Information: $sdkInfo")
361 // Using with for object operations
362 with(locationManager) {
364 println("LocationManager available for operations")
365 // Call LocationManager methods here
369 // Using apply for object configuration
371 setUserHash("ZZZZ-ZZZZ-ZZZZ-ZZZZ")
372 setServer("https://custom.navigine.com")
374 println("SDK settings updated")
378 * Main function for demonstration
382 fun main(args: Array<String>) {
383 val example = NavigineSdkExample()
384 example.printSdkInfo()
385 example.demonstrateManagersUsage()
386 example.demonstrateKotlinFeatures()