mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-01-06 05:19:17 +01:00
Update auto-capitalisation state when input starts
The initial capitalisation state given by the editor (`info.initialCapsMode`) is always 0 in many editors. For some text input types, update the state when typing starts, disregarding the value given by `info.initialCapsMode`.
This commit is contained in:
parent
687d88f4f7
commit
92a8db5e93
@ -49,7 +49,8 @@ final class Autocapitalisation
|
|||||||
}
|
}
|
||||||
_enabled = true;
|
_enabled = true;
|
||||||
_should_enable_shift = (info.initialCapsMode != 0);
|
_should_enable_shift = (info.initialCapsMode != 0);
|
||||||
_callback.update_shift_state(_should_enable_shift, true);
|
_should_update_caps_mode = started_should_update_state(info.inputType);
|
||||||
|
callback_now(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void typed(CharSequence c)
|
public void typed(CharSequence c)
|
||||||
@ -81,7 +82,7 @@ final class Autocapitalisation
|
|||||||
{
|
{
|
||||||
_should_enable_shift = false;
|
_should_enable_shift = false;
|
||||||
_should_update_caps_mode = false;
|
_should_update_caps_mode = false;
|
||||||
callback(true);
|
callback_now(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface Callback
|
public static interface Callback
|
||||||
@ -119,7 +120,11 @@ final class Autocapitalisation
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void callback(final boolean might_disable)
|
/** Update the shift state if [_should_update_caps_mode] is true, then call
|
||||||
|
[_callback.update_shift_state]. This is done after a short delay to wait
|
||||||
|
for the editor to handle the events, as this might be called before the
|
||||||
|
corresponding event is sent. */
|
||||||
|
void callback(boolean might_disable)
|
||||||
{
|
{
|
||||||
_should_disable_shift = might_disable;
|
_should_disable_shift = might_disable;
|
||||||
// The callback must be delayed because [getCursorCapsMode] would sometimes
|
// The callback must be delayed because [getCursorCapsMode] would sometimes
|
||||||
@ -127,6 +132,13 @@ final class Autocapitalisation
|
|||||||
_handler.postDelayed(delayed_callback, 1);
|
_handler.postDelayed(delayed_callback, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Like [callback] but runs immediately. */
|
||||||
|
void callback_now(boolean might_disable)
|
||||||
|
{
|
||||||
|
_should_disable_shift = might_disable;
|
||||||
|
delayed_callback.run();
|
||||||
|
}
|
||||||
|
|
||||||
void type_one_char(char c)
|
void type_one_char(char c)
|
||||||
{
|
{
|
||||||
_cursor++;
|
_cursor++;
|
||||||
@ -146,4 +158,26 @@ final class Autocapitalisation
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Whether the caps state should be updated when input starts. [inputType]
|
||||||
|
is the field from the editor info object. */
|
||||||
|
boolean started_should_update_state(int inputType)
|
||||||
|
{
|
||||||
|
int class_ = inputType & InputType.TYPE_MASK_CLASS;
|
||||||
|
int variation = inputType & InputType.TYPE_MASK_VARIATION;
|
||||||
|
if (class_ != InputType.TYPE_CLASS_TEXT)
|
||||||
|
return false;
|
||||||
|
switch (variation)
|
||||||
|
{
|
||||||
|
case InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE:
|
||||||
|
case InputType.TYPE_TEXT_VARIATION_NORMAL:
|
||||||
|
case InputType.TYPE_TEXT_VARIATION_PERSON_NAME:
|
||||||
|
case InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE:
|
||||||
|
case InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT:
|
||||||
|
case InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user