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 <rami.potinkara@qt.io>
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
This commit is contained in:
Piotr Mikolajczyk 2021-02-09 08:50:11 +01:00
parent 7a4dd166e0
commit e6ca200a3a
3 changed files with 20 additions and 7 deletions
src
android/jar/src/org/qtproject/qt/android
plugins/platforms/android

View File

@ -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<String, Uri> m_cachedUris = new HashMap<String, Uri>();
private static ArrayList<String> m_knownDirs = new ArrayList<String>();
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() {

View File

@ -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<QWindowSystemInterface::TouchPoint> m_touchPoints;
@ -114,7 +113,7 @@ namespace QtAndroidInput
bool isSoftwareKeyboardVisible()
{
return m_softwareKeyboardVisible;
return QJniObject::callStaticMethod<jboolean>(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();

View File

@ -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()