Loading...
Searching...
No Matches
NavigineSdkExample.kt
Go to the documentation of this file.
1package com.navigine.examples
2
3import com.navigine.idl.java.*
4
5/**
6 * NavigineSDK usage example for Kotlin
7 * Demonstrates SDK initialization and access to various managers
8 */
9class NavigineSdkExample {
10
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
23 init {
24 initializeSdk()
25 }
26
27 /**
28 * SDK initialization and basic parameter setup
29 */
30 private fun initializeSdk() {
31 try {
32 // [kotlin_NavigineSdk_getInstance]
33 // Get SDK instance
34 sdk = NavigineSdk.getInstance()
35 // [kotlin_NavigineSdk_getInstance]
36
37 // [kotlin_NavigineSdk_getVersion]
38 // Get SDK version
39 println("Navigine SDK Version: ${NavigineSdk.getVersion()}")
40 // [kotlin_NavigineSdk_getVersion]
41
42 // [kotlin_NavigineSdk_getDeviceId]
43 // Get device ID
44 println("Device ID: ${NavigineSdk.getDeviceId()}")
45 // [kotlin_NavigineSdk_getDeviceId]
46
47 // [kotlin_NavigineSdk_getRelativeTime]
48 // Get relative time
49 println("Relative Time: ${NavigineSdk.getRelativeTime()}")
50 // [kotlin_NavigineSdk_getRelativeTime]
51
52 // [kotlin_NavigineSdk_setUserHash]
53 // Set user hash (authorization token)
54 sdk?.setUserHash("XXXX-XXXX-XXXX-XXXX")
55 // [kotlin_NavigineSdk_setUserHash]
56
57
58 // [kotlin_NavigineSdk_getUserAgent]
59 println("User-Agent: ${NavigineSdk.getUserAgent()}")
60 // [kotlin_NavigineSdk_getUserAgent]
61
62 // [kotlin_NavigineSdk_reset]
63 sdk!!.reset()
64 println("SDK reset to initial state")
65 // [kotlin_NavigineSdk_reset]
66
67 // [kotlin_NavigineSdk_setServer]
68 // Set server URL (optional)
69 sdk?.setServer("https://custom.navigine.com")
70 // [kotlin_NavigineSdk_setServer]
71
72 // Initialize managers
73 initializeManagers()
74
75 } catch (e: Exception) {
76 System.err.println("SDK initialization error: ${e.message}")
77 }
78 }
79
80 /**
81 * Initialize all SDK managers
82 */
83 private fun initializeManagers() {
84 sdk?.let { sdkInstance ->
85 // [kotlin_NavigineSdk_getLocationManager]
86 // Get LocationManager for working with locations
87 locationManager = sdkInstance.locationManager
88 locationManager?.let {
89 println("LocationManager successfully initialized")
90 }
91 // [kotlin_NavigineSdk_getLocationManager]
92
93 // [kotlin_NavigineSdk_getNavigationManager]
94 // Get NavigationManager for navigation
95 locationManager?.let { locationManager ->
96 navigationManager = sdkInstance.getNavigationManager(locationManager)
97 navigationManager?.let {
98 println("NavigationManager successfully initialized")
99 }
100 }
101 // [kotlin_NavigineSdk_getNavigationManager]
102
103 // [kotlin_NavigineSdk_getZoneManager]
104 // Get ZoneManager for working with zones
105 navigationManager?.let { navigationManager ->
106 zoneManager = sdkInstance.getZoneManager(navigationManager)
107 zoneManager?.let {
108 println("ZoneManager successfully initialized")
109 }
110 }
111 // [kotlin_NavigineSdk_getZoneManager]
112
113 // [kotlin_NavigineSdk_getRouteManager]
114 // Get RouteManager for building routes
115 locationManager?.let { locationManager ->
116 navigationManager?.let { navigationManager ->
117 routeManager = sdkInstance.getRouteManager(locationManager, navigationManager)
118 routeManager?.let {
119 println("RouteManager successfully initialized")
120 }
121 }
122 }
123 // [kotlin_NavigineSdk_getRouteManager]
124
125 // [kotlin_NavigineSdk_getAsyncRouteManager]
126 // Get AsyncRouteManager for async route operations
127 locationManager?.let { locationManager ->
128 navigationManager?.let { navigationManager ->
129 asyncRouteManager = sdkInstance.getAsyncRouteManager(locationManager, navigationManager)
130 asyncRouteManager?.let {
131 println("AsyncRouteManager successfully initialized")
132 }
133 }
134 }
135 // [kotlin_NavigineSdk_getAsyncRouteManager]
136
137 // [kotlin_NavigineSdk_getNotificationManager]
138 // Get NotificationManager for notifications
139 locationManager?.let { locationManager ->
140 notificationManager = sdkInstance.getNotificationManager(locationManager)
141 notificationManager?.let {
142 println("NotificationManager successfully initialized")
143 }
144 }
145 // [kotlin_NavigineSdk_getNotificationManager]
146
147 // [kotlin_NavigineSdk_getMeasurementManager]
148 // Get MeasurementManager for measurements
149 locationManager?.let { locationManager ->
150 measurementManager = sdkInstance.getMeasurementManager(locationManager)
151 measurementManager?.let {
152 println("MeasurementManager successfully initialized")
153 }
154 }
155 // [kotlin_NavigineSdk_getMeasurementManager]
156
157 // [kotlin_NavigineSdk_getLocationListManager]
158 // Get LocationListManager for location list operations
159 locationListManager = sdkInstance.locationListManager
160 locationListManager?.let {
161 println("LocationListManager successfully initialized")
162 }
163 // [kotlin_NavigineSdk_getLocationListManager]
164
165 // [kotlin_NavigineSdk_getStorageManager]
166 // Get StorageManager for working with storages
167 storageManager = sdkInstance.storageManager
168 storageManager?.let {
169 println("StorageManager successfully initialized")
170 }
171 // [kotlin_NavigineSdk_getStorageManager]
172
173 // [kotlin_NavigineSdk_getMqttSession]
174 // Get MqttSession for publishing position data via MQTT
175 navigationManager?.let { navigationManager ->
176 mqttSession = sdkInstance.getMqttSession(navigationManager)
177 mqttSession?.let {
178 println("MqttSession successfully initialized")
179 }
180 }
181 // [kotlin_NavigineSdk_getMqttSession]
182 }
183 }
184
185 /**
186 * Get information about current SDK state
187 */
188 fun printSdkInfo() {
189 println("=== Navigine SDK Information ===")
190 println("SDK Version: ${NavigineSdk.getVersion()}")
191 println("Device ID: ${NavigineSdk.getDeviceId()}")
192 println("Relative Time: ${NavigineSdk.getRelativeTime()}")
193 println("LocationManager: ${if (locationManager != null) "available" else "unavailable"}")
194 println("NavigationManager: ${if (navigationManager != null) "available" else "unavailable"}")
195 println("ZoneManager: ${if (zoneManager != null) "available" else "unavailable"}")
196 println("RouteManager: ${if (routeManager != null) "available" else "unavailable"}")
197 println("AsyncRouteManager: ${if (asyncRouteManager != null) "available" else "unavailable"}")
198 println("NotificationManager: ${if (notificationManager != null) "available" else "unavailable"}")
199 println("MeasurementManager: ${if (measurementManager != null) "available" else "unavailable"}")
200 println("LocationListManager: ${if (locationListManager != null) "available" else "unavailable"}")
201 println("StorageManager: ${if (storageManager != null) "available" else "unavailable"}")
202 println("MqttSession: ${if (mqttSession != null) "available" else "unavailable"}")
203 }
204
205 /**
206 * Demonstrate usage of all managers
207 */
208 fun demonstrateManagersUsage() {
209 println("=== Manager Usage Demonstration ===")
210
211 // LocationManager usage example
212 locationManager?.let {
213 println("LocationManager ready for location operations")
214 // Add code here for loading locations, working with them, etc.
215 }
216
217 // NavigationManager usage example
218 navigationManager?.let {
219 println("NavigationManager ready for positioning")
220 // Add code here for getting position, setting up listeners, etc.
221 }
222
223 // ZoneManager usage example
224 zoneManager?.let {
225 println("ZoneManager ready for zone operations")
226 // Add code here for setting up zones, handling enter/exit events, etc.
227 }
228
229 // RouteManager usage example
230 routeManager?.let {
231 println("RouteManager ready for route building")
232 // Add code here for building routes, setting destination points, etc.
233 }
234
235 // AsyncRouteManager usage example
236 asyncRouteManager?.let {
237 println("AsyncRouteManager ready for async route operations")
238 // Add code here for creating routing sessions, etc.
239 }
240
241 // NotificationManager usage example
242 notificationManager?.let {
243 println("NotificationManager ready for notifications")
244 // Add code here for setting up beacon notifications, etc.
245 }
246
247 // MeasurementManager usage example
248 measurementManager?.let {
249 println("MeasurementManager ready for measurements")
250 // Add code here for managing measurement generators, etc.
251 }
252
253 // LocationListManager usage example
254 locationListManager?.let {
255 println("LocationListManager ready for location list operations")
256 // Add code here for getting available locations list, etc.
257 }
258
259 // StorageManager usage example
260 storageManager?.let {
261 println("StorageManager ready for storage operations")
262 // Add code here for creating storages, managing data, etc.
263 }
264
265 // MqttSession usage example
266 mqttSession?.let {
267 println("MqttSession ready for publishing position data via MQTT")
268 // Add code here for connecting to MQTT broker, publishing positions, etc.
269 }
270 }
271
272 /**
273 * Demonstrate Kotlin features usage
274 */
275 fun demonstrateKotlinFeatures() {
276 println("=== Kotlin Features Demonstration ===")
277
278 // Using let for safe calls
279 sdk?.let { sdkInstance ->
280 sdkInstance.setUserHash("YYYY-YYYY-YYYY-YYYY")
281 println("User hash updated")
282 }
283
284 // Using run for code block execution
285 val sdkInfo = run {
286 mapOf(
287 "version" to NavigineSdk.getVersion(),
288 "deviceId" to NavigineSdk.getDeviceId(),
289 "relativeTime" to NavigineSdk.getRelativeTime()
290 )
291 }
292 println("SDK Information: $sdkInfo")
293
294 // Using with for object operations
295 with(locationManager) {
296 this?.let {
297 println("LocationManager available for operations")
298 // Call LocationManager methods here
299 }
300 }
301
302 // Using apply for object configuration
303 sdk?.apply {
304 setUserHash("ZZZZ-ZZZZ-ZZZZ-ZZZZ")
305 setServer("https://custom.navigine.com")
306 }
307 println("SDK settings updated")
308 }
309
310 /**
311 * Main function for demonstration
312 */
313 companion object {
314 @JvmStatic
315 fun main(args: Array<String>) {
316 val example = NavigineSdkExample()
317 example.printSdkInfo()
318 example.demonstrateManagersUsage()
319 example.demonstrateKotlinFeatures()
320 }
321 }
322}