Skip to content

inehemiasm/AiAssistant / skills/display-glasses-with-jetpack-compose-glimmer

display-glasses-with-jetpack-compose-glimmer

Verified

Provides guidelines for developing projected Android XR apps for display glasses using the Jetpack Compose Glimmer UI toolkit. This skill covers foundational Glimmer design principles, workflows for implementing Jetpack Compose Glimmer, and interaction models for the glasses form factor. Use this skill to build an Android XR Augmented Experience app with Jetpack Compose Glimmer that adheres to the Glimmer design system for optimized glasses styling.

FileKindSize
SKILL.mdskill md21.9 KB
references/android/design/ui/ai-glasses/guides/interaction/inputs.mdmarkdown2.3 KB
references/android/develop/xr/jetpack-xr-sdk/access-hardware-projected-context.mdmarkdown21.6 KB
references/android/develop/xr/jetpack-xr-sdk/jetpack-compose-glimmer/buttons.mdmarkdown4.7 KB
references/android/develop/xr/jetpack-xr-sdk/jetpack-compose-glimmer/cards.mdmarkdown6.5 KB
references/android/develop/xr/jetpack-xr-sdk/jetpack-compose-glimmer/focus.mdmarkdown5.6 KB
references/android/develop/xr/jetpack-xr-sdk/jetpack-compose-glimmer/icons.mdmarkdown4.6 KB
references/android/develop/xr/jetpack-xr-sdk/jetpack-compose-glimmer/text.mdmarkdown2.7 KB
references/android/develop/xr/jetpack-xr-sdk/jetpack-compose-glimmer/title-chips.mdmarkdown3.4 KB
references/android/develop/xr/jetpack-xr-sdk/request-hardware-permissions.mdmarkdown8.8 KB
references/button-samples-source.mdmarkdown4.5 KB
references/button-source.mdmarkdown8.8 KB
references/card-samples-source.mdmarkdown8.2 KB
references/card-source.mdmarkdown24.3 KB
references/deptheffect-source.mdmarkdown7.8 KB
references/deptheffectlevels-source.mdmarkdown4.1 KB
references/glimmersansflextypography-source.mdmarkdown11.3 KB
references/glimmertheme-source.mdmarkdown7.6 KB
references/icon-source.mdmarkdown16.9 KB
references/iconbutton-source.mdmarkdown5.2 KB
references/iconsizes-source.mdmarkdown2.3 KB
references/list-source.mdmarkdown18.0 KB
references/listitem-source.mdmarkdown11.6 KB
references/liststate-source.mdmarkdown17.4 KB
references/material-hct-source.mdmarkdown6.3 KB
references/projectedcontext-source.mdmarkdown10.7 KB
references/stack-source.mdmarkdown15.3 KB
references/stackitemscope-source.mdmarkdown16.2 KB
references/stackstate-source.mdmarkdown12.9 KB
references/surface-source.mdmarkdown29.0 KB
references/titlechip-samples-source.mdmarkdown2.9 KB
references/titlechip-source.mdmarkdown5.3 KB

references/card-samples-source.md

View on GitHub
When creating a Glimmer Card component, refer to the following implementation
samples in `CardSamples.kt`:


