feat: support localehints hints when provided for textviews#1892
Open
kikkia wants to merge 1 commit intofuto-org:masterfrom
Open
feat: support localehints hints when provided for textviews#1892kikkia wants to merge 1 commit intofuto-org:masterfrom
kikkia wants to merge 1 commit intofuto-org:masterfrom
Conversation
…e languages the input box provides as expected and if it finds one, swaps to that input language. Ideally helpful for apps like google translate or similar.
|
Please sign our contributor license agreement at https://cla.futo.org |
|
Please sign our contributor license agreement at https://cla.futo.org |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intention
Moving to FUTO from gboard one of the features I miss the most is auto keyboard language switching. For example if I am in google translate and I am translating japanese -> english, when I click on the japanese input box the keyboard automatically pulls up my last used JP keyboard format. If I click the "swap language" button that flips it to english -> japanese, the keyboard layout swaps to english from japanese automatically.
Android allows preferred locales to be hinted at within textViews https://developer.android.com/reference/android/widget/TextView#setImeHintLocales(android.os.LocaleList) . This is up to the app to implement, so it is not guaranteed the app sets them. However when they are set, we may as well support them.
Implementation
I added a setting under a new Advanced Settings category in the language settings. If enabled this will allow the keyboard to swap to a preferred language locale IF one is supplied, AND the user has that locale enabled.
Default: false
When we start the keyboard we run a check on the inputAttribute hints, our current selected locale and all available. If our current locale is not in the provided hints AND we find a suitable on in our enabled locales we swap to that keyboard layout.
There were a few workarounds I had to do, each is explained with a comment in the code. I am not a regular android dev (only did a little back in the android 4.4/5 days) so if I am doing anything not in best practices please let me know and I will be happy to refactor.
Tests
The instrumentation tests seem to be broken. When I try to run them locally I was getting some errors around main thread execution of getService.onCreate(), and more around some XML when I updated to run onCreate() on the main thread. This may just be something I have setup incorrectly. If that is fixable please LMK.
Because of this, for now I added a unit test for parsing the hints into our inputAttributes.
Device testing
I built these changes in a debug APK and loaded it onto my personal phone. I verified that the intended automatic language switching in Translate did work as intended. I tried with several languages and language pairs.
AI Disclaimer
It is a hot topic right now in OSS about AI slop PRs. I feel like one good thing we can all do to respect maintainers time is give a disclaimer at the minimum. Since I am new to the codebase I used some locally running AI models to help me trace and search through the code and learn the relevant things I was touching. AI generated ~30% of the code in this PR, 100% of that was reviewed by me and understood before accepting.
Thanks for your time.