Add code snippets for foldables and multi-window#883
Conversation
There was a problem hiding this comment.
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.
| override fun onSessionEnded(t: Throwable?) { | ||
| if (t != null) { | ||
| Log.e(logTag, "Something was broken: ${t.message}") | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| 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() { |
There was a problem hiding this comment.
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.
| override fun onSessionStarted(session: WindowAreaSession) { | ||
| Log.d(logTag, "onSessionStarted") | ||
| } |
There was a problem hiding this comment.
The windowAreaSession variable must be updated when the session starts so that it can be tracked and closed later.
| override fun onSessionStarted(session: WindowAreaSession) { | |
| Log.d(logTag, "onSessionStarted") | |
| } | |
| override fun onSessionStarted(session: WindowAreaSession) { | |
| windowAreaSession = session | |
| Log.d(logTag, "onSessionStarted") | |
| } |
| override fun onSessionEnded(t: Throwable?) { | ||
| if (t != null) { | ||
| Log.e(logTag, "Something was broken: ${t.message}") | ||
| } | ||
| } |
There was a problem hiding this comment.
The windowAreaSession variable should be reset to null when the session ends to maintain correct state for the toggle logic.
| 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) { |
| // [START android_adaptive_toggle_rear_display] | ||
| fun toggleRearDisplayMode() { | ||
| if(capabilityStatus == WindowAreaCapability.Status.WINDOW_AREA_STATUS_ACTIVE) { | ||
| if(windowAreaSession == null) { |
30ed8db to
c63b7b2
Compare
telpirion
left a comment
There was a problem hiding this comment.
Looks like a faithful recreation of the samples! Thank you.
Code snippets are for:
Migrated Snippets & Changes:
Support multi-window mode (SupportMultiWindowMode.kt)
android_adaptive_launch_adjacent: Migrated as-is.android_adaptive_top_resumed: Addedsuper.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 fromComponentActivity.android_adaptive_fold_feature: Migrated as-is.android_adaptive_tabletop_posture: Migrated as-is.android_adaptive_supported_postures: Corrected platform API name toextensionVersionand referenced static enumSupportedPosture.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: ReplacedTextViewwithComposeViewcallingMyScreen()to make the code Compose-first.android_adaptive_toggle_rear_display: Migrated as-is.android_adaptive_rear_display_callbacks: Added parametersession: WindowAreaSessioninonSessionStarted()to match platform API requirements.android_adaptive_window_callback: RenamedMainActivitytoExampleActivityto avoid name collisions in the package, and corrected interface typo.Skipped Snippets:
AndroidManifest.xmlwere skipped.build.gradledependency snippets were skipped.