Conversation
Extract the three Kotlin blocks from the Quick Settings tiles guide: the TileService skeleton, the tile update in onStartListening(), and the tap handler. https://developer.android.com/develop/ui/views/quicksettings-tiles Two blocks name an identifier the page never declares, so they do not compile as published: - Update your tile: the block sets contentDescription from tile.label, but the Kotlin sample has no tile local. The Java sample on the same page does. Use qsTile.label, as the Handle taps block already does. - Handle taps: the block declares var clicks and then increments counter four times. Name the property counter. Both need a page fix.
hamen
marked this pull request as ready for review
September 2, 2026 11:31
kkuan2011
approved these changes
Sep 9, 2026
kkuan2011
left a comment
There was a problem hiding this comment.
Good catches! Looks good.
For the block at line 420 that adds Intent.FLAG_ACTIVITY_NEW_TASK. - can we migrate this one too and make it a kotlin snippet? After you've added it, feel free to merge!
The reviewer asked for `state.label` instead of `qsTile.label`, so that every right-hand side in the block comes from the model the block declares. She is right, and it is a better answer than the one this branch shipped. Both compile. The page's own line does not: it prints `qsTile.contentDescription = tile.label` where the Kotlin block declares no `tile`, and building that line gives `Unresolved reference 'tile'`. Something had to replace it. `qsTile.label` was the smaller edit, but it reads the property back out of the object it was written into one line earlier, and it left one line in the block not sourced from `state`. The page can be repaired either way, and the description says so: give the Kotlin block the `Tile tile = getQsTile()` line its Java sibling on the same page already has, or read from `state`. Claude-Session: https://claude.ai/code/session_01P9x2zonc8Jow9hajZw96pn
Collaborator
Author
|
The upstream equivalent is open: android#1087 Same file, same three region tags, cut fresh off |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This change adds the three Kotlin snippets from
Quick Settings tiles to
views/src/main/java/com/example/example/snippet/views/quicksettings/QuickSettingsTilesSnippets.kt.Each region gives the same lines that the page shows today. You can include the snippets without a
change to the text around them.
android_views_quicksettings_tile_serviceandroid_views_quicksettings_update_tileandroid_views_quicksettings_handle_tapsThe last column shows what
spotlessApplychanged. ktlint made the indent four spaces in the place oftwo. It also added a space in
class MyQSTileService : TileService(). The number of lines did notchange. Each snippet stays as long as the block that it replaces.
Two lines that are not a copy of the page
Each Kotlin block uses a name that the block does not declare. Neither block compiles as published.
Update your tile sets the content description from
tile.label. The Kotlin block has notile.All the other lines in the block use
qsTile. The Java block on the same page declaresTile tile = getQsTile(), and then usestile. The Kotlin block reads like a translation that lostthe local variable and kept one use of it. A build of the published lines gives
Unresolved reference 'tile'. The snippet usesstate.label, which is the valueqsTile.labelwasassigned one line earlier, so every right-hand side in the block now reads from the model the block
declares. That is the reviewer's suggestion and it is better than the first answer here, which was
qsTile.label: that compiled, but it read the property back out of the object it had just beenwritten into, and it was the one line in the block not sourced from
state.The Java block on the same page keeps its
tilelocal, so the page can be repaired either way: givethe Kotlin block the
Tile tile = getQsTile()line its Java sibling has, or read fromstateasthis snippet does.
Handle taps declares
var clicks = 0, and then increasescounterfour times. A build of thepublished lines gives four errors of
Unresolved reference 'counter'. The snippet gives the namecounterto the declaration. This changes one line and not four.You can correct the block in the other direction. If you give the name
clicksto the four uses, theblock is also correct. The block cannot stay as it is, because it does not compile. The snippet takes
the smaller change. Please use the name that reads better on the page. The snippet does not hold you
to this one.
Both blocks need a correction on the page. A reader who copies them today gets a compile error.
How the file is arranged
StateModelis insideUpdateTileService, and not at the top level. The page shows the data class,then an empty line, then the override. Two spans of one region tag cannot keep that empty line, and
the published snippet would be one line shorter than the block. One span keeps the empty line. The
nesting does not change what the page shows.
getStateFromService()is outside the region tags, and it does not appear on the page. The page callsthis function in the Kotlin block and in the Java block, but the page does not define it anywhere. It
reads as a function of the app, and not as a platform API. The stub is here only to let the module
compile.
The three regions are in three subclasses of
TileService, and not in one class. The first blockoverrides
onStartListening()andonClick(). The second block overridesonStartListening(). Thethird block overrides
onClick(). The second block and the third block cannot go in the first class.The other code blocks on the page
No other block on the page has a region tag. The line numbers are from
quicksettings-tiles.md.txt.Keep the block at line 513. It shows the signature of
requestAddTileService(), and it is not anexample that a reader copies. It belongs with the reference text around it.
The block at line 420 adds
Intent.FLAG_ACTIVITY_NEW_TASK. It sits in the text, and not below aKotlin heading or a Java heading, so it reads as an example for the two languages. But it has a
semicolon, and this makes it Java as it is written. If you remove the semicolon, the block becomes
Kotlin, and it stays correct for a Java reader. This is a decision for the page, so I made no change
to it.
The four XML manifest examples are not Kotlin, and this change does not extract them. The example at
line 140 has a small defect that you can correct while the page is open:
XML has no
//comment. The example does not parse as it is printed, and a reader who copies it getsa manifest that does not build. Put the note above the element as
<!-- 18-character limit. -->. Thenote stays, and the example builds. This has no effect on the snippets.
Thanks for the review. Tell me if you prefer a different choice at any of the points above.