Skip to content

Migrate App resources for Views (providing, runtime changes, localization, strings) snippets - #1194

Open
djubinville wants to merge 2 commits into
android:mainfrom
djubinville:djubinville/app-resources-views-pages-snippets
Open

djubinville wants to merge 2 commits into
android:mainfrom
djubinville:djubinville/app-resources-views-pages-snippets

Conversation

@djubinville

@djubinville djubinville commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Code snippets are for:

Companion DAC CL: cl/1000932997

views/src/main/res/values/strings.xml declares untagged supporting resources (R.string.hello, R.string.world, R.string.welcome_messages, R.string.title, R.array.planets_array, R.plurals.numberOfSongsAvailable, and <item name="permanent_marker" type="font" /> for R.font.permanent_marker) because the tagged Kotlin regions in StringResourceViews.kt (android_resources_string_views_get_string, android_resources_string_views_get_string_array, android_resources_string_views_get_quantity_string, android_resources_string_views_format_string, android_resources_string_views_from_html, android_resources_string_views_html_encode, android_resources_string_views_spannable_chain, and android_resources_string_views_annotation_typeface) reference those resource IDs and cannot compile without them (D27). Note on D11 bypass: <item name="permanent_marker" type="font" /> is retained as a compilation stand-in for R.font.permanent_marker (android_resources_string_views_annotation_typeface) so :views:compileDebugKotlin succeeds without committing a binary .ttf/.otf font file into views/src/main/res/font/.

List of modifications:

File Function/Snippet Description of change Reason for change
RuntimeChangesViews.kt android_resources_runtime_changes_views_keyboard Swapped Configuration.KEYBOARDHIDDEN_YES and Configuration.KEYBOARDHIDDEN_NO branches so KEYBOARDHIDDEN_NO displays "Keyboard available" and KEYBOARDHIDDEN_YES displays "No keyboard" D24: Fixes inverted boolean logic in the original documentation where KEYBOARDHIDDEN_YES ("hardware keyboard is hidden") toasted "Keyboard available" and KEYBOARDHIDDEN_NO ("hardware keyboard is not hidden") toasted "No keyboard".
  • Providing-resources-views page: Extracted the ArrayAdapter Kotlin snippet into views/src/main/java/com/example/example/snippet/views/resources/ProvidingResourcesViews.kt (android_resources_providing_views_list_adapter).
  • Runtime-changes-views page: Extracted the onConfigurationChanged Kotlin snippet into views/src/main/java/com/example/example/snippet/views/resources/RuntimeChangesViews.kt (android_resources_runtime_changes_views_keyboard), fixed inverted KEYBOARDHIDDEN_NO / KEYBOARDHIDDEN_YES branches (D24), and added a trailing full stop to the inline comment (D29).
  • Localization-views page: Extracted the primary locale lookup Kotlin snippet into views/src/main/java/com/example/example/snippet/views/resources/LocalizationViews.kt (android_resources_localization_views_primary_locale).
  • String-resource-views page: Extracted all 12 Kotlin snippets into views/src/main/java/com/example/example/snippet/views/resources/StringResourceViews.kt (android_resources_string_views_get_string, android_resources_string_views_get_string_array, android_resources_string_views_get_quantity_string, android_resources_string_views_format_string, android_resources_string_views_from_html, android_resources_string_views_html_encode, android_resources_string_views_spannable_helpers, android_resources_string_views_spannable_styles, android_resources_string_views_spannable_chain, android_resources_string_views_annotation_typeface, android_resources_string_views_annotation_parcel_send, and android_resources_string_views_annotation_parcel_receive), stripped inline HTML <code><a href="..."> link markup from <pre> blocks (android_resources_string_views_get_string, android_resources_string_views_get_string_array, android_resources_string_views_get_quantity_string, and android_resources_string_views_html_encode), added trailing full stops to natural-language comments (D29), and formatted with Spotless.

