Skip to content

Commit d7a5941

Browse files
Move AI snippets to dedicated module
1 parent 0c07bce commit d7a5941

42 files changed

Lines changed: 1028 additions & 3 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CODEOWNERS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
* @yrezgui @kkuan2011
2-
/compose/ @android/devrel-compose
2+
/ai/ @android/devrel-adaptive-apps
33
/car/ @android/devrel-car
4+
/compose/ @android/devrel-compose
5+
/compose/snippets/src/main/java/com/example/compose/snippets/adaptivelayouts/ @android/devrel-adaptive-apps
46
/watchface/ @android/devrel-wear
57
/wear/ @android/devrel-wear
68
/wearcompanion/ @android/devrel-wear
79
/xr/ @android/devrel-xr
8-
/compose/snippets/src/main/java/com/example/compose/snippets/adaptivelayouts/ @android/devrel-adaptive-apps
9-
/misc/src/main/java/com/example/snippets/ai/ @android/devrel-ai

ai/build.gradle.kts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
plugins {
3+
alias(libs.plugins.android.application)
4+
alias(libs.plugins.ksp)
5+
alias(libs.plugins.hilt)
6+
alias(libs.plugins.compose.compiler)
7+
}
8+
9+
android {
10+
compileSdk = libs.versions.compileSdk.get().toInt()
11+
namespace = "com.example.snippets"
12+
13+
defaultConfig {
14+
applicationId = "com.example.snippets"
15+
minSdk = libs.versions.minSdk.get().toInt()
16+
targetSdk = libs.versions.targetSdk.get().toInt()
17+
versionCode = 1
18+
versionName = "1.0"
19+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
20+
}
21+
22+
kotlin {
23+
jvmToolchain(17)
24+
}
25+
26+
buildTypes {
27+
getByName("debug") {
28+
signingConfig = signingConfigs.getByName("debug")
29+
}
30+
31+
getByName("release") {
32+
isMinifyEnabled = false
33+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"),
34+
"proguard-rules.pro")
35+
}
36+
}
37+
compileOptions {
38+
sourceCompatibility = JavaVersion.VERSION_17
39+
targetCompatibility = JavaVersion.VERSION_17
40+
}
41+
buildFeatures {
42+
compose = true
43+
// Disable unused AGP features
44+
viewBinding = true
45+
}
46+
47+
}
48+
dependencies {
49+
val composeBom = platform(libs.androidx.compose.bom)
50+
implementation(composeBom)
51+
androidTestImplementation(composeBom)
52+
implementation(libs.androidx.core.ktx)
53+
implementation(libs.androidx.activity.compose)
54+
55+
implementation(libs.androidx.appfunctions)
56+
implementation(libs.androidx.appfunctions.service)
57+
ksp(libs.androidx.appfunctions.compiler)
58+
59+
implementation(libs.androidx.compose.runtime)
60+
implementation(libs.androidx.compose.foundation)
61+
implementation(libs.androidx.compose.foundation.layout)
62+
implementation(libs.androidx.compose.ui.util)
63+
implementation(libs.androidx.compose.ui.tooling.preview)
64+
implementation(libs.androidx.compose.material3)
65+
implementation(libs.androidx.media3.common)
66+
implementation(libs.androidx.media3.exoplayer)
67+
implementation(libs.androidx.tracing)
68+
implementation(libs.androidx.work.runtime)
69+
70+
implementation(libs.hilt.android)
71+
implementation(libs.androidx.hilt.navigation.compose)
72+
implementation(libs.kotlinx.serialization.json)
73+
ksp(libs.hilt.compiler)
74+
ksp(libs.kotlinx.metadata.jvm)
75+
76+
implementation(libs.androidx.constraintlayout)
77+
implementation(libs.androidx.lifecycle.runtime)
78+
implementation(libs.androidx.window)
79+
implementation(libs.androidx.startup.runtime)
80+
implementation(libs.androidx.window.java)
81+
implementation(libs.appcompat)
82+
implementation(platform(libs.firebase.bom))
83+
implementation(libs.firebase.ai)
84+
implementation(libs.guava.android)
85+
implementation(libs.reactive.streams)
86+
testImplementation(libs.junit)
87+
testImplementation(kotlin("test"))
88+
androidTestImplementation(libs.androidx.test.ext.junit)
89+
androidTestImplementation(libs.junit)
90+
androidTestImplementation(libs.androidx.test.core)
91+
androidTestImplementation(libs.androidx.test.runner)
92+
androidTestImplementation(libs.androidx.test.espresso.core)
93+
}

