fix #1616 (a11y): Use SP font size for marker labels on the map (#1630)

* Use and SP font size for marker labels on the map

* Fix detekt issue
pull/1637/head
Joshua Soberg 2025-03-02 10:14:12 -05:00 zatwierdzone przez GitHub
rodzic 1a11c3351b
commit 5da827473a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 10 dodań i 2 usunięć

Wyświetl plik

@ -19,6 +19,7 @@ package com.geeksville.mesh.android
import android.app.Activity
import android.content.Context
import android.util.TypedValue
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
@ -35,3 +36,7 @@ fun Activity.hideKeyboard() {
imm?.hideSoftInputFromWindow(v.windowToken, 0)
}
}
// Converts SP to pixels.
fun Context.spToPx(sp: Float): Int =
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, resources.displayMetrics).toInt()

Wyświetl plik

@ -22,6 +22,7 @@ import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.view.MotionEvent
import com.geeksville.mesh.android.spToPx
import org.osmdroid.views.MapView
import org.osmdroid.views.overlay.Marker
import org.osmdroid.views.overlay.Polygon
@ -31,6 +32,8 @@ class MarkerWithLabel(mapView: MapView?, label: String, emoji: String? = null) :
companion object {
private const val LABEL_CORNER_RADIUS = 12F
private const val LABEL_Y_OFFSET = 100F
private const val FONT_SIZE_SP = 14f
private const val EMOJI_FONT_SIZE_SP = 20f
}
private var nodeColor: Int = Color.GRAY
@ -69,14 +72,14 @@ class MarkerWithLabel(mapView: MapView?, label: String, emoji: String? = null) :
private val mLabel = label
private val mEmoji = emoji
private val textPaint = Paint().apply {
textSize = 40f
textSize = mapView?.context?.spToPx(FONT_SIZE_SP)?.toFloat() ?: 40f
color = Color.DKGRAY
isAntiAlias = true
isFakeBoldText = true
textAlign = Paint.Align.CENTER
}
private val emojiPaint = Paint().apply {
textSize = 80f
textSize = mapView?.context?.spToPx(EMOJI_FONT_SIZE_SP)?.toFloat() ?: 80f
isAntiAlias = true
textAlign = Paint.Align.CENTER
}