summaryrefslogtreecommitdiffstats
path: root/src/android/jar
diff options
context:
space:
mode:
authorBogDan Vatra <bogdan@kde.org>2013-10-28 17:09:59 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-29 15:30:39 +0100
commit472e448d6a71f679dd022f7405564c42d8f47916 (patch)
treec5e9576cb1107d49df7630c244c31041045f3bf9 /src/android/jar
parentd536713e96725a7767787b011b7454079f641f72 (diff)
Fix the show/hide logic.
Make sure the back key event is not sent to applicaton as long as the keyboard is still visible. Task-number: QTBUG-30803 Change-Id: I8063981a96ddb8e065c1281b1bdc0fb4a2895bc2 Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Diffstat (limited to 'src/android/jar')
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java52
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtInputConnection.java8
2 files changed, 45 insertions, 15 deletions
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
index 503b38ae79..1f99440428 100644
--- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
@@ -57,6 +57,8 @@ import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.ResultReceiver;
import android.text.method.MetaKeyKeyListener;
import android.util.DisplayMetrics;
import android.util.Log;
@@ -110,7 +112,8 @@ public class QtActivityDelegate
private Process m_debuggerProcess = null; // debugger process
public boolean m_keyboardIsVisible = false;
- public boolean m_keyboardIsHiding = false;
+ public boolean m_backKeyPressedSent = false;
+
public QtLayout getQtLayout()
{
@@ -253,9 +256,21 @@ public class QtActivityDelegate
m_editText.postDelayed(new Runnable() {
@Override
public void run() {
- m_imm.showSoftInput(m_editText, 0);
- m_keyboardIsVisible = true;
- m_keyboardIsHiding = false;
+ m_imm.showSoftInput(m_editText, 0, new ResultReceiver( new Handler()){
+ @Override
+ protected void onReceiveResult(int resultCode, Bundle resultData) {
+ switch (resultCode) {
+ case InputMethodManager.RESULT_SHOWN:
+ case InputMethodManager.RESULT_UNCHANGED_SHOWN:
+ m_keyboardIsVisible = true;
+ break;
+ case InputMethodManager.RESULT_HIDDEN:
+ case InputMethodManager.RESULT_UNCHANGED_HIDDEN:
+ m_keyboardIsVisible = false;
+ break;
+ }
+ }
+ }) ;
m_editText.postDelayed(new Runnable() {
@Override
public void run() {
@@ -270,9 +285,21 @@ public class QtActivityDelegate
{
if (m_imm == null)
return;
- m_imm.hideSoftInputFromWindow(m_editText.getWindowToken(), 0);
- m_keyboardIsVisible = false;
- m_keyboardIsHiding = false;
+ m_imm.hideSoftInputFromWindow(m_editText.getWindowToken(), 0, new ResultReceiver( new Handler()){
+ @Override
+ protected void onReceiveResult(int resultCode, Bundle resultData) {
+ switch (resultCode) {
+ case InputMethodManager.RESULT_SHOWN:
+ case InputMethodManager.RESULT_UNCHANGED_SHOWN:
+ m_keyboardIsVisible = true;
+ break;
+ case InputMethodManager.RESULT_HIDDEN:
+ case InputMethodManager.RESULT_UNCHANGED_HIDDEN:
+ m_keyboardIsVisible = false;
+ break;
+ }
+ }
+ });
}
public boolean isSoftwareKeyboardVisible()
@@ -717,8 +744,12 @@ public class QtActivityDelegate
}
m_lastChar = lc;
- if (keyCode != KeyEvent.KEYCODE_BACK)
- QtNative.keyDown(keyCode, c, event.getMetaState());
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ m_backKeyPressedSent = !m_keyboardIsVisible;
+ if (!m_backKeyPressedSent)
+ return true;
+ }
+ QtNative.keyDown(keyCode, c, event.getMetaState());
return true;
}
@@ -737,8 +768,9 @@ public class QtActivityDelegate
}
}
- if (keyCode == KeyEvent.KEYCODE_BACK && m_keyboardIsVisible && !m_keyboardIsHiding) {
+ if (keyCode == KeyEvent.KEYCODE_BACK && !m_backKeyPressedSent) {
hideSoftwareKeyboard();
+ m_keyboardIsVisible = false;
return true;
}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtInputConnection.java b/src/android/jar/src/org/qtproject/qt5/android/QtInputConnection.java
index 3aba42642a..f28ea3be83 100644
--- a/src/android/jar/src/org/qtproject/qt5/android/QtInputConnection.java
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtInputConnection.java
@@ -139,15 +139,13 @@ public class QtInputConnection extends BaseInputConnection
public boolean finishComposingText()
{
if (m_closing) {
- QtNative.activityDelegate().m_keyboardIsHiding = true;
m_view.postDelayed(new Runnable() {
@Override
public void run() {
- if (QtNative.activityDelegate().m_keyboardIsHiding)
QtNative.activityDelegate().m_keyboardIsVisible=false;
- }
- }, 5000); // it seems finishComposingText comes musch faster than onKeyUp event,
- // so we must delay hide notification
+ }
+ }, 100); // it seems finishComposingText comes much faster than onKeyUp event,
+ // so we must delay hide notification
m_closing = false;
} else {
m_closing = true;