Loading...
Searching...
No Matches
DefaultNavigationViewExample.kt
Go to the documentation of this file.
1package com.navigine.examples
2
3import android.content.Context
4import android.view.ViewGroup
5import com.navigine.view.DefaultNavigationView
6import com.navigine.view.DefaultNavigationViewConfig
7import com.navigine.view.widgets.ZoomControls
8import com.navigine.view.widgets.ZoomControlsConfig
9import com.navigine.view.widgets.FollowMeButton
10import com.navigine.view.widgets.FollowMeButtonConfig
11import com.navigine.view.widgets.FloorSelectorView
12import com.navigine.view.widgets.FloorSelectorViewConfig
13import com.navigine.idl.java.LocationWindow
14
15/**
16 * DefaultNavigationView usage example for Kotlin
17 * Demonstrates config, runtime updates, and widget access
18 */
19class DefaultNavigationViewExample(private val context: Context) {
20
21 private var navigationView: DefaultNavigationView? = null
22 private var locationWindow: LocationWindow? = null
23
24 init {
25 demonstrateConstructor()
26 demonstrateZoomControlsConfig()
27 demonstrateFollowMeButtonConfig()
28 demonstrateFloorSelectorViewConfig()
29 demonstrateConfigAtInit()
30 demonstrateRuntimeConfigUpdate()
31 demonstrateWidgetAccess()
32 }
33
34 /**
35 * Demonstrate ZoomControlsConfig
36 */
37 private fun demonstrateZoomControlsConfig() {
38 // [kotlin_ZoomControlsConfig]
39 val zoomConfig = ZoomControlsConfig.builder()
40 .buttonBackgroundColor(0xF2FAFAFA.toInt())
41 .textColor(0xFF152D47.toInt())
42 .buttonWidth(48f)
43 .zoomControlsHeight(96f)
44 .build()
45 // zoomConfig.zoomInIcon(drawable); zoomConfig.zoomOutIcon(drawable)
46 // [kotlin_ZoomControlsConfig]
47 }
48
49 /**
50 * Demonstrate FollowMeButtonConfig
51 */
52 private fun demonstrateFollowMeButtonConfig() {
53 // [kotlin_FollowMeButtonConfig]
54 val followMeConfig = FollowMeButtonConfig.builder()
55 .accentColor(0xFF30AAD9.toInt())
56 .buttonBackgroundColor(0xF2FAFAFA.toInt())
57 .textColor(0xFF152D47.toInt())
58 .buttonWidth(48f)
59 .buttonHeight(48f)
60 .build()
61 // followMeConfig.followMeIcon(drawable); followMeConfig.followMeIconActive(drawable)
62 // [kotlin_FollowMeButtonConfig]
63 }
64
65 /**
66 * Demonstrate FloorSelectorViewConfig
67 */
68 private fun demonstrateFloorSelectorViewConfig() {
69 // [kotlin_FloorSelectorViewConfig]
70 val floorConfig = FloorSelectorViewConfig.builder()
71 .accentColor(0xFF30AAD9.toInt())
72 .textColor(0xFF152D47.toInt())
73 .buttonBackgroundColor(0xF2FAFAFA.toInt())
74 .marginLeft(16)
75 .marginTop(145)
76 .build()
77 // [kotlin_FloorSelectorViewConfig]
78 }
79
80 /**
81 * Demonstrate DefaultNavigationView constructor
82 */
83 private fun demonstrateConstructor() {
84 // [kotlin_DefaultNavigationView_constructor]
85 // Create with default config
86 navigationView = DefaultNavigationView(context).apply {
87 layoutParams = ViewGroup.LayoutParams(
88 ViewGroup.LayoutParams.MATCH_PARENT,
89 ViewGroup.LayoutParams.MATCH_PARENT
90 )
91 }
92 // [kotlin_DefaultNavigationView_constructor]
93
94 // [kotlin_DefaultNavigationView_constructor_config]
95 // Create with custom configs (configs passed directly)
96 val viewConfig = DefaultNavigationViewConfig.builder()
97 .hideFloorSelector()
98 .build()
99 val followMeConfig = FollowMeButtonConfig.builder()
100 .accentColor(0xFF30AAD9.toInt())
101 .build()
102 val customView = DefaultNavigationView(context, null, viewConfig, null, followMeConfig, null)
103 // [kotlin_DefaultNavigationView_constructor_config]
104 }
105
106 /**
107 * Demonstrate config usage at init
108 */
109 private fun demonstrateConfigAtInit() {
110 // [kotlin_DefaultNavigationView_config]
111 val viewConfig = DefaultNavigationViewConfig.builder()
112 .visibleWidgets(DefaultNavigationViewConfig.WIDGET_ZOOM_CONTROLS or DefaultNavigationViewConfig.WIDGET_FOLLOW_ME)
113 .build()
114 val zoomConfig = ZoomControlsConfig.builder()
115 .buttonBackgroundColor(0xF2FAFAFA.toInt())
116 .build()
117 val followMeConfig = FollowMeButtonConfig.builder()
118 .accentColor(0xFF30AAD9.toInt())
119 .build()
120 // followMeConfig.followMeIcon(drawable)
121 // zoomConfig.zoomInIcon(drawable); zoomConfig.zoomOutIcon(drawable)
122 // [kotlin_DefaultNavigationView_config]
123 }
124
125 /**
126 * Demonstrate runtime config update
127 */
128 private fun demonstrateRuntimeConfigUpdate() {
129 // [kotlin_DefaultNavigationView_runtimeConfig]
130 navigationView?.setConfig(
131 DefaultNavigationViewConfig.builder()
132 .visibleWidgets(DefaultNavigationViewConfig.WIDGET_FOLLOW_ME)
133 .build(),
134 null,
135 FollowMeButtonConfig.builder()
136 .accentColor(0xFFFF0000.toInt())
137 .build(),
138 null
139 ) // null = keep current
140 // [kotlin_DefaultNavigationView_runtimeConfig]
141 }
142
143 /**
144 * Demonstrate direct widget access
145 */
146 private fun demonstrateWidgetAccess() {
147 // [kotlin_DefaultNavigationView_widgetAccess]
148 navigationView?.let { view ->
149 val zoomControls: ZoomControls? = view.zoomControls
150 val followMeButton: FollowMeButton? = view.followMeButton
151 val floorSelector: FloorSelectorView? = view.floorSelectorView
152 // Use for advanced customization (may be null if widget is hidden)
153 }
154 // [kotlin_DefaultNavigationView_widgetAccess]
155 }
156}