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