Allow copying from STK edit box to android edit text
This commit is contained in:
@@ -17,6 +17,11 @@ public class STKEditText extends EditText
|
||||
|
||||
private int m_composing_end;
|
||||
|
||||
STKInputConnection m_stk_input_connection;
|
||||
|
||||
/* Used to avoid infinite calling updateSTKEditBox if setText currently
|
||||
* by jni. */
|
||||
private boolean m_from_stk_editbox;
|
||||
// ------------------------------------------------------------------------
|
||||
private native static void editText2STKEditbox(String full_text, int start,
|
||||
int end, int composing_start,
|
||||
@@ -28,31 +33,29 @@ public class STKEditText extends EditText
|
||||
setFocusableInTouchMode(true);
|
||||
m_composing_start = 0;
|
||||
m_composing_end = 0;
|
||||
m_from_stk_editbox = false;
|
||||
m_stk_input_connection = null;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
@Override
|
||||
public InputConnection onCreateInputConnection(EditorInfo out_attrs)
|
||||
{
|
||||
STKInputConnection sic =
|
||||
new STKInputConnection(super.onCreateInputConnection(out_attrs), this);
|
||||
if (m_stk_input_connection == null)
|
||||
{
|
||||
m_stk_input_connection = new STKInputConnection(
|
||||
super.onCreateInputConnection(out_attrs), this);
|
||||
}
|
||||
out_attrs.actionLabel = null;
|
||||
out_attrs.inputType = InputType.TYPE_CLASS_TEXT;
|
||||
out_attrs.imeOptions = EditorInfo.IME_ACTION_NEXT |
|
||||
EditorInfo.IME_FLAG_NO_FULLSCREEN |
|
||||
EditorInfo.IME_FLAG_NO_EXTRACT_UI;
|
||||
return sic;
|
||||
return m_stk_input_connection;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
@Override
|
||||
public boolean onCheckIsTextEditor() { return true; }
|
||||
// ------------------------------------------------------------------------
|
||||
public void resetWhenFocus()
|
||||
{
|
||||
clearComposingText();
|
||||
getText().clear();
|
||||
m_composing_start = m_composing_end = 0;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
public void setComposingRegion(int start, int end)
|
||||
{
|
||||
// From doc of InputConnectionWrapper, it says:
|
||||
@@ -71,7 +74,7 @@ public class STKEditText extends EditText
|
||||
// ------------------------------------------------------------------------
|
||||
public void updateSTKEditBox()
|
||||
{
|
||||
if (!isFocused())
|
||||
if (!isFocused() || m_from_stk_editbox)
|
||||
return;
|
||||
editText2STKEditbox(getText().toString(), getSelectionStart(),
|
||||
getSelectionEnd(), m_composing_start, m_composing_end);
|
||||
@@ -82,4 +85,14 @@ public class STKEditText extends EditText
|
||||
clearFocus();
|
||||
setVisibility(View.GONE);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
public void setTextFromSTK(final String text)
|
||||
{
|
||||
m_from_stk_editbox = true;
|
||||
super.setText(text);
|
||||
m_from_stk_editbox = false;
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
public STKInputConnection getSTKInputConnection()
|
||||
{ return m_stk_input_connection; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user