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

Commit d4c6e32f authored by Michał Brzeziński's avatar Michał Brzeziński Committed by Android (Google) Code Review
Browse files

Merge "Moving StickyKeyIndicator to use generic Dialog so it doesn't interfere...

Merge "Moving StickyKeyIndicator to use generic Dialog so it doesn't interfere with home gesture" into main
parents 49df5e5a 3e11fe69
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@

package com.android.systemui.compose

import android.app.Dialog
import android.content.Context
import android.view.View
import android.view.WindowInsets
@@ -33,7 +32,6 @@ import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsViewModel
import com.android.systemui.scene.shared.model.Scene
import com.android.systemui.scene.shared.model.SceneKey
import com.android.systemui.scene.ui.viewmodel.SceneContainerViewModel
import com.android.systemui.statusbar.phone.SystemUIDialogFactory
import com.android.systemui.volume.panel.ui.viewmodel.VolumePanelViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.StateFlow
@@ -90,10 +88,10 @@ object ComposeFacade : BaseComposeFacade {
        throwComposeUnavailableError()
    }

    override fun createStickyKeysDialog(
        dialogFactory: SystemUIDialogFactory,
    override fun createStickyKeysIndicatorContent(
        context: Context,
        viewModel: StickyKeysIndicatorViewModel
    ): Dialog {
    ): View {
        throwComposeUnavailableError()
    }

+5 −8
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.compose

import android.app.Dialog
import android.content.Context
import android.graphics.Point
import android.view.View
@@ -39,7 +38,7 @@ import com.android.systemui.communal.ui.compose.CommunalContainer
import com.android.systemui.communal.ui.compose.CommunalHub
import com.android.systemui.communal.ui.viewmodel.BaseCommunalViewModel
import com.android.systemui.communal.widgets.WidgetConfigurator
import com.android.systemui.keyboard.stickykeys.ui.view.StickyKeysIndicator
import com.android.systemui.keyboard.stickykeys.ui.view.createStickyKeyIndicatorView
import com.android.systemui.keyboard.stickykeys.ui.viewmodel.StickyKeysIndicatorViewModel
import com.android.systemui.people.ui.compose.PeopleScreen
import com.android.systemui.people.ui.viewmodel.PeopleViewModel
@@ -50,8 +49,6 @@ import com.android.systemui.scene.shared.model.SceneKey
import com.android.systemui.scene.ui.composable.ComposableScene
import com.android.systemui.scene.ui.composable.SceneContainer
import com.android.systemui.scene.ui.viewmodel.SceneContainerViewModel
import com.android.systemui.statusbar.phone.SystemUIDialogFactory
import com.android.systemui.statusbar.phone.create
import com.android.systemui.volume.panel.ui.composable.VolumePanelRoot
import com.android.systemui.volume.panel.ui.viewmodel.VolumePanelViewModel
import kotlinx.coroutines.CoroutineScope
@@ -140,11 +137,11 @@ object ComposeFacade : BaseComposeFacade {
        }
    }

    override fun createStickyKeysDialog(
        dialogFactory: SystemUIDialogFactory,
    override fun createStickyKeysIndicatorContent(
        context: Context,
        viewModel: StickyKeysIndicatorViewModel
    ): Dialog {
        return dialogFactory.create { StickyKeysIndicator(viewModel) }
    ): View {
        return createStickyKeyIndicatorView(context, viewModel)
    }

    override fun createCommunalView(
+19 −0
Original line number Diff line number Diff line
@@ -16,23 +16,42 @@

package com.android.systemui.keyboard.stickykeys.ui.view

import android.content.Context
import android.view.View
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.android.compose.theme.PlatformTheme
import com.android.systemui.keyboard.stickykeys.shared.model.Locked
import com.android.systemui.keyboard.stickykeys.shared.model.ModifierKey
import com.android.systemui.keyboard.stickykeys.ui.viewmodel.StickyKeysIndicatorViewModel

fun createStickyKeyIndicatorView(context: Context, viewModel: StickyKeysIndicatorViewModel): View {
    return ComposeView(context).apply {
        setContent {
            PlatformTheme {
                val defaultContentColor = MaterialTheme.colorScheme.onSurfaceVariant
                CompositionLocalProvider(LocalContentColor provides defaultContentColor) {
                    StickyKeysIndicator(viewModel)
                }
            }
        }
    }
}

@Composable
fun StickyKeysIndicator(viewModel: StickyKeysIndicatorViewModel) {
    val stickyKeys by viewModel.indicatorContent.collectAsState(emptyMap())
+4 −6
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@

package com.android.systemui.compose

import android.app.Dialog
import android.content.Context
import android.view.View
import android.view.WindowInsets
@@ -33,7 +32,6 @@ import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsViewModel
import com.android.systemui.scene.shared.model.Scene
import com.android.systemui.scene.shared.model.SceneKey
import com.android.systemui.scene.ui.viewmodel.SceneContainerViewModel
import com.android.systemui.statusbar.phone.SystemUIDialogFactory
import com.android.systemui.volume.panel.ui.viewmodel.VolumePanelViewModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.StateFlow
@@ -96,11 +94,11 @@ interface BaseComposeFacade {
        sceneByKey: Map<SceneKey, Scene>,
    ): View

    /** Creates sticky key dialog presenting provided [viewModel] */
    fun createStickyKeysDialog(
        dialogFactory: SystemUIDialogFactory,
    /** Creates sticky key indicator content presenting provided [viewModel] */
    fun createStickyKeysIndicatorContent(
        context: Context,
        viewModel: StickyKeysIndicatorViewModel
    ): Dialog
    ): View

    /** Create a [View] to represent [viewModel] on screen. */
    fun createCommunalView(
+67 −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.stickykeys.ui

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.Window
import android.view.WindowManager
import android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND
import android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
import android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
import android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL
import androidx.activity.ComponentDialog
import com.android.systemui.compose.ComposeFacade
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyboard.stickykeys.ui.viewmodel.StickyKeysIndicatorViewModel
import com.android.systemui.res.R
import javax.inject.Inject

@SysUISingleton
class StickyKeyDialogFactory
@Inject
constructor(
    @Application val context: Context,
) {

    fun create(viewModel: StickyKeysIndicatorViewModel): Dialog {
        return createStickyKeyIndicator(viewModel)
    }

    private fun createStickyKeyIndicator(viewModel: StickyKeysIndicatorViewModel): Dialog {
        return ComponentDialog(context, R.style.Theme_SystemUI_Dialog).apply {
            // because we're requesting window feature it must be called before setting content
            window?.setStickyKeyWindowAttributes()
            setContentView(ComposeFacade.createStickyKeysIndicatorContent(context, viewModel))
        }
    }

    private fun Window.setStickyKeyWindowAttributes() {
        requestFeature(Window.FEATURE_NO_TITLE)
        setType(TYPE_STATUS_BAR_SUB_PANEL)
        addFlags(FLAG_NOT_FOCUSABLE or FLAG_NOT_TOUCHABLE)
        clearFlags(FLAG_DIM_BEHIND)
        setGravity(Gravity.TOP or Gravity.END)
        attributes =
            WindowManager.LayoutParams().apply {
                copyFrom(attributes)
                title = "StickyKeysIndicator"
            }
    }
}
Loading