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

Commit 6fbe5880 authored by Chris Göllner's avatar Chris Göllner Committed by Android (Google) Code Review
Browse files

Merge changes Id926cb37,I86e51ab6 into main

* changes:
  Added Hardcoded Input Shortcuts
  Shortcut Helper - Connect UI layer to shortcuts
parents 7a822326 c5acdeae
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -20,9 +20,11 @@ import android.app.Activity
import com.android.systemui.CoreStartable
import com.android.systemui.Flags.keyboardShortcutHelperRewrite
import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperStateRepository
import com.android.systemui.keyboard.shortcut.data.source.InputShortcutsSource
import com.android.systemui.keyboard.shortcut.data.source.KeyboardShortcutGroupsSource
import com.android.systemui.keyboard.shortcut.data.source.MultitaskingShortcutsSource
import com.android.systemui.keyboard.shortcut.data.source.SystemShortcutsSource
import com.android.systemui.keyboard.shortcut.qualifiers.InputShortcuts
import com.android.systemui.keyboard.shortcut.qualifiers.MultitaskingShortcuts
import com.android.systemui.keyboard.shortcut.qualifiers.SystemShortcuts
import com.android.systemui.keyboard.shortcut.ui.ShortcutHelperActivityStarter
@@ -50,6 +52,10 @@ interface ShortcutHelperModule {
    @MultitaskingShortcuts
    fun multitaskingShortcutsSource(impl: MultitaskingShortcutsSource): KeyboardShortcutGroupsSource

    @Binds
    @InputShortcuts
    fun inputShortcutsSources(impl: InputShortcutsSource): KeyboardShortcutGroupsSource

    companion object {
        @Provides
        @IntoMap
+12 −20
Original line number Diff line number Diff line
@@ -19,16 +19,14 @@ package com.android.systemui.keyboard.shortcut.data.repository
import android.content.Context
import android.hardware.input.InputManager
import android.util.Log
import android.view.InputDevice
import android.view.KeyCharacterMap
import android.view.KeyEvent
import android.view.KeyboardShortcutGroup
import android.view.KeyboardShortcutInfo
import android.view.WindowManager
import android.view.WindowManager.KeyboardShortcutsReceiver
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.keyboard.shortcut.data.source.KeyboardShortcutGroupsSource
import com.android.systemui.keyboard.shortcut.qualifiers.InputShortcuts
import com.android.systemui.keyboard.shortcut.qualifiers.MultitaskingShortcuts
import com.android.systemui.keyboard.shortcut.qualifiers.SystemShortcuts
import com.android.systemui.keyboard.shortcut.shared.model.Shortcut
@@ -44,7 +42,6 @@ import com.android.systemui.keyboard.shortcut.shared.model.ShortcutSubCategory
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext

@SysUISingleton
@@ -55,7 +52,7 @@ constructor(
    @Background private val backgroundDispatcher: CoroutineDispatcher,
    @SystemShortcuts private val systemShortcutsSource: KeyboardShortcutGroupsSource,
    @MultitaskingShortcuts private val multitaskingShortcutsSource: KeyboardShortcutGroupsSource,
    private val windowManager: WindowManager,
    @InputShortcuts private val inputShortcutsSource: KeyboardShortcutGroupsSource,
    private val inputManager: InputManager,
    stateRepository: ShortcutHelperStateRepository
) {
@@ -75,7 +72,7 @@ constructor(
                toShortcutCategory(
                    it.keyCharacterMap,
                    SYSTEM,
                    systemShortcutsSource.shortcutGroups()
                    systemShortcutsSource.shortcutGroups(it.id)
                )
            } else {
                null
@@ -88,7 +85,7 @@ constructor(
                toShortcutCategory(
                    it.keyCharacterMap,
                    MULTI_TASKING,
                    multitaskingShortcutsSource.shortcutGroups()
                    multitaskingShortcutsSource.shortcutGroups(it.id)
                )
            } else {
                null
@@ -96,20 +93,15 @@ constructor(
        }

    val imeShortcutsCategory =
        activeInputDevice.map { if (it != null) retrieveImeShortcuts(it) else null }

    private suspend fun retrieveImeShortcuts(
        inputDevice: InputDevice,
    ): ShortcutCategory? {
        return suspendCancellableCoroutine { continuation ->
            val shortcutsReceiver = KeyboardShortcutsReceiver { shortcutGroups ->
                continuation.resumeWith(
                    Result.success(
                        toShortcutCategory(inputDevice.keyCharacterMap, IME, shortcutGroups)
                    )
        activeInputDevice.map {
            if (it != null) {
                toShortcutCategory(
                    it.keyCharacterMap,
                    IME,
                    inputShortcutsSource.shortcutGroups(it.id)
                )
            }
            windowManager.requestImeKeyboardShortcuts(shortcutsReceiver, inputDevice.id)
            } else {
                null
            }
        }

+66 −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.keyboard.shortcut.data.source

import android.content.res.Resources
import android.view.KeyEvent.KEYCODE_SPACE
import android.view.KeyEvent.META_CTRL_ON
import android.view.KeyEvent.META_SHIFT_ON
import android.view.KeyboardShortcutGroup
import android.view.WindowManager
import android.view.WindowManager.KeyboardShortcutsReceiver
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyboard.shortcut.data.model.shortcutInfo
import com.android.systemui.res.R
import javax.inject.Inject
import kotlinx.coroutines.suspendCancellableCoroutine

class InputShortcutsSource
@Inject
constructor(@Main private val resources: Resources, private val windowManager: WindowManager) :
    KeyboardShortcutGroupsSource {
    override suspend fun shortcutGroups(deviceId: Int): List<KeyboardShortcutGroup> =
        getInputLanguageShortcutGroup() + getImeShortcutGroup(deviceId)

    private fun getInputLanguageShortcutGroup() =
        listOf(
            KeyboardShortcutGroup(
                resources.getString(R.string.shortcut_helper_category_input),
                inputLanguageShortcuts()
            )
        )

    private fun inputLanguageShortcuts() =
        listOf(
            /* Switch input language (next language): Ctrl + Space */
            shortcutInfo(resources.getString(R.string.input_switch_input_language_next)) {
                command(META_CTRL_ON, KEYCODE_SPACE)
            },
            /* Switch previous language (next language): Ctrl + Shift + Space */
            shortcutInfo(resources.getString(R.string.input_switch_input_language_previous)) {
                command(META_CTRL_ON or META_SHIFT_ON, KEYCODE_SPACE)
            }
        )

    private suspend fun getImeShortcutGroup(deviceId: Int): List<KeyboardShortcutGroup> =
        suspendCancellableCoroutine { continuation ->
            val shortcutsReceiver = KeyboardShortcutsReceiver {
                continuation.resumeWith(Result.success(it))
            }
            windowManager.requestImeKeyboardShortcuts(shortcutsReceiver, deviceId)
        }
}
+1 −1
Original line number Diff line number Diff line
@@ -20,5 +20,5 @@ import android.view.KeyboardShortcutGroup

interface KeyboardShortcutGroupsSource {

    fun shortcutGroups(): List<KeyboardShortcutGroup>
    suspend fun shortcutGroups(deviceId: Int): List<KeyboardShortcutGroup>
}
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ import javax.inject.Inject
class MultitaskingShortcutsSource @Inject constructor(@Main private val resources: Resources) :
    KeyboardShortcutGroupsSource {

    override fun shortcutGroups() =
    override suspend fun shortcutGroups(deviceId: Int) =
        listOf(
            KeyboardShortcutGroup(
                resources.getString(R.string.shortcutHelper_category_recent_apps),
Loading