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

Commit 92a481a7 authored by Wes Okuhara's avatar Wes Okuhara
Browse files

Desktop screenshots: Parameterize region box button text and icon

Refactors how the button icon and text are supplied for better component
design.

Bug: 436891566
Test: Manual
Flag: EXEMPT refactor
Change-Id: I5f5eb9902a6c5d8bd7fc95f7632860e4ed1e92b4
parent 6d888f37
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -76,7 +76,14 @@ fun PreCaptureUI(viewModel: PreCaptureViewModel) {
                // TODO(b/427541309) Set the initial width and height of the RegionBox based on the
                // viewmodel state.
                RegionBox(
                    drawableLoaderViewModel = viewModel,
                    buttonText =
                        stringResource(id = R.string.screen_capture_region_selection_button),
                    buttonIcon =
                        loadIcon(
                            viewModel = viewModel,
                            resId = R.drawable.ic_screen_capture_camera,
                            contentDescription = null,
                        ),
                    onRegionSelected = { rect: Rect -> viewModel.updateRegionBox(rect) },
                    onCaptureClick = { viewModel.takePartialScreenshot() },
                )
+7 −4
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ 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
import com.android.systemui.common.shared.model.Icon
import kotlin.math.max
import kotlin.math.min
import kotlin.math.roundToInt
@@ -221,16 +221,18 @@ private class RegionBoxState(private val minSizePx: Float, private val touchArea
/**
 * A composable that allows the user to create, move, resize, and redraw a rectangular region.
 *
 * @param buttonText The text of the capture button.
 * @param buttonIcon The icon of the capture button. Can be null if the icon has not loaded yet.
 * @param onRegionSelected A callback function that is invoked with the final rectangle when the
 *   user finishes a drag gesture. This rectangle is used for taking a screenshot. The rectangle is
 *   of type [android.graphics.Rect] because the screenshot API requires int values.
 * @param drawableLoaderViewModel The view model that is used to load drawables.
 * @param onCaptureClick A callback function that is invoked when the capture button is clicked.
 * @param modifier The modifier to be applied to the composable.
 */
@Composable
fun RegionBox(
    drawableLoaderViewModel: DrawableLoaderViewModel,
    buttonText: String,
    buttonIcon: Icon?,
    onRegionSelected: (rect: IntRect) -> Unit,
    onCaptureClick: () -> Unit,
    modifier: Modifier = Modifier,
@@ -305,10 +307,11 @@ fun RegionBox(
            // The button which initiates capturing the specified region of the screen. It is
            // positioned inside or outside the region box depending on the size of the region box.
            RegionBoxButton(
                text = buttonText,
                icon = buttonIcon,
                boxWidthDp,
                boxHeightDp,
                currentRect,
                drawableLoaderViewModel = drawableLoaderViewModel,
                onClick = onCaptureClick,
            )

+7 −13
Original line number Diff line number Diff line
@@ -27,30 +27,29 @@ import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.IntSize
import com.android.systemui.res.R
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.screencapture.common.ui.compose.PrimaryButton
import com.android.systemui.screencapture.common.ui.compose.loadIcon
import com.android.systemui.screencapture.common.ui.viewmodel.DrawableLoaderViewModel

/**
 * A composable that represents the button that is positioned inside or outside the region box.
 *
 * @param text The button text.
 * @param icon The button icon.
 * @param boxWidthDp The width of the region box in dp.
 * @param boxHeightDp The height of the region box in dp.
 * @param currentRect The current region box.
 * @param drawableLoaderViewModel The view model that is used to load drawables.
 * @param onClick A callback function that is invoked when this button is clicked.
 * @param modifier The modifier to be applied to the composable.
 */
@Composable
fun RegionBoxButton(
    text: String,
    icon: Icon?,
    boxWidthDp: Dp,
    boxHeightDp: Dp,
    currentRect: Rect,
    drawableLoaderViewModel: DrawableLoaderViewModel,
    onClick: () -> Unit,
    modifier: Modifier = Modifier,
) {
@@ -98,13 +97,8 @@ fun RegionBoxButton(
                    translationX = targetTranslationX
                    translationY = targetTranslationY
                },
        text = stringResource(id = R.string.screen_capture_region_selection_button),
        icon =
            loadIcon(
                viewModel = drawableLoaderViewModel,
                resId = R.drawable.ic_screen_capture_camera,
                contentDescription = null,
            ),
        text = text,
        icon = icon,
        onClick = onClick,
    )
}