Skip to content

Commit c216c79

Browse files
committed
Merge branch 'master' of github.com:firebase/quickstart-android into rpf/add-svg-generator
# Conflicts: # firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/FirebaseAISamples.kt # firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/MainActivity.kt # gradle/libs.versions.toml
2 parents 3e122f2 + 2cb62f1 commit c216c79

5 files changed

Lines changed: 90 additions & 13 deletions

File tree

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/FirebaseAISamples.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,17 +394,32 @@ val FIREBASE_AI_SAMPLES = listOf(
394394
templateId = "input-system-instructions",
395395
templateKey = "customerName"
396396
),
397+
Sample(
398+
title = "Thinking",
399+
description = "Gemini 2.5 Flash with dynamic thinking",
400+
navRoute = "chat",
401+
categories = listOf(Category.TEXT),
402+
initialPrompt = content {
403+
text("Analogize photosynthesis and growing up.")
404+
},
405+
generationConfig = generationConfig {
406+
thinkingConfig = thinkingConfig {
407+
includeThoughts = true
408+
thinkingBudget = -1 // Dynamic Thinking
409+
}
410+
}
411+
),
397412
Sample(
398413
title = "SVG Generator",
399-
description = "Use Gemini 3 Flash to create SVG illustrations",
414+
description = "Use Gemini 2.5 Flash to create SVG illustrations",
400415
navRoute = "svg",
401416
categories = listOf(Category.IMAGE, Category.TEXT),
402417
initialPrompt = content {
403418
text(
404419
"a kitten"
405420
)
406421
},
407-
modelName = "gemini-3-flash-preview",
422+
modelName = "gemini-2.5-flash-preview",
408423
generationConfig = generationConfig {
409424
thinkingConfig {
410425
thinkingBudget = -1

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/MainActivity.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ class MainActivity : ComponentActivity() {
4949
@OptIn(ExperimentalMaterial3Api::class)
5050
override fun onCreate(savedInstanceState: Bundle?) {
5151
super.onCreate(savedInstanceState)
52-
52+
if(ContextCompat.checkSelfPermission(this,
53+
Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
54+
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO), 1)
55+
}
5356
enableEdgeToEdge()
5457
catImage = BitmapFactory.decodeResource(applicationContext.resources, R.drawable.cat)
5558
setContent {

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/svg/SvgViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SvgViewModel(
4343

4444
init {
4545
generativeModel = Firebase.ai(
46-
backend = GenerativeBackend.vertexAI("global") // GenerativeBackend.googleAI() by default
46+
backend = sample.backend
4747
).generativeModel(
4848
modelName = sample.modelName ?: "gemini-2.5-flash",
4949
systemInstruction = sample.systemInstructions,

firebase-ai/app/src/main/java/com/google/firebase/quickstart/ai/feature/text/ChatScreen.kt

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ import androidx.compose.material.icons.Icons
3636
import androidx.compose.material.icons.automirrored.filled.Send
3737
import androidx.compose.material.icons.filled.AttachFile
3838
import androidx.compose.material.icons.filled.Attachment
39+
import androidx.compose.material.icons.filled.ExpandLess
40+
import androidx.compose.material.icons.filled.ExpandMore
41+
import androidx.compose.animation.AnimatedVisibility
42+
import androidx.compose.foundation.clickable
3943
import androidx.compose.material3.Card
4044
import androidx.compose.material3.CardDefaults
4145
import androidx.compose.material3.DropdownMenu
@@ -234,11 +238,15 @@ fun ChatBubbleItem(
234238
message.content.parts.forEach { part ->
235239
when (part) {
236240
is TextPart -> {
237-
Text(
238-
text = part.text.trimIndent(),
239-
modifier = Modifier.fillMaxWidth(),
240-
color = textColor
241-
)
241+
if (part.isThought) {
242+
ThoughtBubble(part.text)
243+
} else {
244+
Text(
245+
text = part.text.trimIndent(),
246+
modifier = Modifier.fillMaxWidth(),
247+
color = textColor
248+
)
249+
}
242250
}
243251

244252
is ImagePart -> {
@@ -572,4 +580,55 @@ fun AttachmentsList(
572580
}
573581
}
574582
}
583+
}
584+
585+
@Composable
586+
fun ThoughtBubble(
587+
text: String
588+
) {
589+
var expanded by remember { mutableStateOf(false) }
590+
591+
Column(
592+
modifier = Modifier
593+
.fillMaxWidth()
594+
.padding(vertical = 4.dp)
595+
.clip(RoundedCornerShape(8.dp))
596+
.background(MaterialTheme.colorScheme.tertiaryContainer)
597+
.clickable { expanded = !expanded }
598+
.padding(8.dp)
599+
) {
600+
Row(
601+
verticalAlignment = Alignment.CenterVertically,
602+
modifier = Modifier.fillMaxWidth()
603+
) {
604+
Icon(
605+
imageVector = if (expanded) Icons.Default.ExpandLess else Icons.Default.ExpandMore,
606+
contentDescription = if (expanded) "Collapse thoughts" else "Expand thoughts",
607+
modifier = Modifier.padding(end = 8.dp),
608+
tint = MaterialTheme.colorScheme.onTertiaryContainer
609+
)
610+
Text(
611+
text = "Thoughts",
612+
style = MaterialTheme.typography.labelMedium,
613+
color = MaterialTheme.colorScheme.onTertiaryContainer
614+
)
615+
}
616+
617+
AnimatedVisibility(visible = expanded) {
618+
Column {
619+
HorizontalDivider(
620+
modifier = Modifier.padding(vertical = 8.dp),
621+
color = MaterialTheme.colorScheme.onTertiaryContainer
622+
)
623+
Text(
624+
text = text.trimIndent(),
625+
style = MaterialTheme.typography.bodySmall.copy(
626+
fontStyle = androidx.compose.ui.text.font.FontStyle.Italic
627+
),
628+
modifier = Modifier.fillMaxWidth(),
629+
color = MaterialTheme.colorScheme.onTertiaryContainer
630+
)
631+
}
632+
}
633+
}
575634
}

gradle/libs.versions.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ activityCompose = "1.12.1"
33
agp = "8.13.2"
44
camerax = "1.5.2"
55
coilCompose = "2.7.0"
6+
coil3Compose = "3.3.0"
67
composeBom = "2025.12.00"
78
composeNavigation = "2.9.6"
8-
coil3Compose = "3.3.0"
99
coreKtx = "1.17.0"
1010
espressoCore = "3.7.0"
1111
firebaseBom = "34.7.0"
@@ -37,9 +37,6 @@ androidx-lifecycle-viewmodel-savedstate = { module = "androidx.lifecycle:lifecyc
3737
androidx-material-icons-extended = { module = "androidx.compose.material:material-icons-extended" }
3838
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
3939
androidx-material3-adaptive-navigation-suite = { module = "androidx.compose.material3:material3-adaptive-navigation-suite" }
40-
coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coil3Compose" }
41-
coil-svg = { module = "io.coil-kt.coil3:coil-svg", version.ref = "coil3Compose" }
42-
coil3-coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil3Compose" }
4340
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
4441
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
4542
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
@@ -48,6 +45,9 @@ androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
4845
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
4946
androidx-webkit = { module = "androidx.webkit:webkit", version.ref = "webkit" }
5047
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coilCompose" }
48+
coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coil3Compose" }
49+
coil-svg = { module = "io.coil-kt.coil3:coil-svg", version.ref = "coil3Compose" }
50+
coil3-coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil3Compose" }
5151
compose-navigation = { group = "androidx.navigation", name = "navigation-compose", version.ref = "composeNavigation"}
5252
firebase-ai = { module = "com.google.firebase:firebase-ai" }
5353
firebase-bom = { module = "com.google.firebase:firebase-bom", version.ref = "firebaseBom" }

0 commit comments

Comments
 (0)