mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-11 08:12:26 +01:00
Gearslip leaves the phone's screen once the car's screen is up
The car opens Gearslip on the phone each time it connects, over USB or through auto-connect. Once video is up it now moves to the background, unless the phone was already showing it or a question needs the driver.
This commit is contained in:
1 parent
1e3d4f5188
commit
aadca6019e
1 file changed
+30
@@ -118,6 +118,10 @@ class GearslipActivity : ComponentActivity(), Projection {
|
|||||||
|
|
||||||
/** Android's one-time "Allow" for a car to connect by itself; see [WirelessAuto]. */
|
/** Android's one-time "Allow" for a car to connect by itself; see [WirelessAuto]. */
|
||||||
private var approvingCar: String? = null
|
private var approvingCar: String? = null
|
||||||
|
|
||||||
|
/** Whether the phone showed Gearslip when the car's intent arrived; see [stepAside]. */
|
||||||
|
private var shownOnPhone = false
|
||||||
|
private var stepAsideOnVideo = false
|
||||||
private val carApproval = registerForActivityResult(
|
private val carApproval = registerForActivityResult(
|
||||||
androidx.activity.result.contract.ActivityResultContracts.StartIntentSenderForResult(),
|
androidx.activity.result.contract.ActivityResultContracts.StartIntentSenderForResult(),
|
||||||
) { result ->
|
) { result ->
|
||||||
@@ -223,6 +227,16 @@ class GearslipActivity : ComponentActivity(), Projection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
shownOnPhone = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStop() {
|
||||||
|
super.onStop()
|
||||||
|
shownOnPhone = false
|
||||||
|
}
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
handleIntent(intent)
|
handleIntent(intent)
|
||||||
@@ -323,6 +337,7 @@ class GearslipActivity : ComponentActivity(), Projection {
|
|||||||
// Debug builds only: opens the audio choice for a look, without turning down a real prompt.
|
// Debug builds only: opens the audio choice for a look, without turning down a real prompt.
|
||||||
if (BuildConfig.DEBUG && intent?.getBooleanExtra("show_audio_choice", false) == true) offerBluetooth.value = true
|
if (BuildConfig.DEBUG && intent?.getBooleanExtra("show_audio_choice", false) == true) offerBluetooth.value = true
|
||||||
if (intent?.action == app.seb3thehacker.gearslip.wireless.WirelessAuto.ACTION_CAR_NEARBY) {
|
if (intent?.action == app.seb3thehacker.gearslip.wireless.WirelessAuto.ACTION_CAR_NEARBY) {
|
||||||
|
stepAsideOnVideo = !shownOnPhone
|
||||||
connectToNearbyCar(intent.getStringExtra(app.seb3thehacker.gearslip.wireless.WirelessAuto.EXTRA_ADDRESS))
|
connectToNearbyCar(intent.getStringExtra(app.seb3thehacker.gearslip.wireless.WirelessAuto.EXTRA_ADDRESS))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -340,6 +355,7 @@ class GearslipActivity : ComponentActivity(), Projection {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
GearslipLog.i("accessory attached by the system - permission is implicit on this path")
|
GearslipLog.i("accessory attached by the system - permission is implicit on this path")
|
||||||
|
stepAsideOnVideo = !shownOnPhone
|
||||||
start(accessory)
|
start(accessory)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,6 +467,19 @@ class GearslipActivity : ComponentActivity(), Projection {
|
|||||||
|
|
||||||
// --- Projection ---------------------------------------------------------------------
|
// --- Projection ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The car opens Gearslip on the phone, since Android hands a USB car only to an activity and
|
||||||
|
* auto-connect has to start one too. Once the car's screen is up, go back to whatever the
|
||||||
|
* phone showed, as Home would; the session carries on as it does with the phone locked. A
|
||||||
|
* question for the driver keeps Gearslip in front, and so does the phone already showing it.
|
||||||
|
*/
|
||||||
|
private fun stepAside() {
|
||||||
|
stepAsideOnVideo = false
|
||||||
|
if (offerBluetooth.value || micBlockedNotice.value || approvingCar != null) return
|
||||||
|
GearslipLog.i("the car's screen is up - moving Gearslip off the phone's screen")
|
||||||
|
moveTaskToBack(true)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onSurfaceReady(surface: Surface, width: Int, height: Int, densityDpi: Int) {
|
override fun onSurfaceReady(surface: Surface, width: Int, height: Int, densityDpi: Int) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
this.surface = surface
|
this.surface = surface
|
||||||
@@ -460,6 +489,7 @@ class GearslipActivity : ComponentActivity(), Projection {
|
|||||||
CarEnvironment.setDisplay(width, height, densityDpi)
|
CarEnvironment.setDisplay(width, height, densityDpi)
|
||||||
CarEnvironment.start(this)
|
CarEnvironment.start(this)
|
||||||
showCarUi()
|
showCarUi()
|
||||||
|
if (stepAsideOnVideo) stepAside()
|
||||||
app.seb3thehacker.gearslip.car.CarKeys.focusSink = { code, down ->
|
app.seb3thehacker.gearslip.car.CarKeys.focusSink = { code, down ->
|
||||||
runOnUiThread { screenProjector?.dispatchKey(code, down) }
|
runOnUiThread { screenProjector?.dispatchKey(code, down) }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user