Bug 965548 - Part 8: Guard toolbar views at runtime so tablets do not break. r=bnicholson
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 17 Apr 2014 14:09:43 -0700
changeset 179603 62a5caa65d45503838a232d70a2de7fc3effd789
parent 179602 d46231f4d4ae9e73a5c41c637ca4ac8e1a9eab0d
child 179604 8844503bc63a17e8d77412c05a35d14b3e20b9b2
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersbnicholson
bugs965548
milestone31.0a1
Bug 965548 - Part 8: Guard toolbar views at runtime so tablets do not break. r=bnicholson
mobile/android/base/toolbar/BrowserToolbar.java
--- a/mobile/android/base/toolbar/BrowserToolbar.java
+++ b/mobile/android/base/toolbar/BrowserToolbar.java
@@ -360,22 +360,24 @@ public class BrowserToolbar extends Them
         });
         forwardButton.setOnLongClickListener(new Button.OnLongClickListener() {
             @Override
             public boolean onLongClick(View view) {
                 return Tabs.getInstance().getSelectedTab().showForwardHistory();
             }
         });
 
-        editCancel.setOnClickListener(new OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                cancelEdit();
-            }
-        });
+        if (editCancel != null) {
+            editCancel.setOnClickListener(new OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    cancelEdit();
+                }
+            });
+        }
 
         if (hasSoftMenuButton) {
             menuButton.setVisibility(View.VISIBLE);
             menuIcon.setVisibility(View.VISIBLE);
 
             menuButton.setOnClickListener(new Button.OnClickListener() {
                 @Override
                 public void onClick(View view) {
@@ -589,16 +591,21 @@ public class BrowserToolbar extends Them
         tabsButton.setNextFocusDownId(nextId);
         backButton.setNextFocusDownId(nextId);
         forwardButton.setNextFocusDownId(nextId);
         urlDisplayLayout.setNextFocusDownId(nextId);
         menuButton.setNextFocusDownId(nextId);
     }
 
     private int getUrlBarEntryTranslation() {
+        if (editSeparator == null) {
+            // We are on tablet, and there is no animation so return a translation of 0.
+            return 0;
+        }
+
         // We would ideally use the right-most point of the edit layout instead of the
         // edit separator and its margin, but it is not inflated when this code initially runs.
         final LayoutParams lp = (LayoutParams) editSeparator.getLayoutParams();
         return editSeparator.getLeft() - lp.leftMargin - urlBarEntry.getRight();
     }
 
     private int getUrlBarCurveTranslation() {
         return getWidth() - tabsButton.getLeft();
@@ -878,18 +885,20 @@ public class BrowserToolbar extends Them
                 if (showEditLayout) {
                     setCancelVisibility(View.VISIBLE);
                 }
             }
         });
     }
 
     private void setCancelVisibility(final int visibility) {
-        editSeparator.setVisibility(visibility);
-        editCancel.setVisibility(visibility);
+        if (editSeparator != null && editCancel != null) {
+            editSeparator.setVisibility(visibility);
+            editCancel.setVisibility(visibility);
+        }
     }
 
     /**
      * Disables and dims all toolbar elements which are not
      * related to editing mode.
      */
     private void updateChildrenForEditing() {
         // This is for the tablet UI only
@@ -1320,17 +1329,19 @@ public class BrowserToolbar extends Them
     @Override
     public void setPrivateMode(boolean isPrivate) {
         super.setPrivateMode(isPrivate);
 
         tabsButton.setPrivateMode(isPrivate);
         menuButton.setPrivateMode(isPrivate);
         menuIcon.setPrivateMode(isPrivate);
         urlEditLayout.setPrivateMode(isPrivate);
-        editSeparator.setPrivateMode(isPrivate);
+        if (editSeparator != null) {
+            editSeparator.setPrivateMode(isPrivate);
+        }
 
         if (backButton instanceof BackButton) {
             ((BackButton) backButton).setPrivateMode(isPrivate);
         }
 
         if (forwardButton instanceof ForwardButton) {
             ((ForwardButton) forwardButton).setPrivateMode(isPrivate);
         }