Android: move implementation for checking if keyboard is displayed
Move implementation for checking if keyboard is displayed on the screen from QtInputConnection to QtInputDelegate. The QtInputDelegate class is responsible for showing/hiding the keyboard and handling its visibility. Moving mentioned implementation there seems reasonable. Also, this implementation will be used internally by QtInputDelegate in the future. Task-number: QTBUG-130000 Change-Id: I47cf8e8fb2ee9bea535b9e009dd4b43b28f19b80 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit 229cff37c0b6f822e9c22734e66d8ce117723d22) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
e27e9d4a20
commit
0a32e20b11
@ -16,8 +16,6 @@ import android.view.inputmethod.ExtractedText;
|
|||||||
import android.view.inputmethod.ExtractedTextRequest;
|
import android.view.inputmethod.ExtractedTextRequest;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.WindowInsets;
|
|
||||||
import android.view.WindowInsets.Type;
|
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
@ -68,9 +66,6 @@ class QtInputConnection extends BaseInputConnection
|
|||||||
private static final int ID_COPY_URL = android.R.id.copyUrl;
|
private static final int ID_COPY_URL = android.R.id.copyUrl;
|
||||||
private static final int ID_SWITCH_INPUT_METHOD = android.R.id.switchInputMethod;
|
private static final int ID_SWITCH_INPUT_METHOD = android.R.id.switchInputMethod;
|
||||||
private static final int ID_ADD_TO_DICTIONARY = android.R.id.addToDictionary;
|
private static final int ID_ADD_TO_DICTIONARY = android.R.id.addToDictionary;
|
||||||
// We can't rely on a hardcoded value, because screens have different resolutions.
|
|
||||||
// That is why we assume that the keyboard should be higher than 0.15 of the screen.
|
|
||||||
private static final float KEYBOARD_TO_SCREEN_RATIO = 0.15f;
|
|
||||||
|
|
||||||
private static final String QtTAG = "QtInputConnection";
|
private static final String QtTAG = "QtInputConnection";
|
||||||
|
|
||||||
@ -80,31 +75,11 @@ class QtInputConnection extends BaseInputConnection
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// Check that the keyboard is really no longer there.
|
// Check that the keyboard is really no longer there.
|
||||||
Activity activity = QtNative.activity();
|
|
||||||
if (activity == null) {
|
|
||||||
Log.w(QtTAG, "HideKeyboardRunnable: The activity reference is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (m_qtInputConnectionListener == null) {
|
if (m_qtInputConnectionListener == null) {
|
||||||
Log.w(QtTAG, "HideKeyboardRunnable: QtInputConnectionListener is null");
|
Log.w(QtTAG, "HideKeyboardRunnable: QtInputConnectionListener is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (m_qtInputConnectionListener.isKeyboardHidden())
|
||||||
boolean isKeyboardHidden = true;
|
|
||||||
|
|
||||||
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);
|
|
||||||
int screenHeight = metrics.heightPixels;
|
|
||||||
final int kbHeight = screenHeight - r.bottom;
|
|
||||||
isKeyboardHidden = kbHeight < screenHeight * KEYBOARD_TO_SCREEN_RATIO;
|
|
||||||
} else {
|
|
||||||
WindowInsets w = activity.getWindow().getDecorView().getRootWindowInsets();
|
|
||||||
isKeyboardHidden = !w.isVisible(Type.ime());
|
|
||||||
}
|
|
||||||
if (isKeyboardHidden)
|
|
||||||
m_qtInputConnectionListener.onHideKeyboardRunnableDone(false, System.nanoTime());
|
m_qtInputConnectionListener.onHideKeyboardRunnableDone(false, System.nanoTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,6 +89,7 @@ class QtInputConnection extends BaseInputConnection
|
|||||||
void onHideKeyboardRunnableDone(boolean visibility, long hideTimeStamp);
|
void onHideKeyboardRunnableDone(boolean visibility, long hideTimeStamp);
|
||||||
void onSendKeyEventDefaultCase();
|
void onSendKeyEventDefaultCase();
|
||||||
void onEditTextChanged(QtEditText editText);
|
void onEditTextChanged(QtEditText editText);
|
||||||
|
boolean isKeyboardHidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final QtEditText m_view;
|
private final QtEditText m_view;
|
||||||
|
@ -6,6 +6,7 @@ package org.qtproject.qt.android;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.ResultReceiver;
|
import android.os.ResultReceiver;
|
||||||
@ -16,6 +17,8 @@ import android.view.InputDevice;
|
|||||||
import android.view.KeyCharacterMap;
|
import android.view.KeyCharacterMap;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
import android.view.WindowInsets;
|
||||||
|
import android.view.WindowInsets.Type;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
@ -45,6 +48,10 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
|
|||||||
private QtEditText m_currentEditText = null;
|
private QtEditText m_currentEditText = null;
|
||||||
private InputMethodManager m_imm;
|
private InputMethodManager m_imm;
|
||||||
|
|
||||||
|
// We can't rely on a hardcoded value, because screens have different resolutions.
|
||||||
|
// That is why we assume that the keyboard should be higher than 0.15 of the screen.
|
||||||
|
private static final float KEYBOARD_TO_SCREEN_RATIO = 0.15f;
|
||||||
|
|
||||||
private boolean m_keyboardIsVisible = false;
|
private boolean m_keyboardIsVisible = false;
|
||||||
private boolean m_isKeyboardHidingAnimationOngoing = false;
|
private boolean m_isKeyboardHidingAnimationOngoing = false;
|
||||||
private long m_showHideTimeStamp = System.nanoTime();
|
private long m_showHideTimeStamp = System.nanoTime();
|
||||||
@ -227,6 +234,32 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
|
|||||||
// QtInputInterface implementation end
|
// QtInputInterface implementation end
|
||||||
|
|
||||||
// QtInputConnectionListener methods
|
// QtInputConnectionListener methods
|
||||||
|
@Override
|
||||||
|
public boolean isKeyboardHidden() {
|
||||||
|
Activity activity = QtNative.activity();
|
||||||
|
if (activity == null) {
|
||||||
|
Log.w(TAG, "isKeyboardHidden: The activity reference is null");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isKeyboardHidden = true;
|
||||||
|
|
||||||
|
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);
|
||||||
|
int screenHeight = metrics.heightPixels;
|
||||||
|
final int kbHeight = screenHeight - r.bottom;
|
||||||
|
isKeyboardHidden = kbHeight < screenHeight * KEYBOARD_TO_SCREEN_RATIO;
|
||||||
|
} else {
|
||||||
|
WindowInsets w = activity.getWindow().getDecorView().getRootWindowInsets();
|
||||||
|
isKeyboardHidden = !w.isVisible(Type.ime());
|
||||||
|
}
|
||||||
|
|
||||||
|
return isKeyboardHidden;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSetClosing(boolean closing) {
|
public void onSetClosing(boolean closing) {
|
||||||
if (!closing)
|
if (!closing)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user