mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-18 17:04:40 +00:00
[android] Add function to get all android system languages
Signed-off-by: gekeleda <git@davidgekeler.eu>
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
package app.organicmaps.sdk.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.LocaleList;
|
||||
import android.text.TextUtils;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
import androidx.annotation.Keep;
|
||||
import androidx.annotation.NonNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Language
|
||||
@@ -33,6 +38,36 @@ public class Language
|
||||
return lang;
|
||||
}
|
||||
|
||||
@Keep
|
||||
@SuppressWarnings("unused")
|
||||
@NonNull
|
||||
public static String[] getSystemLocales()
|
||||
{
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
// Check for Android version high enough to support Locale Preference list
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
|
||||
{
|
||||
// Gets user language preference list, on system level - app-specific changes are not applied
|
||||
// (For that a Context object would be necessary)
|
||||
LocaleList list = Resources.getSystem().getConfiguration().getLocales();
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
{
|
||||
String lang = list.get(i).toString();
|
||||
if (lang.startsWith("in"))
|
||||
lang = "id";
|
||||
if (lang.startsWith("iw"))
|
||||
lang = "he";
|
||||
result.add(lang);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result.add(Locale.getDefault().toString());
|
||||
}
|
||||
return result.toArray(new String[0]);
|
||||
}
|
||||
|
||||
// After some testing on Galaxy S4, looks like this method doesn't work on all devices:
|
||||
// sometime it always returns the same value as getDefaultLocale()
|
||||
@NonNull
|
||||
|
||||
Reference in New Issue
Block a user