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

Commit 219794d0 authored by Chris Göllner's avatar Chris Göllner
Browse files

Shortcut Helper - Data sources for system and multi tasking shortcuts

Flag: com.android.systemui.keyboard_shortcut_helper_rewrite
Test: NA
Bug: 341045652
Change-Id: Id4ef94ac2aa1b537535c4cfeb454b4370ff58bfb
parent 64e23d81
Loading
Loading
Loading
Loading
+76 −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_DPAD_LEFT
import android.view.KeyEvent.KEYCODE_DPAD_RIGHT
import android.view.KeyEvent.KEYCODE_DPAD_UP
import android.view.KeyEvent.KEYCODE_TAB
import android.view.KeyEvent.META_ALT_ON
import android.view.KeyEvent.META_CTRL_ON
import android.view.KeyEvent.META_META_ON
import android.view.KeyEvent.META_SHIFT_ON
import com.android.systemui.keyboard.shortcut.shared.model.shortcut
import com.android.systemui.res.R
import javax.inject.Inject

class MultitaskingShortcutsSource @Inject constructor(private val resources: Resources) {

    fun splitScreenShortcuts() =
        listOf(
            //  Enter Split screen with current app to RHS:
            //   - Meta + Ctrl + Right arrow
            shortcut(resources.getString(R.string.system_multitasking_rhs)) {
                command(META_META_ON, META_CTRL_ON, KEYCODE_DPAD_RIGHT)
            },
            //  Enter Split screen with current app to LHS:
            //   - Meta + Ctrl + Left arrow
            shortcut(resources.getString(R.string.system_multitasking_lhs)) {
                command(META_META_ON, META_CTRL_ON, KEYCODE_DPAD_LEFT)
            },
            //  Switch from Split screen to full screen:
            //   - Meta + Ctrl + Up arrow
            shortcut(resources.getString(R.string.system_multitasking_full_screen)) {
                command(META_META_ON, META_CTRL_ON, KEYCODE_DPAD_UP)
            },
            //  Change split screen focus to RHS:
            //   - Meta + Alt + Right arrow
            shortcut(resources.getString(R.string.system_multitasking_splitscreen_focus_rhs)) {
                command(META_META_ON, META_ALT_ON, KEYCODE_DPAD_RIGHT)
            },
            //  Change split screen focus to LHS:
            //   - Meta + Alt + Left arrow
            shortcut(resources.getString(R.string.system_multitasking_splitscreen_focus_rhs)) {
                command(META_META_ON, META_ALT_ON, KEYCODE_DPAD_LEFT)
            },
        )

    fun recentsShortcuts() =
        listOf(
            // Cycle through recent apps (forward):
            //  - Alt + Tab
            shortcut(resources.getString(R.string.group_system_cycle_forward)) {
                command(META_ALT_ON, KEYCODE_TAB)
            },
            // Cycle through recent apps (back):
            //  - Shift + Alt + Tab
            shortcut(resources.getString(R.string.group_system_cycle_back)) {
                command(META_SHIFT_ON, META_ALT_ON, KEYCODE_TAB)
            },
        )
}
+108 −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_A
import android.view.KeyEvent.KEYCODE_DEL
import android.view.KeyEvent.KEYCODE_DPAD_LEFT
import android.view.KeyEvent.KEYCODE_ENTER
import android.view.KeyEvent.KEYCODE_ESCAPE
import android.view.KeyEvent.KEYCODE_H
import android.view.KeyEvent.KEYCODE_I
import android.view.KeyEvent.KEYCODE_L
import android.view.KeyEvent.KEYCODE_N
import android.view.KeyEvent.KEYCODE_S
import android.view.KeyEvent.KEYCODE_SLASH
import android.view.KeyEvent.KEYCODE_TAB
import android.view.KeyEvent.META_CTRL_ON
import android.view.KeyEvent.META_META_ON
import com.android.systemui.keyboard.shortcut.shared.model.shortcut
import com.android.systemui.res.R
import javax.inject.Inject

class SystemShortcutsSource @Inject constructor(private val resources: Resources) {

    fun generalShortcuts() =
        listOf(
            // Access list of all apps and search (i.e. Search/Launcher):
            //  - Meta
            shortcut(resources.getString(R.string.group_system_access_all_apps_search)) {
                command(META_META_ON)
            },
            // Access home screen:
            //  - Meta + H
            //  - Meta + Enter
            shortcut(resources.getString(R.string.group_system_access_home_screen)) {
                command(META_META_ON, KEYCODE_H)
                command(META_META_ON, KEYCODE_ENTER)
            },
            // Overview of open apps:
            //  - Meta + Tab
            shortcut(resources.getString(R.string.group_system_overview_open_apps)) {
                command(META_META_ON, KEYCODE_TAB)
            },
            // Back: go back to previous state (back button)
            //  - Meta + Escape OR
            //  - Meta + Backspace OR
            //  - Meta + Left arrow
            shortcut(resources.getString(R.string.group_system_go_back)) {
                command(META_META_ON, KEYCODE_ESCAPE)
                command(META_META_ON, KEYCODE_DEL)
                command(META_META_ON, KEYCODE_DPAD_LEFT)
            },
            // Take a full screenshot:
            //  - Meta + Ctrl + S
            shortcut(resources.getString(R.string.group_system_full_screenshot)) {
                command(META_META_ON, META_CTRL_ON, KEYCODE_S)
            },
            // Access list of system / apps shortcuts:
            //  - Meta + /
            shortcut(resources.getString(R.string.group_system_access_system_app_shortcuts)) {
                command(META_META_ON, KEYCODE_SLASH)
            },
            // Access notification shade:
            //  - Meta + N
            shortcut(resources.getString(R.string.group_system_access_notification_shade)) {
                command(META_META_ON, KEYCODE_N)
            },
            // Lock screen:
            //  - Meta + L
            shortcut(resources.getString(R.string.group_system_lock_screen)) {
                command(META_META_ON, KEYCODE_L)
            },
        )

    fun systemAppsShortcuts() =
        listOf(
            // Pull up Notes app for quick memo:
            //  - Meta + Ctrl + N
            shortcut(resources.getString(R.string.group_system_quick_memo)) {
                command(META_META_ON, META_CTRL_ON, KEYCODE_N)
            },
            // Access system settings:
            //  - Meta + I
            shortcut(resources.getString(R.string.group_system_access_system_settings)) {
                command(META_META_ON, KEYCODE_I)
            },
            // Access Assistant:
            //  - Meta + A
            shortcut(resources.getString(R.string.group_system_access_google_assistant)) {
                command(META_META_ON, KEYCODE_A)
            },
        )
}
+34 −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.shared.model

import android.graphics.drawable.Icon

data class Shortcut(val label: String, val icon: Icon? = null, val commands: List<ShortcutCommand>)

class ShortcutBuilder(private val label: String, private val icon: Icon? = null) {
    val commands = mutableListOf<ShortcutCommand>()

    fun command(vararg keyCodes: Int) {
        commands += ShortcutCommand(keyCodes.toList())
    }

    fun build() = Shortcut(label, icon, commands)
}

fun shortcut(label: String, icon: Icon? = null, block: ShortcutBuilder.() -> Unit): Shortcut =
    ShortcutBuilder(label).apply(block).build()
+19 −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.shared.model

class ShortcutCommand(val keyCodes: List<Int>)