ai/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.kts.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.snippets;
18+
19+
import androidx.appcompat.app.AppCompatActivity;
20+
import androidx.test.core.app.ActivityScenario;
21+
import androidx.test.ext.junit.rules.ActivityScenarioRule;
22+
import org.junit.Rule;
23+
import org.junit.Test;
24+
import static org.junit.Assert.assertFalse;
25+
26+
public class DeviceCompatibilityModeTestJavaSnippets {
27+
28+
// [START android_device_compatibility_mode_assert_isLetterboxed_java]
29+
@Rule
30+
public ActivityScenarioRule<MainActivity> rule = new ActivityScenarioRule<>(MainActivity.class);
31+
32+
@Test
33+
public void activity_launched_notLetterBoxed() {
34+
try (ActivityScenario<MainActivity> scenario =
35+
ActivityScenario.launch(MainActivity.class)) {
36+
scenario.onActivity( activity -> {
37+
assertFalse(activity.isLetterboxed());
38+
});
39+
}
40+
}
41+
// [END android_device_compatibility_mode_assert_isLetterboxed_java]
42+
43+
44+
// Class used by snippets.
45+
46+
class MainActivity extends AppCompatActivity {
47+
public boolean isLetterboxed() {
48+
return true;
49+
}
50+
}
51+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.snippets
18+
19+
import androidx.appcompat.app.AppCompatActivity
20+
import androidx.test.ext.junit.rules.ActivityScenarioRule
21+
import org.junit.Assert.assertFalse
22+
import org.junit.Rule
23+
import org.junit.Test
24+
25+
class DeviceCompatibilityModeTestKotlinSnippets {
26+
27+
// [START android_device_compatibility_mode_assert_isLetterboxed_kotlin]
28+
@get:Rule
29+
val activityRule = ActivityScenarioRule(MainActivity::class.java)
30+
31+
@Test
32+
fun activity_launched_notLetterBoxed() {
33+
activityRule.scenario.onActivity {
34+
assertFalse(it.isLetterboxed())
35+
}
36+
}
37+
// [END android_device_compatibility_mode_assert_isLetterboxed_kotlin]
38+
39+
// Class used by snippets.
40+
41+
class MainActivity : AppCompatActivity() {
42+
fun isLetterboxed(): Boolean {
43+
return true
44+
}
45+
}
46+
}

ai/src/main/AndroidManifest.xml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
18+
<permission android:name="com.example.snippets.CUSTOM_PERMISSION"/>
19+
20+
<!--[START android_broadcast_receiver_10_manifest_permission]-->
21+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
22+
<!--[END android_broadcast_receiver_10_manifest_permission]-->
23+
24+
<application
25+
android:icon="@mipmap/ic_launcher"
26+
android:label="@string/app_name"
27+
android:roundIcon="@mipmap/ic_launcher_round"
28+
android:supportsRtl="true"
29+
android:theme="@style/Theme.Snippets">
30+
<activity
31+
android:name="com.example.snippets.MainActivity"
32+
android:exported="true"
33+
android:theme="@style/Theme.Snippets">
34+
<intent-filter>
35+
<action android:name="android.intent.action.MAIN" />
36+
<category android:name="android.intent.category.LAUNCHER" />
37+
</intent-filter>
38+
</activity>
39+
<provider
40+
android:name="androidx.startup.InitializationProvider"
41+
android:authorities="com.example.snippets.androidx-startup"
42+
android:exported="false">
43+
<meta-data
44+
android:name="com.example.snippets.ActivityEmbeddingKotlinSnippets.SplitInitializer"
45+
android:value="androidx.startup" />
46+
<meta-data
47+
android:name="com.example.snippets.ActivityEmbeddingJavaSnippets.SplitInitializer"
48+
android:value="androidx.startup" />
49+
</provider>
50+
</application>
51+
52+
</manifest>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.snippets
18+
19+
import android.os.Bundle
20+
import androidx.activity.ComponentActivity
21+
import androidx.activity.compose.setContent
22+
import androidx.activity.enableEdgeToEdge
23+
import androidx.compose.foundation.layout.fillMaxSize
24+
import androidx.compose.material3.MaterialTheme
25+
import androidx.compose.material3.Surface
26+
import androidx.compose.ui.Modifier
27+
import androidx.navigation.compose.NavHost
28+
import androidx.navigation.compose.composable
29+
import androidx.navigation.compose.rememberNavController
30+
import com.example.snippets.navigation.Destination
31+
import com.example.snippets.navigation.LandingScreen
32+
import com.example.snippets.ui.theme.SnippetsTheme
33+
import dagger.hilt.android.AndroidEntryPoint
34+
35+
@AndroidEntryPoint
36+
class MainActivity : ComponentActivity() {
37+
38+
override fun onCreate(savedInstanceState: Bundle?) {
39+
super.onCreate(savedInstanceState)
40+
enableEdgeToEdge()
41+
setContent {
42+
SnippetsTheme {
43+
val navController = rememberNavController()
44+
// A surface container using the 'background' color from the theme
45+
Surface(
46+
modifier = Modifier.fillMaxSize(),
47+
color = MaterialTheme.colorScheme.background
48+
) {
49+
NavHost(navController, startDestination = "LandingScreen") {
50+
composable("LandingScreen") {
51+
LandingScreen { navController.navigate(it.route) }
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}

misc/src/main/java/com/example/snippets/ai/AppFunctionsApiSnippets.kt renamed to ai/src/main/java/com/example/snippets/ai/AppFunctionsApiSnippets.kt

File renamed without changes.

misc/src/main/java/com/example/snippets/ai/GeminiDeveloperApiSnippets.kt renamed to ai/src/main/java/com/example/snippets/ai/GeminiDeveloperApiSnippets.kt

File renamed without changes.

misc/src/main/java/com/example/snippets/ai/GeminiDeveloperApiSnippetsJava.java renamed to ai/src/main/java/com/example/snippets/ai/GeminiDeveloperApiSnippetsJava.java

File renamed without changes.

0 commit comments

Comments
 (0)