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

Commit a941412e authored by Camden Bickel's avatar Camden Bickel Committed by Android (Google) Code Review
Browse files

Merge "Screen capture: Use different icons for selected/unselected state" into main

parents 0d00393b e5582d97
Loading
Loading
Loading
Loading
+26 −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.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="20dp"
    android:height="20dp"
    android:viewportWidth="20"
    android:viewportHeight="20"
    android:tint="?android:attr/colorControlNormal">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M5 17C4.16667 17 3.45833 16.7083 2.875 16.125C2.29167 15.5417 2 14.8333 2 14V7.5C2 6.66667 2.29167 5.95833 2.875 5.375C3.45833 4.79167 4.16667 4.5 5 4.5H6.5L8 3H12L13.5 4.5H15C15.8333 4.5 16.5417 4.79167 17.125 5.375C17.7083 5.95833 18 6.66667 18 7.5V14C18 14.8333 17.7083 15.5417 17.125 16.125C16.5417 16.7083 15.8333 17 15 17H5ZM5 15.5H15C15.4167 15.5 15.7708 15.3542 16.0625 15.0625C16.3542 14.7708 16.5 14.4167 16.5 14V7.5C16.5 7.08333 16.3542 6.72917 16.0625 6.4375C15.7708 6.14583 15.4167 6 15 6H5C4.58333 6 4.22917 6.14583 3.9375 6.4375C3.64583 6.72917 3.5 7.08333 3.5 7.5V14C3.5 14.4167 3.64583 14.7708 3.9375 15.0625C4.22917 15.3542 4.58333 15.5 5 15.5ZM10 13.625C10.7778 13.625 11.4375 13.3542 11.9792 12.8125C12.5208 12.2569 12.7917 11.5903 12.7917 10.8125C12.7917 10.0347 12.5208 9.375 11.9792 8.83333C11.4375 8.29167 10.7778 8.02083 10 8.02083C9.22222 8.02083 8.5625 8.29167 8.02083 8.83333C7.47917 9.375 7.20833 10.0347 7.20833 10.8125C7.20833 11.5903 7.47917 12.2569 8.02083 12.8125C8.5625 13.3542 9.22222 13.625 10 13.625ZM3.5 15.5C3.5 15.5 3.5 15.3542 3.5 15.0625C3.5 14.7708 3.5 14.4167 3.5 14V7.5C3.5 7.08333 3.5 6.72917 3.5 6.4375C3.5 6.14583 3.5 6 3.5 6C3.5 6 3.5 6.14583 3.5 6.4375C3.5 6.72917 3.5 7.08333 3.5 7.5V14C3.5 14.4167 3.5 14.7708 3.5 15.0625C3.5 15.3542 3.5 15.5 3.5 15.5Z" />
</vector>
+2 −1
Original line number Diff line number Diff line
@@ -118,7 +118,8 @@ constructor(
                onClick = { updateCaptureType(ScreenCaptureType.SCREEN_RECORD) },
            ),
            RadioButtonGroupItemViewModel(
                icon = icons?.screenshotToolbar,
                selectedIcon = icons?.screenshotToolbar,
                unselectedIcon = icons?.screenshotToolbarUnselected,
                label =
                    applicationContext.getString(R.string.screen_capture_toolbar_capture_button),
                isSelected = selectedType == ScreenCaptureType.SCREENSHOT,
+28 −4
Original line number Diff line number Diff line
@@ -18,10 +18,34 @@ package com.android.systemui.screencapture.record.largescreen.ui.viewmodel

import com.android.systemui.common.shared.model.Icon

/** Models a single button within the RadioButtonGroup. */
data class RadioButtonGroupItemViewModel(
data class RadioButtonGroupItemViewModel
constructor(
    val label: String? = null,
    val icon: Icon? = null,
    val selectedIcon: Icon? = null,
    val unselectedIcon: Icon? = null,
    val isSelected: Boolean,
    val onClick: () -> Unit,
) {
    init {
        require((selectedIcon != null) == (unselectedIcon != null)) {
            "selectedIcon and unselectedIcon must both be provided or both be null."
        }
    }

    /** Secondary constructor for cases where the icon is the same whether selected or not. */
    constructor(
        label: String? = null,
        icon: Icon? = null,
        isSelected: Boolean,
        onClick: () -> Unit,
    ) : this(
        label = label,
        selectedIcon = icon,
        unselectedIcon = icon,
        isSelected = isSelected,
        onClick = onClick,
    )

    val icon: Icon?
        get() = if (isSelected) selectedIcon else unselectedIcon
}
+3 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import kotlinx.coroutines.withContext

data class ScreenCaptureIcons(
    val screenshotToolbar: Icon,
    val screenshotToolbarUnselected: Icon,
    val screenshotButton: Icon,
    val screenRecord: Icon,
    val fullscreen: Icon,
@@ -57,6 +58,8 @@ constructor(
                emit(
                    ScreenCaptureIcons(
                        screenshotToolbar = loadIcon(R.drawable.ic_screen_capture_camera),
                        screenshotToolbarUnselected =
                            loadIcon(R.drawable.ic_screen_capture_camera_outline),
                        screenshotButton = loadIcon(R.drawable.ic_screen_capture_camera),
                        screenRecord = loadIcon(R.drawable.ic_screenrecord),
                        fullscreen = loadIcon(R.drawable.ic_screen_capture_fullscreen),
+16 −0
Original line number Diff line number Diff line
@@ -95,6 +95,22 @@ class PreCaptureViewModelTest : SysuiTestCase() {
            assertThat(screenshotButton2.isSelected).isFalse()
        }

    @Test
    fun updateCaptureType_usesCorrectIconWhenSelected() =
        testScope.runTest {
            val (screenRecordButton, screenshotButton) = viewModel.captureTypeButtonViewModels
            assertThat(screenRecordButton.icon).isEqualTo(viewModel.icons?.screenRecord)
            // Screenshot is selected by default.
            assertThat(screenshotButton.icon).isEqualTo(viewModel.icons?.screenshotToolbar)

            viewModel.updateCaptureType(ScreenCaptureType.SCREEN_RECORD)

            val (screenRecordButton2, screenshotButton2) = viewModel.captureTypeButtonViewModels
            assertThat(screenRecordButton2.icon).isEqualTo(viewModel.icons?.screenRecord)
            assertThat(screenshotButton2.icon)
                .isEqualTo(viewModel.icons?.screenshotToolbarUnselected)
        }

    @Test
    @EnableFlags(Flags.FLAG_DESKTOP_SCREEN_CAPTURE_APP_WINDOW)
    fun updateCaptureRegion_updatesSelectedCaptureRegionButtonViewModel() =
Loading