Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (c) 2019 Razeware LLC
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * Notwithstanding the foregoing, you may not use, copy, modify, merge, publish,
- * distribute, sublicense, create a derivative work, and/or sell copies of the
- * Software in any work that is designed, intended, or marketed for pedagogical or
- * instructional purposes related to programming, coding, application development,
- * or information technology. Permission for such use, copying, modification,
- * merger, publication, distribution, sublicensing, creation of derivative works,
- * or sale is expressly withheld.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- package com.raywenderlich.where2go
- import android.annotation.SuppressLint
- import android.app.Activity
- import android.app.Application
- import android.content.Intent
- import android.location.Location
- import android.os.Bundle
- import android.os.Environment
- import android.preference.PreferenceManager
- import android.support.v7.app.AppCompatActivity
- import android.util.Log
- import android.widget.Toast
- import com.google.android.gms.common.api.ApiException
- import com.google.android.gms.common.api.ResolvableApiException
- import com.google.android.gms.location.*
- import com.mapbox.android.core.location.LocationEngine
- import com.mapbox.android.core.location.LocationEngineListener
- import com.mapbox.android.core.location.LocationEnginePriority
- import com.mapbox.android.core.location.LocationEngineProvider
- import com.mapbox.android.core.permissions.PermissionsListener
- import com.mapbox.android.core.permissions.PermissionsManager
- import com.mapbox.api.directions.v5.DirectionsCriteria
- import com.mapbox.api.directions.v5.models.DirectionsResponse
- import com.mapbox.api.directions.v5.models.DirectionsRoute
- import com.mapbox.api.matching.v5.MapboxMapMatching
- import com.mapbox.api.matching.v5.models.MapMatchingResponse
- import com.mapbox.geojson.Point
- import com.mapbox.mapboxsdk.Mapbox
- import com.mapbox.mapboxsdk.annotations.MarkerOptions
- import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
- import com.mapbox.mapboxsdk.geometry.LatLng
- import com.mapbox.mapboxsdk.location.LocationComponent
- import com.mapbox.mapboxsdk.location.modes.CameraMode
- import com.mapbox.mapboxsdk.maps.MapboxMap
- import com.mapbox.mapboxsdk.maps.OnMapReadyCallback
- import com.mapbox.mapboxsdk.style.light.Position
- import com.mapbox.services.android.navigation.ui.v5.NavigationLauncher
- import com.mapbox.services.android.navigation.ui.v5.NavigationLauncherOptions
- import com.mapbox.services.android.navigation.ui.v5.route.NavigationMapRoute
- import com.mapbox.services.android.navigation.v5.navigation.*
- import kotlinx.android.synthetic.main.activity_main.*
- import retrofit2.Call
- import retrofit2.Callback
- import retrofit2.Response
- import timber.log.Timber
- import java.io.File
- import java.io.IOException
- import java.io.InputStream
- import java.nio.charset.Charset
- class MainActivity : AppCompatActivity(),
- PermissionsListener, LocationEngineListener, OnMapReadyCallback, MapboxMap.OnMapClickListener {
- //1
- val REQUEST_CHECK_SETTINGS = 1
- var settingsClient: SettingsClient? = null
- private val TEST_GPX = "parcourstestguidos.gpx"
- private val TILE_PATH_NAME = "2018_11_18-22_33_58"
- var flag = true
- var origino: Point? = null
- var druga: Point? = null
- var numo = 0
- //2
- lateinit var map: MapboxMap
- lateinit var permissionManager: PermissionsManager
- var originLocation: Location? = null
- var locationEngine: LocationEngine? = null
- var locationComponent: LocationComponent? = null
- var navigationMapRoute: NavigationMapRoute? = null
- var currentRoute: DirectionsRoute? = null
- var currentRoute2: DirectionsRoute? = null
- private val mapboxOfflineRouter: MapboxOfflineRouter
- get() {
- return MapboxOfflineRouter(obtainOfflineDirectory())
- }
- private fun obtainOfflineDirectory(): String {
- val offline = Environment.getExternalStoragePublicDirectory("Offline")
- if (!offline.exists()) {
- Timber.d("Offline directory does not exist")
- offline.mkdirs()
- }
- return offline.absolutePath
- }
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- Mapbox.getInstance(this, "pk.eyJ1IjoibWFuZXYxNSIsImEiOiJjaWgwazg1a2Mwd2txdnFtM3p1dnNvbjJkIn0.fvNagTH12eCx2IwmoDdgRw")
- setContentView(R.layout.activity_main)
- mapbox.onCreate(savedInstanceState)
- mapbox.getMapAsync(this)
- settingsClient = LocationServices.getSettingsClient(this)
- btnNavigate.isEnabled = true
- btnNavigate.setOnClickListener {
- // val intent = Intent(this, OfflineRegionDownloadActivity::class.java)
- // startActivity(intent)
- val intent = Intent(this, EndNavigationActivity::class.java)
- startActivity(intent)
- // val navigationLauncherOptions = NavigationLauncherOptions.builder() //1
- // .directionsRoute(currentRoute) //2
- // .shouldSimulateRoute(true) //3
- // .build()
- //
- // NavigationLauncher.startNavigation(this, navigationLauncherOptions) //4
- }
- }
- override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
- super.onActivityResult(requestCode, resultCode, data)
- if (requestCode == REQUEST_CHECK_SETTINGS) {
- if (resultCode == Activity.RESULT_OK) {
- enableLocation()
- } else
- if (resultCode == Activity.RESULT_CANCELED) {
- finish()
- }
- }
- }
- @SuppressWarnings("MissingPermission")
- override fun onStart() {
- super.onStart()
- if (PermissionsManager.areLocationPermissionsGranted(this)) {
- locationEngine?.requestLocationUpdates()
- locationComponent?.onStart()
- }
- mapbox.onStart()
- }
- override fun onResume() {
- super.onResume()
- mapbox.onResume()
- }
- override fun onPause() {
- super.onPause()
- mapbox.onPause()
- }
- override fun onStop() {
- super.onStop()
- locationEngine?.removeLocationUpdates()
- locationComponent?.onStop()
- mapbox.onStop()
- }
- override fun onDestroy() {
- super.onDestroy()
- locationEngine?.deactivate()
- mapbox.onDestroy()
- }
- override fun onLowMemory() {
- super.onLowMemory()
- mapbox.onLowMemory()
- }
- override fun onSaveInstanceState(outState: Bundle?) {
- super.onSaveInstanceState(outState)
- if (outState != null) {
- mapbox.onSaveInstanceState(outState)
- }
- }
- override fun onExplanationNeeded(permissionsToExplain: MutableList<String>?) {
- Toast.makeText(this, "This app needs location permission to be able to show your location on the map", Toast.LENGTH_LONG).show()
- }
- override fun onPermissionResult(granted: Boolean) {
- if (granted) {
- enableLocation()
- } else {
- Toast.makeText(this, "User location was not granted", Toast.LENGTH_LONG).show()
- finish()
- }
- }
- override fun onLocationChanged(location: Location?) {
- location?.run {
- originLocation = this
- setCameraPosition(this)
- }
- }
- override fun onConnected() {
- }
- override fun onMapReady(mapboxMap: MapboxMap?) {
- //1
- map = mapboxMap ?: return
- //2
- val locationRequestBuilder = LocationSettingsRequest.Builder().addLocationRequest(LocationRequest()
- .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
- )
- //3
- val locationRequest = locationRequestBuilder?.build()
- settingsClient?.checkLocationSettings(locationRequest)?.run {
- addOnSuccessListener {
- enableLocation()
- }
- addOnFailureListener {
- val statusCode = (it as ApiException).statusCode
- if (statusCode == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) {
- val resolvableException = it as? ResolvableApiException
- resolvableException?.startResolutionForResult(this@MainActivity, REQUEST_CHECK_SETTINGS)
- }
- }
- }
- }
- //1
- fun enableLocation() {
- if (PermissionsManager.areLocationPermissionsGranted(this)) {
- initializeLocationComponent()
- initializeLocationEngine()
- map.addOnMapClickListener(this)
- initlizeRoute()
- } else {
- permissionManager = PermissionsManager(this)
- permissionManager.requestLocationPermissions(this)
- }
- }
- fun initlizeRoute() {
- val mapMatchedPoints = mutableListOf<Point>()
- mapMatchedPoints.add(Point.fromLngLat(21.4384477, 41.9844241))
- mapMatchedPoints.add(Point.fromLngLat(21.438205, 41.9848805))
- mapMatchedPoints.add(Point.fromLngLat(21.4377607, 41.9857103))
- mapMatchedPoints.add(Point.fromLngLat(21.438912, 41.9864523))
- // mapMatchedPoints.add(Point.fromLngLat(21.4372307, 41.9871085))
- // mapMatchedPoints.add(Point.fromLngLat(21.436772, 41.9878366))
- // mapMatchedPoints.add(Point.fromLngLat(21.4368103, 41.9879339))
- // mapMatchedPoints.add(Point.fromLngLat(21.4368747, 41.987948))
- // mapMatchedPoints.add(Point.fromLngLat(21.4371215, 41.9879574))
- // mapMatchedPoints.add(Point.fromLngLat(21.4380211, 41.9886061))
- // mapMatchedPoints.add(Point.fromLngLat(21.4380211,41.9886061))
- mapMatchedPoints.add(Point.fromLngLat(21.4356674, 41.990109))
- mapMatchedPoints.add(Point.fromLngLat(21.4354717, 41.9905303))
- // mapMatchedPoints.add(Point.fromLngLat(21.4470612, 41.9848251))
- // mapMatchedPoints.add(Point.fromLngLat(21.4544094, 41.9806309))
- map.animateCamera(CameraUpdateFactory.newLatLngZoom(LatLng(21.438912, 41.9864523), 50.0))
- MapboxMapMatching.builder()
- .accessToken("pk.eyJ1IjoibWFuZXYxNSIsImEiOiJjaWgwazg1a2Mwd2txdnFtM3p1dnNvbjJkIn0.fvNagTH12eCx2IwmoDdgRw")
- .coordinates(mapMatchedPoints)
- // .waypoints(0, mapMatchedPoints.size - 1)
- .steps(true)
- .voiceInstructions(true)
- .voiceUnits(DirectionsCriteria.METRIC)
- .bannerInstructions(true)
- .profile(DirectionsCriteria.PROFILE_CYCLING)
- .build()
- .enqueueCall(object : Callback<MapMatchingResponse> {
- override fun onResponse(call: Call<MapMatchingResponse>, response: Response<MapMatchingResponse>) {
- // if (response.isSuccessful) {
- if (navigationMapRoute != null) {
- navigationMapRoute?.updateRouteVisibilityTo(false)
- } else {
- navigationMapRoute = NavigationMapRoute(null, mapbox, map)
- }
- currentRoute = response.body()!!.matchings()!![0].toDirectionRoute()
- Engine.route = currentRoute
- if (currentRoute != null) {
- navigationMapRoute?.addRoute(currentRoute)
- }
- btnNavigate.isEnabled = true
- // }
- }
- override fun onFailure(call: Call<MapMatchingResponse>, throwable: Throwable) {
- }
- })
- }
- //2
- @SuppressWarnings("MissingPermission")
- fun initializeLocationEngine() {
- locationEngine = LocationEngineProvider(this).obtainBestLocationEngineAvailable()
- locationEngine?.priority = LocationEnginePriority.HIGH_ACCURACY
- locationEngine?.activate()
- locationEngine?.addLocationEngineListener(this)
- val lastLocation = locationEngine?.lastLocation
- if (lastLocation != null) {
- originLocation = lastLocation
- // setCameraPosition(lastLocation)
- } else {
- locationEngine?.addLocationEngineListener(this)
- }
- }
- @SuppressWarnings("MissingPermission")
- fun initializeLocationComponent() {
- locationComponent = map.locationComponent
- locationComponent?.activateLocationComponent(this)
- locationComponent?.isLocationComponentEnabled = true
- locationComponent?.cameraMode = CameraMode.TRACKING
- }
- //3
- fun setCameraPosition(location: Location) {
- map.animateCamera(CameraUpdateFactory.newLatLngZoom(LatLng(location.latitude,
- location.longitude), 30.0))
- }
- override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults)
- permissionManager.onRequestPermissionsResult(requestCode, permissions, grantResults)
- }
- override fun onMapClick(point: LatLng) {
- if (!map.markers.isEmpty()) {
- map.clear()
- }
- map.addMarker(MarkerOptions().setTitle("I'm a marker :]").setSnippet("This is a snippet about this marker that will show up here").position(point))
- checkLocation()
- originLocation?.run {
- val startPoint = Point.fromLngLat(longitude, latitude)
- val endPoint = Point.fromLngLat(point.longitude, point.latitude)
- getRoute(startPoint, endPoint)
- }
- }
- @SuppressLint("MissingPermission")
- private fun checkLocation() {
- if (originLocation == null) {
- map.locationComponent.lastKnownLocation?.run {
- originLocation = this
- }
- }
- }
- private fun ace() {
- val parser = GpxParser()
- val `inn` = assets.open(TEST_GPX)
- val testRoute = parser.parseGpx(inn)
- var coordinates: List<Point>? = null
- if (testRoute != null) {
- for (item in testRoute) {
- }
- }
- }
- private fun getRoute(originPoint: Point, endPoint: Point) {
- val parser = GpxParser()
- val `inn` = assets.open(TEST_GPX)
- val testRoute = parser.parseGpx(inn)
- val mapMatchedPoints = mutableListOf<Point>()
- var num = 0
- var num2 = 0
- val num1 = testRoute?.size
- var br = (num1!! - 3) / 100
- br += 1
- if (testRoute != null) {
- for (item in testRoute) {
- num++
- if (num2 == 0) {
- mapMatchedPoints.add(Point.fromLngLat(item.longitude, item.latitude))
- }
- if (num == br) {
- num = 0
- num2++
- if (num2 < 100)
- mapMatchedPoints.add(Point.fromLngLat(item.longitude, item.latitude))
- }
- }
- mapMatchedPoints.add(Point.fromLngLat(testRoute[testRoute.size - 1].longitude, testRoute[testRoute.size - 1].latitude))
- }
- // for (i in 0 until mapMatchedPoints.size) {
- // if (i + 1 < mapMatchedPoints.size) {
- // NavigationRoute.builder(this) //1
- // .accessToken(Mapbox.getAccessToken()!!) //2
- // .origin(Point.fromLngLat(mapMatchedPoints[i].longitude(), mapMatchedPoints[i].latitude())) //3
- // .voiceUnits(DirectionsCriteria.METRIC)
- // .profile(DirectionsCriteria.PROFILE_CYCLING)
- // .destination(Point.fromLngLat(mapMatchedPoints[i + 1].longitude(), mapMatchedPoints[i + 1].latitude())) //4
- // .build() //5
- // .getRoute(object : Callback<DirectionsResponse> { //6
- // override fun onFailure(call: Call<DirectionsResponse>, t: Throwable) {
- // Log.d("MainActivity", t.localizedMessage)
- // }
- //
- // override fun onResponse(call: Call<DirectionsResponse>,
- // response: Response<DirectionsResponse>) {
- // if (navigationMapRoute != null) {
- // navigationMapRoute?.updateRouteVisibilityTo(false)
- // } else {
- // navigationMapRoute = NavigationMapRoute(null, mapbox, map)
- // }
- // currentRoute = response.body()!!.routes().first()
- // druga = endPoint
- // numo++
- // if (flag) {
- // flag = false
- // currentRoute2 = currentRoute
- // // currentRoute2?.legs()!!.removeAt(0)
- // } else {
- //
- // currentRoute2!!.routeOptions()!!.coordinates() += currentRoute!!.routeOptions()!!.coordinates()[1]
- //// currentRoute2?.duration()!!.plus(currentRoute?.duration()!!.toDouble())
- //// currentRoute2?.distance()!!.plus(currentRoute?.distance()!!.toDouble())
- // // currentRoute2?.legs()!!.addAll(currentRoute?.legs()!!.toMutableList())
- // // currentRoute2?.legs()!![0].steps()!!.addAll(currentRoute?.legs()!![0].steps()!!)
- // //
- // // currentRoute2?.legs()!!.addAll(currentRoute?.legs()!!.toMutableList())
- // // currentRoute2?.geometry()!!.contentEquals(currentRoute2?.geometry()!!.replace(currentRoute2?.geometry()!!, "~"+currentRoute?.geometry()!!))
- // currentRoute2?.legs()!!.addAll(currentRoute?.legs()!!.toMutableList())
- //// navigationMapRoute?.addRoute(currentRoute2)
- // }
- // if (currentRoute != null) {
- // if (numo == mapMatchedPoints.size-1) {
- // // currentRoute2?.legs()!!.addAll(currentRoute?.legs()!!.toMutableList())
- // navigationMapRoute?.addRoute(currentRoute2)
- // }
- // }
- // btnNavigate.isEnabled = true
- // }
- // })
- // }
- // }
- MapboxMapMatching.builder()
- .accessToken("pk.eyJ1IjoibWFuZXYxNSIsImEiOiJjaWgwazg1a2Mwd2txdnFtM3p1dnNvbjJkIn0.fvNagTH12eCx2IwmoDdgRw")
- .coordinates(mapMatchedPoints)
- // .waypoints(0, mapMatchedPoints.size - 1)
- .steps(true)
- .voiceInstructions(true)
- .bannerInstructions(true)
- .voiceUnits(DirectionsCriteria.METRIC)
- .profile(DirectionsCriteria.PROFILE_CYCLING)
- .build()
- .enqueueCall(object : Callback<MapMatchingResponse> {
- override fun onResponse(call: Call<MapMatchingResponse>, response: Response<MapMatchingResponse>) {
- // if (response.isSuccessful) {
- if (navigationMapRoute != null) {
- navigationMapRoute?.updateRouteVisibilityTo(false)
- } else {
- navigationMapRoute = NavigationMapRoute(null, mapbox, map)
- }
- currentRoute = response.body()!!.matchings()!![0].toDirectionRoute()
- Engine.route = currentRoute
- if (currentRoute != null) {
- navigationMapRoute?.addRoute(currentRoute)
- }
- btnNavigate.isEnabled = true
- // }
- }
- override fun onFailure(call: Call<MapMatchingResponse>, throwable: Throwable) {
- }
- })
- // val parser = GpxParser()
- // val `inn` = assets.open(TEST_GPX)
- // val testRoute = parser.parseGpx(inn)
- // if (flag) {
- // origino = originPoint
- // } else {
- // origino = druga
- // }
- // NavigationRoute.builder(this) //1
- // .accessToken(Mapbox.getAccessToken()!!) //2
- // .origin(origino!!) //3
- // .voiceUnits(DirectionsCriteria.METRIC)
- // .profile(DirectionsCriteria.PROFILE_CYCLING)
- // .destination(endPoint) //4
- // .build() //5
- // .getRoute(object : Callback<DirectionsResponse> { //6
- // override fun onFailure(call: Call<DirectionsResponse>, t: Throwable) {
- // Log.d("MainActivity", t.localizedMessage)
- // }
- //
- // override fun onResponse(call: Call<DirectionsResponse>,
- // response: Response<DirectionsResponse>) {
- // if (navigationMapRoute != null) {
- // navigationMapRoute?.updateRouteVisibilityTo(false)
- // } else {
- // navigationMapRoute = NavigationMapRoute(null, mapbox, map)
- // }
- // currentRoute = response.body()!!.routes().first()
- // druga = endPoint
- // numo++
- // if (flag) {
- // flag = false
- // currentRoute2 = currentRoute
- // // currentRoute2?.legs()!!.removeAt(0)
- // } else {
- //
- // currentRoute2!!.routeOptions()!!.coordinates() += currentRoute!!.routeOptions()!!.coordinates()[1]
- //// currentRoute2?.duration()!!.plus(currentRoute?.duration()!!.toDouble())
- //// currentRoute2?.distance()!!.plus(currentRoute?.distance()!!.toDouble())
- // // currentRoute2?.legs()!!.addAll(currentRoute?.legs()!!.toMutableList())
- // // currentRoute2?.legs()!![0].steps()!!.addAll(currentRoute?.legs()!![0].steps()!!)
- // //
- // // currentRoute2?.legs()!!.addAll(currentRoute?.legs()!!.toMutableList())
- // currentRoute2?.geometry()!!.contentEquals(currentRoute2?.geometry()!!.replace(currentRoute2?.geometry()!!, currentRoute?.geometry()!!))
- // // currentRoute2?.legs()!!.addAll(currentRoute?.legs()!!.toMutableList())
- // }
- // if (currentRoute != null) {
- // if (numo == 20) {
- // // currentRoute2?.legs()!![0].steps()!![1] = currentRoute?.legs()!![0].steps()!![1]
- //// .addAll(currentRoute?.legs()!!.toMutableList())
- // // currentRoute2?.legs()!!.removeAt(0)
- //// currentRoute2?.legs()!!.removeAt(0)
- // // currentRoute2?.legs()!![0].steps()!!.removeAt(0)
- //// currentRoute2?.legs()!!.addAll(currentRoute?.legs()!!.toMutableList())
- // // currentRoute2?.legs()!![1].steps()!!.removeAt(0)
- //// currentRoute2?.legs()!!.removeAt(0)
- // currentRoute2?.legs()!!.addAll(currentRoute?.legs()!!.toMutableList())
- // navigationMapRoute?.addRoute(currentRoute2)
- // Engine.route = currentRoute2
- // }
- // }
- // btnNavigate.isEnabled = true
- // }
- // })
- // val tileDir = File(obtainOfflineDirectory(), TILE_PATH_NAME)
- // if (!tileDir.exists()) {
- // tileDir.mkdirs()
- // }
- // val offlineRouter = MapboxOfflineRouter(tileDir.absolutePath)
- // offlineRouter.configure(retrieveOfflineVersionFromPreferences(), object : OnOfflineTilesConfiguredCallback {
- //
- // override fun onConfigured(numberOfTiles: Int) {
- // Timber.d("Offline tiles configured: $numberOfTiles")
- //// Fetch offline route
- //
- // val origin = Point.fromLngLat(-6.782582, 61.833349)
- // // val bearing = location.bearing.toDouble()
- // val onlineRouteBuilder = NavigationRoute.builder(applicationContext)
- // .origin(origin)
- // .destination(Point.fromLngLat(-6.729809, 61.826144))
- // .accessToken("pk.eyJ1IjoibWFuZXYxNSIsImEiOiJjaWgwazg1a2Mwd2txdnFtM3p1dnNvbjJkIn0.fvNagTH12eCx2IwmoDdgRw")
- // val offlineRoute = OfflineRoute.builder(onlineRouteBuilder).build()
- // mapboxOfflineRouter.findRoute(offlineRoute, object : OnOfflineRouteFoundCallback {
- // override fun onRouteFound(route: DirectionsRoute) {
- // if (navigationMapRoute != null) {
- // navigationMapRoute?.updateRouteVisibilityTo(false)
- // } else {
- // navigationMapRoute = NavigationMapRoute(null, mapbox, map)
- // }
- // currentRoute = route
- //
- //
- // if (currentRoute != null) {
- // navigationMapRoute?.addRoute(currentRoute)
- // }
- //
- // btnNavigate.isEnabled = true
- // }
- //
- // override fun onError(error: OfflineError) {
- //// Handle route error
- // Timber.d("Offline tiles configuration error: {${error.message}}")
- // }
- // })
- // }
- //
- // override fun onConfigurationError(error: OfflineError) {
- // Timber.d("Offline tiles configuration error: {${error.message}}")
- // }
- // })
- }
- // private fun findOfflineRoute(location: Location, destination: Point) {
- // offlineRouteFinder.findRoute(location, destination)
- // }
- private fun retrieveOfflineVersionFromPreferences(): String {
- // val context = getApplication<Application>()
- return PreferenceManager.getDefaultSharedPreferences(applicationContext)
- .getString(applicationContext.getString(R.string.offline_version_key), "")
- }
- fun aaa() {
- val parser = GpxParser()
- val inputStream = buildTestGpxInputStream(TEST_GPX)
- val parsedLocations = parser.parseGpx(inputStream)
- }
- private fun buildTestGpxInputStream(gpxFileName: String): InputStream {
- val classLoader = javaClass.classLoader
- return classLoader.getResourceAsStream(gpxFileName)
- }
- fun loadJsonFromAsset(filename: String): String? {
- try {
- val `is` = assets.open(filename)
- val size = `is`.available()
- val buffer = ByteArray(size)
- `is`.read(buffer)
- `is`.close()
- return String(buffer, Charset.forName("UTF-8"))
- } catch (ex: IOException) {
- ex.printStackTrace()
- return null
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement