2626import android .content .Context ;
2727import android .content .pm .PackageManager ;
2828import android .content .res .Configuration ;
29+ import android .graphics .Color ;
2930import android .graphics .Rect ;
31+ import android .os .Bundle ;
3032import android .view .LayoutInflater ;
3133import android .view .Surface ;
3234import android .view .WindowManager ;
3335import android .widget .RelativeLayout ;
3436
37+ import androidx .activity .EdgeToEdge ;
38+ import androidx .activity .SystemBarStyle ;
3539import androidx .annotation .NonNull ;
40+ import androidx .annotation .Nullable ;
3641import androidx .constraintlayout .widget .ConstraintLayout ;
3742import androidx .constraintlayout .widget .ConstraintSet ;
43+ import androidx .core .graphics .Insets ;
3844import androidx .core .view .ViewCompat ;
3945import androidx .core .view .WindowInsetsCompat ;
4046import androidx .fragment .app .Fragment ;
5258// This activity readjusts its child layouts so that they're displayed on both single-screen and dual-screen device correctly.
5359public class DualScreenActivity extends FragmentActivity {
5460
61+ @ Override
62+ protected void onCreate (@ Nullable Bundle savedInstanceState ) {
63+ super .onCreate (savedInstanceState );
64+
65+ if (CommonFlightsManager .INSTANCE .getFlightsProvider ().isFlightEnabled (CommonFlight .ENABLE_HANDLING_FOR_EDGE_TO_EDGE )) {
66+ // Force set to a light theme (to status and navigation bars) since broker/common activities always have white background.
67+ // We don't support dark mode in broker/common activities yet.
68+ // Until then, having everything consistently rendered with a white background looks better.
69+ // This will also guarantee that the icons on those bars are always visible.
70+ setTheme (R .style .DualScreenActivityTheme );
71+ EdgeToEdge .enable (this ,
72+ SystemBarStyle .light (Color .TRANSPARENT , Color .TRANSPARENT ),
73+ SystemBarStyle .light (Color .TRANSPARENT , Color .TRANSPARENT ));
74+ }
75+ }
76+
5577 @ Override
5678 public void setContentView (int layoutResID ) {
5779 initializeContentView ();
@@ -65,18 +87,19 @@ private void initializeContentView(){
6587 if (CommonFlightsManager .INSTANCE .getFlightsProvider ().isFlightEnabled (CommonFlight .ENABLE_HANDLING_FOR_EDGE_TO_EDGE )) {
6688 try {
6789 ViewCompat .setOnApplyWindowInsetsListener (findViewById (android .R .id .content ), (view , insets ) -> {
68- int topInset = insets . getInsets ( WindowInsetsCompat . Type . systemBars ()). top ;
69- int bottomInset = insets .getInsets (WindowInsetsCompat .Type .systemBars ()). bottom ;
70- int leftInset = insets . getInsets ( WindowInsetsCompat .Type .systemBars ()). left ;
71- int rightInset = insets . getInsets ( WindowInsetsCompat .Type .systemBars ()). right ;
72-
73- view .setPadding (leftInset , topInset , rightInset , bottomInset );
90+ // Set the padding of the view to the insets of system bars, display cutout, system gestures, and Input (keyboards).
91+ final Insets inset = insets .getInsets (WindowInsetsCompat .Type .systemBars ()
92+ | WindowInsetsCompat .Type .displayCutout ()
93+ | WindowInsetsCompat .Type .systemGestures ()
94+ | WindowInsetsCompat . Type . ime ());
95+ view .setPadding (inset . left , inset . top , inset . right , inset . bottom );
7496 return insets ;
7597 });
7698 } catch (final Throwable throwable ) {
7799 Logger .warn ("DualScreenActivity:initializeContentView" , "Failed to set OnApplyWindowInsetsListener" );
78100 }
79101 }
102+
80103 adjustLayoutForDualScreenActivity ();
81104 }
82105
0 commit comments