From e6ca200a3a0aecc2313becf959c1be4fe18bdfa1 Mon Sep 17 00:00:00 2001 From: Piotr Mikolajczyk Date: Tue, 9 Feb 2021 08:50:11 +0100 Subject: [PATCH] Android: Fix constant resize of a large TextEdit on click If there is a large (3/5 of the screen in portrait or 2/3 in landscape) TextEdit on the screen, and it gets focus on click, it will be shrank to fit the screen. Next click on this TextEdit will restore its normal height, the next will shrink. Pick-to: 5.15 Fixes: QTBUG-91056 Change-Id: I3dbf085cbfdc2739d537a304c16e28c58a6e01ce Reviewed-by: Rami Potinkara Reviewed-by: Ville Voutilainen --- .../jar/src/org/qtproject/qt/android/QtNative.java | 14 ++++++++++++++ src/plugins/platforms/android/androidjniinput.cpp | 4 +--- .../platforms/android/qandroidinputcontext.cpp | 9 +++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/android/jar/src/org/qtproject/qt/android/QtNative.java b/src/android/jar/src/org/qtproject/qt/android/QtNative.java index cb2a78b403..5aa3997f91 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtNative.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtNative.java @@ -57,6 +57,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.content.pm.ApplicationInfo; import android.content.UriPermission; +import android.graphics.Rect; import android.net.Uri; import android.os.Build; import android.os.Handler; @@ -67,6 +68,7 @@ import android.content.ClipboardManager.OnPrimaryClipChangedListener; import android.content.ClipData; import android.os.ParcelFileDescriptor; import android.util.Log; +import android.util.DisplayMetrics; import android.view.ContextMenu; import android.view.KeyEvent; import android.view.Menu; @@ -116,6 +118,7 @@ public class QtNative public static QtThread m_qtThread = new QtThread(); private static HashMap m_cachedUris = new HashMap(); private static ArrayList m_knownDirs = new ArrayList(); + private static final int KEYBOARD_HEIGHT_THRESHOLD = 100; private static final Runnable runPendingCppRunnablesRunnable = new Runnable() { @Override @@ -949,6 +952,17 @@ public class QtNative }); } + public static boolean isSoftwareKeyboardVisible() + { + Activity activity = QtNative.activity(); + Rect r = new Rect(); + activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r); + DisplayMetrics metrics = new DisplayMetrics(); + activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); + final int kbHeight = metrics.heightPixels - r.bottom; + return (kbHeight >= KEYBOARD_HEIGHT_THRESHOLD); + } + private static void notifyAccessibilityLocationChange() { runAction(new Runnable() { diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp index d720f1a317..5f803badf9 100644 --- a/src/plugins/platforms/android/androidjniinput.cpp +++ b/src/plugins/platforms/android/androidjniinput.cpp @@ -58,7 +58,6 @@ using namespace QtAndroid; namespace QtAndroidInput { static bool m_ignoreMouseEvents = false; - static bool m_softwareKeyboardVisible = false; static QRect m_softwareKeyboardRect; static QList m_touchPoints; @@ -114,7 +113,7 @@ namespace QtAndroidInput bool isSoftwareKeyboardVisible() { - return m_softwareKeyboardVisible; + return QJniObject::callStaticMethod(applicationClass(), "isSoftwareKeyboardVisible"); } QRect softwareKeyboardRect() @@ -807,7 +806,6 @@ namespace QtAndroidInput static void keyboardVisibilityChanged(JNIEnv */*env*/, jobject /*thiz*/, jboolean visibility) { - m_softwareKeyboardVisible = visibility; if (!visibility) m_softwareKeyboardRect = QRect(); diff --git a/src/plugins/platforms/android/qandroidinputcontext.cpp b/src/plugins/platforms/android/qandroidinputcontext.cpp index 378dfa03c8..9ed6dd396d 100644 --- a/src/plugins/platforms/android/qandroidinputcontext.cpp +++ b/src/plugins/platforms/android/qandroidinputcontext.cpp @@ -890,10 +890,11 @@ void QAndroidInputContext::showInputPanel() m_updateCursorPosConnection = connect(qGuiApp->focusObject(), SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition())); QRect rect = cursorRect(); - QtAndroidInput::showSoftwareKeyboard(rect.left(), rect.top(), rect.width(), rect.height(), - screenInputItemRectangle().height(), - query->value(Qt::ImHints).toUInt(), - query->value(Qt::ImEnterKeyType).toUInt()); + if (!isInputPanelVisible()) + QtAndroidInput::showSoftwareKeyboard(rect.left(), rect.top(), rect.width(), rect.height(), + screenInputItemRectangle().height(), + query->value(Qt::ImHints).toUInt(), + query->value(Qt::ImEnterKeyType).toUInt()); } QRect QAndroidInputContext::cursorRect()