Bug 1152314 - Duplicate action bar configuration in code. r=liuche, a=sledru
authorMichael Comella <michael.l.comella@gmail.com>
Tue, 14 Apr 2015 17:42:45 -0700
changeset 260316 cdfd06d73d17
parent 260315 5d903629f9bd
child 260317 f1cd36f7e0e1
push id746
push userryanvm@gmail.com
push date2015-04-28 22:47 +0000
treeherdermozilla-release@348c2ae68d50 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche, sledru
bugs1152314
milestone38.0
Bug 1152314 - Duplicate action bar configuration in code. r=liuche, a=sledru This is necessary because the configuration breaks on some devices if it's just set in XML - see the code comments for more details.
mobile/android/base/preferences/GeckoPreferences.java
mobile/android/base/resources/values-v11/styles.xml
--- a/mobile/android/base/preferences/GeckoPreferences.java
+++ b/mobile/android/base/preferences/GeckoPreferences.java
@@ -335,16 +335,17 @@ OnSharedPreferenceChangeListener
                     // If we try rejigging fragments, we'll crash, so don't
                     // enable locale switching at all.
                     localeSwitchingIsEnabled = false;
                 }
             }
         }
 
         super.onCreate(savedInstanceState);
+        initActionBar();
 
         // Use setResourceToOpen to specify these extras.
         Bundle intentExtras = getIntent().getExtras();
 
         // For versions of Android lower than Honeycomb, use xml resources instead of
         // Fragments because of an Android bug in ActionBar (described in bug 866352 and
         // fixed in bug 833625).
         if (Versions.preHC) {
@@ -405,16 +406,37 @@ OnSharedPreferenceChangeListener
         // If launched from notification, explicitly cancel the notification.
         if (intentExtras != null && intentExtras.containsKey(DataReportingNotification.ALERT_NAME_DATAREPORTING_NOTIFICATION)) {
             NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
             notificationManager.cancel(DataReportingNotification.ALERT_NAME_DATAREPORTING_NOTIFICATION.hashCode());
         }
     }
 
     /**
+     * Initializes the action bar configuration in code.
+     *
+     * Declaring these attributes in XML does not work on some devices for an unknown reason
+     * (e.g. the back button stops working or the logo disappears; see bug 1152314) so we
+     * duplicate those attributes in code here. Note: the order of these calls matters.
+     *
+     * We keep the XML attributes because not all of these methods are available on pre-v14.
+     */
+    private void initActionBar() {
+        if (Versions.feature14Plus) {
+            final ActionBar actionBar = getActionBar();
+            if (actionBar != null) {
+                actionBar.setHomeButtonEnabled(true);
+                actionBar.setDisplayHomeAsUpEnabled(true);
+                actionBar.setLogo(R.drawable.logo);
+                actionBar.setDisplayUseLogoEnabled(true);
+            }
+        }
+    }
+
+    /**
      * Set intent to display top-level settings fragment,
      * and show the correct title.
      */
     private void setupTopLevelFragmentIntent() {
         Intent intent = getIntent();
         // Check intent to determine settings screen to display.
         Bundle intentExtras = intent.getExtras();
         Bundle fragmentArgs = new Bundle();
--- a/mobile/android/base/resources/values-v11/styles.xml
+++ b/mobile/android/base/resources/values-v11/styles.xml
@@ -43,16 +43,17 @@
         <item name="android:ellipsize">marquee</item>
     </style>
 
     <!-- ActionBar -->
     <style name="ActionBar" parent="android:style/Widget.Holo.ActionBar" />
  
     <!-- GeckoPreferences ActionBar -->
     <style name="ActionBar.GeckoPreferences">
+         <!-- Partially duplicated in GeckoPreferences.initActionBar - look there for more details. -->
          <item name="android:displayOptions">showHome|homeAsUp|showTitle|useLogo</item>
     </style>
  
     <!-- TabsLayout ActionBar -->
     <style name="ActionBar.TabsLayout">
          <item name="android:visibility">gone</item>
     </style>