diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-11 01:24:31 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-11 01:24:31 -0600 |
commit | a19528d06b415d6c89047c965870fcca21aadcdc (patch) | |
tree | 5896893146f52d604a0eb1fb0a2fe7b80ffff513 /androidApp | |
parent | e93ad9e3251013c07c71f20dc4523e4d09aa26bd (diff) | |
download | etbsa-trackermap-mobile-a19528d06b415d6c89047c965870fcca21aadcdc.tar.gz etbsa-trackermap-mobile-a19528d06b415d6c89047c965870fcca21aadcdc.tar.bz2 etbsa-trackermap-mobile-a19528d06b415d6c89047c965870fcca21aadcdc.zip |
MapFragment properly draws reports and renamed icons
Diffstat (limited to 'androidApp')
22 files changed, 125 insertions, 40 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( diff --git a/androidApp/src/main/res/drawable/ic_baseline_person_24.xml b/androidApp/src/main/res/drawable/device_contact.xml index 0faf05d..0faf05d 100644 --- a/androidApp/src/main/res/drawable/ic_baseline_person_24.xml +++ b/androidApp/src/main/res/drawable/device_contact.xml diff --git a/androidApp/src/main/res/drawable/ic_baseline_lock_open_24.xml b/androidApp/src/main/res/drawable/device_locked.xml index 1fe62c8..1fe62c8 100644 --- a/androidApp/src/main/res/drawable/ic_baseline_lock_open_24.xml +++ b/androidApp/src/main/res/drawable/device_locked.xml diff --git a/androidApp/src/main/res/drawable/ic_baseline_fiber_manual_record_24.xml b/androidApp/src/main/res/drawable/device_status.xml index 13890d5..13890d5 100644 --- a/androidApp/src/main/res/drawable/ic_baseline_fiber_manual_record_24.xml +++ b/androidApp/src/main/res/drawable/device_status.xml diff --git a/androidApp/src/main/res/drawable/ic_baseline_lock_24.xml b/androidApp/src/main/res/drawable/device_unlocked.xml index ed352bf..ed352bf 100644 --- a/androidApp/src/main/res/drawable/ic_baseline_lock_24.xml +++ b/androidApp/src/main/res/drawable/device_unlocked.xml diff --git a/androidApp/src/main/res/drawable/ic_baseline_list_24.xml b/androidApp/src/main/res/drawable/icon_list.xml index b0e68e0..b0e68e0 100644 --- a/androidApp/src/main/res/drawable/ic_baseline_list_24.xml +++ b/androidApp/src/main/res/drawable/icon_list.xml diff --git a/androidApp/src/main/res/drawable/ic_baseline_map_24.xml b/androidApp/src/main/res/drawable/icon_map.xml index d1274d8..d1274d8 100644 --- a/androidApp/src/main/res/drawable/ic_baseline_map_24.xml +++ b/androidApp/src/main/res/drawable/icon_map.xml diff --git a/androidApp/src/main/res/drawable/ic_baseline_menu_24.xml b/androidApp/src/main/res/drawable/icon_menu.xml index 4350ba9..4350ba9 100644 --- a/androidApp/src/main/res/drawable/ic_baseline_menu_24.xml +++ b/androidApp/src/main/res/drawable/icon_menu.xml diff --git a/androidApp/src/main/res/drawable/map_report_end.xml b/androidApp/src/main/res/drawable/map_report_end.xml new file mode 100644 index 0000000..de4d015 --- /dev/null +++ b/androidApp/src/main/res/drawable/map_report_end.xml @@ -0,0 +1,12 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#008000" + android:pathData="M12.36,6H7v6h7.24l0.4,2H18V8h-5.24z"/> + <path + android:fillColor="@android:color/black" + android:pathData="M14.4,6L14,4L5,4v17h2v-7h5.6l0.4,2h7L20,6h-5.6zM18,14h-3.36l-0.4,-2L7,12L7,6h5.36l0.4,2L18,8v6z"/> +</vector> diff --git a/androidApp/src/main/res/drawable/map_report_position.xml b/androidApp/src/main/res/drawable/map_report_position.xml new file mode 100644 index 0000000..fab1db5 --- /dev/null +++ b/androidApp/src/main/res/drawable/map_report_position.xml @@ -0,0 +1,12 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#008000" + android:pathData="M12,18c3.31,0 6,-2.69 6,-6s-2.69,-6 -6,-6 -6,2.69 -6,6 2.69,6 6,6z"/> + <path + android:fillColor="@android:color/black" + android:pathData="M12,20c4.42,0 8,-3.58 8,-8s-3.58,-8 -8,-8 -8,3.58 -8,8 3.58,8 8,8zM12,6c3.31,0 6,2.69 6,6s-2.69,6 -6,6 -6,-2.69 -6,-6 2.69,-6 6,-6z"/> +</vector> diff --git a/androidApp/src/main/res/drawable/map_report_start.xml b/androidApp/src/main/res/drawable/map_report_start.xml new file mode 100644 index 0000000..fc29b53 --- /dev/null +++ b/androidApp/src/main/res/drawable/map_report_start.xml @@ -0,0 +1,12 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24"> + <path + android:fillColor="#008000" + android:pathData="M12,20c4.41,0 8,-3.59 8,-8s-3.59,-8 -8,-8 -8,3.59 -8,8 3.59,8 8,8zM10,7.5l6,4.5 -6,4.5v-9z"/> + <path + android:fillColor="@android:color/black" + android:pathData="M12,22c5.52,0 10,-4.48 10,-10S17.52,2 12,2 2,6.48 2,12s4.48,10 10,10zM12,4c4.41,0 8,3.59 8,8s-3.59,8 -8,8 -8,-3.59 -8,-8 3.59,-8 8,-8zM10,7.5v9l6,-4.5z"/> +</vector> diff --git a/androidApp/src/main/res/drawable/ic_baseline_location_on_24.xml b/androidApp/src/main/res/drawable/position_address.xml index 71ef7bc..71ef7bc 100644 --- a/androidApp/src/main/res/drawable/ic_baseline_location_on_24.xml +++ b/androidApp/src/main/res/drawable/position_address.xml diff --git a/androidApp/src/main/res/drawable/ic_baseline_calendar_today_24.xml b/androidApp/src/main/res/drawable/position_datetime.xml index e059617..e059617 100644 --- a/androidApp/src/main/res/drawable/ic_baseline_calendar_today_24.xml +++ b/androidApp/src/main/res/drawable/position_datetime.xml diff --git a/androidApp/src/main/res/drawable/ic_baseline_speed_24.xml b/androidApp/src/main/res/drawable/position_speed.xml index febd057..febd057 100644 --- a/androidApp/src/main/res/drawable/ic_baseline_speed_24.xml +++ b/androidApp/src/main/res/drawable/position_speed.xml diff --git a/androidApp/src/main/res/layout/unit_details_reports.xml b/androidApp/src/main/res/layout/unit_details_reports.xml index 1eaf68c..dc649e4 100644 --- a/androidApp/src/main/res/layout/unit_details_reports.xml +++ b/androidApp/src/main/res/layout/unit_details_reports.xml @@ -10,7 +10,7 @@ android:name="mx.trackermap.TrackerMap.android.map.MapFragment" android:layout_width="0dp" android:layout_height="0dp" - android:layout_margin="@dimen/margin" + android:layout_marginBottom="@dimen/margin" app:layout_constraintBottom_toTopOf="@id/periodSection" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -21,7 +21,7 @@ android:id="@+id/eventsScroll" android:layout_width="0dp" android:layout_height="0dp" - android:layout_margin="@dimen/margin" + android:layout_marginBottom="@dimen/margin" android:visibility="gone" app:layout_constraintBottom_toTopOf="@id/periodSection" app:layout_constraintEnd_toEndOf="parent" diff --git a/androidApp/src/main/res/layout/unit_item.xml b/androidApp/src/main/res/layout/unit_item.xml index c44ec56..7c0241e 100644 --- a/androidApp/src/main/res/layout/unit_item.xml +++ b/androidApp/src/main/res/layout/unit_item.xml @@ -82,7 +82,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="5dp" - android:src="@drawable/ic_baseline_fiber_manual_record_24" + android:src="@drawable/device_status" app:tint="?android:textColorPrimary" tools:ignore="ContentDescription" /> @@ -93,7 +93,7 @@ android:layout_toEndOf="@id/statusIcon" android:visibility="gone" android:layout_marginEnd="5dp" - android:src="@drawable/ic_baseline_lock_24" + android:src="@drawable/device_unlocked" tools:ignore="ContentDescription" /> <TextView @@ -118,7 +118,7 @@ android:layout_column="0" android:layout_row="1" android:contentDescription="@string/unit_driver_name" - android:src="@drawable/ic_baseline_person_24" + android:src="@drawable/device_contact" app:tint="?android:textColorSecondary" /> <TextView @@ -138,7 +138,7 @@ android:layout_row="2" style="@style/TextAppearance.MaterialComponents.Caption" android:contentDescription="@string/unit_speed" - android:src="@drawable/ic_baseline_speed_24" + android:src="@drawable/position_speed" app:tint="?android:textColorSecondary" /> <TextView @@ -157,7 +157,7 @@ android:layout_column="0" android:layout_row="3" android:contentDescription="@string/unit_last_address" - android:src="@drawable/ic_baseline_location_on_24" + android:src="@drawable/position_address" app:tint="?android:textColorSecondary" /> <TextView @@ -176,7 +176,7 @@ android:layout_column="0" android:layout_row="4" android:contentDescription="@string/unit_last_date" - android:src="@drawable/ic_baseline_calendar_today_24" + android:src="@drawable/position_datetime" app:tint="?android:textColorSecondary" /> diff --git a/androidApp/src/main/res/layout/unit_map_fragment.xml b/androidApp/src/main/res/layout/unit_map_fragment.xml index f476c66..abe31d8 100644 --- a/androidApp/src/main/res/layout/unit_map_fragment.xml +++ b/androidApp/src/main/res/layout/unit_map_fragment.xml @@ -40,7 +40,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginEnd="5dp" - android:src="@drawable/ic_baseline_fiber_manual_record_24" + android:src="@drawable/device_status" app:tint="?android:textColorPrimary" tools:ignore="ContentDescription" /> @@ -51,7 +51,7 @@ android:layout_toEndOf="@id/statusIcon" android:visibility="gone" android:layout_marginEnd="5dp" - android:src="@drawable/ic_baseline_lock_24" + android:src="@drawable/device_unlocked" tools:ignore="ContentDescription" /> <TextView @@ -76,7 +76,7 @@ android:layout_column="0" android:layout_row="1" android:contentDescription="@string/unit_driver_name" - android:src="@drawable/ic_baseline_person_24" + android:src="@drawable/device_contact" app:tint="?android:textColorSecondary" /> <TextView @@ -96,7 +96,7 @@ android:layout_row="2" style="@style/TextAppearance.MaterialComponents.Caption" android:contentDescription="@string/unit_speed" - android:src="@drawable/ic_baseline_speed_24" + android:src="@drawable/position_speed" app:tint="?android:textColorSecondary" /> <TextView @@ -115,7 +115,7 @@ android:layout_column="0" android:layout_row="3" android:contentDescription="@string/unit_last_address" - android:src="@drawable/ic_baseline_location_on_24" + android:src="@drawable/position_address" app:tint="?android:textColorSecondary" /> <TextView @@ -134,7 +134,7 @@ android:layout_column="0" android:layout_row="4" android:contentDescription="@string/unit_last_date" - android:src="@drawable/ic_baseline_calendar_today_24" + android:src="@drawable/position_datetime" app:tint="?android:textColorSecondary" /> diff --git a/androidApp/src/main/res/layout/units_activity.xml b/androidApp/src/main/res/layout/units_activity.xml index bff3789..f0fd2ee 100644 --- a/androidApp/src/main/res/layout/units_activity.xml +++ b/androidApp/src/main/res/layout/units_activity.xml @@ -28,7 +28,7 @@ android:layout_marginStart="@dimen/fab_margin" android:layout_marginTop="@dimen/fab_margin" app:elevation="@dimen/fab_elevation" - android:src="@drawable/ic_baseline_menu_24" + android:src="@drawable/icon_menu" android:contentDescription="@string/open_drawer"/> <com.google.android.material.card.MaterialCardView |