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