Skip to content

Add code snippets for foldables and multi-window#883

Merged
kkuan2011 merged 2 commits intomainfrom
katherinekuan/foldables-multi-window
Apr 23, 2026
Merged

Add code snippets for foldables and multi-window#883
kkuan2011 merged 2 commits intomainfrom
katherinekuan/foldables-multi-window

Conversation

@kkuan2011
Copy link
Copy Markdown
Contributor

Code snippets are for:

Migrated Snippets & Changes:

Support multi-window mode (SupportMultiWindowMode.kt)

  • android_adaptive_launch_adjacent: Migrated as-is.
  • android_adaptive_top_resumed: Added super.onTopResumedActivityChanged(topResumed) to preserve platform behavior.
  • android_adaptive_metrics_other_displays: Migrated as-is.

Make your app fold-aware (MakeYourAppFoldAware.kt)

  • android_adaptive_fold_aware_flows: Removed view binding references to make it Compose-first, updated to extend from ComponentActivity.
  • android_adaptive_fold_feature: Migrated as-is.
  • android_adaptive_tabletop_posture: Migrated as-is.
  • android_adaptive_supported_postures: Corrected platform API name to extensionVersion and referenced static enum SupportedPosture.TABLETOP.
  • android_adaptive_book_posture: Migrated as-is.

Support foldable display modes (SupportFoldableDisplayModes.kt)

  • android_adaptive_foldable_vars: Migrated as-is.
  • android_adaptive_foldable_init: Migrated as-is.
  • android_adaptive_capability_check: Migrated as-is.
  • android_adaptive_toggle_dual_screen: Migrated as-is.
  • android_adaptive_session_callbacks: Replaced TextView with ComposeView calling MyScreen() to make the code Compose-first.
  • android_adaptive_toggle_rear_display: Migrated as-is.
  • android_adaptive_rear_display_callbacks: Added parameter session: WindowAreaSession in onSessionStarted() to match platform API requirements.
  • android_adaptive_window_callback: Renamed MainActivity to ExampleActivity to avoid name collisions in the package, and corrected interface typo.

Skipped Snippets:

  • Java snippets: All Java code blocks were skipped as per skill guidelines (Focus on Kotlin/Compose).
  • Manifest/Metadata snippets: XML snippets intended for AndroidManifest.xml were skipped.
  • Build configuration snippets: build.gradle dependency snippets were skipped.
  • RxJava snippets: Snippets demonstrating RxJava usage were skipped in favor of standard Kotlin Flows.

@kkuan2011 kkuan2011 requested a review from a team as a code owner April 23, 2026 00:30
@kkuan2011 kkuan2011 requested a review from rebeccasg April 23, 2026 00:30
@snippet-bot
Copy link
Copy Markdown

snippet-bot Bot commented Apr 23, 2026

Here is the summary of changes.

You are about to add 16 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

@kkuan2011 kkuan2011 requested review from telpirion and removed request for rebeccasg April 23, 2026 00:31
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for foldable and adaptive layouts, including utilities for tracking folding features and managing dual-screen and rear-display modes. The review identifies a critical bug in RearDisplayActivity where uninitialized properties would lead to a crash, and emphasizes the importance of correctly managing the windowAreaSession state during session transitions. Suggestions were also provided to improve code formatting and consistency.

Comment on lines +140 to +144
override fun onSessionEnded(t: Throwable?) {
if (t != null) {
Log.e(logTag, "Something was broken: ${t.message}")
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The windowAreaSession variable should be reset to null when the session ends. This ensures that the toggleDualScreenMode logic correctly identifies that a new session needs to be started on the next interaction.

Suggested change
override fun onSessionEnded(t: Throwable?) {
if (t != null) {
Log.e(logTag, "Something was broken: ${t.message}")
}
}
override fun onSessionEnded(t: Throwable?) {
windowAreaSession = null
if (t != null) {
Log.e(logTag, "Something was broken: ${t.message}")
}
}

private val operation = WindowAreaCapability.Operation.OPERATION_TRANSFER_ACTIVITY_TO_AREA

// [START android_adaptive_toggle_rear_display]
fun toggleRearDisplayMode() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The RearDisplayActivity is missing initialization logic for its properties. windowAreaController and displayExecutor are lateinit and will cause a crash if toggleRearDisplayMode is called. Additionally, there is no code to update capabilityStatus or windowAreaInfo, which are required for the toggle logic to function. Consider adding an onCreate block similar to the one in ExampleActivity.

Comment on lines +198 to +200
override fun onSessionStarted(session: WindowAreaSession) {
Log.d(logTag, "onSessionStarted")
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The windowAreaSession variable must be updated when the session starts so that it can be tracked and closed later.

Suggested change
override fun onSessionStarted(session: WindowAreaSession) {
Log.d(logTag, "onSessionStarted")
}
override fun onSessionStarted(session: WindowAreaSession) {
windowAreaSession = session
Log.d(logTag, "onSessionStarted")
}

Comment on lines +202 to +206
override fun onSessionEnded(t: Throwable?) {
if (t != null) {
Log.e(logTag, "Something was broken: ${t.message}")
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The windowAreaSession variable should be reset to null when the session ends to maintain correct state for the toggle logic.

Suggested change
override fun onSessionEnded(t: Throwable?) {
if (t != null) {
Log.e(logTag, "Something was broken: ${t.message}")
}
}
override fun onSessionEnded(t: Throwable?) {
windowAreaSession = null
if (t != null) {
Log.e(logTag, "Something was broken: ${t.message}")
}
}


// [START android_adaptive_toggle_rear_display]
fun toggleRearDisplayMode() {
if(capabilityStatus == WindowAreaCapability.Status.WINDOW_AREA_STATUS_ACTIVE) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Missing space after if keyword.

Suggested change
if(capabilityStatus == WindowAreaCapability.Status.WINDOW_AREA_STATUS_ACTIVE) {
if (capabilityStatus == WindowAreaCapability.Status.WINDOW_AREA_STATUS_ACTIVE) {

// [START android_adaptive_toggle_rear_display]
fun toggleRearDisplayMode() {
if(capabilityStatus == WindowAreaCapability.Status.WINDOW_AREA_STATUS_ACTIVE) {
if(windowAreaSession == null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Missing space after if keyword.

Suggested change
if(windowAreaSession == null) {
if (windowAreaSession == null) {

@kkuan2011 kkuan2011 force-pushed the katherinekuan/foldables-multi-window branch from 30ed8db to c63b7b2 Compare April 23, 2026 17:00
Copy link
Copy Markdown
Contributor

@telpirion telpirion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a faithful recreation of the samples! Thank you.

@kkuan2011 kkuan2011 merged commit 1469984 into main Apr 23, 2026
5 checks passed
@kkuan2011 kkuan2011 deleted the katherinekuan/foldables-multi-window branch April 23, 2026 23:02
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.

3 participants