hide Languages pref on >= android-24
Android 24 and later provides tons of languages, and a way to rank multiple languages instead of choosing one. The Languages pref is a big hack and can be problematic, so its better to disable it when its not needed. This will make it so it is no longer possible to set F-Droid to a language that the system does not support. #943
This commit is contained in:
parent
50982060ac
commit
add570ab4b
@ -117,6 +117,11 @@ public final class Languages {
|
||||
|
||||
@TargetApi(17)
|
||||
public static void setLanguage(final ContextWrapper contextWrapper, String language, boolean refresh) {
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
Utils.debugLog(TAG, "Languages.setLanguage() ignored on >= android-24");
|
||||
Preferences.get().clearLanguage();
|
||||
return;
|
||||
}
|
||||
if (locale != null && TextUtils.equals(locale.getLanguage(), language) && (!refresh)) {
|
||||
return; // already configured
|
||||
} else if (language == null || language.equals(USE_SYSTEM_DEFAULT)) {
|
||||
@ -148,6 +153,10 @@ public final class Languages {
|
||||
* @param activity the {@code Activity} to force reload
|
||||
*/
|
||||
public static void forceChangeLanguage(Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
Utils.debugLog(TAG, "Languages.forceChangeLanguage() ignored on >= android-24");
|
||||
return;
|
||||
}
|
||||
Intent intent = activity.getIntent();
|
||||
if (intent == null) { // when launched as LAUNCHER
|
||||
return;
|
||||
@ -159,18 +168,6 @@ public final class Languages {
|
||||
activity.overridePendingTransition(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the language based on the locale.
|
||||
*/
|
||||
public String getName(String locale) {
|
||||
String ret = nameMap.get(locale);
|
||||
// if no match, try to return a more general name (i.e. English for en_IN)
|
||||
if (ret == null && locale.contains("_")) {
|
||||
ret = nameMap.get(locale.split("_")[0]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an array of the names of all the supported languages, sorted to
|
||||
* match what is returned by {@link Languages#getSupportedLocales()}.
|
||||
@ -179,19 +176,6 @@ public final class Languages {
|
||||
return nameMap.values().toArray(new String[nameMap.size()]);
|
||||
}
|
||||
|
||||
public int getPosition(Locale locale) {
|
||||
String localeName = locale.getLanguage();
|
||||
int i = 0;
|
||||
for (String key : nameMap.keySet()) {
|
||||
if (TextUtils.equals(key, localeName)) {
|
||||
return i;
|
||||
} else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return sorted list of supported locales.
|
||||
*/
|
||||
|
@ -65,10 +65,15 @@ public class PreferencesFragment extends PreferenceFragment
|
||||
updatePrivilegedExtensionPref = findPreference(Preferences.PREF_UNINSTALL_PRIVILEGED_APP);
|
||||
|
||||
AppCompatListPreference languagePref = (AppCompatListPreference) findPreference(Preferences.PREF_LANGUAGE);
|
||||
Languages languages = Languages.get(getActivity());
|
||||
languagePref.setDefaultValue(Languages.USE_SYSTEM_DEFAULT);
|
||||
languagePref.setEntries(languages.getAllNames());
|
||||
languagePref.setEntryValues(languages.getSupportedLocales());
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
PreferenceCategory category = (PreferenceCategory) findPreference("pref_category_display");
|
||||
category.removePreference(languagePref);
|
||||
} else {
|
||||
Languages languages = Languages.get(getActivity());
|
||||
languagePref.setDefaultValue(Languages.USE_SYSTEM_DEFAULT);
|
||||
languagePref.setEntries(languages.getAllNames());
|
||||
languagePref.setEntryValues(languages.getSupportedLocales());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkSummary(String key, int resId) {
|
||||
@ -78,7 +83,9 @@ public class PreferencesFragment extends PreferenceFragment
|
||||
|
||||
private void entrySummary(String key) {
|
||||
ListPreference pref = (ListPreference) findPreference(key);
|
||||
pref.setSummary(pref.getEntry());
|
||||
if (pref != null) {
|
||||
pref.setSummary(pref.getEntry());
|
||||
}
|
||||
}
|
||||
|
||||
private void textSummary(String key, int resId) {
|
||||
|
@ -41,7 +41,8 @@
|
||||
android:defaultValue="true"
|
||||
android:key="updateNotify" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/display">
|
||||
<PreferenceCategory android:title="@string/display"
|
||||
android:key="pref_category_display">
|
||||
<com.geecko.QuickLyric.view.AppCompatListPreference android:title="@string/pref_language"
|
||||
android:key="language"/>
|
||||
<com.geecko.QuickLyric.view.AppCompatListPreference android:title="@string/theme"
|
||||
|
Loading…
x
Reference in New Issue
Block a user