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 265798 9b92167bac1809ffb9a4e7c62292009e8fc29698
parent 265797 838556f52b8da634898c7d6ca7a42212dd299d84
child 265799 b326e8c2ef060d9cd9e55de6598f979476e04af7
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche, sledru
bugs1152314
milestone39.0a2
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
@@ -338,16 +338,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) {
@@ -408,16 +409,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>