mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-12-01 07:40:31 +01:00
Car audio is one choice of three everywhere (Bluetooth, through Gearslip, or through Gearslip with Shizuku), and Connection moves from the app's Settings into the car settings on Home
This commit is contained in:
1 parent
b010c35a73
commit
70b3466a5f
6 files changed
+127
-75
No files matched your search
@@ -270,6 +270,23 @@ private const val KEY_CLUSTER_VIDEO = "cluster_video_enabled"
|
||||
AppSettings.putString(app, KEY_SHIZUKU_AUDIO, on.toString())
|
||||
}
|
||||
|
||||
/**
|
||||
* How music reaches the car, as the driver sees it: one choice of three, kept as the two
|
||||
* switches underneath ([pipeAudio] and [shizukuAudio]) so nothing that reads them changes.
|
||||
*/
|
||||
enum class AudioRoute { BLUETOOTH, GEARSLIP, SHIZUKU }
|
||||
|
||||
fun audioRoute(pipe: Boolean, shizuku: Boolean) = when {
|
||||
!pipe -> AudioRoute.BLUETOOTH
|
||||
shizuku -> AudioRoute.SHIZUKU
|
||||
else -> AudioRoute.GEARSLIP
|
||||
}
|
||||
|
||||
fun setAudioRoute(route: AudioRoute) {
|
||||
setShizukuAudio(route == AudioRoute.SHIZUKU)
|
||||
setPipeAudio(route != AudioRoute.BLUETOOTH)
|
||||
}
|
||||
|
||||
private val navBarFlow = MutableStateFlow(NavBarMode.SHOW)
|
||||
val navBarMode: StateFlow<NavBarMode> = navBarFlow
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ fun CarSettingsScreen() {
|
||||
val screenFit by CarSettings.screenFit.collectAsState()
|
||||
val whatsNew by CarSettings.whatsNewAfterUpdates.collectAsState()
|
||||
val pipeAudio by CarSettings.pipeAudio.collectAsState()
|
||||
val shizukuAudio by CarSettings.shizukuAudio.collectAsState()
|
||||
val speakDirections by CarSettings.speakDirections.collectAsState()
|
||||
val directionsOverMusic by CarSettings.directionsOverMusic.collectAsState()
|
||||
val bluetoothWarning by CarSettings.bluetoothWarning.collectAsState()
|
||||
@@ -214,9 +215,13 @@ fun CarSettingsScreen() {
|
||||
item {
|
||||
ChoiceRow(
|
||||
stringResource(R.string.car_audio),
|
||||
listOf(false to stringResource(R.string.guide_audio_bluetooth), true to stringResource(R.string.guide_audio_usb)),
|
||||
pipeAudio,
|
||||
) { CarSettings.setPipeAudio(it) }
|
||||
listOf(
|
||||
CarSettings.AudioRoute.BLUETOOTH to stringResource(R.string.guide_audio_bluetooth),
|
||||
CarSettings.AudioRoute.GEARSLIP to stringResource(R.string.guide_audio_usb),
|
||||
CarSettings.AudioRoute.SHIZUKU to stringResource(R.string.audio_shizuku),
|
||||
),
|
||||
CarSettings.audioRoute(pipeAudio, shizukuAudio),
|
||||
) { CarSettings.setAudioRoute(it) }
|
||||
}
|
||||
item { Note(stringResource(R.string.carset_audio_note)) }
|
||||
item {
|
||||
|
||||
@@ -73,6 +73,7 @@ enum class CarGroup(@param:StringRes val title: Int) {
|
||||
SCREEN(R.string.car_group_screen),
|
||||
NAV_BAR(R.string.car_group_nav_bar),
|
||||
SOUND(R.string.car_group_sound),
|
||||
CONNECTION(R.string.settings_connection),
|
||||
PLACES(R.string.places_title),
|
||||
BROWSER(R.string.app_browser),
|
||||
WARNINGS(R.string.car_group_warnings),
|
||||
@@ -243,6 +244,7 @@ internal fun HomeCarSettings(onOpen: (CarGroup) -> Unit, modifier: Modifier = Mo
|
||||
val open by CarSettings.openOnConnect.collectAsState()
|
||||
val navBar by CarSettings.navBarMode.collectAsState()
|
||||
val pipeAudio by CarSettings.pipeAudio.collectAsState()
|
||||
val shizukuAudio by CarSettings.shizukuAudio.collectAsState()
|
||||
val speakDirections by CarSettings.speakDirections.collectAsState()
|
||||
val bluetoothWarning by CarSettings.bluetoothWarning.collectAsState()
|
||||
val locationWarning by CarSettings.locationWarning.collectAsState()
|
||||
@@ -265,9 +267,16 @@ internal fun HomeCarSettings(onOpen: (CarGroup) -> Unit, modifier: Modifier = Mo
|
||||
CarGroup.SCREEN -> listOf(opens.label(open), sizes.label(scale), themes.label(theme))
|
||||
CarGroup.NAV_BAR -> listOf(navBars.label(navBar), str(if (playerLeft) R.string.summary_player_left else R.string.summary_player_right))
|
||||
CarGroup.SOUND -> listOf(
|
||||
str(if (pipeAudio) R.string.summary_usb_audio else R.string.summary_bluetooth_audio),
|
||||
str(
|
||||
when (CarSettings.audioRoute(pipeAudio, shizukuAudio)) {
|
||||
CarSettings.AudioRoute.BLUETOOTH -> R.string.summary_bluetooth_audio
|
||||
CarSettings.AudioRoute.GEARSLIP -> R.string.summary_usb_audio
|
||||
CarSettings.AudioRoute.SHIZUKU -> R.string.summary_shizuku_audio
|
||||
},
|
||||
),
|
||||
str(if (speakDirections) R.string.summary_directions_on else R.string.summary_directions_off),
|
||||
)
|
||||
CarGroup.CONNECTION -> connectionSummary(context)
|
||||
CarGroup.PLACES -> places.mapIndexedNotNull { i, place ->
|
||||
when {
|
||||
place.address.isBlank() -> null
|
||||
@@ -311,6 +320,21 @@ internal fun HomeCarSettings(onOpen: (CarGroup) -> Unit, modifier: Modifier = Mo
|
||||
}
|
||||
}
|
||||
|
||||
/** Which link Gearslip tries first, and any that are switched off. */
|
||||
private fun connectionSummary(context: android.content.Context): List<String> {
|
||||
val cable = app.seb3thehacker.gearslip.AppSettings.cableEnabled(context)
|
||||
val wireless = app.seb3thehacker.gearslip.AppSettings.wirelessAutoConnect(context)
|
||||
val cableFirst = app.seb3thehacker.gearslip.AppSettings.connectionOrder(context) ==
|
||||
app.seb3thehacker.gearslip.AppSettings.ConnectionOrder.CABLE_FIRST
|
||||
return when {
|
||||
!app.seb3thehacker.gearslip.AppSettings.gearslipEnabled(context) -> listOf(context.getString(R.string.summary_gearslip_off))
|
||||
cable && wireless -> listOf(context.getString(if (cableFirst) R.string.summary_cable_first else R.string.summary_wireless_first))
|
||||
cable -> listOf(context.getString(R.string.summary_cable_only))
|
||||
wireless -> listOf(context.getString(R.string.summary_wireless_only))
|
||||
else -> listOf(context.getString(R.string.summary_no_link))
|
||||
}
|
||||
}
|
||||
|
||||
/** One group of the car's settings, on a screen of its own. */
|
||||
@OptIn(androidx.compose.material3.ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -344,8 +368,8 @@ internal fun CarGroupScreen(group: CarGroup, onBack: () -> Unit) {
|
||||
}
|
||||
else -> Unit
|
||||
}
|
||||
// The car's own Settings has no list of apps.
|
||||
if (group != CarGroup.APPS) Text(
|
||||
// The car's own Settings has no list of apps, and connecting is set up on the phone.
|
||||
if (group != CarGroup.APPS && group != CarGroup.CONNECTION) Text(
|
||||
stringResource(R.string.car_group_same),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
@@ -386,8 +410,6 @@ private fun GroupRows(group: CarGroup) {
|
||||
val speechServer by CarSettings.speechServer.collectAsState()
|
||||
val aiServer by CarSettings.aiServer.collectAsState()
|
||||
val appCommands by CarSettings.appCommands.collectAsState()
|
||||
val shizukuAudio by CarSettings.shizukuAudio.collectAsState()
|
||||
val shizuku by app.seb3thehacker.gearslip.shizuku.ShizukuSetup.state.collectAsState()
|
||||
|
||||
when (group) {
|
||||
CarGroup.APPS -> AppRows()
|
||||
@@ -472,11 +494,8 @@ private fun GroupRows(group: CarGroup) {
|
||||
ServerRow(stringResource(R.string.car_ai_server), stringResource(R.string.car_ai_server_note), stringResource(R.string.ai_server_hint), "http://192.168.1.20:11434", aiServer, CarSettings::setAiServer)
|
||||
SettingsDivider()
|
||||
Toggle(stringResource(R.string.car_app_commands), appCommands, CarSettings::setAppCommands, note = stringResource(R.string.car_app_commands_note))
|
||||
if (shizuku != app.seb3thehacker.gearslip.shizuku.ShizukuSetup.State.MISSING) {
|
||||
SettingsDivider()
|
||||
Toggle(stringResource(R.string.car_shizuku_audio), shizukuAudio, CarSettings::setShizukuAudio, note = stringResource(R.string.car_shizuku_audio_note))
|
||||
}
|
||||
}
|
||||
CarGroup.CONNECTION -> ConnectionRows()
|
||||
CarGroup.PLACES -> Unit
|
||||
CarGroup.WARNINGS -> {
|
||||
if (!pipeAudio) {
|
||||
@@ -732,27 +751,55 @@ private fun WebPageRow() {
|
||||
}
|
||||
}
|
||||
|
||||
/** How music reaches the car: by Bluetooth as usual, or through Gearslip over USB. Same choice as setup. */
|
||||
/**
|
||||
* How music reaches the car, one choice of three: Bluetooth as usual, through Gearslip with
|
||||
* Android's capture (a prompt each drive), or through Gearslip recorded by Shizuku (no prompt,
|
||||
* every app). The same choice as setup and the car's own Settings.
|
||||
*/
|
||||
@Composable
|
||||
internal fun CarAudioSection() {
|
||||
val usb by CarSettings.pipeAudio.collectAsState()
|
||||
val pipe by CarSettings.pipeAudio.collectAsState()
|
||||
val shizukuAudio by CarSettings.shizukuAudio.collectAsState()
|
||||
val shizuku by app.seb3thehacker.gearslip.shizuku.ShizukuSetup.state.collectAsState()
|
||||
val route = CarSettings.audioRoute(pipe, shizukuAudio)
|
||||
LaunchedEffect(Unit) { app.seb3thehacker.gearslip.shizuku.ShizukuSetup.refresh() }
|
||||
SettingsSection(
|
||||
stringResource(R.string.car_audio),
|
||||
footer = stringResource(if (usb) R.string.car_audio_usb_footer else R.string.car_audio_bt_footer),
|
||||
footer = stringResource(
|
||||
when (route) {
|
||||
CarSettings.AudioRoute.BLUETOOTH -> R.string.car_audio_bt_footer
|
||||
CarSettings.AudioRoute.GEARSLIP -> R.string.car_audio_usb_footer
|
||||
CarSettings.AudioRoute.SHIZUKU -> R.string.car_audio_bt_footer
|
||||
},
|
||||
),
|
||||
) {
|
||||
SettingsRow(
|
||||
stringResource(R.string.car_audio_bt),
|
||||
Modifier.selectable(!usb, role = androidx.compose.ui.semantics.Role.RadioButton) { CarSettings.setPipeAudio(false) },
|
||||
subtitle = stringResource(R.string.car_audio_bt_sub),
|
||||
trailing = { androidx.compose.material3.RadioButton(selected = !usb, onClick = null) },
|
||||
)
|
||||
SettingsDivider()
|
||||
SettingsRow(
|
||||
stringResource(R.string.guide_audio_usb),
|
||||
Modifier.selectable(usb, role = androidx.compose.ui.semantics.Role.RadioButton) { CarSettings.setPipeAudio(true) },
|
||||
subtitle = stringResource(R.string.car_audio_usb_sub),
|
||||
trailing = { androidx.compose.material3.RadioButton(selected = usb, onClick = null) },
|
||||
)
|
||||
listOf(
|
||||
Triple(CarSettings.AudioRoute.BLUETOOTH, R.string.car_audio_bt, R.string.car_audio_bt_sub),
|
||||
Triple(CarSettings.AudioRoute.GEARSLIP, R.string.guide_audio_usb, R.string.car_audio_usb_sub),
|
||||
Triple(CarSettings.AudioRoute.SHIZUKU, R.string.audio_shizuku, R.string.audio_shizuku_sub),
|
||||
).forEachIndexed { i, (value, title, sub) ->
|
||||
if (i > 0) SettingsDivider()
|
||||
val chosen = route == value
|
||||
SettingsRow(
|
||||
stringResource(title),
|
||||
Modifier.selectable(chosen, role = androidx.compose.ui.semantics.Role.RadioButton) { CarSettings.setAudioRoute(value) },
|
||||
subtitle = stringResource(sub),
|
||||
trailing = { androidx.compose.material3.RadioButton(selected = chosen, onClick = null) },
|
||||
)
|
||||
}
|
||||
// Shizuku chosen: what it still needs, right under it.
|
||||
if (route == CarSettings.AudioRoute.SHIZUKU) {
|
||||
if (shizuku == app.seb3thehacker.gearslip.shizuku.ShizukuSetup.State.MISSING) {
|
||||
Text(
|
||||
stringResource(R.string.audio_shizuku_missing),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||
)
|
||||
} else {
|
||||
ShizukuGrantButton(Modifier.padding(horizontal = 16.dp, vertical = 12.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,6 @@ fun SettingsScreen(
|
||||
stringResource(R.string.settings_support),
|
||||
footer = stringResource(R.string.settings_support_footer),
|
||||
) { DonateRows() }
|
||||
if (ready(2)) ConnectionSection()
|
||||
if (ready(2)) ShizukuSection()
|
||||
if (SHOW_RECOMMENDED_APPS && ready(6)) AppsSection(onOpenRecommendedApps)
|
||||
if (ready(7)) SettingsSection(
|
||||
@@ -224,12 +223,16 @@ private fun AboutSection(onReplayTutorial: () -> Unit) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Off, a stock Android Auto app or head unit answers the USB connection instead of Gearslip. */
|
||||
/**
|
||||
* How the phone reaches the car, under Home > Car > Connection: whether Gearslip answers at all
|
||||
* (off, a stock Android Auto app answers the USB connection instead), cable and wireless in the
|
||||
* order it tries them, launcher mode, and the phone's Bluetooth address.
|
||||
*/
|
||||
@Composable
|
||||
private fun ConnectionSection() {
|
||||
internal fun ConnectionRows() {
|
||||
val context = LocalContext.current
|
||||
var enabled by remember { mutableStateOf(AppSettings.gearslipEnabled(context)) }
|
||||
SettingsSection(stringResource(R.string.settings_connection)) {
|
||||
run {
|
||||
SettingsRow(
|
||||
stringResource(R.string.settings_use_in_car),
|
||||
Modifier.toggleable(enabled, role = Role.Switch) {
|
||||
@@ -255,7 +258,6 @@ private fun ConnectionSection() {
|
||||
icon = Icons.Filled.Home,
|
||||
trailing = { Switch(checked = launcher, onCheckedChange = null) },
|
||||
)
|
||||
CarAudioSetting()
|
||||
var address by remember { mutableStateOf(CarBluetooth.typedAddress(context)) }
|
||||
var editing by remember { mutableStateOf(false) }
|
||||
SettingsRow(
|
||||
@@ -351,42 +353,6 @@ private fun ConnectionOrderRows() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Where the car's sound comes from: Bluetooth, or through Gearslip over the car link. Takes
|
||||
* effect at once when a car is connected. The chosen pill is filled in the main colour, the
|
||||
* other tonal, like the buttons on Home.
|
||||
*/
|
||||
@Composable
|
||||
private fun CarAudioSetting() {
|
||||
val pipe by app.seb3thehacker.gearslip.car.CarSettings.pipeAudio.collectAsState()
|
||||
val thisCar by app.seb3thehacker.gearslip.car.CarSettings.thisCarPipes.collectAsState()
|
||||
val through = pipe || thisCar
|
||||
val scheme = MaterialTheme.colorScheme
|
||||
// Android won't let Gearslip capture navigation voices, only media, so they stay on the phone.
|
||||
SettingsRow(
|
||||
stringResource(R.string.car_audio),
|
||||
subtitle = if (through) stringResource(R.string.home_audio_usb_warning) else null,
|
||||
icon = app.seb3thehacker.gearslip.car.MediaIcons.MusicNote,
|
||||
)
|
||||
androidx.compose.foundation.layout.Row(
|
||||
Modifier.fillMaxWidth().padding(start = 56.dp, end = 16.dp, bottom = 12.dp),
|
||||
horizontalArrangement = androidx.compose.foundation.layout.Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
listOf(false to R.string.guide_audio_bluetooth, true to R.string.guide_audio_usb).forEach { (value, label) ->
|
||||
val chosen = through == value
|
||||
androidx.compose.material3.Button(
|
||||
onClick = { app.seb3thehacker.gearslip.car.CarSettings.setPipeAudio(value) },
|
||||
colors = androidx.compose.material3.ButtonDefaults.buttonColors(
|
||||
containerColor = if (chosen) scheme.primary else scheme.secondaryContainer,
|
||||
contentColor = if (chosen) scheme.onPrimary else scheme.onSecondaryContainer,
|
||||
),
|
||||
contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 12.dp),
|
||||
modifier = Modifier.weight(1f).height(48.dp).semantics { selected = chosen },
|
||||
) { Text(stringResource(label), maxLines = 1) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The phone's Bluetooth address, typed in by hand: Android doesn't let apps read it. */
|
||||
@Composable
|
||||
internal fun AddressDialog(initial: String, onDismiss: () -> Unit, onSave: (String) -> Boolean) {
|
||||
|
||||
@@ -405,18 +405,26 @@ private fun VoiceDownloadStatus() {
|
||||
@Composable
|
||||
private fun AudioChoice() {
|
||||
val usb by CarSettings.pipeAudio.collectAsState()
|
||||
val shizukuAudio by CarSettings.shizukuAudio.collectAsState()
|
||||
val route = CarSettings.audioRoute(usb, shizukuAudio)
|
||||
LaunchedEffect(Unit) { if (!CarSettings.pipeAudioChosen) CarSettings.setPipeAudio(false) }
|
||||
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
AudioCard(
|
||||
stringResource(R.string.guide_audio_bluetooth), stringResource(R.string.guide_recommended),
|
||||
stringResource(R.string.guide_audio_bluetooth_body),
|
||||
selected = !usb,
|
||||
) { CarSettings.setPipeAudio(false) }
|
||||
selected = route == CarSettings.AudioRoute.BLUETOOTH,
|
||||
) { CarSettings.setAudioRoute(CarSettings.AudioRoute.BLUETOOTH) }
|
||||
AudioCard(
|
||||
stringResource(R.string.guide_audio_usb), null,
|
||||
stringResource(R.string.guide_audio_usb_body),
|
||||
selected = usb,
|
||||
) { CarSettings.setPipeAudio(true) }
|
||||
selected = route == CarSettings.AudioRoute.GEARSLIP,
|
||||
) { CarSettings.setAudioRoute(CarSettings.AudioRoute.GEARSLIP) }
|
||||
AudioCard(
|
||||
stringResource(R.string.audio_shizuku), null,
|
||||
stringResource(R.string.audio_shizuku_sub),
|
||||
selected = route == CarSettings.AudioRoute.SHIZUKU,
|
||||
) { CarSettings.setAudioRoute(CarSettings.AudioRoute.SHIZUKU) }
|
||||
if (route == CarSettings.AudioRoute.SHIZUKU) ShizukuGrantButton()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -190,6 +190,13 @@
|
||||
<string name="summary_player_right">Player on the right</string>
|
||||
<string name="summary_usb_audio">Audio through Gearslip</string>
|
||||
<string name="summary_bluetooth_audio">Bluetooth audio</string>
|
||||
<string name="summary_shizuku_audio">Audio through Shizuku</string>
|
||||
<string name="summary_cable_first">Cable first</string>
|
||||
<string name="summary_wireless_first">Wireless first</string>
|
||||
<string name="summary_cable_only">Cable only</string>
|
||||
<string name="summary_wireless_only">Wireless only</string>
|
||||
<string name="summary_no_link">Cable and wireless off</string>
|
||||
<string name="summary_gearslip_off">Gearslip off</string>
|
||||
<string name="summary_directions_on">Directions on</string>
|
||||
<string name="summary_directions_off">Directions off</string>
|
||||
<string name="summary_bluetooth_on">Bluetooth on</string>
|
||||
@@ -241,8 +248,10 @@
|
||||
<string name="choice_touch_auto">Automatic</string>
|
||||
<string name="choice_touch_as_sent">As the car sends them</string>
|
||||
<string name="choice_touch_scaled">Scaled to the screen</string>
|
||||
<string name="car_shizuku_audio">Record music through Shizuku</string>
|
||||
<string name="car_shizuku_audio_note">Sends everything the phone plays, with no screen sharing prompt, Spotify included. Your map app\'s own voice comes through too, so you may want Spoken directions off.</string>
|
||||
<!-- The third car audio choice: music recorded through the Shizuku app instead of Android's screen-sharing capture. -->
|
||||
<string name="audio_shizuku">Through Gearslip with Shizuku</string>
|
||||
<string name="audio_shizuku_sub">No prompt each drive, and every app reaches the car, Spotify included. Your map app\'s voice comes through too. Needs the free Shizuku app running</string>
|
||||
<string name="audio_shizuku_missing">Install the free Shizuku app and start it first. Until then, Gearslip asks to share the screen as usual.</string>
|
||||
<string name="car_speech_server">Your own speech server</string>
|
||||
<string name="car_speech_server_note">Hears your voice on a server you run, such as whisper.cpp or faster-whisper, so the phone loads no speech model.</string>
|
||||
<string name="car_ai_server">Your own AI server</string>
|
||||
|
||||
Reference in new issue
Block a user