Clear text when closing keyboard if onEnterPressed returns true

This commit is contained in:
Benau 2019-05-28 15:21:06 +08:00
parent 391b61be95
commit d487a2e72e
4 changed files with 32 additions and 13 deletions

View File

@ -26,7 +26,7 @@ public class STKEditText extends EditText
private STKInputConnection m_stk_input_connection;
/* Used to avoid infinite calling updateSTKEditBox if setText currently
* by jni. */
* by jni or clearing text when out focus. */
private boolean m_from_stk_editbox;
// ------------------------------------------------------------------------
private native static void editText2STKEditbox(int widget_id,
@ -89,7 +89,7 @@ public class STKEditText extends EditText
// Always remove the focus on STKEdit when pressing back button in
// phone, which hideSoftInputFromWindow is called by java itself
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK)
beforeHideKeyboard();
beforeHideKeyboard(false/*clear_text*/);
return false;
}
// ------------------------------------------------------------------------
@ -118,10 +118,27 @@ public class STKEditText extends EditText
m_composing_end);
}
// ------------------------------------------------------------------------
public void beforeHideKeyboard()
public void beforeHideKeyboard(final boolean clear_text)
{
clearFocus();
setVisibility(View.GONE);
try
{
if (clear_text)
{
// No need updating stk editbox on clearing text when out focus
m_from_stk_editbox = true;
{
super.clearComposingText();
super.getText().clear();
}
m_from_stk_editbox = false;
}
clearFocus();
setVisibility(View.GONE);
}
catch (Exception e)
{
m_from_stk_editbox = false;
}
}
// ------------------------------------------------------------------------
/* Called by STK with JNI to set this view with new text (like user focus

View File

@ -22,12 +22,12 @@ public class SuperTuxKartActivity extends NativeActivity
// ------------------------------------------------------------------------
private native void saveKeyboardHeight(int height);
// ------------------------------------------------------------------------
private void hideKeyboardNative()
private void hideKeyboardNative(final boolean clear_text)
{
if (m_stk_edittext == null)
return;
m_stk_edittext.beforeHideKeyboard();
m_stk_edittext.beforeHideKeyboard(clear_text);
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
@ -118,7 +118,7 @@ public class SuperTuxKartActivity extends NativeActivity
public void onPause()
{
super.onPause();
hideKeyboardNative();
hideKeyboardNative(false/*clear_text*/);
}
// ------------------------------------------------------------------------
@Override
@ -168,14 +168,14 @@ public class SuperTuxKartActivity extends NativeActivity
}
// ------------------------------------------------------------------------
/* Called by STK in JNI. */
public void hideKeyboard()
public void hideKeyboard(final boolean clear_text)
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
hideKeyboardNative();
hideKeyboardNative(clear_text);
}
});
}

View File

@ -1229,7 +1229,7 @@ void CIrrDeviceAndroid::toggleOnScreenKeyboard(bool show, s32 type)
if (show)
method_id = env->GetMethodID(class_native_activity, "showKeyboard", "(I)V");
else
method_id = env->GetMethodID(class_native_activity, "hideKeyboard", "()V");
method_id = env->GetMethodID(class_native_activity, "hideKeyboard", "(Z)V");
if (method_id == NULL)
{
@ -1244,7 +1244,7 @@ void CIrrDeviceAndroid::toggleOnScreenKeyboard(bool show, s32 type)
if (show)
env->CallVoidMethod(native_activity, method_id, (jint)type);
else
env->CallVoidMethod(native_activity, method_id);
env->CallVoidMethod(native_activity, method_id, (jboolean)(type != 0));
if (was_detached)
{
Android->activity->vm->DetachCurrentThread();

View File

@ -318,7 +318,9 @@ ANDROID_HANDLE_ACTION_NEXT_CALLBACK(ANDROID_PACKAGE_CALLBACK_NAME)
// First test for onEnterPressed, if true then close keyboard
if (eb->handleEnterPressed())
{
GUIEngine::getDevice()->toggleOnScreenKeyboard(false);
// Clear text like onEnterPressed callback
GUIEngine::getDevice()->toggleOnScreenKeyboard(false,
1/*clear_text*/);
return;
}