```kotlin
/*
 * Copyright 2025 The Android Open Source Project
 *
 * 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 androidx.xr.glimmer.samples

import androidx.annotation.Sampled
import androidx.compose.foundation.Image
import androidx.compose.runtime.Composable
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.BrushPainter
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.xr.glimmer.Button
import androidx.xr.glimmer.Card
import androidx.xr.glimmer.GlimmerTheme
import androidx.xr.glimmer.Icon
import androidx.xr.glimmer.Text
import androidx.xr.glimmer.list.GlimmerLazyColumn

@Composable
fun CardSampleUsage() {
    GlimmerLazyColumn {
        item { CardSample() }
        item { CardWithTrailingIconSample() }
        item { CardWithTitleAndSubtitleAndLeadingIconSample() }
        item { CardWithTitleAndHeaderSample() }
        item { CardWithTitleAndActionSample() }
        item { CardWithTitleAndLeadingIconAndHeader() }
        item { CardWithTitleAndLeadingIconAndHeaderAndAction() }
        item { CardWithLongText() }
        item { CardWithTitleAndSubtitleAndLeadingIconLongText() }
        item { CardWithTitleAndSubtitleAndLeadingIconAndTrailingIconLongText() }
    }
}

@Sampled
@Composable
fun CardSample() {
    Card { Text("This is a card") }
}

@Sampled
@Composable
fun CardWithTrailingIconSample() {
    Card(trailingIcon = { Icon(FavoriteIcon, "Localized description") }) {
        Text("This is a card with a trailing icon")
    }
}

@Sampled
@Composable
fun CardWithTitleAndSubtitleAndLeadingIconSample() {
    Card(
        title = { Text("Title") },
        subtitle = { Text("Subtitle") },
        leadingIcon = { Icon(FavoriteIcon, "Localized description") },
    ) {
        Text("This is a card with a title, subtitle, and leading icon")
    }
}

@Sampled
@Composable
fun CardWithTitleAndHeaderSample() {
    Card(
        title = { Text("Title") },
        header = {
            Image(MyHeaderImage, "Localized description", contentScale = ContentScale.FillWidth)
        },
    ) {
        Text("This is a card with a title and header image")
    }
}

@Sampled
@Composable
fun CardWithTitleAndActionSample() {
    Card(action = { Button(onClick = {}) { Text("Send") } }, title = { Text("Title") }) {
        Text("This is a card with a title and action")
    }
}

@Sampled
@Composable
fun ClickableCardSample() {
    Card(onClick = {}) { Text("This is a card") }
}

@Sampled
@Composable
fun ClickableCardWithTrailingIconSample() {
    Card(onClick = {}, trailingIcon = { Icon(FavoriteIcon, "Localized description") }) {
        Text("This is a card with a trailing icon")
    }
}

@Sampled
@Composable
fun ClickableCardWithTitleAndSubtitleAndLeadingIconSample() {
    Card(
        onClick = {},
        title = { Text("Title") },
        subtitle = { Text("Subtitle") },
        leadingIcon = { Icon(FavoriteIcon, "Localized description") },
    ) {
        Text("This is a card with a title, subtitle, and leading icon")
    }
}

@Sampled
@Composable
fun ClickableCardWithTitleAndHeaderSample() {
    Card(
        onClick = {},
        title = { Text("Title") },
        header = {
            Image(MyHeaderImage, "Localized description", contentScale = ContentScale.FillWidth)
        },
    ) {
        Text("This is a card with a title and header image")
    }
}

@Composable
fun CardWithTitleAndLeadingIconAndHeader() {
    Card(
        title = { Text("Title") },
        leadingIcon = { Icon(FavoriteIcon, "Localized description") },
        header = {
            Image(MyHeaderImage, "Localized description", contentScale = ContentScale.FillWidth)
        },
    ) {
        Text("This is a card with a title, leading icon, and header image")
    }
}

@Composable
fun CardWithTitleAndLeadingIconAndHeaderAndAction() {
    Card(
        action = {
            Button(onClick = {}, trailingIcon = { Icon(FavoriteIcon, "Localized description") }) {
                Text("Send")
            }
        },
        title = { Text("Title") },
        leadingIcon = { Icon(FavoriteIcon, "Localized description") },
        header = {
            Image(MyHeaderImage, "Localized description", contentScale = ContentScale.FillWidth)
        },
    ) {
        Text("This is a card with a title, leading icon, header image, and action")
    }
}

@Composable
fun CardWithLongText() {
    Card {
        Text(
            "This is a card with a lot of text that will wrap to multiple lines. The maximum recommend number of lines of text for a card is 10.",
            maxLines = 10,
            overflow = TextOverflow.Ellipsis,
        )
    }
}

@Composable
fun CardWithTitleAndSubtitleAndLeadingIconLongText() {
    Card(
        title = { Text("Title") },
        subtitle = { Text("Subtitle") },
        leadingIcon = { Icon(FavoriteIcon, "Localized description") },
    ) {
        Text(
            "This is a card with a lot of text that will wrap to multiple lines. The maximum recommend number of lines of text for a card is 10."
        )
    }
}

@Composable
fun CardWithTitleAndSubtitleAndLeadingIconAndTrailingIconLongText() {
    Card(
        title = { Text("Title") },
        subtitle = { Text("Subtitle") },
        leadingIcon = { Icon(FavoriteIcon, "Localized description") },
        trailingIcon = { Icon(FavoriteIcon, "Localized description") },
    ) {
        Text(
            "This is a card with a lot of text that will wrap to multiple lines. The maximum recommend number of lines of text for a card is 10."
        )
    }
}

@Preview
@Composable
private fun CardPreview() {
    GlimmerTheme { CardSample() }
}

@Preview
@Composable
private fun CardWithTrailingIconPreview() {
    GlimmerTheme { CardWithTrailingIconSample() }
}

@Preview
@Composable
private fun CardWithTitleAndSubtitleAndLeadingIconPreview() {
    GlimmerTheme { CardWithTitleAndSubtitleAndLeadingIconSample() }
}

@Preview
@Composable
private fun CardWithTitleAndHeaderPreview() {
    GlimmerTheme { CardWithTitleAndHeaderSample() }
}

@Preview
@Composable
private fun CardWithTitleAndActionPreview() {
    GlimmerTheme { CardWithTitleAndActionSample() }
}

@Preview
@Composable
private fun CardWithTitleAndLeadingIconAndHeaderPreview() {
    GlimmerTheme { CardWithTitleAndLeadingIconAndHeader() }
}

@Preview
@Composable
private fun CardWithTitleAndLeadingIconAndHeaderAndActionPreview() {
    GlimmerTheme { CardWithTitleAndLeadingIconAndHeaderAndAction() }
}

@Preview
@Composable
private fun CardWithLongTextPreview() {
    GlimmerTheme { CardWithLongText() }
}

@Preview
@Composable
private fun CardWithTitleAndSubtitleAndLeadingIconLongTextPreview() {
    GlimmerTheme { CardWithTitleAndSubtitleAndLeadingIconLongText() }
}

@Preview
@Composable
private fun CardWithTitleAndSubtitleAndLeadingIconAndTrailingIconLongTextPreview() {
    GlimmerTheme { CardWithTitleAndSubtitleAndLeadingIconAndTrailingIconLongText() }
}

fun placeholderImagePainter(intrinsicSize: Size): Painter =
    BrushPainter(
        Brush.linearGradient(
            0.0f to Color(0xFF3C8CDE),
            0.4f to Color(0xFFED73A8),
            0.6f to Color(0xFFED73A8),
            1.0f to Color(0xFFE763F9),
            start = Offset.Zero,
            end = Offset(intrinsicSize.width, intrinsicSize.height),
        )
    )

/**
 * Placeholder image with a large intrinsic size, to simulate a real life use case of loading a
 * bitmap
 */
private val MyHeaderImage = placeholderImagePainter(Size(1000f, 1000f))
```

<br />
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall