Skip to content

Commit ccf6a04

Browse files
committed
Merge branch 'main' into feature/sticker
# Conflicts: # data/src/main/java/com/android/developers/androidify/data/ImageGenerationRepository.kt # feature/results/src/main/java/com/android/developers/androidify/customize/ImageRenderer.kt
2 parents 3b8f82c + 2aefcd2 commit ccf6a04

File tree

13 files changed

+82
-56
lines changed

13 files changed

+82
-56
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ fontName="Roboto Flex"
4343

4444
For Googlers, get this info from go/androidify-api-setup
4545

46+
## Availability
47+
Due to the background vibe feature using
48+
`gemini-2.0-flash-preview-image-generation`, its not currently supported in a number of countries in Europe, Middle East & Africa.
49+
See [this](https://ai.google.dev/gemini-api/docs/models#gemini-2.0-flash-preview-image-generation) doc for more information.
50+
4651
## Contributing
4752

4853
See [Contributing](CONTRIBUTING.md).

core/network/src/main/java/com/android/developers/androidify/RemoteConfigDataSource.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ interface RemoteConfigDataSource {
4040
fun getFineTunedModelName(): String
4141

4242
fun getImageGenerationEditsModelName(): String
43+
44+
fun getBotBackgroundInstructionPrompt(): String
4345
}
4446

4547
@Singleton
@@ -100,4 +102,8 @@ class RemoteConfigDataSourceImpl @Inject constructor() : RemoteConfigDataSource
100102
override fun getImageGenerationEditsModelName(): String {
101103
return remoteConfig.getString("image_generation_model_edits")
102104
}
105+
106+
override fun getBotBackgroundInstructionPrompt(): String {
107+
return remoteConfig.getString("bot_background_instruction_prompt")
108+
}
103109
}

core/network/src/main/java/com/android/developers/androidify/vertexai/FirebaseAiDataSource.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ class FirebaseAiDataSourceImpl @Inject constructor(
8585
return Firebase.ai(backend = GenerativeBackend.vertexAI()).imagenModel(
8686
remoteConfigDataSource.imageModelName(),
8787
safetySettings =
88-
ImagenSafetySettings(
89-
safetyFilterLevel = ImagenSafetyFilterLevel.BLOCK_LOW_AND_ABOVE,
90-
// Uses `ALLOW_ADULT` filter since `ALLOW_ALL` requires a special approval
91-
// See https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen
92-
personFilterLevel = ImagenPersonFilterLevel.ALLOW_ADULT,
93-
),
88+
ImagenSafetySettings(
89+
safetyFilterLevel = ImagenSafetyFilterLevel.BLOCK_LOW_AND_ABOVE,
90+
// Uses `ALLOW_ADULT` filter since `ALLOW_ALL` requires a special approval
91+
// See https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen
92+
personFilterLevel = ImagenPersonFilterLevel.ALLOW_ADULT,
93+
),
9494
)
9595
}
9696

core/network/src/main/res/xml/remote_config_defaults.xml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,25 @@
1616
-->
1717
<defaults>
1818
<entry>
19-
<key>image_generation_model_edits</key>
20-
<value>gemini-2.0-flash-preview-image-generation</value>
19+
<key>bot_background_instruction_prompt</key>
20+
<value>Add the input image android bot as the main subject to the result,
21+
it should be the most prominent element of the resultant image, large and
22+
filling the foreground - more than 50% of the resultant frame,
23+
standing in the center of the frame with the central
24+
focus, and the background just underneath the content.
25+
26+
Always include the input Android Bot in the final result image as the subject of the image.
27+
It should be prominently featured in the foreground, center of the frame, without any adjustments other
28+
than the lighting of the surrounding environment. There should only be one of the bots in the image.
29+
style="3d animation style, simplified shapes, mouthless character, realistic physics simulation"
30+
31+
Do not alter the input Android Bot image, do not change its shape or add any hands, eyes, mouths etc. Do not change the characters color scheme.
32+
33+
The background is described as follows:</value>
2134
</entry>
2235
<entry>
2336
<key>use_imagen</key>
24-
<value>true</value>
37+
<value>false</value>
2538
</entry>
2639
<entry>
2740
<key>prompt_image_validation</key>
@@ -127,6 +140,10 @@
127140
<key>promo_video_link</key>
128141
<value>https://services.google.com/fh/files/misc/androidfy_storyboard_b_v07.mp4</value>
129142
</entry>
143+
<entry>
144+
<key>image_generation_model_edits</key>
145+
<value>gemini-2.0-flash-preview-image-generation</value>
146+
</entry>
130147
<entry>
131148
<key>text_model_name</key>
132149
<value>gemini-2.5-flash</value>

core/testing/src/main/java/com/android/developers/testing/network/TestRemoteConfigDataSource.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,8 @@ class TestRemoteConfigDataSource(private val useGeminiNano: Boolean) : RemoteCon
7171
override fun getImageGenerationEditsModelName(): String {
7272
return "test_image_model"
7373
}
74+
75+
override fun getBotBackgroundInstructionPrompt(): String {
76+
return "bot_background_instruction_prompt"
77+
}
7478
}

