Bug 1019981 - Part 1: remove Language section from preferences if locale switching is disabled. r=nalexander
authorRichard Newman <rnewman@mozilla.com>
Wed, 04 Jun 2014 19:21:33 -0700
changeset 186791 a5088ee3f9211611b2f87197e6e18d71a5b86720
parent 186790 0dc1743249550e578e3aca7fb980501729a252f0
child 186792 d8174c0580e5eec81f17bcede4557c2cfd87fcd0
push id26900
push usercbook@mozilla.com
push dateThu, 05 Jun 2014 13:09:12 +0000
treeherdermozilla-central@219b3ed1b996 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1019981
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1019981 - Part 1: remove Language section from preferences if locale switching is disabled. r=nalexander
configure.in
mobile/android/base/AppConstants.java.in
mobile/android/base/BrowserLocaleManager.java
mobile/android/base/LocaleManager.java
mobile/android/base/preferences/GeckoPreferences.java
mobile/android/base/resources/xml-v11/preference_headers.xml
mobile/android/confvars.sh
--- a/configure.in
+++ b/configure.in
@@ -3933,16 +3933,17 @@ if test -n "$MOZ_RTSP"; then
 fi
 USE_ARM_KUSER=
 BUILD_CTYPES=1
 MOZ_USE_NATIVE_POPUP_WINDOWS=
 MOZ_ANDROID_HISTORY=
 MOZ_WEBSMS_BACKEND=
 MOZ_ANDROID_BEAM=
 MOZ_ANDROID_SYNTHAPKS=
+MOZ_LOCALE_SWITCHER=
 ACCESSIBILITY=1
 MOZ_TIME_MANAGER=
 MOZ_PAY=
 MOZ_AUDIO_CHANNEL_MANAGER=
 NSS_NO_LIBPKIX=
 MOZ_CONTENT_SANDBOX=
 MOZ_CONTENT_SANDBOX_REPORTER=1
 JSGC_USE_EXACT_ROOTING=
@@ -4943,16 +4944,23 @@ MOZ_ARG_DISABLE_BOOL(websms-backend,
     MOZ_WEBSMS_BACKEND=,
     MOZ_WEBSMS_BACKEND=1)
 
 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 ========================================================
 if test -n "$MOZ_ANDROID_BEAM"; then
     AC_DEFINE(MOZ_ANDROID_BEAM)
 fi
 
 dnl ========================================================
 dnl = Synthesized Webapp APKs on Android
@@ -8562,16 +8570,17 @@ AC_SUBST(MOZ_D3DCOMPILER_XP_DLL)
 AC_SUBST(MOZ_D3DCOMPILER_XP_CAB)
 
 AC_SUBST(MOZ_METRO)
 
 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)
 AC_SUBST(STRIP_FLAGS)
 AC_SUBST(USE_ELF_HACK)
 AC_SUBST(INCREMENTAL_LINKER)
 AC_SUBST(MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS)
 AC_SUBST(MOZ_COMPONENT_NSPR_LIBS)
--- a/mobile/android/base/AppConstants.java.in
+++ b/mobile/android/base/AppConstants.java.in
@@ -116,16 +116,23 @@ public class AppConstants {
 
     public static final boolean MOZ_DATA_REPORTING =
 #ifdef MOZ_DATA_REPORTING
       true;
 #else
     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;
 #else
     false;
 #endif
 
     public static final boolean MOZ_WEBSMS_BACKEND =
--- a/mobile/android/base/BrowserLocaleManager.java
+++ b/mobile/android/base/BrowserLocaleManager.java
@@ -70,16 +70,20 @@ public class BrowserLocaleManager implem
         localeManager = new BrowserLocaleManager();
         if (instance.compareAndSet(null, localeManager)) {
             return localeManager;
         } else {
             return instance.get();
         }
     }
 
+    public boolean isEnabled() {
+        return AppConstants.MOZ_LOCALE_SWITCHER;
+    }
+
     /**
      * Gecko uses locale codes like "es-ES", whereas a Java {@link Locale}
      * stringifies as "es_ES".
      *
      * This method approximates the Java 7 method <code>Locale#toLanguageTag()</code>.
      *
      * @return a locale string suitable for passing to Gecko.
      */
--- a/mobile/android/base/LocaleManager.java
+++ b/mobile/android/base/LocaleManager.java
@@ -13,16 +13,21 @@ import android.content.res.Resources;
 /**
  * Implement this interface to provide Fennec's locale switching functionality.
  *
  * The LocaleManager is responsible for persisting and applying selected locales,
  * and correcting configurations after Android has changed them.
  */
 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);
     void updateConfiguration(Context context, Locale locale);
     String setSelectedLocale(Context context, String localeCode);
     boolean systemLocaleDidChange();
     void resetToSystemLocale(Context context);
 
--- a/mobile/android/base/preferences/GeckoPreferences.java
+++ b/mobile/android/base/preferences/GeckoPreferences.java
@@ -126,16 +126,17 @@ OnSharedPreferenceChangeListener
     // Callers can recognize this code to refresh themselves to
     // accommodate a locale change.
     public static final int RESULT_CODE_LOCALE_DID_CHANGE = 7;
 
     /**
      * 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) {
             final String newTitle = getString(title);
             if (newTitle != null) {
                 Log.v(LOGTAG, "Setting action bar title to " + newTitle);
 
                 final ActionBar actionBar = getActionBar();
@@ -263,16 +264,19 @@ OnSharedPreferenceChangeListener
         onLocaleChanged(currentLocale);
     }
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         // 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
         // the correct Fragment resource.
 
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
             if (!getIntent().hasExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT)) {
                 // Set up the default fragment if there is no explicit fragment to show.
@@ -392,16 +396,28 @@ OnSharedPreferenceChangeListener
     public boolean isValidFragment(String fragmentName) {
         return GeckoPreferenceFragment.class.getName().equals(fragmentName);
     }
 
     @Override
     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;
+                    }
+                }
+            }
         }
     }
 
     @Override
     public void onWindowFocusChanged(boolean hasFocus) {
         if (!hasFocus || mInitialized)
             return;
 
@@ -559,19 +575,30 @@ OnSharedPreferenceChangeListener
       * @param prefs An ArrayList to fill with Gecko preferences that need to be
       *        initialized
       * @return The integer id for the PrefsHelper.PrefHandlerBase listener added
       *         to monitor changes to Gecko prefs.
       */
     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);
                         i--;
                         continue;
                     }
                 } else if (pref instanceof PanelsPreferenceCategory) {
                     mPanelsPreferenceCategory = (PanelsPreferenceCategory) pref;
--- a/mobile/android/base/resources/xml-v11/preference_headers.xml
+++ b/mobile/android/base/resources/xml-v11/preference_headers.xml
@@ -23,17 +23,18 @@
 
     <header android:fragment="org.mozilla.gecko.preferences.GeckoPreferenceFragment"
             android:title="@string/pref_header_privacy_short">
         <extra android:name="resource"
                android:value="preferences_privacy"/>
     </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>
 
     <header android:fragment="org.mozilla.gecko.preferences.GeckoPreferenceFragment"
             android:title="@string/pref_header_vendor">
         <extra android:name="resource"
                android:value="preferences_vendor"/>
--- a/mobile/android/confvars.sh
+++ b/mobile/android/confvars.sh
@@ -59,13 +59,16 @@ MOZ_PAY=1
 MOZ_SERVICES_HEALTHREPORT=1
 
 # Enable FirefoxAccounts
 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
 
 # Enable second screen and casting support for external devices.
 MOZ_DEVICES=1