|
58 | 58 | import android.view.ViewGroup; |
59 | 59 | import android.view.ViewParent; |
60 | 60 | import android.view.ViewTreeObserver; |
| 61 | +import android.view.Window; |
| 62 | +import android.view.WindowInsets; |
61 | 63 | import android.view.WindowManager; |
62 | 64 | import android.view.inputmethod.EditorInfo; |
63 | 65 | import android.view.inputmethod.InputMethodManager; |
@@ -1376,12 +1378,56 @@ public void run() { |
1376 | 1378 |
|
1377 | 1379 |
|
1378 | 1380 |
|
1379 | | - private static void setEditMode(final boolean resize){ |
| 1381 | + private static void setEditMode(final boolean resize) { |
1380 | 1382 | resizeMode = resize; |
| 1383 | + |
| 1384 | + final Activity activity = sInstance.impl.getActivity(); |
| 1385 | + final Window window = activity.getWindow(); |
| 1386 | + |
1381 | 1387 | if (resize) { |
1382 | | - sInstance.impl.getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); |
| 1388 | + if (Build.VERSION.SDK_INT >= 34) { |
| 1389 | + // On Android 14+, adjustResize doesn't work with immersive layouts |
| 1390 | + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); |
| 1391 | + View rootView = window.getDecorView().findViewById(android.R.id.content); |
| 1392 | + applyImeInsetPaddingReflection(rootView); |
| 1393 | + } else { |
| 1394 | + // Old behavior works fine |
| 1395 | + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); |
| 1396 | + } |
1383 | 1397 | } else { |
1384 | | - sInstance.impl.getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); |
| 1398 | + window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); |
| 1399 | + } |
| 1400 | + } |
| 1401 | + |
| 1402 | + |
| 1403 | + private static void applyImeInsetPaddingReflection(View rootView) { |
| 1404 | + try { |
| 1405 | + rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { |
| 1406 | + @Override |
| 1407 | + public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { |
| 1408 | + try { |
| 1409 | + Class<?> typeClass = Class.forName("android.view.WindowInsets$Type"); |
| 1410 | + Class<?> insetsClass = Class.forName("android.view.WindowInsets"); |
| 1411 | + int imeType = ((Integer) typeClass.getMethod("ime").invoke(null)).intValue(); |
| 1412 | + |
| 1413 | + Object imeInsets = insetsClass.getMethod("getInsets", int.class).invoke(insets, imeType); |
| 1414 | + Class<?> insetsRectClass = imeInsets.getClass(); |
| 1415 | + |
| 1416 | + int bottom = ((Integer) insetsRectClass.getField("bottom").get(imeInsets)).intValue(); |
| 1417 | + boolean isVisible = ((Boolean) insetsClass.getMethod("isVisible", int.class).invoke(insets, imeType)).booleanValue(); |
| 1418 | + |
| 1419 | + v.setPadding(0, 0, 0, isVisible ? bottom : 0); |
| 1420 | + } catch (Throwable e) { |
| 1421 | + e.printStackTrace(); |
| 1422 | + } |
| 1423 | + return insets; |
| 1424 | + } |
| 1425 | + }); |
| 1426 | + |
| 1427 | + rootView.requestApplyInsets(); |
| 1428 | + |
| 1429 | + } catch (Throwable e) { |
| 1430 | + e.printStackTrace(); |
1385 | 1431 | } |
1386 | 1432 | } |
1387 | 1433 |
|
|
0 commit comments