Android: use WindowInsets for 30 API and above

For Android above API 30 we can directly just check if the keyboard is
visible. We do not need to calculate it size. This is useful as
floating keyboard has wrong size.

Task-number: QTBUG-130000
Change-Id: Ia91d8b9ddefc97f8d65a657aa7e75bb146feb00e
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Rami Potinkara <rami.potinkara@qt.io>
(cherry picked from commit d97bfafa86e752cc3a739d8efb749ddea2120ca5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Bartlomiej Moskal 2024-10-30 13:51:33 +01:00 committed by Qt Cherry-pick Bot
parent 0cb75c28af
commit e27e9d4a20

View File

@ -16,6 +16,8 @@ import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputMethodManager;
import android.view.KeyEvent;
import android.view.WindowInsets;
import android.view.WindowInsets.Type;
import android.graphics.Rect;
import android.app.Activity;
import android.util.DisplayMetrics;
@ -88,20 +90,21 @@ class QtInputConnection extends BaseInputConnection
return;
}
Rect r = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
boolean isKeyboardHidden = true;
int screenHeight;
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
Rect r = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
screenHeight = metrics.heightPixels;
int screenHeight = metrics.heightPixels;
final int kbHeight = screenHeight - r.bottom;
isKeyboardHidden = kbHeight < screenHeight * KEYBOARD_TO_SCREEN_RATIO;
} else {
final WindowMetrics maximumWindowMetrics = activity.getWindowManager().getMaximumWindowMetrics();
screenHeight = maximumWindowMetrics.getBounds().height();
WindowInsets w = activity.getWindow().getDecorView().getRootWindowInsets();
isKeyboardHidden = !w.isVisible(Type.ime());
}
final int kbHeight = screenHeight - r.bottom;
if (kbHeight < screenHeight * KEYBOARD_TO_SCREEN_RATIO)
if (isKeyboardHidden)
m_qtInputConnectionListener.onHideKeyboardRunnableDone(false, System.nanoTime());
}
}