Bug 1019981 - Part 1: remove Language section from preferences if locale switching is disabled. r=nalexander

This commit is contained in:
Richard Newman 2014-06-04 19:21:33 -07:00
parent 877c2ac1bb
commit 8ed5c36169
7 changed files with 58 additions and 2 deletions

View File

@ -3938,6 +3938,7 @@ MOZ_ANDROID_HISTORY=
MOZ_WEBSMS_BACKEND=
MOZ_ANDROID_BEAM=
MOZ_ANDROID_SYNTHAPKS=
MOZ_LOCALE_SWITCHER=
ACCESSIBILITY=1
MOZ_TIME_MANAGER=
MOZ_PAY=
@ -4947,6 +4948,13 @@ if test -n "$MOZ_WEBSMS_BACKEND"; then
AC_DEFINE(MOZ_WEBSMS_BACKEND)
fi
dnl ========================================================
dnl = Enable runtime locale switching on Android
dnl ========================================================
if test -n "$MOZ_LOCALE_SWITCHER"; then
AC_DEFINE(MOZ_LOCALE_SWITCHER)
fi
dnl ========================================================
dnl = Enable NFC permission on Android
dnl ========================================================
@ -8567,6 +8575,7 @@ AC_SUBST(MOZ_ANDROID_HISTORY)
AC_SUBST(MOZ_WEBSMS_BACKEND)
AC_SUBST(MOZ_ANDROID_BEAM)
AC_SUBST(MOZ_ANDROID_SYNTHAPKS)
AC_SUBST(MOZ_LOCALE_SWITCHER)
AC_SUBST(MOZ_DISABLE_GECKOVIEW)
AC_SUBST(ENABLE_STRIP)
AC_SUBST(PKG_SKIP_STRIP)

View File

@ -121,6 +121,13 @@ public class AppConstants {
false;
#endif
public static final boolean MOZ_LOCALE_SWITCHER =
#ifdef MOZ_LOCALE_SWITCHER
true;
#else
false;
#endif
public static final boolean MOZ_UPDATER =
#ifdef MOZ_UPDATER
true;

View File

@ -75,6 +75,10 @@ public class BrowserLocaleManager implements LocaleManager {
}
}
public boolean isEnabled() {
return AppConstants.MOZ_LOCALE_SWITCHER;
}
/**
* Gecko uses locale codes like "es-ES", whereas a Java {@link Locale}
* stringifies as "es_ES".

View File

@ -18,6 +18,11 @@ import android.content.res.Resources;
*/
public interface LocaleManager {
void initialize(Context context);
/**
* @return true if locale switching is enabled.
*/
boolean isEnabled();
Locale getCurrentLocale(Context context);
String getAndApplyPersistedLocale(Context context);
void correctLocale(Context context, Resources resources, Configuration newConfig);

View File

@ -131,6 +131,7 @@ OnSharedPreferenceChangeListener
* Track the last locale so we know whether to redisplay.
*/
private Locale lastLocale = Locale.getDefault();
private boolean localeSwitchingIsEnabled;
private void updateActionBarTitle(int title) {
if (Build.VERSION.SDK_INT >= 14) {
@ -268,6 +269,9 @@ OnSharedPreferenceChangeListener
// Apply the current user-selected locale, if necessary.
checkLocale();
// Track this so we can decide whether to show locale options.
localeSwitchingIsEnabled = BrowserLocaleManager.getInstance().isEnabled();
// For Android v11+ where we use Fragments (v11+ only due to bug 866352),
// check that PreferenceActivity.EXTRA_SHOW_FRAGMENT has been set
// (or set it) before super.onCreate() is called so Android can display
@ -397,6 +401,18 @@ OnSharedPreferenceChangeListener
public void onBuildHeaders(List<Header> target) {
if (onIsMultiPane()) {
loadHeadersFromResource(R.xml.preference_headers, target);
// If locale switching is disabled, remove the section
// entirely. This logic will need to be extended when
// content language selection (Bug 881510) is implemented.
if (!localeSwitchingIsEnabled) {
for (Header header : target) {
if (header.id == R.id.pref_header_language) {
target.remove(header);
break;
}
}
}
}
}
@ -564,9 +580,20 @@ OnSharedPreferenceChangeListener
private void setupPreferences(PreferenceGroup preferences, ArrayList<String> prefs) {
for (int i = 0; i < preferences.getPreferenceCount(); i++) {
Preference pref = preferences.getPreference(i);
// Eliminate locale switching if necessary.
// This logic will need to be extended when
// content language selection (Bug 881510) is implemented.
if (!localeSwitchingIsEnabled &&
"preferences_locale".equals(pref.getExtras().getString("resource", null))) {
preferences.removePreference(pref);
i--;
continue;
}
String key = pref.getKey();
if (pref instanceof PreferenceGroup) {
// If no datareporting is enabled, remove UI.
// If datareporting is disabled, remove UI.
if (PREFS_DATA_REPORTING_PREFERENCES.equals(key)) {
if (!AppConstants.MOZ_DATA_REPORTING) {
preferences.removePreference(pref);

View File

@ -28,7 +28,8 @@
</header>
<header android:fragment="org.mozilla.gecko.preferences.GeckoPreferenceFragment"
android:title="@string/pref_header_language">
android:title="@string/pref_header_language"
android:id="@+id/pref_header_language">
<extra android:name="resource"
android:value="preferences_locale" />
</header>

View File

@ -64,6 +64,9 @@ MOZ_SERVICES_FXACCOUNTS=1
# Enable Wifi-AP/cell tower data reporting
MOZ_DATA_REPORTING=1
# Enable runtime locale switching.
MOZ_LOCALE_SWITCHER=1
# Enable the "synthetic APKs" implementation of Open Web Apps.
MOZ_ANDROID_SYNTHAPKS=1