react-native-pointr 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # react-native-pointr
2
+ Public repository for Pointr Mobile SDK React-Native Package
3
+ https://npmjs.org/pointrlabs/react-native-pointr
@@ -0,0 +1,105 @@
1
+ buildscript {
2
+ // Buildscript is evaluated before everything else so we can't use getExtOrDefault
3
+ def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["Pointr_kotlinVersion"]
4
+
5
+ repositories {
6
+ google()
7
+ mavenCentral()
8
+ }
9
+
10
+ dependencies {
11
+ classpath "com.android.tools.build:gradle:7.2.1"
12
+ // noinspection DifferentKotlinGradleVersion
13
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
+ }
15
+ }
16
+
17
+ def reactNativeArchitectures() {
18
+ def value = rootProject.getProperties().get("reactNativeArchitectures")
19
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
20
+ }
21
+
22
+ def isNewArchitectureEnabled() {
23
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
24
+ }
25
+
26
+ apply plugin: "com.android.library"
27
+ apply plugin: "kotlin-android"
28
+
29
+ if (isNewArchitectureEnabled()) {
30
+ apply plugin: "com.facebook.react"
31
+ }
32
+
33
+ def getExtOrDefault(name) {
34
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Pointr_" + name]
35
+ }
36
+
37
+ def getExtOrIntegerDefault(name) {
38
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Pointr_" + name]).toInteger()
39
+ }
40
+
41
+ def supportsNamespace() {
42
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
43
+ def major = parsed[0].toInteger()
44
+ def minor = parsed[1].toInteger()
45
+
46
+ // Namespace support was added in 7.3.0
47
+ return (major == 7 && minor >= 3) || major >= 8
48
+ }
49
+
50
+ android {
51
+ if (supportsNamespace()) {
52
+ namespace "com.pointr"
53
+
54
+ sourceSets {
55
+ main {
56
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
57
+ }
58
+ }
59
+ }
60
+
61
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
62
+
63
+ defaultConfig {
64
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
65
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
66
+
67
+ }
68
+
69
+ buildTypes {
70
+ release {
71
+ minifyEnabled false
72
+ }
73
+ }
74
+
75
+ lintOptions {
76
+ disable "GradleCompatible"
77
+ }
78
+
79
+ compileOptions {
80
+ sourceCompatibility JavaVersion.VERSION_1_8
81
+ targetCompatibility JavaVersion.VERSION_1_8
82
+ }
83
+ }
84
+
85
+ repositories {
86
+ mavenCentral()
87
+ google()
88
+ }
89
+
90
+ def kotlin_version = getExtOrDefault("kotlinVersion")
91
+
92
+ dependencies {
93
+ // For < 0.71, this will be from the local maven repo
94
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
95
+ //noinspection GradleDynamicVersion
96
+ implementation "com.facebook.react:react-native:+"
97
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
98
+ implementation "com.pointrlabs:pointr:8.13.0"
99
+ implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
100
+ implementation 'androidx.appcompat:appcompat:1.7.0'
101
+ implementation 'com.google.android.material:material:1.12.0'
102
+ implementation 'androidx.activity:activity:1.9.1'
103
+ implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
104
+ }
105
+
@@ -0,0 +1,5 @@
1
+ Pointr_kotlinVersion=1.8.10
2
+ Pointr_minSdkVersion=28
3
+ Pointr_targetSdkVersion=34
4
+ Pointr_compileSdkVersion=34
5
+ Pointr_ndkversion=25.2.9519653
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
3
+ <application>
4
+ <activity
5
+ android:name="com.pointr.PointrMapWidgetActivity"
6
+ android:exported="true"
7
+ android:launchMode="singleTask"
8
+ android:screenOrientation="portrait">
9
+ </activity>
10
+ </application>
11
+ </manifest>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
3
+ <application>
4
+ <activity
5
+ android:name="com.pointr.PointrMapWidgetActivity"
6
+ android:exported="true"
7
+ android:launchMode="singleTask"
8
+ android:screenOrientation="portrait">
9
+ </activity>
10
+ </application>
11
+ </manifest>
@@ -0,0 +1,403 @@
1
+ package com.pointr
2
+
3
+ import android.annotation.SuppressLint
4
+ import android.content.Intent
5
+ import android.os.Build
6
+ import android.os.Bundle
7
+ import android.os.Handler
8
+ import android.util.Log
9
+ import android.view.WindowManager
10
+ import android.widget.TextView
11
+ import android.widget.Toast
12
+ import androidx.appcompat.app.AppCompatActivity
13
+ import androidx.constraintlayout.widget.ConstraintLayout
14
+ import com.pointrlabs.core.management.Pointr
15
+ import com.pointrlabs.core.management.interfaces.PointrListener
16
+ import com.pointrlabs.core.map.viewmodels.PTRMapWidgetConfiguration
17
+ import com.pointrlabs.core.map.views.PTRMapAnimationType
18
+ import com.pointrlabs.core.map.views.PTRMapWidgetFragment
19
+ import com.pointrlabs.core.nativecore.wrappers.Plog
20
+ import com.pointrlabs.core.positioning.model.PositioningTypes.INVALID_INTEGER
21
+ import com.facebook.react.bridge.Callback
22
+ import com.pointr.PointrModule.Companion.mapEventsListenerKey
23
+ import com.pointrlabs.core.geometry.GeoPoint
24
+ import com.pointrlabs.core.map.handlers.ExitButtonEventsHandler
25
+ import com.pointrlabs.core.map.models.PTRMapSymbolLayer
26
+ import com.pointrlabs.core.map.models.events_listeners.MapEventsListener
27
+ import java.lang.IllegalArgumentException
28
+
29
+
30
+ /**
31
+ * This activity is the activity where the Pointr Map is served to the user.
32
+ * Any UI related operation can be performed here
33
+ */
34
+ @SuppressLint("LogNotTimber")
35
+ class PointrMapWidgetActivity : AppCompatActivity() {
36
+
37
+ companion object {
38
+ const val destinationPoiExternalIdentifierKey = "destinationPoiExternalIdentifier"
39
+ const val sourcePoiExternalIdentifierKey = "sourcePoiExternalIdentifier"
40
+ const val SHOW_PATHFINDING_BETWEEN_POIS = "showPathBetweenPOIs"
41
+ const val SHOW_SITE = "showSite"
42
+ const val SHOW_BUILDING = "showBuilding"
43
+ const val SHOW_LEVEL = "showLevel"
44
+ const val SHOW_PATHFINDING_TO_POI = "showPathfindingToPoi"
45
+ const val SHOW_POI_DETAILS = "showPoiDetails"
46
+ const val animationTypeKey = "animationType"
47
+ const val siteExternalIdentifierKey = "siteExternalId"
48
+ const val buildingExternalIdentifierKey = "buildingExternalId"
49
+ const val levelIndexKey = "levelIndex"
50
+ const val poiExternalIdentifierKey = "poiExternalId"
51
+ var callback: Callback? = null
52
+ val mapWidgetConfiguration = PTRMapWidgetConfiguration.defaultConfiguration()
53
+ }
54
+
55
+ var pendingAction: () -> Unit = {}
56
+
57
+ private var ptrMapWidgetFragment: PTRMapWidgetFragment? = null
58
+
59
+ private var mapEventsListener: MapEventsListener? = null
60
+
61
+ val pointr: Pointr?
62
+ get() {
63
+ return Pointr.getPointr()
64
+ }
65
+
66
+ private val pointrListener = object : PointrListener {
67
+ override fun onStateUpdated(p0: Pointr.State?) {
68
+ Plog.v("Pointr state updated: ${p0?.name}")
69
+ if (p0 == Pointr.State.RUNNING) {
70
+ Plog.v("Pointr is Running")
71
+ pointr?.removeListener(this)
72
+ runOnUiThread {
73
+ pendingAction.invoke()
74
+ pendingAction = {}
75
+ }
76
+ } else if (p0 == Pointr.State.FAILED_VALIDATION
77
+ || p0 == Pointr.State.FAILED_REGISTRATION
78
+ || p0 == Pointr.State.FAILED_INVALID_DEEPLINK_URL
79
+ || p0 == Pointr.State.NO_INTERNET
80
+ || p0 == Pointr.State.OFF
81
+ ) {
82
+ Plog.e("Pointr could not start. Current state: ${p0.name}")
83
+ callback?.invoke("Starting Pointr resulted in ${p0.name}")
84
+ callback = null
85
+ pointr?.removeListener(this)
86
+ runOnUiThread {
87
+ Toast.makeText(applicationContext, "Could not start maps.", Toast.LENGTH_LONG)
88
+ .show()
89
+ finish()
90
+ }
91
+
92
+ }
93
+ }
94
+ }
95
+
96
+ override fun onCreate(savedInstanceState: Bundle?) {
97
+ super.onCreate(savedInstanceState)
98
+ setContentView(R.layout.pointr_map_widget_activity_layout)
99
+ val attrib = window.attributes
100
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
101
+ attrib.layoutInDisplayCutoutMode =
102
+ WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
103
+ findViewById<ConstraintLayout>(R.id.pointr_map_widget_activity_layout).setOnApplyWindowInsetsListener { _, windowInsets ->
104
+ val inset = windowInsets.displayCutout
105
+ Log.d("Tag", "Inset: $inset")
106
+ windowInsets
107
+ }
108
+ }
109
+ if (pointr == null) {
110
+ Plog.e("CRITICAL!! Pointr is null. Did you call Pointr.with before?")
111
+ return
112
+ }
113
+ pointr?.addListener(pointrListener)
114
+ pendingAction = { showMapWidgetBasedOnAction() }
115
+ if (pointr?.state == Pointr.State.RUNNING) {
116
+ Plog.v("Pointr already running - will invoke the action.")
117
+ pendingAction.invoke()
118
+ pendingAction = {}
119
+ pointr?.removeListener(pointrListener)
120
+ } else {
121
+ Plog.v("Starting Pointr...")
122
+ Thread {
123
+ pointr?.start()
124
+ }.start()
125
+ }
126
+ }
127
+
128
+ override fun onDestroy() {
129
+ pointr?.removeListener(pointrListener)
130
+ mapEventsListener?.let { ptrMapWidgetFragment?.removeListener(it) }
131
+ ptrMapWidgetFragment?.let {
132
+ supportFragmentManager.beginTransaction().remove(it).commitAllowingStateLoss()
133
+ }
134
+ callback = null
135
+ pendingAction = {}
136
+ super.onDestroy()
137
+ }
138
+
139
+ private fun showMapWidgetBasedOnAction() {
140
+
141
+ PTRMapWidgetFragment.newInstance(configuration = mapWidgetConfiguration) {
142
+ ptrMapWidgetFragment = it.show(supportFragmentManager, R.id.fragment_container)
143
+ ptrMapWidgetFragment?.exitButtonEventsHandler = object : ExitButtonEventsHandler() {
144
+ override fun onExitClicked(mapWidget: PTRMapWidgetFragment, exitButton: TextView) {
145
+ this@PointrMapWidgetActivity.finish()
146
+ }
147
+ }
148
+ mapEventsListener = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
149
+ intent.getParcelableExtra(
150
+ mapEventsListenerKey,
151
+ PointrModule.CustomMapEventsListener::class.java
152
+ )
153
+ } else {
154
+ intent.getParcelableExtra(mapEventsListenerKey)
155
+ }
156
+ mapEventsListener?.let { ptrMapWidgetFragment?.addListener(it) }
157
+ when (intent.action) {
158
+ SHOW_SITE -> {
159
+ val siteExternalId = intent.getStringExtra(siteExternalIdentifierKey)
160
+ if (siteExternalId != null) {
161
+ val animationTypeInt = intent.getIntExtra(animationTypeKey, 0)
162
+ val animationType = try {
163
+ PTRMapAnimationType.entries[animationTypeInt]
164
+ } catch (ex: IllegalArgumentException) {
165
+ PTRMapAnimationType.flyOver
166
+ }
167
+ ptrMapWidgetFragment?.showSite(siteExternalId, animationType) {
168
+ callback?.invoke(it)
169
+ callback = null
170
+ }
171
+ } else {
172
+ Plog.e("Site External Id not provided")
173
+ callback?.invoke("Site External Id not provided")
174
+ callback = null
175
+ }
176
+ }
177
+
178
+ SHOW_BUILDING -> {
179
+ val siteExternalId = intent.getStringExtra(siteExternalIdentifierKey)
180
+ val buildingExternalId = intent.getStringExtra(buildingExternalIdentifierKey)
181
+ if (siteExternalId != null && buildingExternalId != null) {
182
+ val animationTypeInt = intent.getIntExtra(animationTypeKey, 0)
183
+ val animationType = try {
184
+ PTRMapAnimationType.values()[animationTypeInt]
185
+ } catch (ex: IllegalArgumentException) {
186
+ PTRMapAnimationType.flyOver
187
+ }
188
+ ptrMapWidgetFragment?.showBuilding(
189
+ siteExternalId,
190
+ buildingExternalId,
191
+ animationType
192
+ ) {
193
+ callback?.invoke(it)
194
+ callback = null
195
+ }
196
+ } else {
197
+ Plog.e("Site or Building Id not provided")
198
+ callback?.invoke("Site or Building Id not provided")
199
+ callback = null
200
+ }
201
+ }
202
+
203
+ SHOW_LEVEL -> {
204
+ val siteExternalId = intent.getStringExtra(siteExternalIdentifierKey)
205
+ val buildingExternalId = intent.getStringExtra(buildingExternalIdentifierKey)
206
+ val levelIndex = intent.getIntExtra(levelIndexKey, INVALID_INTEGER)
207
+ if (siteExternalId != null && buildingExternalId != null && levelIndex != INVALID_INTEGER) {
208
+ val animationTypeInt = intent.getIntExtra(animationTypeKey, 0)
209
+ val animationType = try {
210
+ PTRMapAnimationType.values()[animationTypeInt]
211
+ } catch (ex: IllegalArgumentException) {
212
+ PTRMapAnimationType.flyOver
213
+ }
214
+ ptrMapWidgetFragment?.showLevel(
215
+ siteExternalId,
216
+ buildingExternalId,
217
+ levelIndex,
218
+ animationType
219
+ ) {
220
+ callback?.invoke(it)
221
+ callback = null
222
+ }
223
+ } else {
224
+ Plog.e("Site or Building Id not provided")
225
+ callback?.invoke("Site or Building Id not provided")
226
+ callback = null
227
+ }
228
+ }
229
+
230
+ SHOW_POI_DETAILS -> {
231
+ val siteExternalId = intent.getStringExtra(siteExternalIdentifierKey)
232
+ val poiExternalId = intent.getStringExtra(poiExternalIdentifierKey)
233
+ if (siteExternalId != null && poiExternalId != null) {
234
+ val animationTypeInt = intent.getIntExtra(animationTypeKey, 0)
235
+ val animationType = try {
236
+ PTRMapAnimationType.values()[animationTypeInt]
237
+ } catch (ex: IllegalArgumentException) {
238
+ PTRMapAnimationType.flyOver
239
+ }
240
+ ptrMapWidgetFragment?.showPoiDetails(
241
+ siteExternalId,
242
+ poiExternalId,
243
+ animationType
244
+ ) {
245
+ callback?.invoke(it)
246
+ callback = null
247
+ }
248
+ } else {
249
+ Plog.e("Site or Poi Id not provided")
250
+ callback?.invoke("Site or Poi Id not provided")
251
+ callback = null
252
+ }
253
+ }
254
+
255
+ SHOW_PATHFINDING_TO_POI -> {
256
+ val siteExternalId = intent.getStringExtra(siteExternalIdentifierKey)
257
+ val poiExternalId = intent.getStringExtra(poiExternalIdentifierKey)
258
+ if (siteExternalId != null && poiExternalId != null) {
259
+ val animationTypeInt = intent.getIntExtra(animationTypeKey, 0)
260
+ val animationType = try {
261
+ PTRMapAnimationType.values()[animationTypeInt]
262
+ } catch (ex: IllegalArgumentException) {
263
+ PTRMapAnimationType.flyOver
264
+ }
265
+ ptrMapWidgetFragment?.showPathFinding(
266
+ siteExternalId,
267
+ poiExternalId,
268
+ animationType
269
+ ) {
270
+ callback?.invoke(it)
271
+ callback = null
272
+ }
273
+ } else {
274
+ Plog.e("Site or Poi Id not provided")
275
+ callback?.invoke("Site or Poi Id not provided")
276
+ callback = null
277
+ }
278
+ }
279
+
280
+ SHOW_PATHFINDING_BETWEEN_POIS -> {
281
+ internalShowPathFindingBetweenPois(intent)
282
+ }
283
+ }
284
+ }
285
+ }
286
+
287
+ private fun internalShowPathFindingBetweenPois(intent: Intent) {
288
+ val siteExternalId = intent.getStringExtra(siteExternalIdentifierKey) ?: run {
289
+ this@PointrMapWidgetActivity.finish()
290
+ callback?.invoke("Site is not provided")
291
+ callback = null
292
+ return
293
+ }
294
+ val sourcePoiExternalId = intent.getStringExtra(sourcePoiExternalIdentifierKey) ?: run {
295
+ this@PointrMapWidgetActivity.finish()
296
+ callback?.invoke("Source poi is not provided")
297
+ callback = null
298
+ return
299
+ }
300
+ val destinationPoiExternalId =
301
+ intent.getStringExtra(destinationPoiExternalIdentifierKey) ?: run {
302
+ this@PointrMapWidgetActivity.finish()
303
+ callback?.invoke("Destination poi is not provided")
304
+ callback = null
305
+ return
306
+ }
307
+ val animationTypeInt = intent.getIntExtra(animationTypeKey, 0)
308
+ val animationType = try {
309
+ PTRMapAnimationType.values()[animationTypeInt]
310
+ } catch (ex: IllegalArgumentException) {
311
+ PTRMapAnimationType.flyOver
312
+ }
313
+ val siteManager = pointr?.siteManager ?: run {
314
+ this@PointrMapWidgetActivity.finish()
315
+ callback?.invoke("Site Manager is not ready")
316
+ callback = null
317
+ return
318
+ }
319
+ val poiManager = pointr?.poiManager ?: run {
320
+ this@PointrMapWidgetActivity.finish()
321
+ callback?.invoke("Poi Manager is not ready")
322
+ callback = null
323
+ return
324
+ }
325
+ val pathManager = pointr?.pathManager ?: run {
326
+ this@PointrMapWidgetActivity.finish()
327
+ callback?.invoke("Path Manager is not ready")
328
+ callback = null
329
+ return
330
+ }
331
+ val site = siteManager.getSite(siteExternalId) ?: run {
332
+ this@PointrMapWidgetActivity.finish()
333
+ callback?.invoke("Site `$siteExternalId` does not exist.")
334
+ callback = null
335
+ return
336
+ }
337
+ val sourcePoi = poiManager.getPoiByExternalIdentifier(site, sourcePoiExternalId) ?: run {
338
+ this@PointrMapWidgetActivity.finish()
339
+ callback?.invoke("Source poi `$sourcePoiExternalId` does not exist within site `${site.title}`.")
340
+ callback = null
341
+ return
342
+ }
343
+ val destinationPoi =
344
+ poiManager.getPoiByExternalIdentifier(site, destinationPoiExternalId) ?: run {
345
+ this@PointrMapWidgetActivity.finish()
346
+ callback?.invoke("Destination poi `$destinationPoiExternalId` does not exist within site ${site.title}.")
347
+ callback = null
348
+ return
349
+ }
350
+ val path = pathManager.calculatePath(sourcePoi, listOf(destinationPoi)) ?: run {
351
+ this@PointrMapWidgetActivity.finish()
352
+ callback?.invoke("Unable to calculate path")
353
+ callback = null
354
+ return
355
+ }
356
+ ptrMapWidgetFragment?.showLevel(sourcePoi.level!!, animationType, true) { error ->
357
+ error?.let {
358
+ this@PointrMapWidgetActivity.finish()
359
+ callback?.invoke(it)
360
+ callback = null
361
+ return@showLevel
362
+ }
363
+ val handler = Handler(mainLooper)
364
+ handler.post {
365
+ val mapFragment = ptrMapWidgetFragment?.mapFragment ?: run {
366
+ this@PointrMapWidgetActivity.finish()
367
+ callback?.invoke("Map is not ready")
368
+ callback = null
369
+ return@post
370
+ }
371
+ val layer = PTRMapSymbolLayer()
372
+ mapFragment.addLayer(layer) { b1, e1 ->
373
+ if (!b1) {
374
+ this@PointrMapWidgetActivity.finish()
375
+ callback?.invoke(e1)
376
+ callback = null
377
+ return@addLayer
378
+ }
379
+ mapFragment.addFeatures(
380
+ listOf(sourcePoi, destinationPoi),
381
+ layer.identifier
382
+ ) { b2, e2 ->
383
+ if (!b2) {
384
+ this@PointrMapWidgetActivity.finish()
385
+ callback?.invoke(e2)
386
+ callback = null
387
+ return@addFeatures
388
+ }
389
+ mapFragment.zoomToLocation(
390
+ GeoPoint(
391
+ sourcePoi.location.lat,
392
+ sourcePoi.location.lon
393
+ )
394
+ )
395
+ mapFragment.currentPath = path
396
+ callback?.invoke(null)
397
+ callback = null
398
+ }
399
+ }
400
+ }
401
+ }
402
+ }
403
+ }