/* * 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.eyedroppertester.ui import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.material3.Button import androidx.compose.material3.Text 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.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.android.eyedroppertester.R /** * Primary composable that builds the main UI with a button, background image, and received color. * Only reads the current color state; state management is otherwise hoisted up to MainActivity. */ @Composable fun LaunchEyeDropperScreen( uiColorState: ColorState, onClick: () -> Unit, ) { // Container box for whole UI Box(modifier = Modifier.fillMaxSize()) { // (1) Colorful background image that we will select colors from Image( painter = painterResource(id = R.drawable.parrot_stock_image), contentDescription = "background_image", modifier = Modifier.fillMaxSize(), contentScale = ContentScale.Crop ) // (2) All other UI elements on top Column( modifier = Modifier .fillMaxSize() .padding(16.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center ) { // (2a) Title of application Text( text = stringResource(R.string.app_name), color = Color.White, fontSize = 48.sp ) Spacer(modifier = Modifier.height(32.dp)) // (2b) "Launch EyeDropper" button to start EyeDropper activity Button( modifier = Modifier.fillMaxWidth(0.25f), onClick = onClick ) { Text( text = stringResource(R.string.button_label), fontSize = 16.sp ) } Spacer(modifier = Modifier.height(16.dp)) // (2c) Beneath the button, display the hex of the received result. Row( verticalAlignment = Alignment.CenterVertically ) { Text( text = stringResource(R.string.received_color), color = Color.White, fontSize = 32.sp, ) Text( text = uiColorState.currentColorHex, color = Color(uiColorState.currentColor), fontSize = 32.sp, ) } Spacer(modifier = Modifier.height(16.dp)) // (2d) Also display color of the received result in small square. Box( modifier = Modifier .size(64.dp) .background(color = Color(uiColorState.currentColor)) .border(BorderStroke(4.dp, Color.White)) ) } } }