Merge "Android: Fix constant resize of a large TextEdit on click"

This commit is contained in:
Piotr Mikolajczyk 2021-02-09 08:50:11 +01:00 committed by Qt CI Bot
commit 153716a914
3 changed files with 20 additions and 7 deletions

View File

@ -57,6 +57,7 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.UriPermission; import android.content.UriPermission;
import android.graphics.Rect;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
@ -67,6 +68,7 @@ import android.content.ClipboardManager.OnPrimaryClipChangedListener;
import android.content.ClipData; import android.content.ClipData;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.util.Log; import android.util.Log;
import android.util.DisplayMetrics;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
@ -116,6 +118,7 @@ public class QtNative
public static QtThread m_qtThread = new QtThread(); public static QtThread m_qtThread = new QtThread();
private static HashMap<String, Uri> m_cachedUris = new HashMap<String, Uri>(); private static HashMap<String, Uri> m_cachedUris = new HashMap<String, Uri>();
private static ArrayList<String> m_knownDirs = new ArrayList<String>(); private static ArrayList<String> m_knownDirs = new ArrayList<String>();
private static final int KEYBOARD_HEIGHT_THRESHOLD = 100;
private static final Runnable runPendingCppRunnablesRunnable = new Runnable() { private static final Runnable runPendingCppRunnablesRunnable = new Runnable() {
@Override @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() private static void notifyAccessibilityLocationChange()
{ {
runAction(new Runnable() { runAction(new Runnable() {

View File

@ -58,7 +58,6 @@ using namespace QtAndroid;
namespace QtAndroidInput namespace QtAndroidInput
{ {
static bool m_ignoreMouseEvents = false; static bool m_ignoreMouseEvents = false;
static bool m_softwareKeyboardVisible = false;
static QRect m_softwareKeyboardRect; static QRect m_softwareKeyboardRect;
static QList<QWindowSystemInterface::TouchPoint> m_touchPoints; static QList<QWindowSystemInterface::TouchPoint> m_touchPoints;
@ -114,7 +113,7 @@ namespace QtAndroidInput
bool isSoftwareKeyboardVisible() bool isSoftwareKeyboardVisible()
{ {
return m_softwareKeyboardVisible; return QJniObject::callStaticMethod<jboolean>(applicationClass(), "isSoftwareKeyboardVisible");
} }
QRect softwareKeyboardRect() QRect softwareKeyboardRect()
@ -807,7 +806,6 @@ namespace QtAndroidInput
static void keyboardVisibilityChanged(JNIEnv */*env*/, jobject /*thiz*/, jboolean visibility) static void keyboardVisibilityChanged(JNIEnv */*env*/, jobject /*thiz*/, jboolean visibility)
{ {
m_softwareKeyboardVisible = visibility;
if (!visibility) if (!visibility)
m_softwareKeyboardRect = QRect(); m_softwareKeyboardRect = QRect();

View File

@ -890,10 +890,11 @@ void QAndroidInputContext::showInputPanel()
m_updateCursorPosConnection = connect(qGuiApp->focusObject(), SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition())); m_updateCursorPosConnection = connect(qGuiApp->focusObject(), SIGNAL(cursorPositionChanged()), this, SLOT(updateCursorPosition()));
QRect rect = cursorRect(); QRect rect = cursorRect();
QtAndroidInput::showSoftwareKeyboard(rect.left(), rect.top(), rect.width(), rect.height(), if (!isInputPanelVisible())
screenInputItemRectangle().height(), QtAndroidInput::showSoftwareKeyboard(rect.left(), rect.top(), rect.width(), rect.height(),
query->value(Qt::ImHints).toUInt(), screenInputItemRectangle().height(),
query->value(Qt::ImEnterKeyType).toUInt()); query->value(Qt::ImHints).toUInt(),
query->value(Qt::ImEnterKeyType).toUInt());
} }
QRect QAndroidInputContext::cursorRect() QRect QAndroidInputContext::cursorRect()