Skip to content

Commit a87ef18

Browse files
authored
fix: [3904] Fixed android async editing with form resizing on API 34+ (#3905)
* fix: [3904] Fixed android async editing with form resizing on API 34+ Android 34+ no longer supports the WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE parameter for resizing the form for the soft editor. This broke our in place editor when using formbottompadding editing mode as described in #3904. This fix uses a different approach to add the insets manually. * replaced lambda, because not supported on source 1.6 * fixed build error
1 parent 7a058b8 commit a87ef18

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

Ports/Android/src/com/codename1/impl/android/InPlaceEditView.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
import android.view.ViewGroup;
5959
import android.view.ViewParent;
6060
import android.view.ViewTreeObserver;
61+
import android.view.Window;
62+
import android.view.WindowInsets;
6163
import android.view.WindowManager;
6264
import android.view.inputmethod.EditorInfo;
6365
import android.view.inputmethod.InputMethodManager;
@@ -1376,12 +1378,56 @@ public void run() {
13761378

13771379

13781380

1379-
private static void setEditMode(final boolean resize){
1381+
private static void setEditMode(final boolean resize) {
13801382
resizeMode = resize;
1383+
1384+
final Activity activity = sInstance.impl.getActivity();
1385+
final Window window = activity.getWindow();
1386+
13811387
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+
}
13831397
} 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();
13851431
}
13861432
}
13871433

0 commit comments

Comments
 (0)