/* * 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.eyedropper.ui.touchscreen import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults.buttonColors import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.integerResource import androidx.compose.ui.res.stringResource import com.android.eyedropper.R /** * Subcomponent of [TouchscreenMainScreen] which manages the Apply (select color) / cancel buttons. * * "Apply" selects the centered pixel beneath the reticle and calls `onSelectClicked`. * "Cancel" aborts EyeDropper and calls `onCancelClicked`. */ @Composable fun ControlBar( isLandscape: Boolean, onSelectClicked: () -> Unit, onCancelClicked: () -> Unit, ) { val buttonPadding = Modifier.padding( top = dimensionResource(R.dimen.button_group_vertical_padding_top), bottom = dimensionResource(R.dimen.button_group_vertical_padding_bottom), end = dimensionResource(R.dimen.color_picker_buttons_padding_end) ) val buttonsAlignment = if (isLandscape) Alignment.BottomEnd else Alignment.BottomCenter Box( modifier = Modifier .fillMaxSize() .background(Color.White), contentAlignment = buttonsAlignment ) { Row( modifier = Modifier .fillMaxSize() .then(buttonPadding), horizontalArrangement = Arrangement.End, verticalAlignment = Alignment.Bottom, ) { // Text with no background fill -> Secondary action TextButton( onClick = onCancelClicked, shape = RoundedCornerShape( integerResource( R.integer.apply_cancel_button_rounded_corner_percent ) ), modifier = Modifier.padding( end = dimensionResource(R.dimen.color_picker_cancel_button_padding_end) ) ) { Text( text = stringResource(R.string.color_picker_cancel_button_text), color = colorResource(R.color.google_blue500) ) } // Primary action Button( onClick = onSelectClicked, shape = RoundedCornerShape( integerResource(R.integer.apply_cancel_button_rounded_corner_percent) ), colors = buttonColors(containerColor = colorResource(R.color.google_blue500)) ) { Text( text = stringResource(R.string.color_picker_apply_button_text), color = Color.White ) } } } }