Bug 1248908 - modified class ToolbarDisplayLayout in order to eliminate useless tab against null checking and pass is as @NonNull since we are sure it's a valid object. r?sebastian draft
authorBogdan Postelnicu <bogdan.postelnicu@softvision.ro>
Thu, 18 Feb 2016 11:18:09 +0200
changeset 331769 6dc11ece2af1a11ef0b2b60902bd4b75adda04b1
parent 331663 0629918a09ae87808efdda432d7852371ba37db6
child 514465 1a581a2848960bf0f3dc6181e39658d56bd1fb98
push id11078
push userBogdan.Postelnicu@softvision.ro
push dateThu, 18 Feb 2016 09:38:11 +0000
reviewerssebastian
bugs1248908
milestone47.0a1
Bug 1248908 - modified class ToolbarDisplayLayout in order to eliminate useless tab against null checking and pass is as @NonNull since we are sure it's a valid object. r?sebastian MozReview-Commit-ID: LBtVN8F0oO4
mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbar.java
mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbar.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/BrowserToolbar.java
@@ -51,16 +51,17 @@ import android.view.LayoutInflater;
 import android.view.MenuInflater;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewTreeObserver.OnGlobalLayoutListener;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.Button;
 import android.widget.LinearLayout;
 import android.widget.PopupWindow;
