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

Commit f482fa05 authored by Jerry Liu's avatar Jerry Liu Committed by Android (Google) Code Review
Browse files

Merge "Desktop screenshots: Dim the region outside partial screenshot" into main

parents fe8c0109 16d79ef0
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.screencapture.common.ui.compose

import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color

/** Defines colors used throughout the screen capture UI. */
object ScreenCaptureColors {

    /** The color of the scrim that dims the screen content. */
    val scrimColor: Color
        @Composable get() = MaterialTheme.colorScheme.surface.copy(alpha = 0.54f)
}
+8 −3
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -32,6 +31,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import com.android.systemui.res.R
import com.android.systemui.screencapture.common.ui.compose.PrimaryButton
import com.android.systemui.screencapture.common.ui.compose.ScreenCaptureColors
import com.android.systemui.screencapture.common.ui.compose.loadIcon
import com.android.systemui.screencapture.record.largescreen.ui.viewmodel.PreCaptureViewModel
import com.android.systemui.screencapture.record.largescreen.ui.viewmodel.ScreenCaptureRegion
@@ -56,8 +56,13 @@ fun PreCaptureUI(viewModel: PreCaptureViewModel) {

        when (viewModel.captureRegion) {
            ScreenCaptureRegion.FULLSCREEN -> {
                val scrimColor = MaterialTheme.colorScheme.surface.copy(alpha = .54f)
                Box(modifier = Modifier.zIndex(0f).fillMaxSize().background(color = scrimColor)) {
                // Dim the entire screen with a scrim before taking a fullscreen screenshot.
                Box(
                    modifier =
                        Modifier.zIndex(0f)
                            .fillMaxSize()
                            .background(color = ScreenCaptureColors.scrimColor)
                ) {
                    PrimaryButton(
                        modifier = Modifier.align(Alignment.Center),
                        icon =
+22 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.screencapture.record.largescreen.ui.compose

import android.graphics.Rect as IntRect
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.layout.Box
@@ -31,6 +32,8 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.PointerInputChange
import androidx.compose.ui.input.pointer.pointerInput
@@ -41,6 +44,7 @@ import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.screencapture.common.ui.compose.ScreenCaptureColors
import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt
@@ -247,6 +251,7 @@ fun RegionBox(
    val touchAreaPx = remember(density) { with(density) { touchArea.toPx() } }

    val state = remember { RegionBoxState(minSizePx, touchAreaPx) }
    val scrimColor = ScreenCaptureColors.scrimColor

    Box(
        modifier =
@@ -284,6 +289,23 @@ fun RegionBox(
                    )
                }
    ) {
        // Dim the area outside the selected region by drawing a full-screen scrim,
        // and then punching a transparent hole in it that matches the selected region.
        // Before a region is drawn, the entire canvas is covered by the scrim.
        Canvas(modifier = Modifier.fillMaxSize()) {
            drawRect(scrimColor)
            // This clears the scrim within the bounds of the selected region, highlighting
            // the actual screenshot area.
            state.rect?.let {
                drawRect(
                    topLeft = it.topLeft,
                    size = it.size,
                    color = Color.Transparent,
                    blendMode = BlendMode.Clear,
                )
            }
        }

        // The width of the border stroke around the region box.
        val borderStrokeWidth = 4.dp