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>
bb10
BogDan Vatra 2013-10-28 17:09:59 +02:00 committed by The Qt Project
parent d536713e96
commit 472e448d6a
2 changed files with 45 additions and 15 deletions

View File

@ -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;
}

View File

@ -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;