summaryrefslogtreecommitdiffstats
path: root/src/android/jar/src/org/qtproject/qt/android/QtInputConnection.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt/android/QtInputConnection.java')
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/QtInputConnection.java164
1 files changed, 91 insertions, 73 deletions
diff --git a/src/android/jar/src/org/qtproject/qt/android/QtInputConnection.java b/src/android/jar/src/org/qtproject/qt/android/QtInputConnection.java
index 6cf1aca5bf..1bfe05e7ac 100644
--- a/src/android/jar/src/org/qtproject/qt/android/QtInputConnection.java
+++ b/src/android/jar/src/org/qtproject/qt/android/QtInputConnection.java
@@ -1,46 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Android port of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2012 BogDan Vatra <bogdan@kde.org>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
package org.qtproject.qt.android;
import android.content.Context;
+import android.os.Build;
+import android.util.Log;
+import android.view.WindowMetrics;
import android.view.inputmethod.BaseInputConnection;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.ExtractedText;
@@ -83,26 +50,11 @@ class QtNativeInputConnection
static native boolean copyURL();
static native boolean paste();
static native boolean updateCursorPosition();
+ static native void reportFullscreenMode(boolean enabled);
+ static native boolean fullscreenMode();
}
-class HideKeyboardRunnable implements Runnable {
- private long m_hideTimeStamp = System.nanoTime();
-
- @Override
- public void run() {
- // Check that the keyboard is really no longer there.
- 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;
- if (kbHeight < 100)
- QtNative.activityDelegate().setKeyboardVisibility(false, m_hideTimeStamp);
- }
-}
-
-public class QtInputConnection extends BaseInputConnection
+class QtInputConnection extends BaseInputConnection
{
private static final int ID_SELECT_ALL = android.R.id.selectAll;
private static final int ID_CUT = android.R.id.cut;
@@ -112,21 +64,71 @@ public class QtInputConnection extends BaseInputConnection
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 QtEditText m_view = null;
+ private static final String QtTAG = "QtInputConnection";
+
+ private final QtInputConnectionListener m_qtInputConnectionListener;
+
+ class HideKeyboardRunnable implements Runnable {
+ @Override
+ public void run() {
+ // 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;
+ }
+
+ Rect r = new Rect();
+ activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(r);
+
+ int screenHeight;
+ if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
+ DisplayMetrics metrics = new DisplayMetrics();
+ activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
+ screenHeight = metrics.heightPixels;
+ } else {
+ final WindowMetrics maximumWindowMetrics = activity.getWindowManager().getMaximumWindowMetrics();
+ screenHeight = maximumWindowMetrics.getBounds().height();
+ }
+ final int kbHeight = screenHeight - r.bottom;
+ if (kbHeight < 100)
+ m_qtInputConnectionListener.onHideKeyboardRunnableDone(false, System.nanoTime());
+ }
+ }
+
+ public interface QtInputConnectionListener {
+ void onSetClosing(boolean closing);
+ void onHideKeyboardRunnableDone(boolean visibility, long hideTimeStamp);
+ void onSendKeyEventDefaultCase();
+ }
+
+ private final QtEditText m_view;
+ private final InputMethodManager m_imm;
private void setClosing(boolean closing)
{
- if (closing) {
+ if (closing)
m_view.postDelayed(new HideKeyboardRunnable(), 100);
- } else {
- QtNative.activityDelegate().setKeyboardVisibility(true, System.nanoTime());
- }
+ else
+ m_qtInputConnectionListener.onSetClosing(false);
}
- public QtInputConnection(QtEditText targetView)
+ public QtInputConnection(QtEditText targetView, QtInputConnectionListener listener)
{
super(targetView, true);
m_view = targetView;
+ m_imm = (InputMethodManager)m_view.getContext().getSystemService(
+ Context.INPUT_METHOD_SERVICE);
+ m_qtInputConnectionListener = listener;
+ }
+
+ public void restartImmInput()
+ {
+ if (QtNativeInputConnection.fullscreenMode()) {
+ if (m_imm != null)
+ m_imm.restartInput(m_view);
+ }
+
}
@Override
@@ -137,6 +139,18 @@ public class QtInputConnection extends BaseInputConnection
}
@Override
+ public boolean reportFullscreenMode (boolean enabled)
+ {
+ QtNativeInputConnection.reportFullscreenMode(enabled);
+ // Always ignored on calling editor.
+ // Always false on Android 8 and later, true with earlier.
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+ return false;
+
+ return true;
+ }
+
+ @Override
public boolean endBatchEdit()
{
setClosing(false);
@@ -154,6 +168,7 @@ public class QtInputConnection extends BaseInputConnection
public boolean commitText(CharSequence text, int newCursorPosition)
{
setClosing(false);
+ restartImmInput();
return QtNativeInputConnection.commitText(text.toString(), newCursorPosition);
}
@@ -219,23 +234,25 @@ public class QtInputConnection extends BaseInputConnection
{
switch (id) {
case ID_SELECT_ALL:
+ restartImmInput();
return QtNativeInputConnection.selectAll();
case ID_COPY:
+ restartImmInput();
return QtNativeInputConnection.copy();
case ID_COPY_URL:
+ restartImmInput();
return QtNativeInputConnection.copyURL();
case ID_CUT:
+ restartImmInput();
return QtNativeInputConnection.cut();
case ID_PASTE:
+ restartImmInput();
return QtNativeInputConnection.paste();
-
case ID_SWITCH_INPUT_METHOD:
- InputMethodManager imm = (InputMethodManager)m_view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm != null)
- imm.showInputMethodPicker();
+ if (m_imm != null)
+ m_imm.showInputMethodPicker();
return true;
-
case ID_ADD_TO_DICTIONARY:
// TODO
// String word = m_editable.subSequence(0, m_editable.length()).toString();
@@ -268,8 +285,7 @@ public class QtInputConnection extends BaseInputConnection
event.getRepeatCount(),
event.getMetaState());
return super.sendKeyEvent(fakeEvent);
-
- case android.view.inputmethod.EditorInfo.IME_ACTION_PREVIOUS:
+ case android.view.inputmethod.EditorInfo.IME_ACTION_PREVIOUS:
fakeEvent = new KeyEvent(event.getDownTime(),
event.getEventTime(),
event.getAction(),
@@ -277,12 +293,14 @@ public class QtInputConnection extends BaseInputConnection
event.getRepeatCount(),
KeyEvent.META_SHIFT_ON);
return super.sendKeyEvent(fakeEvent);
-
+ case android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION:
+ restartImmInput();
+ break;
default:
- break;
+ m_qtInputConnectionListener.onSendKeyEventDefaultCase();
+ break;
}
}
-
return super.sendKeyEvent(event);
}