aboutsummaryrefslogtreecommitdiff
path: root/androidApp/src/main/java/mx/trackermap/TrackerMap/android
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-01-11 01:24:31 -0600
committerIván Ávalos <avalos@disroot.org>2022-01-11 01:24:31 -0600
commit62d1be3102a322b9eb14280c003f99f4606f507e (patch)
treebf05960704661b98b7cb18f853b72a599de20417 /androidApp/src/main/java/mx/trackermap/TrackerMap/android
parent4475382b482e9b20cb34dfd2e6896546bf86c485 (diff)
downloadetbsa-trackermap-mobile-62d1be3102a322b9eb14280c003f99f4606f507e.tar.gz
etbsa-trackermap-mobile-62d1be3102a322b9eb14280c003f99f4606f507e.tar.bz2
etbsa-trackermap-mobile-62d1be3102a322b9eb14280c003f99f4606f507e.zip
MapFragment properly draws reports and renamed icons
Diffstat (limited to 'androidApp/src/main/java/mx/trackermap/TrackerMap/android')
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt6
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt6
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt71
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt9
-rw-r--r--androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt7
5 files changed, 74 insertions, 25 deletions
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt
index 33b0dfc..b701990 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/details/reports/UnitReportsFragment.kt
@@ -147,7 +147,8 @@ class UnitReportsFragment : Fragment() {
binding.reportsMapContainer.visibility = View.VISIBLE
reportsMapFragment.display(
- positions.mapNotNull(MarkerTransformations::positionToMarker).toTypedArray()
+ positions.mapNotNull(MarkerTransformations::positionToMarker).toTypedArray(),
+ isReport = true
)
}
@@ -224,7 +225,8 @@ class UnitReportsFragment : Fragment() {
binding.reportsMapContainer.visibility = View.VISIBLE
reportsMapFragment.display(
- stops.mapNotNull(MarkerTransformations::stopToMarker).toTypedArray()
+ stops.mapNotNull(MarkerTransformations::stopToMarker).toTypedArray(),
+ isReport = true
)
}
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt
index d715e8d..56b114d 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/devices/DevicesAdapter.kt
@@ -53,9 +53,9 @@ class DevicesAdapter(
engineStopIcon.visibility = View.VISIBLE
engineStopIcon.setImageResource(
when (attributes["out1"].toString()) {
- "true" -> R.drawable.ic_baseline_lock_24
- "false" -> R.drawable.ic_baseline_lock_open_24
- else -> R.drawable.ic_baseline_lock_open_24
+ "true" -> R.drawable.device_unlocked
+ "false" -> R.drawable.device_locked
+ else -> R.drawable.device_locked
}
)
engineStopIcon.contentDescription = when (attributes["out1"].toString()) {
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
index ebd75fb..681a21f 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/MapFragment.kt
@@ -1,12 +1,14 @@
package mx.trackermap.TrackerMap.android.map
import android.graphics.Bitmap
-import android.graphics.BitmapFactory
+import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import androidx.core.content.res.ResourcesCompat
+import androidx.core.graphics.drawable.toBitmap
import com.mousebird.maply.*
import java.io.File
import mx.trackermap.TrackerMap.android.R
@@ -25,7 +27,7 @@ class MapFragment : GlobeMapFragment() {
var markerCallback: MarkerCallback? = null
- private val markers = mutableListOf<Pair<ScreenMarker, ComponentObject>>()
+ private val objects = mutableListOf<ComponentObject>()
override fun chooseDisplayType(): MapDisplayType {
return MapDisplayType.Map
@@ -93,35 +95,77 @@ class MapFragment : GlobeMapFragment() {
markerCallback?.let { it(null) }
}
- fun clear() {
+ private fun clear() {
mapControl.removeObjects(
- markers.map { it.second },
+ objects,
ThreadMode.ThreadAny
)
+ objects.clear()
}
- fun display(markers: Array<Marker>) {
+ fun display(markers: Array<Marker>, isReport: Boolean) {
Log.d("MapFragment", "Displaying markers")
clear()
- val screenMarkers = markers.map { marker ->
+ val screenMarkers = markers.mapIndexed { i, marker ->
val screenMarker = ScreenMarker()
val markerSize = Point2d(144.0, 144.0)
screenMarker.loc = Point2d.FromDegrees(marker.longitude, marker.latitude)
- screenMarker.image = getIcon(marker.type)
+ screenMarker.image = if (isReport) {
+ when (i) {
+ 0 -> getIcon(MarkerType.REPORT_START)
+ markers.size - 1 -> getIcon(MarkerType.REPORT_END)
+ else -> getIcon(MarkerType.REPORT_POSITION)
+ }
+ } else getIcon(marker.type)
screenMarker.size = markerSize
screenMarker.userObject = marker.id
screenMarker.selectable = true
screenMarker
}
- mapControl.addScreenMarkers(
+
+ objects.add(mapControl.addScreenMarkers(
screenMarkers,
MarkerInfo(),
ThreadMode.ThreadAny
- )
+ ))
+
+ if (isReport && markers.isNotEmpty()) {
+ Log.d("MapFragment", "Displaying report")
+
+ val points = markers.map { marker ->
+ Point2d.FromDegrees(marker.longitude, marker.latitude)
+ }.toTypedArray()
+
+ // Draw polyline
+ val vector = VectorObject()
+ vector.addAreal(points)
+
+ val vectorInfo = VectorInfo()
+ vectorInfo.setColor(Color.GREEN)
+ vectorInfo.setLineWidth(25.0f)
+
+ objects.add(mapControl.addVector(
+ vector,
+ vectorInfo,
+ ThreadMode.ThreadAny
+ ))
+
+ // Center map to polyline bounds
+ val mbr = Mbr()
+ points.forEach {
+ mbr.addPoint(it)
+ }
+ mbr.expandByFraction(0.1)
+
+ mapControl.addPostSurfaceRunnable {
+ val zoom = mapControl.findHeightToViewBounds(mbr, mbr.middle())
+ mapControl.setPositionGeo(mbr.middle(), zoom)
+ }
+ }
}
fun focusOn(latitude: Double, longitude: Double, zoom: Double = 0.0000144, animated: Boolean = true) {
@@ -135,7 +179,7 @@ class MapFragment : GlobeMapFragment() {
}
private fun getIcon(markerType: MarkerType): Bitmap {
- return BitmapFactory.decodeResource(
+ return ResourcesCompat.getDrawable(
activity!!.resources,
when (markerType) {
MarkerType.ANIMAL -> R.drawable.map_animal
@@ -159,7 +203,10 @@ class MapFragment : GlobeMapFragment() {
MarkerType.TROLLEYBUS -> R.drawable.map_trolleybus
MarkerType.TRUCK -> R.drawable.map_truck
MarkerType.VAN -> R.drawable.map_van
- }
- )
+
+ MarkerType.REPORT_POSITION -> R.drawable.map_report_position
+ MarkerType.REPORT_START -> R.drawable.map_report_start
+ MarkerType.REPORT_END -> R.drawable.map_report_end
+ }, activity!!.theme)!!.toBitmap(144, 144)
}
} \ No newline at end of file
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt
index 427f020..3c34abb 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/map/UnitMapFragment.kt
@@ -56,7 +56,8 @@ class UnitMapFragment : Fragment() {
Log.d("UnitMapFragment", "Available units: $units")
unitsMapFragment.display(
- units.mapNotNull(MarkerTransformations::unitToMarker).toTypedArray()
+ units.mapNotNull(MarkerTransformations::unitToMarker).toTypedArray(),
+ isReport = false
)
}
@@ -92,9 +93,9 @@ class UnitMapFragment : Fragment() {
engineStopIcon.visibility = View.VISIBLE
engineStopIcon.setImageResource(
when (attributes["out1"].toString()) {
- "true" -> R.drawable.ic_baseline_lock_24
- "false" -> R.drawable.ic_baseline_lock_open_24
- else -> R.drawable.ic_baseline_lock_open_24
+ "true" -> R.drawable.device_unlocked
+ "false" -> R.drawable.device_locked
+ else -> R.drawable.device_locked
}
)
engineStopIcon.contentDescription =
diff --git a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt
index 796c29f..6bc7aab 100644
--- a/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt
+++ b/androidApp/src/main/java/mx/trackermap/TrackerMap/android/units/UnitsActivity.kt
@@ -9,7 +9,6 @@ import kotlinx.coroutines.DelicateCoroutinesApi
import mx.trackermap.TrackerMap.android.R
import mx.trackermap.TrackerMap.android.databinding.UnitsActivityBinding
import mx.trackermap.TrackerMap.android.devices.DevicesFragment
-import mx.trackermap.TrackerMap.android.map.MapFragment
import mx.trackermap.TrackerMap.android.map.UnitMapFragment
import org.koin.androidx.viewmodel.ext.android.viewModel
@@ -54,9 +53,9 @@ class UnitsActivity : AppCompatActivity() {
unitsViewModel.unitsDisplayMode.observe(this) { displayMode ->
binding.displayModeToggle.setImageResource(
when (displayMode) {
- UnitsViewModel.UnitsDisplayMode.LIST -> R.drawable.ic_baseline_map_24
- UnitsViewModel.UnitsDisplayMode.MAP -> R.drawable.ic_baseline_list_24
- else -> R.drawable.ic_baseline_map_24
+ UnitsViewModel.UnitsDisplayMode.LIST -> R.drawable.icon_map
+ UnitsViewModel.UnitsDisplayMode.MAP -> R.drawable.icon_list
+ else -> R.drawable.icon_map
}
)
binding.displayModeToggle.contentDescription = getString(