notedeck
notedeck copied to clipboard
Sidequest: add GameActivity_setImeEditorInfo support to android-activity
This is needed for setting the keyboard type from rust. It currently doesn't exist. Needed for
- damus-io/notedeck#199
For autocompletion to work, we need to be able to set various softkeyboard input options. This is done via GameActivity_setImeEditorInfo. Unfortunately this is not exposed in android-activity yet. Let's add this.
@lucasmerlin has a patch that simply sets some sane default in
- https://github.com/lucasmerlin/android-activity/commit/b34c97fdc72193d80422b51a333a6bd4b29687f7
but it would make more sense to have this as something you can call independently from showing the keyboard.
First thing we need to do is make the interface a bit more rusty by making the imeOptions and inputTypes into proper bitflag types.
Winit updates
todo: split this off into a separate issue
One thing to note is that winit abstracts the IME a bit, but it does provide an ImePurpose enum with the following variants:
- Normal
- Password
- Terminal
We can definitely update the imeOptions depending on Password for example from IME_FLAG_FORCE_ASCII:
Flag of imeOptions: used to request an IME that is capable of inputting ASCII characters. The intention of this flag is to ensure that the user can type Roman alphabet characters in a TextView. It is typically used for an account ID or password input. A lot of the time, IMEs are already able to input ASCII even without being told so (such IMEs already respect this flag in a sense), but there are cases when this is not the default. For instance, users of languages using a different script like Arabic, Greek, Hebrew or Russian typically have a keyboard that can't input ASCII characters by default. Applications need to be aware that the flag is not a guarantee, and some IMEs may not respect it. However, it is strongly recommended for IME authors to respect this flag especially when their IME could end up with a state where only languages using non-ASCII are enabled.
As for inputType, we might want to look into updating ImePurpose to include DateTime, Number, Phone so that we can show the correct input type from winit. (cc @lukaslihotzki)
The input types have many variations:
public interface InputType {
field public static final int TYPE_CLASS_DATETIME = 4; // 0x4
field public static final int TYPE_CLASS_NUMBER = 2; // 0x2
field public static final int TYPE_CLASS_PHONE = 3; // 0x3
field public static final int TYPE_CLASS_TEXT = 1; // 0x1
field public static final int TYPE_DATETIME_VARIATION_DATE = 16; // 0x10
field public static final int TYPE_DATETIME_VARIATION_NORMAL = 0; // 0x0
field public static final int TYPE_DATETIME_VARIATION_TIME = 32; // 0x20
field public static final int TYPE_MASK_CLASS = 15; // 0xf
field public static final int TYPE_MASK_FLAGS = 16773120; // 0xfff000
field public static final int TYPE_MASK_VARIATION = 4080; // 0xff0
field public static final int TYPE_NULL = 0; // 0x0
field public static final int TYPE_NUMBER_FLAG_DECIMAL = 8192; // 0x2000
field public static final int TYPE_NUMBER_FLAG_SIGNED = 4096; // 0x1000
field public static final int TYPE_NUMBER_VARIATION_NORMAL = 0; // 0x0
field public static final int TYPE_NUMBER_VARIATION_PASSWORD = 16; // 0x10
field public static final int TYPE_TEXT_FLAG_AUTO_COMPLETE = 65536; // 0x10000
field public static final int TYPE_TEXT_FLAG_AUTO_CORRECT = 32768; // 0x8000
field public static final int TYPE_TEXT_FLAG_CAP_CHARACTERS = 4096; // 0x1000
field public static final int TYPE_TEXT_FLAG_CAP_SENTENCES = 16384; // 0x4000
field public static final int TYPE_TEXT_FLAG_CAP_WORDS = 8192; // 0x2000
field public static final int TYPE_TEXT_FLAG_ENABLE_TEXT_CONVERSION_SUGGESTIONS = 1048576; // 0x100000
field public static final int TYPE_TEXT_FLAG_IME_MULTI_LINE = 262144; // 0x40000
field public static final int TYPE_TEXT_FLAG_MULTI_LINE = 131072; // 0x20000
field public static final int TYPE_TEXT_FLAG_NO_SUGGESTIONS = 524288; // 0x80000
field public static final int TYPE_TEXT_VARIATION_EMAIL_ADDRESS = 32; // 0x20
field public static final int TYPE_TEXT_VARIATION_EMAIL_SUBJECT = 48; // 0x30
field public static final int TYPE_TEXT_VARIATION_FILTER = 176; // 0xb0
field public static final int TYPE_TEXT_VARIATION_LONG_MESSAGE = 80; // 0x50
field public static final int TYPE_TEXT_VARIATION_NORMAL = 0; // 0x0
field public static final int TYPE_TEXT_VARIATION_PASSWORD = 128; // 0x80
field public static final int TYPE_TEXT_VARIATION_PERSON_NAME = 96; // 0x60
field public static final int TYPE_TEXT_VARIATION_PHONETIC = 192; // 0xc0
field public static final int TYPE_TEXT_VARIATION_POSTAL_ADDRESS = 112; // 0x70
field public static final int TYPE_TEXT_VARIATION_SHORT_MESSAGE = 64; // 0x40
field public static final int TYPE_TEXT_VARIATION_URI = 16; // 0x10
field public static final int TYPE_TEXT_VARIATION_VISIBLE_PASSWORD = 144; // 0x90
field public static final int TYPE_TEXT_VARIATION_WEB_EDIT_TEXT = 160; // 0xa0
field public static final int TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS = 208; // 0xd0
field public static final int TYPE_TEXT_VARIATION_WEB_PASSWORD = 224; // 0xe0
}