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

Commit ca52300c authored by Cam Bickel's avatar Cam Bickel
Browse files

Screen capture: Add dimensions below region box

This CL creates a new Composeable called
RegionDimensionsPill and places it under
the partial capture box.

Bug: 423962268
Test: Manual
Flag: com.android.systemui.desktop_screen_capture
Change-Id: I9bd02907f90a7d4f5137868e105e69201c9e5546
parent 98e2bfb0
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -366,6 +366,9 @@
    <!-- Button text in the toolbar for choosing the screen recording type. [CHAR LIMIT=35] -->
    <string name="screen_capture_toolbar_record_button">Record</string>

    <!-- Text shown beneath partial screenshot region displaying the dimensions (width and height) of the area to be captured. [CHAR LIMIT=NONE] [SCREENSHOT=screen/7ytguTQdu3cEn4f] -->
    <string name="screen_capture_region_dimensions"><xliff:g example="210" id="width">%1$d</xliff:g> x <xliff:g example="129" id="height">%2$d</xliff:g></string>

    <!-- Content description for the status bar chip shown to the user when they're sharing their screen to another app on the device [CHAR LIMIT=NONE] -->
    <string name="share_to_app_chip_accessibility_label">Sharing screen</string>
    <!-- Content description for the status bar chip shown to the user when they're sharing their screen or audio to another app on the device [CHAR LIMIT=NONE] -->
+27 −0
Original line number Diff line number Diff line
@@ -35,8 +35,10 @@ import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.PointerInputChange
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.layout
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import com.android.systemui.screencapture.common.ui.viewmodel.DrawableLoaderViewModel
@@ -305,6 +307,31 @@ fun RegionBox(
                currentRect,
                drawableLoaderViewModel = drawableLoaderViewModel,
            )

            /** Vertical spacing in DP between the region box and the dimensions pill below it. */
            val pillVerticalSpacingDp = 16.dp

            RegionDimensionsPill(
                widthPx = currentRect.width.roundToInt(),
                heightPx = currentRect.height.roundToInt(),
                modifier =
                    Modifier.layout { measurable, _ ->
                        // Measure the pill's layout size, then center it horizontally based on the
                        // currentRect.
                        val dimensionsPillPlaceable = measurable.measure(Constraints())
                        val pillX =
                            currentRect.left +
                                (currentRect.width - dimensionsPillPlaceable.width) / 2
                        val pillY =
                            currentRect.bottom + with(density) { pillVerticalSpacingDp.toPx() }
                        layout(dimensionsPillPlaceable.width, dimensionsPillPlaceable.height) {
                            dimensionsPillPlaceable.placeRelative(
                                pillX.roundToInt(),
                                pillY.roundToInt(),
                            )
                        }
                    },
            )
        }
    }
}
+56 −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.record.largescreen.ui.compose

import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.android.systemui.res.R

/**
 * A composable that displays width and height dimensions in a styled "pill" shape.
 *
 * @param widthPx The width in pixels to display.
 * @param heightPx The height in pixels to display.
 * @param modifier The modifier to be applied to the composable.
 */
@Composable
fun RegionDimensionsPill(widthPx: Int, heightPx: Int, modifier: Modifier = Modifier) {
    Surface(
        modifier = modifier.wrapContentWidth(),
        shadowElevation = 4.dp,
        shape = RoundedCornerShape(percent = 50),
        color = MaterialTheme.colorScheme.surfaceBright,
    ) {
        Text(
            text = stringResource(R.string.screen_capture_region_dimensions, widthPx, heightPx),
            color = MaterialTheme.colorScheme.onSurface,
            fontSize = MaterialTheme.typography.titleMedium.fontSize,
            fontWeight = FontWeight.Medium,
            softWrap = false,
            modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp),
        )
    }
}