core/testing/src/main/java/com/android/developers/testing/repository/FakeImageGenerationRepository.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ class FakeImageGenerationRepository : ImageGenerationRepository {
5858
return imageUri
5959
}
6060

61-
override suspend fun generateImageWithEdit(
61+
override suspend fun addBackgroundToBot(
6262
image: Bitmap,
63-
editPrompt: String,
63+
backgroundPrompt: String,
6464
): Bitmap {
6565
return createBitmap(1, 1)
6666
}

core/testing/src/main/java/com/android/developers/testing/util/FakeComposableBitmapRenderer.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ import androidx.core.graphics.createBitmap
2222
import com.android.developers.androidify.customize.ComposableBitmapRenderer
2323

2424
class FakeComposableBitmapRenderer : ComposableBitmapRenderer {
25-
override fun initialize() {
26-
}
27-
28-
override fun dispose() {
29-
}
3025

3126
override suspend fun renderComposableToBitmap(
3227
canvasSize: Size,

data/src/main/java/com/android/developers/androidify/data/ImageGenerationRepository.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import android.graphics.Bitmap
1919
import android.graphics.BitmapFactory
2020
import android.net.Uri
2121
import android.util.Log
22+
import com.android.developers.androidify.RemoteConfigDataSource
2223
import com.android.developers.androidify.model.ValidatedDescription
2324
import com.android.developers.androidify.model.ValidatedImage
2425
import com.android.developers.androidify.ondevice.LocalSegmentationDataSource
@@ -36,8 +37,8 @@ interface ImageGenerationRepository {
3637
suspend fun saveImage(imageBitmap: Bitmap): Uri
3738
suspend fun saveImageToExternalStorage(imageBitmap: Bitmap): Uri
3839
suspend fun saveImageToExternalStorage(imageUri: Uri): Uri
39-
suspend fun generateImageWithEdit(image: Bitmap, editPrompt: String): Bitmap
4040

41+
suspend fun addBackgroundToBot(image: Bitmap, backgroundPrompt: String) : Bitmap
4142
suspend fun removeBackground(image: Bitmap): Bitmap
4243
}
4344

@@ -47,6 +48,7 @@ internal class ImageGenerationRepositoryImpl @Inject constructor(
4748
private val internetConnectivityManager: InternetConnectivityManager,
4849
private val geminiNanoDataSource: GeminiNanoGenerationDataSource,
4950
private val firebaseAiDataSource: FirebaseAiDataSource,
51+
private val remoteConfigDataSource: RemoteConfigDataSource,
5052
private val localSegmentationDataSource: LocalSegmentationDataSource,
5153
) : ImageGenerationRepository {
5254

@@ -130,8 +132,10 @@ internal class ImageGenerationRepositoryImpl @Inject constructor(
130132
}
131133
}
132134

133-
override suspend fun generateImageWithEdit(image: Bitmap, editPrompt: String): Bitmap {
134-
return firebaseAiDataSource.generateImageWithEdit(image, editPrompt)
135+
override suspend fun addBackgroundToBot(image: Bitmap, backgroundPrompt: String): Bitmap {
136+
val backgroundBotInstructions = remoteConfigDataSource.getBotBackgroundInstructionPrompt() +
137+
"\"" + backgroundPrompt + "\""
138+
return firebaseAiDataSource.generateImageWithEdit(image, backgroundBotInstructions)
135139
}
136140

137141
override suspend fun removeBackground(image: Bitmap): Bitmap {

feature/results/src/main/java/com/android/developers/androidify/customize/AspectRatioTool.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import androidx.compose.foundation.layout.fillMaxSize
2424
import androidx.compose.foundation.layout.padding
2525
import androidx.compose.foundation.layout.size
2626
import androidx.compose.foundation.layout.wrapContentSize
27+
import androidx.compose.foundation.rememberScrollState
28+
import androidx.compose.foundation.verticalScroll
2729
import androidx.compose.material3.MaterialTheme
2830
import androidx.compose.runtime.Composable
2931
import androidx.compose.ui.Alignment
@@ -41,10 +43,11 @@ fun AspectRatioTool(
4143
selectedOption: SizeOption,
4244
onSizeOptionSelected: (SizeOption) -> Unit,
4345
modifier: Modifier = Modifier,
44-
singleLine: Boolean = true,
46+
singleLine: Boolean = false,
4547
) {
4648
GenericTool(
47-
modifier = modifier.wrapContentSize(),
49+
modifier = modifier.wrapContentSize()
50+
.verticalScroll(rememberScrollState()),
4851
tools = sizeOptions,
4952
singleLine = singleLine,
5053
selectedOption = selectedOption,

feature/results/src/main/java/com/android/developers/androidify/customize/BackgroundTool.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fun BackgroundTool(
6161
individualToolContent = { tool ->
6262
Box(
6363
modifier = Modifier
64-
.aspectRatio(1f)
64+
.size(70.dp)
6565
.border(
6666
2.dp,
6767
color = MaterialTheme.colorScheme.primary,

0 commit comments

Comments
 (0)