Implement per-app language setting for Android 13 #1554
Closed
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.
Overview
This addresses #929 and #879
Android 13 introduces per-app language setting where you can now change the app language on a centralized location in the system settings without relying on the currently active system language. And also without having to create a custom language picker inside the app.
Accessible via
Settings > System > Languages & Input > App Languages
However only apps that explicitly support Per-App Language settings will appear on the menu.
This PR enables that.
There are two changes that have been done in order to do that:
Updating the compile SDK version to API level 33 (Android 13)
This will enable us to use the
android:localeConfig
attribute on the AndroidManifest. I've also took the liberty of also updating the target SDK version to match. In doing so, however, there are a breaking change with theGestureDetector.OnGestureListener
interface. In which theMotionEvent
parameters on the interface methods are now non-nullable. There are only two implementing classes namelyAndroidDataView.kt
andScrollableChart.kt
in which I updated the implementing method parameters. UI tests that use these classes has also been updated.Added a
locales_config.xml
resource file to specify the supported languages that should appear on the menu. As of now I based the language codes from the availablestrings.xml
localized files.Testing
I've manually tested this on a Pixel 6 emulator and a physical Pixel 4a both running Android 13.
There is a warning on the Android manifest file about
android:localeConfig
being only available for API 33 and not on lower sdk versions but the app still works fine. I tested on an emulated Pixel 4 running Android 11. My guess is since Per-App language setting doesn't exist in < API 33, theandroid:localeConfig
attribute will never be queried anyway.For automated tests, all existing unit tests passed.
Some of the UI tests are failing even before I made these changes. While tests involving
AndroidDataView.kt
andScrollableChart.kt
are still passing.