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

Commit 62c19ce1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ifc4e989b,I51bda79d into main

* changes:
  Tutorial correctly handling META key event
  Adding logger for touchpad and keyboard tutorials
parents 9302f849 297e4792
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.inputdevice.tutorial

import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.dagger.InputDeviceTutorialLog
import com.android.systemui.touchpad.tutorial.ui.viewmodel.Screen
import com.google.errorprone.annotations.CompileTimeConstant
import javax.inject.Inject

private const val TAG = "InputDeviceTutorial"

class InputDeviceTutorialLogger
@Inject
constructor(@InputDeviceTutorialLog private val buffer: LogBuffer) {

    fun log(@CompileTimeConstant s: String) {
        buffer.log(TAG, LogLevel.INFO, message = s)
    }

    fun logGoingToScreen(screen: Screen, context: TutorialContext) {
        buffer.log(
            TAG,
            LogLevel.INFO,
            {
                str1 = screen.toString()
                str2 = context.string
            },
            { "Emitting new screen $str1 in $str2" }
        )
    }

    fun logCloseTutorial(context: TutorialContext) {
        buffer.log(TAG, LogLevel.INFO, { str1 = context.string }, { "Closing $str1" })
    }

    enum class TutorialContext(val string: String) {
        KEYBOARD_TOUCHPAD_TUTORIAL("keyboard touchpad tutorial"),
        TOUCHPAD_TUTORIAL("touchpad tutorial"),
    }
}
+19 −6
Original line number Diff line number Diff line
@@ -17,15 +17,19 @@
package com.android.systemui.inputdevice.tutorial.ui.composable

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
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.KeyEvent
import androidx.compose.ui.input.key.KeyEventType
@@ -46,18 +50,27 @@ fun ActionKeyTutorialScreen(
    BackHandler(onBack = onBack)
    val screenConfig = buildScreenConfig()
    var actionState by remember { mutableStateOf(NOT_STARTED) }
    val focusRequester = remember { FocusRequester() }
    Box(
        modifier =
            Modifier.fillMaxSize().onKeyEvent { keyEvent: KeyEvent ->
                // temporary before we can access Action/Meta key
                if (keyEvent.key == Key.AltLeft && keyEvent.type == KeyEventType.KeyUp) {
            Modifier.fillMaxSize()
                .onKeyEvent { keyEvent: KeyEvent ->
                    if (keyEvent.key == Key.MetaLeft && keyEvent.type == KeyEventType.KeyUp) {
                        actionState = FINISHED
                    }
                    true
                }
                .focusRequester(focusRequester)
                .focusable()
    ) {
        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
+1 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ constructor(
        enableEdgeToEdge()
        // required to handle 3+ fingers on touchpad
        window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY)
        window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_ALLOW_ACTION_KEY_EVENTS)
        lifecycle.addObserver(vm)
        lifecycleScope.launch {
            vm.closeActivity.collect { finish ->
+25 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.log.dagger

import javax.inject.Qualifier

/** A [com.android.systemui.log.LogBuffer] for input device tutorial. */
@Qualifier
@MustBeDocumented
@Retention(AnnotationRetention.RUNTIME)
annotation class InputDeviceTutorialLog
+8 −0
Original line number Diff line number Diff line
@@ -660,6 +660,14 @@ public class LogModule {
        return factory.create("KeyboardLog", 50);
    }

    /** Provides a {@link LogBuffer} for the input devices tutorial. */
    @Provides
    @SysUISingleton
    @InputDeviceTutorialLog
    public static LogBuffer provideInputDeviceTutorialLogBuffer(LogBufferFactory factory) {
        return factory.create("InputDeviceTutorialLog", 50);
    }

    /** Provides a {@link LogBuffer} for {@link PackageChangeRepository} */
    @Provides
    @SysUISingleton
Loading