-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: implement Jetpack Compose sample catalog #2422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+5,061
−303
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9fcd9b6
feat: implement Jetpack Compose sample catalog
dkhawk 00e59fa
fix(catalog): remove literal region tags from SampleCodeProvider to r…
dkhawk 495829d
refactor(catalog): remove embedded source code snippets in favor of k…
dkhawk c735bda
chore(catalog): remove unreferenced fowler_rattlesnake.gpx from commo…
dkhawk 15463c0
refactor(catalog): replace material-icons-extended with core icons an…
dkhawk 17ebf39
refactor(catalog): modularize CatalogScreen and add unit test suite
dkhawk 0a80666
fix(catalog): resolve cross-framework targetPackage and handle Activi…
dkhawk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
686 changes: 686 additions & 0 deletions
686
...os/project/common-ui/src/main/java/com/example/common_ui/catalog/SampleCatalogRegistry.kt
Large diffs are not rendered by default.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
ApiDemos/project/common-ui/src/main/java/com/example/common_ui/catalog/SampleEvaluation.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * 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.example.common_ui.catalog | ||
|
|
||
| import java.io.Serializable | ||
|
|
||
| /** | ||
| * Domain data model representing a sample manual review evaluation. | ||
| */ | ||
| data class SampleEvaluation( | ||
| val sampleId: String, | ||
| val sampleTitle: String = "", | ||
| val activityName: String = "", | ||
| val category: String = "", | ||
| val framework: String = "", | ||
| val status: String = ReviewStatus.UNCHECKED.name, | ||
| val notes: String = "", | ||
| val screenshotPath: String? = null, | ||
| val lastUpdated: Long = System.currentTimeMillis() | ||
| ) : Serializable |
179 changes: 179 additions & 0 deletions
179
ApiDemos/project/common-ui/src/main/java/com/example/common_ui/catalog/SampleMetadata.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * 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.example.common_ui.catalog | ||
|
|
||
| import java.io.Serializable | ||
|
|
||
| /** | ||
| * Annotation for Google Maps Platform sample activities and snippet entry points. | ||
| * | ||
| * Provides metadata consumed by the dynamic catalog builder and the on-device reviewer mode. | ||
| */ | ||
| @Target(AnnotationTarget.CLASS) | ||
| @Retention(AnnotationRetention.RUNTIME) | ||
| annotation class Sample( | ||
| val id: String, | ||
| val title: String, | ||
| val description: String, | ||
| val category: String, | ||
| val complexity: Complexity = Complexity.SIMPLE, | ||
| val tags: Array<String> = [], | ||
| val apiCalls: Array<String> = [], | ||
| val purpose: String = "", | ||
| val successCriteria: String = "", | ||
| val failureIndicators: String = "", | ||
| val helpHtml: String = "", | ||
| val framework: Framework = Framework.KOTLIN_VIEWS | ||
| ) | ||
|
|
||
| /** | ||
| * Complexity classification for samples. | ||
| */ | ||
| enum class Complexity(val displayName: String, val badge: String, val order: Int) : Serializable { | ||
| SNIPPET("Snippet", "🔹", 1), | ||
| SIMPLE("Simple", "🟢", 2), | ||
| ADVANCED("Advanced", "🔴", 3); | ||
|
|
||
| companion object { | ||
| fun fromString(value: String?): Complexity { | ||
| return entries.find { it.name.equals(value, ignoreCase = true) } ?: SIMPLE | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Supported development frameworks in this repository. | ||
| */ | ||
| enum class Framework( | ||
| val id: String, | ||
| val displayName: String, | ||
| val badge: String, | ||
| val iconEmoji: String, | ||
| val accentColorHex: Long | ||
| ) : Serializable { | ||
| KOTLIN_VIEWS( | ||
| id = "kotlin", | ||
| displayName = "Kotlin Views", | ||
| badge = "Kotlin", | ||
| iconEmoji = "💜", | ||
| accentColorHex = 0xFF7F52FF | ||
| ), | ||
| JAVA_VIEWS( | ||
| id = "java", | ||
| displayName = "Java Views", | ||
| badge = "Java", | ||
| iconEmoji = "☕", | ||
| accentColorHex = 0xFFE76F51 | ||
| ); | ||
|
|
||
| companion object { | ||
| fun fromId(id: String?): Framework { | ||
| return entries.find { it.id.equals(id, ignoreCase = true) } ?: KOTLIN_VIEWS | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Manual review evaluation status for a sample. | ||
| */ | ||
| enum class ReviewStatus( | ||
| val displayName: String, | ||
| val badge: String, | ||
| val iconEmoji: String, | ||
| val colorHex: Long | ||
| ) : Serializable { | ||
| UNCHECKED("Unchecked", "UNCHECKED", "⚪", 0xFF9E9E9E), | ||
| NEEDS_WORK("Needs Work", "NEEDS_WORK", "🔴", 0xFFF44336), | ||
| PASSING("Passing", "PASSING", "🟢", 0xFF4CAF50); | ||
|
|
||
| companion object { | ||
| fun fromString(value: String?): ReviewStatus { | ||
| return entries.find { it.name.equals(value, ignoreCase = true) } ?: UNCHECKED | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Immutable domain model representing a sample entry across Kotlin and Java frameworks. | ||
| */ | ||
| data class SampleItem( | ||
| val id: String, | ||
| val title: String, | ||
| val description: String, | ||
| val category: String, | ||
| val complexity: Complexity = Complexity.SIMPLE, | ||
| val tags: List<String> = emptyList(), | ||
| val apiCalls: List<String> = emptyList(), | ||
| val purpose: String = "", | ||
| val successCriteria: String = "", | ||
| val failureIndicators: String = "", | ||
| val helpHtml: String = "", | ||
| val kotlinActivity: String? = null, | ||
| val javaActivity: String? = null | ||
| ) : Serializable { | ||
|
|
||
| /** | ||
| * Builds an HTML formatted help box for reviewer and developer guidance. | ||
| * When [isReviewerMode] is false (Developer/Learner mode), evaluation criteria | ||
| * (Success Criteria and Failure Indicators) are omitted to keep the UI clean. | ||
| */ | ||
| fun getFormattedHelpHtml(isReviewerMode: Boolean = true): String { | ||
| if (helpHtml.isNotBlank()) { | ||
| return helpHtml | ||
| } | ||
| val builder = StringBuilder() | ||
| builder.append("<h3><b>${title}</b></h3>") | ||
| builder.append("<p><i>${description}</i></p>") | ||
| builder.append("<hr/>") | ||
|
|
||
| if (purpose.isNotBlank()) { | ||
| builder.append("<p><b>🎯 Purpose:</b><br/>${purpose}</p>") | ||
| } | ||
| if (isReviewerMode) { | ||
| if (successCriteria.isNotBlank()) { | ||
| builder.append("<p><b>✅ Success Criteria:</b><br/>${successCriteria}</p>") | ||
| } | ||
| if (failureIndicators.isNotBlank()) { | ||
| builder.append("<p><b>⚠️ Failure / Broken Indicators:</b><br/>${failureIndicators}</p>") | ||
| } | ||
| } | ||
|
|
||
| if (tags.isNotEmpty()) { | ||
| builder.append("<p><b>🏷️ Tags:</b> ") | ||
| builder.append(tags.joinToString(" ")) | ||
| builder.append("</p>") | ||
| } | ||
| return builder.toString() | ||
| } | ||
|
|
||
| /** | ||
| * Resolves the activity class name for a given target framework. | ||
| */ | ||
| fun getActivityForFramework(framework: Framework): String? { | ||
| return when (framework) { | ||
| Framework.KOTLIN_VIEWS -> kotlinActivity ?: javaActivity | ||
| Framework.JAVA_VIEWS -> javaActivity ?: kotlinActivity | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns the Fully Qualified Class Name (FQCN) identifier for the given framework. | ||
| */ | ||
| fun getTargetFqcn(framework: Framework): String { | ||
| return getActivityForFramework(framework) ?: id | ||
| } | ||
| } |
93 changes: 93 additions & 0 deletions
93
.../project/common-ui/src/main/java/com/example/common_ui/catalog/compose/CatalogActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * 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.example.common_ui.catalog.compose | ||
|
|
||
| import android.content.ActivityNotFoundException | ||
| import android.content.Intent | ||
| import android.os.Bundle | ||
| import android.widget.Toast | ||
| import androidx.activity.ComponentActivity | ||
| import androidx.activity.compose.setContent | ||
| import androidx.activity.enableEdgeToEdge | ||
| import com.example.common_ui.catalog.Framework | ||
| import com.example.common_ui.catalog.SampleItem | ||
|
|
||
| /** | ||
| * Clean, modern Jetpack Compose Catalog application for end-user developers. | ||
| * | ||
| * Provides multi-framework browsing, instant search, complexity filters, and sample expectation guides. | ||
| */ | ||
| open class CatalogActivity : ComponentActivity() { | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| enableEdgeToEdge() | ||
|
|
||
| setContent { | ||
| CatalogTheme { | ||
| CatalogScreen( | ||
| isReviewerMode = false, | ||
| onLaunchSample = { sample, framework -> | ||
| launchSample(sample, framework) | ||
| }, | ||
| onSwitchMode = { | ||
| try { | ||
| val intent = Intent().setClassName(packageName, "com.example.reviewer.compose.ReviewerActivity") | ||
| startActivity(intent) | ||
| finish() | ||
| } catch (e: ActivityNotFoundException) { | ||
| Toast.makeText(this@CatalogActivity, "Reviewer mode is not available", Toast.LENGTH_SHORT).show() | ||
| } catch (e: Exception) { | ||
| Toast.makeText(this@CatalogActivity, "Could not switch to Reviewer mode: ${e.message}", Toast.LENGTH_SHORT).show() | ||
| } | ||
| } | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected fun launchSample(sample: SampleItem, framework: Framework) { | ||
| val className = sample.getActivityForFramework(framework) | ||
| if (className.isNullOrBlank()) { | ||
| Toast.makeText(this, "No ${framework.displayName} implementation available for ${sample.title}", Toast.LENGTH_SHORT).show() | ||
| return | ||
| } | ||
|
|
||
| val targetPackage = when { | ||
| className.startsWith("com.example.mapdemo.") -> "com.example.mapdemo" | ||
| className.startsWith("com.example.kotlindemos.") -> "com.example.kotlindemos" | ||
| else -> packageName | ||
| } | ||
|
|
||
| try { | ||
| val intent = Intent().apply { | ||
| setClassName(targetPackage, className) | ||
| putExtra("extra_sample_id", sample.id) | ||
| putExtra("extra_is_reviewer_mode", false) | ||
| } | ||
| startActivity(intent) | ||
| } catch (e: ActivityNotFoundException) { | ||
| Toast.makeText( | ||
| this, | ||
| "${framework.displayName} app ($targetPackage) is not installed", | ||
| Toast.LENGTH_LONG | ||
| ).show() | ||
| } catch (e: Exception) { | ||
| Toast.makeText(this, "Could not launch ${sample.title}: ${e.message}", Toast.LENGTH_LONG).show() | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both
:ApiDemos:kotlin-appand:ApiDemos:java-appsubclassCatalogActivity, butCatalogStatehardcodesinitialFramework = Framework.KOTLIN_VIEWS.When launching
:ApiDemos:java-app(com.example.mapdemo), it opens on the Kotlin tab by default and tapping any sample fails with"Sample not installed in current app build"ifkotlin-appisn't installed.We should pass
initialFramework = if (packageName == "com.example.mapdemo") Framework.JAVA_VIEWS else Framework.KOTLIN_VIEWSintoCatalogScreeninCatalogActivity.onCreate().