+import android.support.annotation.NonNull;
 
 /**
 * {@code BrowserToolbar} is single entry point for users of the toolbar
 * subsystem i.e. this should be the only import outside the 'toolbar'
 * package.
 *
 * {@code BrowserToolbar} serves at the single event bus for all
 * sub-components in the toolbar. It tracks tab events and gecko messages
@@ -397,17 +398,17 @@ public abstract class BrowserToolbar ext
         if (!isEditing()) {
             throw new IllegalStateException("Expected to be editing");
         }
 
         urlEditLayout.restoreTabEditingState(editingState);
     }
 
     @Override
-    public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
+    public void onTabChanged(@NonNull Tab tab, Tabs.TabEvents msg, Object data) {
         Log.d(LOGTAG, "onTabChanged: " + msg);
         final Tabs tabs = Tabs.getInstance();
 
         // These conditions are split into three phases:
         // * Always do first
         // * Handling specific to the selected tab
         // * Always do afterwards.
 
@@ -586,17 +587,17 @@ public abstract class BrowserToolbar ext
         }
 
         // Update A11y information
         tabsButton.setContentDescription((count > 1) ?
                                          activity.getString(R.string.num_tabs, count) :
                                          activity.getString(R.string.one_tab));
     }
 
-    private void updateDisplayLayout(Tab tab, EnumSet<UpdateFlags> flags) {
+    private void updateDisplayLayout(@NonNull Tab tab, EnumSet<UpdateFlags> flags) {
         if (isSwitchingTabs) {
             flags.add(UpdateFlags.DISABLE_ANIMATIONS);
         }
 
         urlDisplayLayout.updateFromTab(tab, flags);
 
         if (flags.contains(UpdateFlags.TITLE)) {
             if (!isEditing()) {
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
@@ -20,33 +20,33 @@ import org.mozilla.gecko.SiteIdentity.Tr
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.animation.PropertyAnimator;
 import org.mozilla.gecko.animation.ViewHelper;
 import org.mozilla.gecko.toolbar.BrowserToolbarTabletBase.ForwardButtonAnimation;
 import org.mozilla.gecko.util.ColorUtils;
 import org.mozilla.gecko.util.StringUtils;
 import org.mozilla.gecko.widget.themed.ThemedLinearLayout;
 import org.mozilla.gecko.widget.themed.ThemedTextView;
-
 import android.content.Context;
 import android.content.res.Resources;
 import android.os.SystemClock;
 import android.text.Spannable;
 import android.text.SpannableStringBuilder;
 import android.text.TextUtils;
 import android.text.style.ForegroundColorSpan;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.animation.AlphaAnimation;
 import android.view.animation.Animation;
 import android.view.animation.TranslateAnimation;
 import android.widget.Button;
 import android.widget.ImageButton;
+import android.support.annotation.NonNull;
 
 /**
 * {@code ToolbarDisplayLayout} is the UI for when the toolbar is in
 * display state. It's used to display the state of the currently selected
 * tab. It should always be updated through a single entry point
 * (updateFromTab) and should never track any tab events or gecko messages
 * on its own to keep it as dumb as possible.
 *
@@ -194,17 +194,17 @@ public class ToolbarDisplayLayout extend
         mSiteSecurity.setNextFocusDownId(nextId);
         mPageActionLayout.setNextFocusDownId(nextId);
     }
 
     void setToolbarPrefs(final ToolbarPrefs prefs) {
         mPrefs = prefs;
     }
 
-    void updateFromTab(Tab tab, EnumSet<UpdateFlags> flags) {
+    void updateFromTab(@NonNull Tab tab, EnumSet<UpdateFlags> flags) {
         // Several parts of ToolbarDisplayLayout's state depends
         // on the views being attached to the view tree.
         if (!mIsAttached) {
             return;
         }
 
         if (flags.contains(UpdateFlags.TITLE)) {
             updateTitle(tab);
@@ -214,32 +214,32 @@ public class ToolbarDisplayLayout extend
             updateSiteIdentity(tab);
         }
 
         if (flags.contains(UpdateFlags.PROGRESS)) {
             updateProgress(tab);
         }
 
         if (flags.contains(UpdateFlags.PRIVATE_MODE)) {
-            mTitle.setPrivateMode(tab != null && tab.isPrivate());
+            mTitle.setPrivateMode(tab.isPrivate());
         }
     }
 
     void setTitle(CharSequence title) {
         mTitle.setText(title);
 
         if (mTitleChangeListener != null) {
             mTitleChangeListener.onTitleChange(title);
         }
     }
 
-    private void updateTitle(Tab tab) {
+    private void updateTitle(@NonNull Tab tab) {
         // Keep the title unchanged if there's no selected tab,
         // or if the tab is entering reader mode.
-        if (tab == null || tab.isEnteringReaderMode()) {
+        if (tab.isEnteringReaderMode()) {
             return;
         }
 
         final String url = tab.getURL();
 
         // Setting a null title will ensure we just see the
         // "Enter Search or Address" placeholder text.
         if (AboutPages.isTitlelessAboutPage(url)) {
@@ -286,23 +286,18 @@ public class ToolbarDisplayLayout extend
     private String stripAboutReaderURL(final String url) {
         if (!AboutPages.isAboutReader(url)) {
             return url;
         }
 
         return ReaderModeUtils.getUrlFromAboutReader(url);
     }
 
-    private void updateSiteIdentity(Tab tab) {
-        final SiteIdentity siteIdentity;
-        if (tab == null) {
-            siteIdentity = null;
-        } else {
-            siteIdentity = tab.getSiteIdentity();
-        }
+    private void updateSiteIdentity(@NonNull Tab tab) {
+        final SiteIdentity siteIdentity = tab.getSiteIdentity();
 
         mSiteIdentityPopup.setSiteIdentity(siteIdentity);
 
         final SecurityMode securityMode;
         final MixedMode activeMixedMode;
         final MixedMode displayMixedMode;
         final TrackingMode trackingMode;
         final boolean loginInsecure;
@@ -349,19 +344,18 @@ public class ToolbarDisplayLayout extend
             mSecurityImageLevel = imageLevel;
             mSiteSecurity.setImageLevel(mSecurityImageLevel);
             updatePageActions();
         }
 
         mTrackingProtectionEnabled = trackingMode == TrackingMode.TRACKING_CONTENT_BLOCKED;
     }
 
-    private void updateProgress(Tab tab) {
-        final boolean shouldShowThrobber = (tab != null &&
-                                            tab.getState() == Tab.STATE_LOADING);
+    private void updateProgress(@NonNull Tab tab) {
+        final boolean shouldShowThrobber = tab.getState() == Tab.STATE_LOADING;
 
         updateUiMode(shouldShowThrobber ? UIMode.PROGRESS : UIMode.DISPLAY);
 
         if (Tab.STATE_SUCCESS == tab.getState() && mTrackingProtectionEnabled) {
             mActivity.showTrackingProtectionPromptIfApplicable();
         }
     }