Clear text when closing keyboard if onEnterPressed returns true
This commit is contained in:
parent
391b61be95
commit
d487a2e72e
@ -26,7 +26,7 @@ public class STKEditText extends EditText
|
|||||||
private STKInputConnection m_stk_input_connection;
|
private STKInputConnection m_stk_input_connection;
|
||||||
|
|
||||||
/* Used to avoid infinite calling updateSTKEditBox if setText currently
|
/* 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 boolean m_from_stk_editbox;
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
private native static void editText2STKEditbox(int widget_id,
|
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
|
// Always remove the focus on STKEdit when pressing back button in
|
||||||
// phone, which hideSoftInputFromWindow is called by java itself
|
// phone, which hideSoftInputFromWindow is called by java itself
|
||||||
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK)
|
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK)
|
||||||
beforeHideKeyboard();
|
beforeHideKeyboard(false/*clear_text*/);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -118,10 +118,27 @@ public class STKEditText extends EditText
|
|||||||
m_composing_end);
|
m_composing_end);
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
public void beforeHideKeyboard()
|
public void beforeHideKeyboard(final boolean clear_text)
|
||||||
{
|
{
|
||||||
clearFocus();
|
try
|
||||||
setVisibility(View.GONE);
|
{
|
||||||
|
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
|
/* Called by STK with JNI to set this view with new text (like user focus
|
||||||
|
@ -22,12 +22,12 @@ public class SuperTuxKartActivity extends NativeActivity
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
private native void saveKeyboardHeight(int height);
|
private native void saveKeyboardHeight(int height);
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
private void hideKeyboardNative()
|
private void hideKeyboardNative(final boolean clear_text)
|
||||||
{
|
{
|
||||||
if (m_stk_edittext == null)
|
if (m_stk_edittext == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_stk_edittext.beforeHideKeyboard();
|
m_stk_edittext.beforeHideKeyboard(clear_text);
|
||||||
|
|
||||||
InputMethodManager imm = (InputMethodManager)
|
InputMethodManager imm = (InputMethodManager)
|
||||||
getSystemService(Context.INPUT_METHOD_SERVICE);
|
getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
@ -118,7 +118,7 @@ public class SuperTuxKartActivity extends NativeActivity
|
|||||||
public void onPause()
|
public void onPause()
|
||||||
{
|
{
|
||||||
super.onPause();
|
super.onPause();
|
||||||
hideKeyboardNative();
|
hideKeyboardNative(false/*clear_text*/);
|
||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@Override
|
@Override
|
||||||
@ -168,14 +168,14 @@ public class SuperTuxKartActivity extends NativeActivity
|
|||||||
}
|
}
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/* Called by STK in JNI. */
|
/* Called by STK in JNI. */
|
||||||
public void hideKeyboard()
|
public void hideKeyboard(final boolean clear_text)
|
||||||
{
|
{
|
||||||
runOnUiThread(new Runnable()
|
runOnUiThread(new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
hideKeyboardNative();
|
hideKeyboardNative(clear_text);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1229,7 +1229,7 @@ void CIrrDeviceAndroid::toggleOnScreenKeyboard(bool show, s32 type)
|
|||||||
if (show)
|
if (show)
|
||||||
method_id = env->GetMethodID(class_native_activity, "showKeyboard", "(I)V");
|
method_id = env->GetMethodID(class_native_activity, "showKeyboard", "(I)V");
|
||||||
else
|
else
|
||||||
method_id = env->GetMethodID(class_native_activity, "hideKeyboard", "()V");
|
method_id = env->GetMethodID(class_native_activity, "hideKeyboard", "(Z)V");
|
||||||
|
|
||||||
if (method_id == NULL)
|
if (method_id == NULL)
|
||||||
{
|
{
|
||||||
@ -1244,7 +1244,7 @@ void CIrrDeviceAndroid::toggleOnScreenKeyboard(bool show, s32 type)
|
|||||||
if (show)
|
if (show)
|
||||||
env->CallVoidMethod(native_activity, method_id, (jint)type);
|
env->CallVoidMethod(native_activity, method_id, (jint)type);
|
||||||
else
|
else
|
||||||
env->CallVoidMethod(native_activity, method_id);
|
env->CallVoidMethod(native_activity, method_id, (jboolean)(type != 0));
|
||||||
if (was_detached)
|
if (was_detached)
|
||||||
{
|
{
|
||||||
Android->activity->vm->DetachCurrentThread();
|
Android->activity->vm->DetachCurrentThread();
|
||||||
|
@ -318,7 +318,9 @@ ANDROID_HANDLE_ACTION_NEXT_CALLBACK(ANDROID_PACKAGE_CALLBACK_NAME)
|
|||||||
// First test for onEnterPressed, if true then close keyboard
|
// First test for onEnterPressed, if true then close keyboard
|
||||||
if (eb->handleEnterPressed())
|
if (eb->handleEnterPressed())
|
||||||
{
|
{
|
||||||
GUIEngine::getDevice()->toggleOnScreenKeyboard(false);
|
// Clear text like onEnterPressed callback
|
||||||
|
GUIEngine::getDevice()->toggleOnScreenKeyboard(false,
|
||||||
|
1/*clear_text*/);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user