mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-06-24 11:41:32 +02:00
Fix crash due to auto capitalisation
It is unclear how _autocap.started is not called first but nothing is preventing to initialize things earlier.
This commit is contained in:
parent
7f51cf001a
commit
d9a8688237
@ -27,25 +27,10 @@ final class Autocapitalisation
|
|||||||
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES |
|
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES |
|
||||||
InputType.TYPE_TEXT_FLAG_CAP_WORDS;
|
InputType.TYPE_TEXT_FLAG_CAP_WORDS;
|
||||||
|
|
||||||
Runnable delayed_callback = new Runnable()
|
public Autocapitalisation(Looper looper, Callback cb)
|
||||||
{
|
{
|
||||||
public void run()
|
_handler = new Handler(looper);
|
||||||
{
|
_callback = cb;
|
||||||
if (_should_update_caps_mode)
|
|
||||||
{
|
|
||||||
_should_enable_shift = _enabled && (_ic.getCursorCapsMode(_caps_mode) != 0);
|
|
||||||
_should_update_caps_mode = false;
|
|
||||||
}
|
|
||||||
_callback.update_shift_state(_should_enable_shift, _should_disable_shift);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void callback(final boolean might_disable)
|
|
||||||
{
|
|
||||||
_should_disable_shift = might_disable;
|
|
||||||
// The callback must be delayed because [getCursorCapsMode] would sometimes
|
|
||||||
// be called before the editor finished handling the previous event.
|
|
||||||
_handler.postDelayed(delayed_callback, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,11 +38,9 @@ final class Autocapitalisation
|
|||||||
* [started] does initialisation work and must be called before any other
|
* [started] does initialisation work and must be called before any other
|
||||||
* event.
|
* event.
|
||||||
*/
|
*/
|
||||||
public void started(Looper looper, Callback cb, EditorInfo info, InputConnection ic)
|
public void started(EditorInfo info, InputConnection ic)
|
||||||
{
|
{
|
||||||
_handler = new Handler(looper);
|
|
||||||
_ic = ic;
|
_ic = ic;
|
||||||
_callback = cb;
|
|
||||||
_caps_mode = info.inputType & TextUtils.CAP_MODE_SENTENCES;
|
_caps_mode = info.inputType & TextUtils.CAP_MODE_SENTENCES;
|
||||||
if (!Config.globalConfig().autocapitalisation || _caps_mode == 0)
|
if (!Config.globalConfig().autocapitalisation || _caps_mode == 0)
|
||||||
{
|
{
|
||||||
@ -82,15 +65,6 @@ final class Autocapitalisation
|
|||||||
callback(false);
|
callback(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void type_one_char(char c)
|
|
||||||
{
|
|
||||||
_cursor++;
|
|
||||||
if (is_trigger_character(c))
|
|
||||||
_should_update_caps_mode = true;
|
|
||||||
else
|
|
||||||
_should_enable_shift = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void event_sent(int code)
|
public void event_sent(int code)
|
||||||
{
|
{
|
||||||
switch (code)
|
switch (code)
|
||||||
@ -103,12 +77,17 @@ final class Autocapitalisation
|
|||||||
callback(true);
|
callback(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static interface Callback
|
||||||
|
{
|
||||||
|
public void update_shift_state(boolean should_enable, boolean should_disable);
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns [true] if shift might be disabled. */
|
/** Returns [true] if shift might be disabled. */
|
||||||
public void selection_updated(int old_cursor, int new_cursor)
|
public void selection_updated(int old_cursor, int new_cursor)
|
||||||
{
|
{
|
||||||
if (new_cursor == _cursor) // Just typing
|
if (new_cursor == _cursor) // Just typing
|
||||||
return;
|
return;
|
||||||
if (new_cursor == 0)
|
if (new_cursor == 0 && _ic != null)
|
||||||
{
|
{
|
||||||
// Detect whether the input box has been cleared
|
// Detect whether the input box has been cleared
|
||||||
CharSequence t = _ic.getTextAfterCursor(1, 0);
|
CharSequence t = _ic.getTextAfterCursor(1, 0);
|
||||||
@ -120,6 +99,36 @@ final class Autocapitalisation
|
|||||||
callback(true);
|
callback(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Runnable delayed_callback = new Runnable()
|
||||||
|
{
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (_should_update_caps_mode && _ic != null)
|
||||||
|
{
|
||||||
|
_should_enable_shift = _enabled && (_ic.getCursorCapsMode(_caps_mode) != 0);
|
||||||
|
_should_update_caps_mode = false;
|
||||||
|
}
|
||||||
|
_callback.update_shift_state(_should_enable_shift, _should_disable_shift);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void callback(final boolean might_disable)
|
||||||
|
{
|
||||||
|
_should_disable_shift = might_disable;
|
||||||
|
// The callback must be delayed because [getCursorCapsMode] would sometimes
|
||||||
|
// be called before the editor finished handling the previous event.
|
||||||
|
_handler.postDelayed(delayed_callback, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void type_one_char(char c)
|
||||||
|
{
|
||||||
|
_cursor++;
|
||||||
|
if (is_trigger_character(c))
|
||||||
|
_should_update_caps_mode = true;
|
||||||
|
else
|
||||||
|
_should_enable_shift = false;
|
||||||
|
}
|
||||||
|
|
||||||
boolean is_trigger_character(char c)
|
boolean is_trigger_character(char c)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
@ -130,9 +139,4 @@ final class Autocapitalisation
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface Callback
|
|
||||||
{
|
|
||||||
public void update_shift_state(boolean should_enable, boolean should_disable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class Keyboard2 extends InputMethodService
|
|||||||
private ViewGroup _emojiPane = null;
|
private ViewGroup _emojiPane = null;
|
||||||
|
|
||||||
private Config _config;
|
private Config _config;
|
||||||
private Autocapitalisation _autocap = new Autocapitalisation();
|
private Autocapitalisation _autocap;
|
||||||
|
|
||||||
private boolean _debug_logs = false;
|
private boolean _debug_logs = false;
|
||||||
|
|
||||||
@ -57,6 +57,7 @@ public class Keyboard2 extends InputMethodService
|
|||||||
_keyboardView = (Keyboard2View)inflate_view(R.layout.keyboard);
|
_keyboardView = (Keyboard2View)inflate_view(R.layout.keyboard);
|
||||||
_keyboardView.reset();
|
_keyboardView.reset();
|
||||||
_debug_logs = getResources().getBoolean(R.bool.debug_logs);
|
_debug_logs = getResources().getBoolean(R.bool.debug_logs);
|
||||||
|
_autocap = new Autocapitalisation(getMainLooper(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update_shift_state(boolean should_enable, boolean should_disable)
|
public void update_shift_state(boolean should_enable, boolean should_disable)
|
||||||
@ -233,7 +234,7 @@ public class Keyboard2 extends InputMethodService
|
|||||||
_keyboardView.setKeyboard(getLayout(R.xml.numeric));
|
_keyboardView.setKeyboard(getLayout(R.xml.numeric));
|
||||||
else
|
else
|
||||||
_keyboardView.setKeyboard(getLayout(_currentTextLayout));
|
_keyboardView.setKeyboard(getLayout(_currentTextLayout));
|
||||||
_autocap.started(getMainLooper(), this, info, getCurrentInputConnection());
|
_autocap.started(info, getCurrentInputConnection());
|
||||||
setInputView(_keyboardView);
|
setInputView(_keyboardView);
|
||||||
if (_debug_logs)
|
if (_debug_logs)
|
||||||
log_editor_info(info);
|
log_editor_info(info);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user