mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-12-01 15:40:32 +01:00
Map apps draw their own buttons and text smaller on a short screen, and Map app size in Settings picks the size by hand
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4e3f8e6657
commit
1f292b5cef
5 files changed
+95
-2
No files matched your search
@@ -178,7 +178,9 @@ private fun AppSurface(
|
|||||||
modifier.onGloballyPositioned { bounds = it.boundsInWindow() },
|
modifier.onGloballyPositioned { bounds = it.boundsInWindow() },
|
||||||
) {
|
) {
|
||||||
val epoch by connection.surfaceEpoch.collectAsState()
|
val epoch by connection.surfaceEpoch.collectAsState()
|
||||||
androidx.compose.runtime.key(constraints.maxWidth, constraints.maxHeight, epoch) {
|
// A new size for map apps takes a new surface, as a new size of screen does.
|
||||||
|
val mapSize by CarSettings.mapAppSize.collectAsState()
|
||||||
|
androidx.compose.runtime.key(constraints.maxWidth, constraints.maxHeight, epoch, mapSize) {
|
||||||
SurfaceHost(connection, frame, onSize = { size = it }, Modifier.fillMaxSize())
|
SurfaceHost(connection, frame, onSize = { size = it }, Modifier.fillMaxSize())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -243,7 +245,7 @@ private fun SurfaceHost(
|
|||||||
) {
|
) {
|
||||||
GearslipLog.i("stage: surface ready at ${width}x$height")
|
GearslipLog.i("stage: surface ready at ${width}x$height")
|
||||||
onSize(width to height)
|
onSize(width to height)
|
||||||
connection.attachSurface(holder.surface, width, height, frame.densityDpi)
|
connection.attachSurface(holder.surface, width, height, CarSettings.mapAppDensity(frame.densityDpi, height))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun surfaceDestroyed(holder: SurfaceHolder) {
|
override fun surfaceDestroyed(holder: SurfaceHolder) {
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ object CarSettings {
|
|||||||
|
|
||||||
private const val KEY_SCALE = "car_scale"
|
private const val KEY_SCALE = "car_scale"
|
||||||
private const val KEY_DENSITY = "car_density"
|
private const val KEY_DENSITY = "car_density"
|
||||||
|
private const val KEY_MAP_SIZE = "car_map_size"
|
||||||
private const val KEY_OPEN = "car_open_on_connect"
|
private const val KEY_OPEN = "car_open_on_connect"
|
||||||
private const val KEY_NIGHT = "car_night_mode"
|
private const val KEY_NIGHT = "car_night_mode"
|
||||||
private const val KEY_PIPE_AUDIO = "car_pipe_audio"
|
private const val KEY_PIPE_AUDIO = "car_pipe_audio"
|
||||||
@@ -103,6 +104,7 @@ private const val KEY_CLUSTER_VIDEO = "cluster_video_enabled"
|
|||||||
|
|
||||||
private val scaleFlow = MutableStateFlow(1f)
|
private val scaleFlow = MutableStateFlow(1f)
|
||||||
private val carDensityFlow = MutableStateFlow(DENSITY_FROM_CAR)
|
private val carDensityFlow = MutableStateFlow(DENSITY_FROM_CAR)
|
||||||
|
private val mapSizeFlow = MutableStateFlow(MAP_SIZE_AUTO)
|
||||||
private val openFlow = MutableStateFlow(HOME)
|
private val openFlow = MutableStateFlow(HOME)
|
||||||
private val nightFlow = MutableStateFlow(NightMode.AUTO)
|
private val nightFlow = MutableStateFlow(NightMode.AUTO)
|
||||||
private val pipeAudioFlow = MutableStateFlow(true)
|
private val pipeAudioFlow = MutableStateFlow(true)
|
||||||
@@ -263,6 +265,26 @@ private const val KEY_CLUSTER_VIDEO = "cluster_video_enabled"
|
|||||||
|
|
||||||
/** The density to draw at, for a car or preview that would otherwise use [carDpi]. */
|
/** The density to draw at, for a car or preview that would otherwise use [carDpi]. */
|
||||||
fun effectiveDensity(carDpi: Int) = carDensityFlow.value.takeIf { it != DENSITY_FROM_CAR } ?: carDpi
|
fun effectiveDensity(carDpi: Int) = carDensityFlow.value.takeIf { it != DENSITY_FROM_CAR } ?: carDpi
|
||||||
|
|
||||||
|
/** [mapAppSize] when Gearslip picks: smaller on a short screen, as drawn elsewhere. */
|
||||||
|
const val MAP_SIZE_AUTO = 0
|
||||||
|
val MAP_SIZES = listOf(100, 90, 80, 70, 60)
|
||||||
|
private const val MAP_MIN_HEIGHT_DP = 320
|
||||||
|
|
||||||
|
/** How big map apps draw their own buttons and text: a percent of the car UI's density, or [MAP_SIZE_AUTO]. */
|
||||||
|
val mapAppSize: StateFlow<Int> = mapSizeFlow
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The density to lend a map app a [heightPx]-tall surface at, when the car UI draws at [dpi].
|
||||||
|
* Automatic shrinks it only until the map is [MAP_MIN_HEIGHT_DP] tall, and no further than
|
||||||
|
* the smallest size: a single-DIN SOOEMAKA left Google Maps 226dp, and its own buttons and
|
||||||
|
* search bar filled most of it while Gearslip's nav bar looked right.
|
||||||
|
*/
|
||||||
|
fun mapAppDensity(dpi: Int, heightPx: Int): Int {
|
||||||
|
val percent = mapSizeFlow.value
|
||||||
|
if (percent != MAP_SIZE_AUTO) return dpi * percent / 100
|
||||||
|
return (heightPx * 160 / MAP_MIN_HEIGHT_DP).coerceIn(dpi * MAP_SIZES.last() / 100, dpi)
|
||||||
|
}
|
||||||
val openOnConnect: StateFlow<String> = openFlow
|
val openOnConnect: StateFlow<String> = openFlow
|
||||||
val nightMode: StateFlow<NightMode> = nightFlow
|
val nightMode: StateFlow<NightMode> = nightFlow
|
||||||
|
|
||||||
@@ -390,6 +412,7 @@ private const val KEY_CLUSTER_VIDEO = "cluster_video_enabled"
|
|||||||
app = context.applicationContext
|
app = context.applicationContext
|
||||||
scaleFlow.value = AppSettings.getString(app, KEY_SCALE, "1.0").toFloatOrNull() ?: 1f
|
scaleFlow.value = AppSettings.getString(app, KEY_SCALE, "1.0").toFloatOrNull() ?: 1f
|
||||||
carDensityFlow.value = AppSettings.getString(app, KEY_DENSITY, "").toIntOrNull()?.takeIf { it in DENSITIES || it in CUSTOM_DENSITIES } ?: DENSITY_FROM_CAR
|
carDensityFlow.value = AppSettings.getString(app, KEY_DENSITY, "").toIntOrNull()?.takeIf { it in DENSITIES || it in CUSTOM_DENSITIES } ?: DENSITY_FROM_CAR
|
||||||
|
mapSizeFlow.value = AppSettings.getString(app, KEY_MAP_SIZE, "").toIntOrNull()?.takeIf { it in MAP_SIZES } ?: MAP_SIZE_AUTO
|
||||||
openFlow.value = AppSettings.getString(app, KEY_OPEN, HOME)
|
openFlow.value = AppSettings.getString(app, KEY_OPEN, HOME)
|
||||||
lastNavFlow.value = AppSettings.getString(app, KEY_LAST_NAV, "").ifEmpty { null }
|
lastNavFlow.value = AppSettings.getString(app, KEY_LAST_NAV, "").ifEmpty { null }
|
||||||
lastMediaFlow.value = AppSettings.getString(app, KEY_LAST_MEDIA, "").ifEmpty { null }
|
lastMediaFlow.value = AppSettings.getString(app, KEY_LAST_MEDIA, "").ifEmpty { null }
|
||||||
@@ -455,6 +478,11 @@ private const val KEY_CLUSTER_VIDEO = "cluster_video_enabled"
|
|||||||
AppSettings.putString(app, KEY_DENSITY, dpi.toString())
|
AppSettings.putString(app, KEY_DENSITY, dpi.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setMapAppSize(percent: Int) {
|
||||||
|
mapSizeFlow.value = percent
|
||||||
|
AppSettings.putString(app, KEY_MAP_SIZE, percent.toString())
|
||||||
|
}
|
||||||
|
|
||||||
fun setOpenOnConnect(id: String) {
|
fun setOpenOnConnect(id: String) {
|
||||||
openFlow.value = id
|
openFlow.value = id
|
||||||
AppSettings.putString(app, KEY_OPEN, id)
|
AppSettings.putString(app, KEY_OPEN, id)
|
||||||
|
|||||||
@@ -92,6 +92,11 @@ private fun densityChoices(current: Int): List<Pair<Int, String>> {
|
|||||||
(DENSITY_CUSTOM to stringResource(R.string.choice_density_custom))
|
(DENSITY_CUSTOM to stringResource(R.string.choice_density_custom))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun mapSizeChoices(): List<Pair<Int, String>> =
|
||||||
|
listOf(CarSettings.MAP_SIZE_AUTO to stringResource(R.string.choice_map_size_auto)) +
|
||||||
|
CarSettings.MAP_SIZES.map { it to stringResource(R.string.choice_map_size_percent, it) }
|
||||||
|
|
||||||
/** Types in any density in [CarSettings.CUSTOM_DENSITIES] (issue #82). */
|
/** Types in any density in [CarSettings.CUSTOM_DENSITIES] (issue #82). */
|
||||||
@Composable
|
@Composable
|
||||||
private fun CustomDensityDialog(current: Int, onDismiss: () -> Unit, onSave: (Int) -> Unit) {
|
private fun CustomDensityDialog(current: Int, onDismiss: () -> Unit, onSave: (Int) -> Unit) {
|
||||||
@@ -270,6 +275,7 @@ internal fun CarGroupScreen(group: CarGroup, onBack: () -> Unit) {
|
|||||||
private fun GroupRows(group: CarGroup) {
|
private fun GroupRows(group: CarGroup) {
|
||||||
val scale by CarSettings.scale.collectAsState()
|
val scale by CarSettings.scale.collectAsState()
|
||||||
val density by CarSettings.carDensity.collectAsState()
|
val density by CarSettings.carDensity.collectAsState()
|
||||||
|
val mapSize by CarSettings.mapAppSize.collectAsState()
|
||||||
val open by CarSettings.openOnConnect.collectAsState()
|
val open by CarSettings.openOnConnect.collectAsState()
|
||||||
val night by CarSettings.nightMode.collectAsState()
|
val night by CarSettings.nightMode.collectAsState()
|
||||||
val units by CarSettings.units.collectAsState()
|
val units by CarSettings.units.collectAsState()
|
||||||
@@ -312,6 +318,11 @@ private fun GroupRows(group: CarGroup) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SettingsDivider()
|
SettingsDivider()
|
||||||
|
Choice(
|
||||||
|
stringResource(R.string.car_map_size), mapSizeChoices(), mapSize, CarSettings::setMapAppSize,
|
||||||
|
note = stringResource(R.string.car_map_size_note),
|
||||||
|
)
|
||||||
|
SettingsDivider()
|
||||||
Choice(stringResource(R.string.car_app_theme), themeChoices(), theme, CarSettings::setAppTheme)
|
Choice(stringResource(R.string.car_app_theme), themeChoices(), theme, CarSettings::setAppTheme)
|
||||||
SettingsDivider()
|
SettingsDivider()
|
||||||
if (theme != AppTheme.LIGHT) {
|
if (theme != AppTheme.LIGHT) {
|
||||||
|
|||||||
@@ -206,6 +206,10 @@
|
|||||||
<string name="choice_density_car">From car</string>
|
<string name="choice_density_car">From car</string>
|
||||||
<string name="choice_density_dpi">%1$d DPI</string>
|
<string name="choice_density_dpi">%1$d DPI</string>
|
||||||
<string name="choice_density_custom">Custom…</string>
|
<string name="choice_density_custom">Custom…</string>
|
||||||
|
<string name="car_map_size">Map app size</string>
|
||||||
|
<string name="car_map_size_note">The buttons and text that map apps draw themselves. Automatic shrinks them on a short screen and leaves others alone.</string>
|
||||||
|
<string name="choice_map_size_auto">Automatic</string>
|
||||||
|
<string name="choice_map_size_percent">%1$d%%</string>
|
||||||
<string name="car_app_theme">App theme</string>
|
<string name="car_app_theme">App theme</string>
|
||||||
<string name="car_dark_mode">Dark mode</string>
|
<string name="car_dark_mode">Dark mode</string>
|
||||||
<string name="car_buttons">Buttons</string>
|
<string name="car_buttons">Buttons</string>
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package app.seb3thehacker.gearslip.car
|
||||||
|
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class MapAppSizeTest {
|
||||||
|
private val context = InMemoryContext()
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun startOnAutomatic() {
|
||||||
|
CarSettings.init(context)
|
||||||
|
CarSettings.setMapAppSize(CarSettings.MAP_SIZE_AUTO)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun automaticLeavesAnOrdinaryScreenAlone() {
|
||||||
|
// 800x480 at 160 with the nav bar over it: the map is 424 tall.
|
||||||
|
assertEquals(160, CarSettings.mapAppDensity(160, 424))
|
||||||
|
assertEquals(240, CarSettings.mapAppDensity(240, 650))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun automaticShrinksAShortScreenUntilTheMapIs320dpTall() {
|
||||||
|
// The SOOEMAKA's map, squashed and above the nav bar: 240 px at 170 dpi.
|
||||||
|
assertEquals(120, CarSettings.mapAppDensity(170, 240))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun automaticStopsAtTheSmallestSize() {
|
||||||
|
assertEquals(102, CarSettings.mapAppDensity(170, 100))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun aChosenSizeIsAPercentOfTheCarUi() {
|
||||||
|
for (percent in CarSettings.MAP_SIZES) {
|
||||||
|
CarSettings.setMapAppSize(percent)
|
||||||
|
assertEquals(200 * percent / 100, CarSettings.mapAppDensity(200, 240))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun theChoiceOutlivesARestart() {
|
||||||
|
CarSettings.setMapAppSize(70)
|
||||||
|
CarSettings.init(context)
|
||||||
|
assertEquals(70, CarSettings.mapAppSize.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user