@@ -1376,16 +1376,14 @@ public void run() {
13761376 }
13771377 }
13781378
1379-
1380-
13811379 private static void setEditMode (final boolean resize ) {
13821380 resizeMode = resize ;
13831381
13841382 final Activity activity = sInstance .impl .getActivity ();
13851383 final Window window = activity .getWindow ();
13861384
13871385 if (resize ) {
1388- if (Build .VERSION .SDK_INT >= 34 ) {
1386+ if (Build .VERSION .SDK_INT >= 34 && isImmersive ( window ) ) {
13891387 // On Android 14+, adjustResize doesn't work with immersive layouts
13901388 window .setSoftInputMode (WindowManager .LayoutParams .SOFT_INPUT_ADJUST_NOTHING );
13911389 View rootView = window .getDecorView ().findViewById (android .R .id .content );
@@ -1399,6 +1397,53 @@ private static void setEditMode(final boolean resize) {
13991397 }
14001398 }
14011399
1400+ private static boolean isImmersive (Window window ) {
1401+ View decor = window .getDecorView ();
1402+
1403+ // ---------- Modern branch : API 30+ ----------
1404+ if (Build .VERSION .SDK_INT >= 30 ) {
1405+ try {
1406+ // WindowInsets insets = decor.getRootWindowInsets();
1407+ Object insets = View .class
1408+ .getMethod ("getRootWindowInsets" )
1409+ .invoke (decor );
1410+ if (insets == null ) return false ;
1411+
1412+ // int mask = WindowInsets.Type.systemBars();
1413+ Class <?> typeCls =
1414+ Class .forName ("android.view.WindowInsets$Type" );
1415+ int systemBars = (Integer ) typeCls
1416+ .getMethod ("systemBars" )
1417+ .invoke (null );
1418+
1419+ // boolean barsVisible = insets.isVisible(mask);
1420+ boolean barsVisible = (Boolean ) insets .getClass ()
1421+ .getMethod ("isVisible" , int .class )
1422+ .invoke (insets , systemBars );
1423+
1424+ /* --------------------------------------------------
1425+ * Edge-to-edge is guaranteed on API 35+ anyway, and
1426+ * `getDecorFitsSystemWindows()` no longer exists on
1427+ * API 36. We treat everything >=30 as edge-to-edge
1428+ * (decorFits = false) and only look at bar visibility
1429+ * to decide if we’re *immersive*.
1430+ * -------------------------------------------------- */
1431+ return !barsVisible ; // immersive ⇢ bars are hidden
1432+ } catch (Throwable ignore ) {
1433+ System .out .println ("Error: " + ignore );
1434+ }
1435+ }
1436+
1437+ // ---------- Legacy branch : API 19-29 ----------
1438+ int f = decor .getSystemUiVisibility ();
1439+ boolean immersiveBits =
1440+ (f & View .SYSTEM_UI_FLAG_IMMERSIVE_STICKY ) != 0 ||
1441+ (f & View .SYSTEM_UI_FLAG_IMMERSIVE ) != 0 ;
1442+ boolean barsHidden =
1443+ (f & View .SYSTEM_UI_FLAG_HIDE_NAVIGATION ) != 0 &&
1444+ (f & View .SYSTEM_UI_FLAG_FULLSCREEN ) != 0 ;
1445+ return immersiveBits && barsHidden ;
1446+ }
14021447
14031448 private static void applyImeInsetPaddingReflection (View rootView ) {
14041449 try {
0 commit comments