Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.unit.IntOffset
import androidx.lifecycle.viewmodel.navigation3.ViewModelStoreNavEntryDecorator
import androidx.lifecycle.viewmodel.navigation3.rememberViewModelStoreNavEntryDecorator
import androidx.navigation3.runtime.SavedStateNavEntryDecorator
import androidx.navigation3.runtime.entry
import androidx.navigation3.runtime.entryProvider
import androidx.navigation3.runtime.rememberSavedStateNavEntryDecorator
import androidx.navigation3.ui.NavDisplay
import androidx.navigation3.ui.SceneSetupNavEntryDecorator
import com.android.developers.androidify.camera.CameraPreviewScreen
import com.android.developers.androidify.creation.CreationScreen
import com.android.developers.androidify.home.AboutScreen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import com.android.developers.androidify.model.ValidatedImage
import com.google.firebase.Firebase
import com.google.firebase.ai.GenerativeModel
import com.google.firebase.ai.ImagenModel
import com.google.firebase.ai.ai
import com.google.firebase.ai.type.GenerativeBackend
import com.google.firebase.ai.type.HarmBlockThreshold
import com.google.firebase.ai.type.HarmCategory
import com.google.firebase.ai.type.ImagenPersonFilterLevel
Expand All @@ -34,8 +36,6 @@ import com.google.firebase.ai.type.SafetySetting
import com.google.firebase.ai.type.Schema
import com.google.firebase.ai.type.content
import com.google.firebase.ai.type.generationConfig
import com.google.firebase.ai.ai
import com.google.firebase.ai.type.GenerativeBackend
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.booleanOrNull
import kotlinx.serialization.json.decodeFromJsonElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ import android.provider.MediaStore
import androidx.annotation.WorkerThread
import androidx.core.content.FileProvider
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.nio.file.Files
import java.util.UUID
import javax.inject.Inject
import javax.inject.Named
Expand All @@ -39,15 +37,20 @@ import javax.inject.Singleton
interface LocalFileProvider {
@WorkerThread
suspend fun saveBitmapToFile(bitmap: Bitmap, file: File)

@WorkerThread
suspend fun getFileFromCache(fileName: String): File

@WorkerThread
suspend fun createCacheFile(fileName: String): File

@WorkerThread
suspend fun saveToSharedStorage(file: File, fileName: String, mimeType: String): Uri
fun sharingUriForFile(file: File): Uri

@WorkerThread
suspend fun copyToInternalStorage(uri: Uri): File

@WorkerThread
suspend fun saveUriToSharedStorage(inputUri: Uri, fileName: String, mimeType: String): Uri
}
Expand Down Expand Up @@ -104,7 +107,7 @@ open class LocalFileProviderImpl @Inject constructor(
inputUri: Uri,
fileName: String,
mimeType: String,
): Uri = withContext(ioDispatcher) {
): Uri = withContext(ioDispatcher) {
val (newUri, contentValues) = createSharedStorageEntry(fileName, mimeType)
application.contentResolver.openOutputStream(newUri)?.use { outputStream ->
application.contentResolver.openInputStream(inputUri)?.use { inputStream ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal fun CameraControls(
ZoomToolbar(
defaultZoomOptions = defaultZoomOptions,
zoomLevel = zoomLevel,
onZoomLevelSelected = onZoomLevelSelected
onZoomLevelSelected = onZoomLevelSelected,
)
Spacer(Modifier.height(12.dp))
Row(verticalAlignment = Alignment.CenterVertically) {
Expand Down Expand Up @@ -74,7 +74,7 @@ private fun CameraControlsPreview() {
canFlipCamera = true,
flipCameraDirectionClicked = { },
detectedPose = true,
zoomLevel = {0.4f},
zoomLevel = { 0.4f },
onZoomLevelSelected = {},
defaultZoomOptions = listOf(.6f, 1f),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal fun CameraLayout(
) {
val mContext = LocalContext.current
var isCameraLeft by remember { mutableStateOf(false) }
LifecycleStartEffect(Unit){
LifecycleStartEffect(Unit) {
val displayManager = mContext.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
val displayListener = object : DisplayManager.DisplayListener {
override fun onDisplayChanged(displayId: Int) {
Expand Down Expand Up @@ -115,7 +115,7 @@ internal fun CameraLayout(
zoomButton,
guideText,
guide,
isCameraLeft
isCameraLeft,
)

this.maxWidth > maxHeight && allowsFullContent() -> CompactHorizontalCameraLayout(
Expand Down Expand Up @@ -472,9 +472,9 @@ private fun VerticalControlsLayout(
Row(
modifier = modifier,
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = if(isCameraLeft) Arrangement.End else Arrangement.Start,
horizontalArrangement = if (isCameraLeft) Arrangement.End else Arrangement.Start,
) {
if(isCameraLeft){
if (isCameraLeft) {
if (zoomButton != null) zoomButton(Modifier)
Spacer(Modifier.width(12.dp))
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Expand All @@ -484,7 +484,7 @@ private fun VerticalControlsLayout(
captureButton(Modifier)
Spacer(modifier = Modifier.weight(1f))
}
}else{
} else {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Box(Modifier.weight(1f), contentAlignment = Alignment.Center) {
if (flipCameraButton != null) flipCameraButton(Modifier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fun CameraPreviewScreen(
shouldShowRearCameraFeature = viewModel::shouldShowRearDisplayFeature,
toggleRearCameraFeature = { viewModel.toggleRearDisplayFeature(activity) },
isRearCameraEnabled = uiState.isRearCameraActive,
cameraSessionId = uiState.cameraSessionId
cameraSessionId = uiState.cameraSessionId,
)
}
} else {
Expand Down Expand Up @@ -304,13 +304,13 @@ private fun CameraPreviewContent(
toggleRearCameraFeature: () -> Unit = {},
isRearCameraEnabled: Boolean = false,
) {
val scope = rememberCoroutineScope()
val scope = rememberCoroutineScope()
val zoomState = remember(cameraSessionId) {
ZoomState(
initialZoomLevel = zoomLevel(),
onChangeZoomLevel = onChangeZoomLevel,
zoomRange = zoomRange,
)
ZoomState(
initialZoomLevel = zoomLevel(),
onChangeZoomLevel = onChangeZoomLevel,
zoomRange = zoomRange,
)
}
// Delegate the layout to the stateless version
StatelessCameraPreviewContent(
Expand All @@ -321,7 +321,7 @@ private fun CameraPreviewContent(
surfaceRequest = surfaceRequest,
autofocusUiState = autofocusUiState,
tapToFocus = tapToFocus,
onScaleZoom = { scope.launch { zoomState.scaleZoom(it) }},
onScaleZoom = { scope.launch { zoomState.scaleZoom(it) } },
modifier = viewfinderModifier.onSizeChanged { size -> // Apply modifier from slot
if (size.height > 0) {
aspectRatio = calculateCorrectAspectRatio(size.height, size.width, aspectRatio)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ private val TAP_TO_FOCUS_INDICATOR_SIZE = 48.dp

@Composable
internal fun CameraViewfinder(
surfaceRequest: SurfaceRequest,
autofocusUiState: AutofocusUiState,
tapToFocus: (tapCoords: Offset) -> Unit,
onScaleZoom: (zoomScaleFactor: Float) -> Unit,
modifier: Modifier = Modifier,
surfaceRequest: SurfaceRequest,
autofocusUiState: AutofocusUiState,
tapToFocus: (tapCoords: Offset) -> Unit,
onScaleZoom: (zoomScaleFactor: Float) -> Unit,
modifier: Modifier = Modifier,
) {
val onScaleCurrentZoom by rememberUpdatedState(onScaleZoom)
val currentTapToFocus by rememberUpdatedState(tapToFocus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.developers.androidify.camera

import androidx.compose.animation.core.Animatable
Expand Down Expand Up @@ -69,4 +68,4 @@ class ZoomState(
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import android.net.Uri
import androidx.activity.ComponentActivity
import androidx.compose.material3.SnackbarHostState
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.assertIsOff
import androidx.compose.ui.test.assertIsOn
import androidx.compose.ui.test.junit4.createAndroidComposeRule
Expand Down Expand Up @@ -223,7 +221,6 @@ class CreationScreenTest {
}
}


composeTestRule.onNodeWithText(headlineText).assertIsDisplayed()
// TODO: Fails in pixel 5
// composeTestRule.onNodeWithText(writingChipText).assertIsDisplayed().assertIsNotEnabled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ fun CreationScreen(
creationViewModel.onBackPress()
}
LaunchedEffect(Unit) {
if (fileName != null) creationViewModel.onImageSelected(fileName.toUri())
else creationViewModel.onImageSelected(null)
if (fileName != null) {
creationViewModel.onImageSelected(fileName.toUri())
} else {
creationViewModel.onImageSelected(null)
}
}
val pickMedia = rememberLauncherForActivityResult(PickVisualMedia()) { uri ->
if (uri != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ import androidx.compose.ui.layout.onLayoutRectChanged
import androidx.compose.ui.layout.onVisibilityChanged
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
Expand Down Expand Up @@ -543,9 +542,8 @@ private fun VideoPlayer(
.background(MaterialTheme.colorScheme.surfaceContainerLowest)
.onVisibilityChanged(
minDurationMs = 100,
minFractionVisible = 1f
)
{ fullyVisible -> videoFullyOnScreen = fullyVisible }
minFractionVisible = 1f,
) { fullyVisible -> videoFullyOnScreen = fullyVisible }
.then(modifier),
) {
player?.let { currentPlayer ->
Expand Down