summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/plugins/utils/PluginGenerationUtil.kt
blob: 9049a282985b229c7d9eab3f5d3ad447d7f3be73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.mapbox.mapboxsdk.plugins.utils

import android.content.Context
import android.support.v7.app.AppCompatActivity
import com.mapbox.android.core.location.LocationEngine
import com.mapbox.mapboxsdk.maps.MapView
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerOptions
import com.mapbox.mapboxsdk.plugins.locationlayer.LocationLayerPlugin

class PluginGenerationUtil {
  companion object {
    fun getLocationLayerPluginProvider(activity: AppCompatActivity,
                                       useDefaultEngine: Boolean = false,
                                       engine: LocationEngine? = null,
                                       options: LocationLayerOptions? = null,
                                       registerLifecycleObserver: Boolean = true)
      : GenericPluginAction.PluginProvider<LocationLayerPlugin> {
      return object : GenericPluginAction.PluginProvider<LocationLayerPlugin> {
        override fun providePlugin(mapView: MapView, mapboxMap: MapboxMap, context: Context): LocationLayerPlugin {
          val plugin = if (useDefaultEngine) {
              if (options != null) {
                  LocationLayerPlugin(mapView, mapboxMap, options)
              } else {
                  LocationLayerPlugin(mapView, mapboxMap)
              }
          } else {
              if (options != null) {
                  LocationLayerPlugin(mapView, mapboxMap, engine, options)
              } else {
                  LocationLayerPlugin(mapView, mapboxMap, engine)
              }
          }

          if (registerLifecycleObserver) {
            activity.lifecycle.addObserver(plugin)
          }

          return plugin
        }

        override fun isPluginDataReady(plugin: LocationLayerPlugin, mapboxMap: MapboxMap): Boolean {
          return mapboxMap.getSource("mapbox-location-source") != null
        }
      }
    }

    const val MAP_RENDER_DELAY = 250L
    const val MAP_CONNECTION_DELAY = 1000L
  }
}