Android: Implement input connection listener in QtInputDelegate
This way we can just pass the input delegate as the listener for QtEditText when we create it, and having the listener in a separate member doesn't provide a real benefit anyway. Task-number: QTBUG-118139 Change-Id: I0125c87ecd39eed550a120ea8326d2c50a1b016e Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> (cherry picked from commit 0e95d3ab57f4f57e65f7bb6019064ce4e31135a3) Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
This commit is contained in:
parent
467749ce99
commit
76a40b2e73
@ -47,17 +47,13 @@ class QtEditText extends View
|
||||
private final int ImhUrlCharactersOnly = 0x400000;
|
||||
private final int ImhLatinOnly = 0x800000;
|
||||
|
||||
private QtInputConnectionListener m_qtInputConnectionListener;
|
||||
private final QtInputConnectionListener m_qtInputConnectionListener;
|
||||
|
||||
public QtEditText(Context context)
|
||||
public QtEditText(Context context, QtInputConnectionListener listener)
|
||||
{
|
||||
super(context);
|
||||
setFocusable(true);
|
||||
setFocusableInTouchMode(true);
|
||||
}
|
||||
|
||||
public void setQtInputConnectionListener(QtInputConnectionListener listener)
|
||||
{
|
||||
m_qtInputConnectionListener = listener;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ import android.view.inputmethod.InputMethodManager;
|
||||
import org.qtproject.qt.android.QtInputConnection.QtInputConnectionListener;
|
||||
|
||||
/** @noinspection FieldCanBeLocal*/
|
||||
class QtInputDelegate {
|
||||
class QtInputDelegate implements QtInputConnection.QtInputConnectionListener {
|
||||
|
||||
// keyboard methods
|
||||
public static native void keyDown(int key, int unicode, int modifier, boolean autoRepeat);
|
||||
@ -83,31 +83,31 @@ class QtInputDelegate {
|
||||
}
|
||||
|
||||
private final KeyboardVisibilityListener m_keyboardVisibilityListener;
|
||||
private final QtInputConnectionListener m_inputConnectionListener;
|
||||
|
||||
QtInputDelegate(Activity activity, KeyboardVisibilityListener listener)
|
||||
{
|
||||
this.m_keyboardVisibilityListener = listener;
|
||||
m_imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
m_inputConnectionListener = new QtInputConnectionListener() {
|
||||
@Override
|
||||
public void onSetClosing(boolean closing) {
|
||||
if (!closing)
|
||||
setKeyboardVisibility(true, System.nanoTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHideKeyboardRunnableDone(boolean visibility, long hideTimeStamp) {
|
||||
setKeyboardVisibility(visibility, hideTimeStamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendKeyEventDefaultCase() {
|
||||
hideSoftwareKeyboard();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// QtInputConnectionListener methods
|
||||
@Override
|
||||
public void onSetClosing(boolean closing) {
|
||||
if (!closing)
|
||||
setKeyboardVisibility(true, System.nanoTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHideKeyboardRunnableDone(boolean visibility, long hideTimeStamp) {
|
||||
setKeyboardVisibility(visibility, hideTimeStamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendKeyEventDefaultCase() {
|
||||
hideSoftwareKeyboard();
|
||||
}
|
||||
// QtInputConnectionListener methods
|
||||
|
||||
public boolean isKeyboardVisible()
|
||||
{
|
||||
return m_keyboardIsVisible;
|
||||
@ -172,9 +172,6 @@ class QtInputDelegate {
|
||||
void setFocusedView(QtEditText currentEditText)
|
||||
{
|
||||
m_currentEditText = currentEditText;
|
||||
// TODO rather set the listener when creating the edit text
|
||||
if (m_currentEditText != null)
|
||||
m_currentEditText.setQtInputConnectionListener(m_inputConnectionListener);
|
||||
}
|
||||
|
||||
public void showSoftwareKeyboard(Activity activity, QtLayout layout,
|
||||
|
@ -26,11 +26,11 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
|
||||
private static native void setSurface(int windowId, Surface surface);
|
||||
static native void windowFocusChanged(boolean hasFocus, int id);
|
||||
|
||||
public QtWindow(Context context, QtWindow parentWindow)
|
||||
public QtWindow(Context context, QtWindow parentWindow, QtInputDelegate delegate)
|
||||
{
|
||||
super(context);
|
||||
setId(View.generateViewId());
|
||||
m_editText = new QtEditText(context);
|
||||
m_editText = new QtEditText(context, delegate);
|
||||
setParent(parentWindow);
|
||||
setFocusableInTouchMode(true);
|
||||
|
||||
|
@ -57,7 +57,8 @@ QAndroidPlatformWindow::QAndroidPlatformWindow(QWindow *window)
|
||||
|
||||
m_nativeQtWindow = QJniObject::construct<QtJniTypes::QtWindow>(
|
||||
QNativeInterface::QAndroidApplication::context(),
|
||||
m_nativeParentQtWindow);
|
||||
m_nativeParentQtWindow,
|
||||
QtAndroid::qtInputDelegate());
|
||||
m_nativeViewId = m_nativeQtWindow.callMethod<jint>("getId");
|
||||
|
||||
if (window->isTopLevel())
|
||||
|
Loading…
x
Reference in New Issue
Block a user