Add callback before hiding the soft keyboard

This commit is contained in:
Benau 2019-05-25 13:34:36 +08:00
parent e6d5346e5e
commit e1a7901c4c
3 changed files with 29 additions and 11 deletions

View File

@ -6,6 +6,7 @@ import android.content.Context;
import android.text.InputType;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.View;
import android.widget.EditText;
// We need to extend EditText instead of view to allow copying to our STK
@ -75,4 +76,10 @@ public class STKEditText extends EditText
editText2STKEditbox(getText().toString(), getSelectionStart(),
getSelectionEnd(), m_composing_start, m_composing_end);
}
// ------------------------------------------------------------------------
public void beforeHideKeyboard()
{
clearFocus();
setVisibility(View.GONE);
}
}

View File

@ -9,7 +9,7 @@ public class STKInputConnection extends InputConnectionWrapper
{
/* The global edittext which will be "copied" to the current focused STK
* box. */
private STKEditText m_stk_edittext;
final private STKEditText m_stk_edittext;
// ------------------------------------------------------------------------
public STKInputConnection(InputConnection target, STKEditText stk_edittext)

View File

@ -22,6 +22,18 @@ public class SuperTuxKartActivity extends NativeActivity
// ------------------------------------------------------------------------
private native void saveKeyboardHeight(int height);
// ------------------------------------------------------------------------
private void hideKeyboardNative()
{
if (m_stk_edittext == null)
return;
m_stk_edittext.beforeHideKeyboard();
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(m_stk_edittext.getWindowToken(), 0);
}
// ------------------------------------------------------------------------
private void hideNavBar(View decor_view)
{
if (Build.VERSION.SDK_INT < 19)
@ -72,6 +84,13 @@ public class SuperTuxKartActivity extends NativeActivity
}
// ------------------------------------------------------------------------
@Override
public void onPause()
{
super.onPause();
hideKeyboardNative();
}
// ------------------------------------------------------------------------
@Override
public void onWindowFocusChanged(boolean has_focus)
{
super.onWindowFocusChanged(has_focus);
@ -142,6 +161,7 @@ public class SuperTuxKartActivity extends NativeActivity
});
}
// ------------------------------------------------------------------------
/* Called by STK in JNI. */
public void hideKeyboard()
{
runOnUiThread(new Runnable()
@ -149,16 +169,7 @@ public class SuperTuxKartActivity extends NativeActivity
@Override
public void run()
{
if (m_stk_edittext == null)
return;
m_stk_edittext.clearFocus();
m_stk_edittext.setVisibility(View.GONE);
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(m_stk_edittext.getWindowToken(),
0);
hideKeyboardNative();
}
});
}