diff --git a/briar-android/src/main/java/org/briarproject/briar/android/Localizer.java b/briar-android/src/main/java/org/briarproject/briar/android/Localizer.java index 74864b03f..f4eef4fc7 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/Localizer.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/Localizer.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; +import android.support.v4.text.TextUtilsCompat; import org.briarproject.bramble.api.nullsafety.NotNullByDefault; @@ -12,6 +13,7 @@ import java.util.Locale; import javax.annotation.Nullable; import static android.os.Build.VERSION.SDK_INT; +import static android.support.v4.view.ViewCompat.LAYOUT_DIRECTION_LTR; import static org.briarproject.briar.android.settings.SettingsFragment.LANGUAGE; @NotNullByDefault @@ -91,6 +93,7 @@ public class Localizer { private void setLocaleAndSystemConfiguration() { Locale.setDefault(locale); + if (SDK_INT >= 23) return; Configuration systemConfiguration = Resources.getSystem().getConfiguration(); updateConfiguration(systemConfiguration, locale); @@ -98,4 +101,27 @@ public class Localizer { Resources.getSystem().updateConfiguration(systemConfiguration, Resources.getSystem().getDisplayMetrics()); } + + // Indicates whether the language represented by locale + // should be offered to the user on this device. + // * Android doesn't pick up Asturian on API < 21 + // * Android can't render Devanagari characters on API 15. + // * RTL languages are supported since API >= 17 + public static boolean isLocaleSupported(Locale locale) { + if (SDK_INT >= 21) return true; + if (locale.getLanguage().equals("ast")) return false; + if (SDK_INT == 15 && locale.getLanguage().equals("hi")) return false; + if (SDK_INT >= 17) return true; + return isLeftToRight(locale); + } + + // Exclude RTL locales on API < 17, they won't be laid out correctly + private static boolean isLeftToRight(Locale locale) { + // TextUtilsCompat returns the wrong direction for Hebrew on some phones + String language = locale.getLanguage(); + if (language.equals("iw") || language.equals("he")) return false; + int direction = TextUtilsCompat.getLayoutDirectionFromLocale(locale); + return direction == LAYOUT_DIRECTION_LTR; + } + } diff --git a/briar-android/src/main/java/org/briarproject/briar/android/settings/SettingsFragment.java b/briar-android/src/main/java/org/briarproject/briar/android/settings/SettingsFragment.java index 7412b213f..2be89b19e 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/settings/SettingsFragment.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/settings/SettingsFragment.java @@ -44,7 +44,6 @@ import javax.inject.Inject; import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.core.content.ContextCompat; -import androidx.core.text.TextUtilsCompat; import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.Preference.OnPreferenceChangeListener; @@ -70,7 +69,6 @@ import static android.provider.Settings.EXTRA_APP_PACKAGE; import static android.provider.Settings.EXTRA_CHANNEL_ID; import static android.provider.Settings.System.DEFAULT_NOTIFICATION_URI; import static android.widget.Toast.LENGTH_SHORT; -import static androidx.core.view.ViewCompat.LAYOUT_DIRECTION_LTR; import static java.util.Objects.requireNonNull; import static java.util.logging.Level.INFO; import static java.util.logging.Level.WARNING; @@ -296,10 +294,10 @@ public class SettingsFragment extends PreferenceFragmentCompat Locale locale = Localizer.getLocaleFromTag(tag); if (locale == null) throw new IllegalStateException(); - // Exclude RTL locales on API < 17, they won't be laid out correctly - if (SDK_INT < 17 && !isLeftToRight(locale)) { + // Check if the locale is supported on this device + if (!Localizer.isLocaleSupported(locale)) { if (LOG.isLoggable(INFO)) - LOG.info("Skipping RTL locale " + tag); + LOG.info("Skipping unsupported locale " + tag); continue; } String nativeName = locale.getDisplayName(locale); @@ -319,13 +317,6 @@ public class SettingsFragment extends PreferenceFragmentCompat language.setEntryValues(entryValues.toArray(new CharSequence[0])); } - private boolean isLeftToRight(Locale locale) { - // TextUtilsCompat returns the wrong direction for Hebrew on some phones - String language = locale.getLanguage(); - if (language.equals("iw") || language.equals("he")) return false; - int direction = TextUtilsCompat.getLayoutDirectionFromLocale(locale); - return direction == LAYOUT_DIRECTION_LTR; - } private void setTorNetworkSummary(int torNetworkSetting) { if (torNetworkSetting != PREF_TOR_NETWORK_AUTOMATIC) {