Snippets not migrated:

  • Providing-resources-views page: Directory tree listings (lines 33–47 and 190–198); two findViewById / getString example blocks inside <section> tabs (lines 650–653 and 688–706) left hardcoded with SNIPPET_GITHUB because they reference 8 hypothetical resources across 4 resource types (R.id.myimageview, R.drawable.myimage, R.drawable.my_background_image, R.string.main_title, R.layout.main_screen, R.anim.hyperspace_in, R.id.msg, R.string.hello_message) not defined on the page (D1 / D11 — unlike the migrated ArrayAdapter block which uses platform android.R.layout.simple_list_item_1 and a single <string-array name="planets_array"> resource); obsolete Java duplicates (lines 657–661, 710–728, and 887–889, removed per D15); and short XML View layout fragments (<merge>, <Button>, <EditText>) and resource/alias syntax examples (<drawable>, <color>/<string>, <bitmap>) left hardcoded on the guide page (D1).
  • Runtime-changes-views page: Lines 165–177 obsolete Java duplicate (removed per D15).
  • Localization-views page: Lines 109–112 obsolete Java duplicate (removed per D15).
  • String-resource-views page: All 12 obsolete Java duplicates (removed per D15); <dl class="xml"> syntax templates containing HTML anchor tags (<string>, <string-array>, <plurals>); <TextView> View layout XML fragment (D1); and <string>, <string-array>, and <plurals> XML resource example blocks left hardcoded with SNIPPET_GITHUB because each block is a complete standalone <?xml version="1.0" encoding="utf-8"?><resources>...</resources> file template (including a localized res/values-pl/strings.xml Polish variant) that cannot be nested inside the module's single views/src/main/res/values/strings.xml <resources> root without omitting the XML declaration and <resources> wrapper shown on the page.

@djubinville
djubinville force-pushed the djubinville/app-resources-views-pages-snippets branch from 5b7cf5b to 09569a6 Compare October 16, 2026 17:07
@djubinville
djubinville marked this pull request as ready for review October 16, 2026 18:48
@snippet-bot

snippet-bot Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 15 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@djubinville
djubinville force-pushed the djubinville/app-resources-views-pages-snippets branch 2 times, most recently from 45ba209 to 1f0c02c Compare October 19, 2026 11:49
@djubinville

Copy link
Copy Markdown
Contributor Author

Addressed review feedback on PR #1194 and companion CL cl/1000932997:

  1. Must Fix (D24 — RuntimeChangesViews.kt L29–33): Swapped the Configuration.KEYBOARDHIDDEN_YES and Configuration.KEYBOARDHIDDEN_NO branches in android_resources_runtime_changes_views_keyboard so KEYBOARDHIDDEN_NO ("hardware keyboard is not hidden") displays "Keyboard available" and KEYBOARDHIDDEN_YES ("hardware keyboard is hidden") displays "No keyboard", and added the D24 modification table to the PR description.
  2. Warning 1 (Phase 4 CL Description): Updated cl/1000932997's description to use PR: https://github.com/android/snippets/pull/1194, added the pre-merge staging note, and preserved the -------------- (KEEP THIS LINE) --- delimiter and triage metadata.
  3. Warnings 3 & 4 (Snippets not migrated: clarifications): Updated Snippets not migrated: in the PR description with the concrete technical reasons why:
    • The two findViewById / getString blocks on providing-resources-views.md (lines 650–653 and 688–706) were left hardcoded with SNIPPET_GITHUB: they reference 8 hypothetical resources across 4 resource types (R.id.myimageview, R.drawable.myimage, R.drawable.my_background_image, R.string.main_title, R.layout.main_screen, R.anim.hyperspace_in, R.id.msg, R.string.hello_message) not defined on the page (D1 / D11), whereas the migrated ArrayAdapter block uses platform android.R.layout.simple_list_item_1 and a single <string-array name="planets_array"> resource.
    • The <string>, <string-array>, and <plurals> XML example blocks on string-resource-views.md were left hardcoded with SNIPPET_GITHUB: each block is a complete standalone <?xml version="1.0" encoding="utf-8"?><resources>...</resources> file template (including a localized res/values-pl/strings.xml Polish variant) that cannot be nested inside the module's single views/src/main/res/values/strings.xml <resources> root without omitting the XML declaration and <resources> wrapper shown on the page.

Documented Rule Bypasses & Rulebook Recommendations

  • D11 bypass (views/src/main/res/values/strings.xml — <item name="permanent_marker" type="font" />): Bypassed D11 ("Do not use <item type="..."> stand-in declarations in strings.xml as a shortcut when a real resource file or entry should exist") to retain <item name="permanent_marker" type="font" /> for R.font.permanent_marker (android_resources_string_views_annotation_typeface in StringResourceViews.kt), as accepted in the review with D27 disclosure in the PR description, avoiding committing a binary .ttf/.otf font file into views/src/main/res/font/. Rulebook update recommendation: Update D11 / D27 to explicitly allow <item type="font" /> stand-in declarations in res/values/strings.xml (with D27 disclosure) when a snippet references a custom R.font.* resource and adding a binary font file is undesirable.

@djubinville
djubinville force-pushed the djubinville/app-resources-views-pages-snippets branch 2 times, most recently from cbfae1d to 1ddfa7f Compare October 20, 2026 18:47
@djubinville
djubinville force-pushed the djubinville/app-resources-views-pages-snippets branch from 1ddfa7f to 6acbe3c Compare October 21, 2026 17:46

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant