Bug 1047264 - Dynamically retrieve Views for Display Mode on tablet. r=lucasr, a=sledru
authorMichael Comella <michael.l.comella@gmail.com>
Tue, 05 Aug 2014 10:51:42 -0700
changeset 208261 e8fbf14de311
parent 208260 c755d28a5266
child 208262 9d8f79b400bf
push id3794
push userryanvm@gmail.com
push date2014-08-07 20:40 +0000
treeherdermozilla-beta@599c7756380c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr, sledru
bugs1047264
milestone32.0
Bug 1047264 - Dynamically retrieve Views for Display Mode on tablet. r=lucasr, a=sledru
mobile/android/base/toolbar/BrowserToolbar.java
--- a/mobile/android/base/toolbar/BrowserToolbar.java
+++ b/mobile/android/base/toolbar/BrowserToolbar.java
@@ -138,17 +138,17 @@ public class BrowserToolbar extends Them
     private ThemedImageButton menuButton;
     private ThemedImageView menuIcon;
     private LinearLayout actionItemBar;
     private MenuPopup menuPopup;
     private List<View> focusOrder;
 
     private final ThemedImageView editCancel;
 
-    private final View[] tabletDisplayModeViews;
+    private List<View> tabletDisplayModeViews;
     private boolean hidForwardButtonOnStartEditing = false;
 
     private boolean shouldShrinkURLBar = false;
 
     private OnActivateListener activateListener;
     private OnFocusChangeListener focusChangeListener;
     private OnStartEditingListener startEditingListener;
     private OnStopEditingListener stopEditingListener;
@@ -280,25 +280,44 @@ public class BrowserToolbar extends Them
 
                 isAnimatingEntry = false;
 
                 // Trigger animation to update the tabs counter once the
                 // tabs button is back on screen.
                 updateTabCountAndAnimate(Tabs.getInstance().getDisplayCount());
             }
         };
+    }
 
-        tabletDisplayModeViews = new View[] {
+    public ArrayList<View> populateTabletViews() {
+        if (!HardwareUtils.isTablet()) {
+            // Avoid the runtime and memory overhead for non-tablet devices.
+            return null;
+        }
+
+        final View[] allTabletDisplayModeViews = new View[] {
             actionItemBar,
             backButton,
             menuButton,
             menuIcon,
             tabsButton,
             tabsCounter,
         };
+        final ArrayList<View> listToPopulate = new ArrayList<View>(allTabletDisplayModeViews.length);
+
+        // Some tablet devices do not display all of the Views but instead rely on visibility
+        // to hide them. Find and return the ones that are relevant to our device.
+        for (final View v : allTabletDisplayModeViews) {
+            // These views should all be initialized and we explicitly do not
+            // check for null because we may be hiding bugs.
+            if (v.getVisibility() == View.VISIBLE) {
+                listToPopulate.add(v);
+            }
+        };
+        return listToPopulate;
     }
 
     @Override
     public void onAttachedToWindow() {
         super.onAttachedToWindow();
 
         setOnClickListener(new Button.OnClickListener() {
             @Override
@@ -1034,16 +1053,20 @@ public class BrowserToolbar extends Them
             menuButton.setEnabled(false);
 
             ViewHelper.setTranslationX(menuButton, curveTranslation);
             ViewHelper.setTranslationX(menuIcon, curveTranslation);
         }
     }
 
     private void showEditingOnTablet() {
+        if (tabletDisplayModeViews == null) {
+            tabletDisplayModeViews = populateTabletViews();
+        }
+
         urlBarEntry.setLayoutParams(urlBarEntryShrunkenLayoutParams);
 
         // Hide display elements.
         updateChildrenEnabledStateForEditing();
         for (final View v : tabletDisplayModeViews) {
             v.setVisibility(View.INVISIBLE);
         }
 
@@ -1170,16 +1193,22 @@ public class BrowserToolbar extends Them
             menuButton.setEnabled(true);
 
             ViewHelper.setTranslationX(menuButton, 0);
             ViewHelper.setTranslationX(menuIcon, 0);
         }
     }
 
     private void stopEditingOnTablet() {
+        if (tabletDisplayModeViews == null) {
+            throw new IllegalStateException("We initialize tabletDisplayModeViews in the " +
+                    "transition to show editing mode and don't expect stop editing to be called " +
+                    "first.");
+        }
+
         urlBarEntry.setLayoutParams(urlBarEntryDefaultLayoutParams);
 
         // Show display elements.
         updateChildrenEnabledStateForEditing();
         for (final View v : tabletDisplayModeViews) {
             v.setVisibility(View.VISIBLE);
         }