Add a line tracking animal history
This commit is contained in:
parent
3cecc1e121
commit
7716d77f25
|
@ -1,8 +1,10 @@
|
|||
package com.danilafe.fencelessgrazing
|
||||
|
||||
import android.app.Application
|
||||
import android.graphics.Color
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import com.android.volley.Request
|
||||
|
@ -17,8 +19,10 @@ import com.danilafe.fencelessgrazing.requests.CollarHistoryRequest
|
|||
import org.osmdroid.util.GeoPoint
|
||||
import org.osmdroid.views.MapView
|
||||
import org.osmdroid.views.overlay.Marker
|
||||
import org.osmdroid.views.overlay.Polyline
|
||||
import java.sql.Time
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.concurrent.timerTask
|
||||
|
||||
class CollarDetailActivity : AppCompatActivity() {
|
||||
|
@ -43,6 +47,7 @@ class CollarDetailActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
private lateinit var mapMarker: Marker
|
||||
private lateinit var mapPolyline: Polyline
|
||||
private var dataPoints: List<GeoPoint> = listOf()
|
||||
set(newValue) {
|
||||
if(newValue.isNotEmpty()) updateAnimalHistory(newValue)
|
||||
|
@ -64,6 +69,7 @@ class CollarDetailActivity : AppCompatActivity() {
|
|||
map = findViewById(R.id.detailMap)
|
||||
mapPolygon = org.osmdroid.views.overlay.Polygon(map)
|
||||
mapMarker = Marker(map)
|
||||
mapPolyline = Polyline(map)
|
||||
configureMapPolygon()
|
||||
|
||||
boundingBox = Polygon(
|
||||
|
@ -122,13 +128,16 @@ class CollarDetailActivity : AppCompatActivity() {
|
|||
private fun updateAnimalHistory(points : List<GeoPoint>) {
|
||||
val currentPoint = points.first()
|
||||
mapMarker.position = currentPoint
|
||||
mapPolyline.setPoints(points)
|
||||
collarPos.text = getString(R.string.collarSummaryLocation, currentPoint.longitude, currentPoint.latitude)
|
||||
if(!map.overlays.contains(mapMarker)) map.overlays.add(mapMarker)
|
||||
if(!map.overlays.contains(mapPolyline)) map.overlays.add(mapPolyline)
|
||||
map.invalidate()
|
||||
}
|
||||
|
||||
private fun clearAnimalHistory() {
|
||||
map.overlays.remove(mapMarker)
|
||||
map.overlays.remove(mapPolyline)
|
||||
map.invalidate()
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,6 @@ class CollarListActivity : AppCompatActivity() {
|
|||
map.onResume()
|
||||
refreshTimer = Timer()
|
||||
refreshTimer.schedule(timerTask { triggerRefresh() }, 0L, 5000L)
|
||||
Log.d("FencelessGrazing", "Should be resumed")
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
@ -69,7 +68,6 @@ class CollarListActivity : AppCompatActivity() {
|
|||
map.onPause()
|
||||
refreshTimer.cancel()
|
||||
refreshTimer.purge()
|
||||
Log.d("FencelessGrazing", "Should be paused")
|
||||
}
|
||||
|
||||
private fun triggerRefresh() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user