Open WillJonesMagic opened 5 years ago
This does not work as expected on Samsung Galaxy devices. Calling setText() calls onKeyDown which eventually calls setText(), ad infinitum/until crash.
setText()
onKeyDown
A simple fix for this is as follows (all in TimeEditText.java):
Top of file: boolean ignoreKeyPress = false;
boolean ignoreKeyPress = false;
Replace updateText() with the following:
updateText()
private void updateText() { int bold = currentPosition > 1 ? currentPosition+1 : currentPosition; int color = getTextColors().getDefaultColor(); Spannable text = new SpannableString(String.format("%02d:%02d", getHour(), getMinutes())); if (bold >= 0) { text.setSpan(new ForegroundColorSpan(color & 0xFFFFFF | 0xA0000000), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); text.setSpan(new StyleSpan(Typeface.BOLD), bold, bold+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); text.setSpan(new ForegroundColorSpan(Color.BLACK), bold, bold+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); text.setSpan(new BackgroundColorSpan(0x40808080), bold, bold+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } ignoreKeyPress = true; setText(text); ignoreKeyPress = false; }
Replace sendKeyEvent inside return new BaseInputConnection at the bottom of the file with the following
sendKeyEvent
return new BaseInputConnection
@Override public boolean sendKeyEvent(KeyEvent event) { if(!ignoreKeyPress) onKeyEvent(event.getKeyCode(), event); return true; }
Tested on a Galaxy S9, Android 9.
Hi, feel free to send a pull request to include the fix in the repo. Thanks
This does not work as expected on Samsung Galaxy devices. Calling
setText()
callsonKeyDown
which eventually callssetText()
, ad infinitum/until crash.A simple fix for this is as follows (all in TimeEditText.java):
Top of file:
boolean ignoreKeyPress = false;
Replace
updateText()
with the following:Replace
sendKeyEvent
insidereturn new BaseInputConnection
at the bottom of the file with the followingTested on a Galaxy S9, Android 9.