mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 14:49:53 +01:00
Don't show unsupported locales in the settings
This commit is contained in:
@@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.support.v4.text.TextUtilsCompat;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@ import java.util.Locale;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
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;
|
import static org.briarproject.briar.android.settings.SettingsFragment.LANGUAGE;
|
||||||
|
|
||||||
@NotNullByDefault
|
@NotNullByDefault
|
||||||
@@ -91,6 +93,7 @@ public class Localizer {
|
|||||||
|
|
||||||
private void setLocaleAndSystemConfiguration() {
|
private void setLocaleAndSystemConfiguration() {
|
||||||
Locale.setDefault(locale);
|
Locale.setDefault(locale);
|
||||||
|
if (SDK_INT >= 23) return;
|
||||||
Configuration systemConfiguration =
|
Configuration systemConfiguration =
|
||||||
Resources.getSystem().getConfiguration();
|
Resources.getSystem().getConfiguration();
|
||||||
updateConfiguration(systemConfiguration, locale);
|
updateConfiguration(systemConfiguration, locale);
|
||||||
@@ -98,4 +101,27 @@ public class Localizer {
|
|||||||
Resources.getSystem().updateConfiguration(systemConfiguration,
|
Resources.getSystem().updateConfiguration(systemConfiguration,
|
||||||
Resources.getSystem().getDisplayMetrics());
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ import javax.inject.Inject;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.text.TextUtilsCompat;
|
|
||||||
import androidx.preference.ListPreference;
|
import androidx.preference.ListPreference;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
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.EXTRA_CHANNEL_ID;
|
||||||
import static android.provider.Settings.System.DEFAULT_NOTIFICATION_URI;
|
import static android.provider.Settings.System.DEFAULT_NOTIFICATION_URI;
|
||||||
import static android.widget.Toast.LENGTH_SHORT;
|
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.Objects.requireNonNull;
|
||||||
import static java.util.logging.Level.INFO;
|
import static java.util.logging.Level.INFO;
|
||||||
import static java.util.logging.Level.WARNING;
|
import static java.util.logging.Level.WARNING;
|
||||||
@@ -296,10 +294,10 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
Locale locale = Localizer.getLocaleFromTag(tag);
|
Locale locale = Localizer.getLocaleFromTag(tag);
|
||||||
if (locale == null)
|
if (locale == null)
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
// Exclude RTL locales on API < 17, they won't be laid out correctly
|
// Check if the locale is supported on this device
|
||||||
if (SDK_INT < 17 && !isLeftToRight(locale)) {
|
if (!Localizer.isLocaleSupported(locale)) {
|
||||||
if (LOG.isLoggable(INFO))
|
if (LOG.isLoggable(INFO))
|
||||||
LOG.info("Skipping RTL locale " + tag);
|
LOG.info("Skipping unsupported locale " + tag);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String nativeName = locale.getDisplayName(locale);
|
String nativeName = locale.getDisplayName(locale);
|
||||||
@@ -319,13 +317,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
language.setEntryValues(entryValues.toArray(new CharSequence[0]));
|
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) {
|
private void setTorNetworkSummary(int torNetworkSetting) {
|
||||||
if (torNetworkSetting != PREF_TOR_NETWORK_AUTOMATIC) {
|
if (torNetworkSetting != PREF_TOR_NETWORK_AUTOMATIC) {
|
||||||
|
|||||||
Reference in New Issue
Block a user