mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-14 20:08:32 -04:00
better map location pin
This commit is contained in:
@@ -5,6 +5,7 @@ import android.content.SharedPreferences
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Rect
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@@ -136,7 +137,7 @@ class MapFragment : ScreenFragment("Map"), Logging {
|
||||
marker.position = GeoPoint(p.latitude, p.longitude)
|
||||
marker.icon = ContextCompat.getDrawable(
|
||||
requireActivity(),
|
||||
R.drawable.ic_twotone_location_on_24
|
||||
R.drawable.ic_baseline_location_on_24
|
||||
)
|
||||
}
|
||||
marker
|
||||
@@ -233,6 +234,17 @@ class MapFragment : ScreenFragment("Map"), Logging {
|
||||
private inner class MarkerWithLabel(mapView: MapView?, label: String) : Marker(mapView) {
|
||||
val mLabel = label
|
||||
|
||||
private fun getTextBackgroundSize(text: String, x: Float, y: Float, paint: Paint): Rect {
|
||||
val fontMetrics: Paint.FontMetrics = paint.fontMetrics
|
||||
val halfTextLength: Float = paint.measureText(text) / 2 + 3
|
||||
return Rect(
|
||||
(x - halfTextLength).toInt(),
|
||||
(y + fontMetrics.top).toInt(),
|
||||
(x + halfTextLength).toInt(),
|
||||
(y + fontMetrics.bottom).toInt()
|
||||
)
|
||||
}
|
||||
|
||||
override fun draw(c: Canvas, osmv: MapView?, shadow: Boolean) {
|
||||
draw(c, osmv)
|
||||
}
|
||||
@@ -244,11 +256,17 @@ class MapFragment : ScreenFragment("Map"), Logging {
|
||||
|
||||
val textPaint = Paint()
|
||||
textPaint.textSize = 40f
|
||||
textPaint.color = Color.RED
|
||||
textPaint.color = Color.DKGRAY
|
||||
textPaint.isAntiAlias = true
|
||||
textPaint.isFakeBoldText = true
|
||||
textPaint.textAlign = Paint.Align.CENTER
|
||||
|
||||
c.drawText(mLabel, (p.x - 0f), (p.y - 80f), textPaint)
|
||||
val bgRect = getTextBackgroundSize(mLabel, (p.x - 0f), (p.y - 110f), textPaint)
|
||||
val bgPaint = Paint()
|
||||
bgPaint.color = Color.WHITE
|
||||
|
||||
c.drawRect(bgRect, bgPaint)
|
||||
c.drawText(mLabel, (p.x - 0f), (p.y - 110f), textPaint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
14
app/src/main/res/drawable/ic_baseline_location_on_24.xml
Normal file
14
app/src/main/res/drawable/ic_baseline_location_on_24.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="30dp"
|
||||
android:height="30dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#3388ff"
|
||||
android:strokeWidth="1.25"
|
||||
android:strokeColor="@android:color/white"
|
||||
android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z" />
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,9m-2.5,0a2.5,2.5 0,1 1,5 0a2.5,2.5 0,1 1,-5 0" />
|
||||
</vector>
|
||||
@@ -1,18 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#3388ff"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillAlpha="0.3"
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,4C9.24,4 7,6.24 7,9c0,2.85 2.92,7.21 5,9.88 2.11,-2.69 5,-7 5,-9.88 0,-2.76 -2.24,-5 -5,-5zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"
|
||||
android:strokeAlpha="0.3" />
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM7,9c0,-2.76 2.24,-5 5,-5s5,2.24 5,5c0,2.88 -2.88,7.19 -5,9.88C9.92,16.21 7,11.85 7,9z" />
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M12,9m-2.5,0a2.5,2.5 0,1 1,5 0a2.5,2.5 0,1 1,-5 0" />
|
||||
</vector>
|
||||
@@ -20,7 +20,7 @@
|
||||
app:icon="@drawable/ic_twotone_layers_24"
|
||||
app:iconGravity="textStart"
|
||||
app:iconPadding="0dp"
|
||||
app:iconTint="@color/colorIconTint"
|
||||
app:iconTint="@color/unselectedColor"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user