Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 297e4792 authored by Michal Brzezinski's avatar Michal Brzezinski
Browse files

Tutorial correctly handling META key event

Removing previous workaround where ALT key was needed to be pressed.
Also fixing the bug when you have to press non-modifier button first and only after that modifier key is intercepted by our view.

Bug: 358587037
Flag: com.android.systemui.shared.new_touchpad_gestures_tutorial
Test: open keyboard tutorial and use Meta/Action key to finish it!
Change-Id: Ifc4e989b54650bd0ee239b48c248fde90c76a3c6
parent ef6d496d
Loading
Loading
Loading
Loading
+19 −6
Original line number Original line Diff line number Diff line
@@ -17,15 +17,19 @@
package com.android.systemui.inputdevice.tutorial.ui.composable
package com.android.systemui.inputdevice.tutorial.ui.composable


import androidx.activity.compose.BackHandler
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.input.key.KeyEventType
import androidx.compose.ui.input.key.KeyEventType
@@ -46,18 +50,27 @@ fun ActionKeyTutorialScreen(
    BackHandler(onBack = onBack)
    BackHandler(onBack = onBack)
    val screenConfig = buildScreenConfig()
    val screenConfig = buildScreenConfig()
    var actionState by remember { mutableStateOf(NOT_STARTED) }
    var actionState by remember { mutableStateOf(NOT_STARTED) }
    val focusRequester = remember { FocusRequester() }
    Box(
    Box(
        modifier =
        modifier =
            Modifier.fillMaxSize().onKeyEvent { keyEvent: KeyEvent ->
            Modifier.fillMaxSize()
                // temporary before we can access Action/Meta key
                .onKeyEvent { keyEvent: KeyEvent ->
                if (keyEvent.key == Key.AltLeft && keyEvent.type == KeyEventType.KeyUp) {
                    if (keyEvent.key == Key.MetaLeft && keyEvent.type == KeyEventType.KeyUp) {
                        actionState = FINISHED
                        actionState = FINISHED
                    }
                    }
                    true
                    true
                }
                }
                .focusRequester(focusRequester)
                .focusable()
    ) {
    ) {
        ActionTutorialContent(actionState, onDoneButtonClicked, screenConfig)
        ActionTutorialContent(actionState, onDoneButtonClicked, screenConfig)
    }
    }
    LaunchedEffect(Unit) {
        // we need to request focus on main container so it can handle all key events immediately
        // when it's open. Otherwise user needs to press non-modifier key before modifier key can
        // be handled as nothing is focused
        focusRequester.requestFocus()
    }
}
}


@Composable
@Composable
+1 −0
Original line number Original line Diff line number Diff line
@@ -68,6 +68,7 @@ constructor(
        enableEdgeToEdge()
        enableEdgeToEdge()
        // required to handle 3+ fingers on touchpad
        // required to handle 3+ fingers on touchpad
        window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY)
        window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY)
        window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_ALLOW_ACTION_KEY_EVENTS)
        lifecycle.addObserver(vm)
        lifecycle.addObserver(vm)
        lifecycleScope.launch {
        lifecycleScope.launch {
            vm.closeActivity.collect { finish ->
            vm.closeActivity.collect { finish ->
+1 −0
Original line number Original line Diff line number Diff line
@@ -57,6 +57,7 @@ constructor(
        }
        }
        // required to handle 3+ fingers on touchpad
        // required to handle 3+ fingers on touchpad
        window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY)
        window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY)
        window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_ALLOW_ACTION_KEY_EVENTS)
    }
    }


    private fun finishTutorial() {
    private fun finishTutorial() {