[flexiglass] Enable toggling legacy SysUI on/off.

To manually toggle legacy SysUI on/off, top 5 times in quick succession
on the device camera (top center). That particular spot was chosen
because it's the least likely one to have actual UI tap targets
underneath that the toggle would interfere with.

Note: due to b/290984671, the tap target after initial unlock moves
directly below the camera.

Fix: 290927217
Test: manually verified by tapping on the camera to toggle the UI on and
off.

Change-Id: I0d7d905a31842a8450436472a0a94d9e58bc2fda
This commit is contained in:
burakov
2023-07-14 19:44:51 +00:00
parent 39759a9ed1
commit 2e17cd6cd8

View File

@@ -16,19 +16,25 @@
package com.android.systemui.scene.ui.view
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.activity.OnBackPressedDispatcher
import androidx.activity.OnBackPressedDispatcherOwner
import androidx.activity.setViewTreeOnBackPressedDispatcherOwner
import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.android.systemui.R
import com.android.systemui.compose.ComposeFacade
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.scene.shared.model.Scene
import com.android.systemui.scene.shared.model.SceneContainerConfig
import com.android.systemui.scene.shared.model.SceneKey
import com.android.systemui.scene.ui.viewmodel.SceneContainerViewModel
import java.time.Instant
import kotlinx.coroutines.launch
object SceneWindowRootViewBinder {
@@ -77,6 +83,9 @@ object SceneWindowRootViewBinder {
)
)
val legacyView = view.requireViewById<View>(R.id.legacy_window_root)
view.addView(createVisibilityToggleView(legacyView))
launch {
viewModel.isVisible.collect { isVisible ->
onVisibilityChangedInternal(isVisible)
@@ -89,4 +98,28 @@ object SceneWindowRootViewBinder {
}
}
}
private var clickCount = 0
private var lastClick = Instant.now()
/**
* A temporary UI to toggle on/off the visibility of the given [otherView]. It is toggled by
* tapping 5 times in quick succession on the device camera (top center).
*/
// TODO(b/291321285): Remove this when the Flexiglass UI is mature enough to turn off legacy
// SysUI altogether.
private fun createVisibilityToggleView(otherView: View): View {
val toggleView = View(otherView.context)
toggleView.layoutParams = FrameLayout.LayoutParams(200, 200, Gravity.CENTER_HORIZONTAL)
toggleView.setOnClickListener {
val now = Instant.now()
clickCount = if (now.minusSeconds(2) > lastClick) 1 else clickCount + 1
if (clickCount == 5) {
otherView.isVisible = !otherView.isVisible
clickCount = 0
}
lastClick = now
}
return toggleView
}
}