Android: Fix software keyboard show/hide state

Task-number: QTBUG-34831

Change-Id: Ic38334d011ceef2dc75e4fb3fcea48f62aeea757
Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
This commit is contained in:
BogDan Vatra 2014-03-22 08:08:08 +02:00 committed by The Qt Project
parent a0dc3e608f
commit f1f07eae2d
2 changed files with 20 additions and 41 deletions

View File

@ -120,7 +120,7 @@ public class QtActivityDelegate
private boolean m_keyboardIsVisible = false;
public boolean m_backKeyPressedSent = false;
private long m_showHideTimeStamp = System.nanoTime();
public void setFullScreen(boolean enterFullScreen)
{
@ -201,12 +201,18 @@ public class QtActivityDelegate
private final int ApplicationInactive = 0x2;
private final int ApplicationActive = 0x4;
public void setKeyboardVisibility(boolean visibility)
public boolean setKeyboardVisibility(boolean visibility, long timeStamp)
{
if (m_showHideTimeStamp > timeStamp)
return false;
m_showHideTimeStamp = timeStamp;
if (m_keyboardIsVisible == visibility)
return;
return false;
m_keyboardIsVisible = visibility;
QtNative.keyboardVisibilityChanged(m_keyboardIsVisible);
return true;
}
public void resetSoftwareKeyboard()
{
@ -304,11 +310,11 @@ public class QtActivityDelegate
QtNativeInputConnection.updateCursorPosition();
//FALLTHROUGH
case InputMethodManager.RESULT_UNCHANGED_SHOWN:
setKeyboardVisibility(true);
setKeyboardVisibility(true, System.nanoTime());
break;
case InputMethodManager.RESULT_HIDDEN:
case InputMethodManager.RESULT_UNCHANGED_HIDDEN:
setKeyboardVisibility(false);
setKeyboardVisibility(false, System.nanoTime());
break;
}
}
@ -331,11 +337,11 @@ public class QtActivityDelegate
switch (resultCode) {
case InputMethodManager.RESULT_SHOWN:
case InputMethodManager.RESULT_UNCHANGED_SHOWN:
setKeyboardVisibility(true);
setKeyboardVisibility(true, System.nanoTime());
break;
case InputMethodManager.RESULT_HIDDEN:
case InputMethodManager.RESULT_UNCHANGED_HIDDEN:
setKeyboardVisibility(false);
setKeyboardVisibility(false, System.nanoTime());
break;
}
}
@ -827,7 +833,7 @@ public class QtActivityDelegate
if (keyCode == KeyEvent.KEYCODE_BACK && !m_backKeyPressedSent) {
hideSoftwareKeyboard();
setKeyboardVisibility(false);
setKeyboardVisibility(false, System.nanoTime());
return true;
}

View File

@ -82,18 +82,11 @@ class QtNativeInputConnection
}
class HideKeyboardRunnable implements Runnable {
private QtInputConnection m_connection;
HideKeyboardRunnable(QtInputConnection connection)
{
m_connection = connection;
}
private long m_hideTimeStamp = System.nanoTime();
@Override
public void run() {
if (m_connection.getInputState() == QtInputConnection.InputStates.Hiding) {
QtNative.activityDelegate().setKeyboardVisibility(false);
m_connection.reset();
}
QtNative.activityDelegate().setKeyboardVisibility(false, m_hideTimeStamp);
}
}
@ -107,34 +100,14 @@ 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;
enum InputStates { Visible, FinishComposing, Hiding };
private QtEditText m_view = null;
private InputStates m_inputState = InputStates.Visible;
public void reset()
{
m_inputState = InputStates.Visible;
}
public InputStates getInputState()
{
return m_inputState;
}
private void setClosing(boolean closing)
{
if (closing && m_inputState == InputStates.Hiding)
return;
if (closing && m_view.getActivityDelegate().isSoftwareKeyboardVisible()) {
m_view.postDelayed(new HideKeyboardRunnable(this), 100);
m_inputState = InputStates.Hiding;
if (closing) {
m_view.postDelayed(new HideKeyboardRunnable(), 100);
} else {
if (m_inputState == InputStates.Hiding)
QtNative.activityDelegate().setKeyboardVisibility(true);
m_inputState = closing ? InputStates.FinishComposing : InputStates.Visible;
QtNative.activityDelegate().setKeyboardVisibility(true, System.nanoTime());
}
}
@ -154,7 +127,7 @@ public class QtInputConnection extends BaseInputConnection
@Override
public boolean endBatchEdit()
{
// setClosing(false);
setClosing(false);
return true;
}