Bug 1236431 - (Pre) ToolbarDisplayLayout: Address lint warnings and clean up code. r?mcomella draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Wed, 10 Feb 2016 12:27:33 +0100
changeset 330065 c092f09054cf9d5c2b7510e17c55da158a34b2a5
parent 330064 e7db24356516de14301bbfd70e92bc9b8a596c1e
child 330066 d39bc748b95c031a691d573f2b5ac9e7aa072b83
push id10669
push users.kaspari@gmail.com
push dateWed, 10 Feb 2016 12:07:30 +0000
reviewersmcomella
bugs1236431
milestone47.0a1
Bug 1236431 - (Pre) ToolbarDisplayLayout: Address lint warnings and clean up code. r?mcomella MozReview-Commit-ID: H3JupGI1zDo
mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarDisplayLayout.java
@@ -22,17 +22,16 @@ import org.mozilla.gecko.animation.Prope
 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;
@@ -80,21 +79,21 @@ public class ToolbarDisplayLayout extend
     }
 
     private enum UIMode {
         PROGRESS,
         DISPLAY
     }
 
     interface OnStopListener {
-        public Tab onStop();
+        Tab onStop();
     }
 
     interface OnTitleChangeListener {
-        public void onTitleChange(CharSequence title);
+        void onTitleChange(CharSequence title);
     }
 
     private final BrowserApp mActivity;
 
     private UIMode mUiMode;
 
     private boolean mIsAttached;
 
@@ -115,25 +114,23 @@ public class ToolbarDisplayLayout extend
     private TranslateAnimation mTitleSlideRight;
 
     private final SiteIdentityPopup mSiteIdentityPopup;
     private int mSecurityImageLevel;
 
     // Security level constants, which map to the icons / levels defined in:
     // http://mxr.mozilla.org/mozilla-central/source/mobile/android/base/java/org/mozilla/gecko/resources/drawable/site_security_level.xml
     // Default level (unverified pages) - globe icon:
-    private final int LEVEL_DEFAULT_GLOBE = 0;
+    private static final int LEVEL_DEFAULT_GLOBE = 0;
     // Levels for displaying Mixed Content state icons.
-    private final int LEVEL_WARNING_MINOR = 3;
-    private final int LEVEL_LOCK_DISABLED = 4;
+    private static final int LEVEL_WARNING_MINOR = 3;
+    private static final int LEVEL_LOCK_DISABLED = 4;
     // Levels for displaying Tracking Protection state icons.
-    private final int LEVEL_SHIELD_ENABLED = 5;
-    private final int LEVEL_SHIELD_DISABLED = 6;
-
-    private PropertyAnimator mForwardAnim;
+    private static final int LEVEL_SHIELD_ENABLED = 5;
+    private static final int LEVEL_SHIELD_DISABLED = 6;
 
     private final ForegroundColorSpan mUrlColor;
     private final ForegroundColorSpan mBlockedColor;
     private final ForegroundColorSpan mDomainColor;
     private final ForegroundColorSpan mPrivateDomainColor;
 
     public ToolbarDisplayLayout(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -141,18 +138,16 @@ public class ToolbarDisplayLayout extend
 
         mActivity = (BrowserApp) context;
 
         LayoutInflater.from(context).inflate(R.layout.toolbar_display_layout, this);
 
         mTitle = (ThemedTextView) findViewById(R.id.url_bar_title);
         mTitlePadding = mTitle.getPaddingRight();
 
-        final Resources res = getResources();
-
         mUrlColor = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.url_bar_urltext));
         mBlockedColor = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.url_bar_blockedtext));
         mDomainColor = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.url_bar_domaintext));
         mPrivateDomainColor = new ForegroundColorSpan(ColorUtils.getColor(context, R.color.url_bar_domaintext_private));
 
         mSiteSecurity = (ImageButton) findViewById(R.id.site_security);
 
         mSiteIdentityPopup = new SiteIdentityPopup(mActivity);
@@ -160,16 +155,18 @@ public class ToolbarDisplayLayout extend
         mSiteIdentityPopup.setOnVisibilityChangeListener(mActivity);
 
         mStop = (ImageButton) findViewById(R.id.stop);
         mPageActionLayout = (PageActionLayout) findViewById(R.id.page_action_layout);
     }
 
     @Override
     public void onAttachedToWindow() {
+        super.onAttachedToWindow();
+
         mIsAttached = true;
 
         mSiteSecurity.setOnClickListener(new Button.OnClickListener() {
             @Override
             public void onClick(View view) {
                 mSiteIdentityPopup.show();
             }
         });
@@ -177,17 +174,17 @@ public class ToolbarDisplayLayout extend
         mStop.setOnClickListener(new Button.OnClickListener() {
             @Override
             public void onClick(View v) {
                 if (mStopListener != null) {
                     // Force toolbar to switch to Display mode
                     // immediately based on the stopped tab.
                     final Tab tab = mStopListener.onStop();
                     if (tab != null) {
-                        updateUiMode(UIMode.DISPLAY, EnumSet.noneOf(UpdateFlags.class));
+                        updateUiMode(UIMode.DISPLAY);
                     }
                 }
             }
         });
 
         float slideWidth = getResources().getDimension(R.dimen.browser_toolbar_site_security_width);
 
         LayoutParams siteSecParams = (LayoutParams) mSiteSecurity.getLayoutParams();
@@ -260,21 +257,21 @@ public class ToolbarDisplayLayout extend
             return;
         }
 
         if (flags.contains(UpdateFlags.TITLE)) {
             updateTitle(tab);
         }
 
         if (flags.contains(UpdateFlags.SITE_IDENTITY)) {
-            updateSiteIdentity(tab, flags);
+            updateSiteIdentity(tab);
         }
 
         if (flags.contains(UpdateFlags.PROGRESS)) {
-            updateProgress(tab, flags);
+            updateProgress(tab);
         }
 
         if (flags.contains(UpdateFlags.PRIVATE_MODE)) {
             mTitle.setPrivateMode(tab != null && tab.isPrivate());
         }
     }
 
     void setTitle(CharSequence title) {
@@ -340,17 +337,17 @@ 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, EnumSet<UpdateFlags> flags) {
+    private void updateSiteIdentity(Tab tab) {
         final SiteIdentity siteIdentity;
         if (tab == null) {
             siteIdentity = null;
         } else {
             siteIdentity = tab.getSiteIdentity();
         }
 
         mSiteIdentityPopup.setSiteIdentity(siteIdentity);
@@ -397,53 +394,53 @@ public class ToolbarDisplayLayout extend
             imageLevel = LEVEL_LOCK_DISABLED;
         } else if (displayMixedMode == MixedMode.MIXED_CONTENT_LOADED) {
             imageLevel = LEVEL_WARNING_MINOR;
         }
 
         if (mSecurityImageLevel != imageLevel) {
             mSecurityImageLevel = imageLevel;
             mSiteSecurity.setImageLevel(mSecurityImageLevel);
-            updatePageActions(flags);
+            updatePageActions();
         }
 
         mTrackingProtectionEnabled = trackingMode == TrackingMode.TRACKING_CONTENT_BLOCKED;
     }
 
-    private void updateProgress(Tab tab, EnumSet<UpdateFlags> flags) {
+    private void updateProgress(Tab tab) {
         final boolean shouldShowThrobber = (tab != null &&
                                             tab.getState() == Tab.STATE_LOADING);
 
-        updateUiMode(shouldShowThrobber ? UIMode.PROGRESS : UIMode.DISPLAY, flags);
+        updateUiMode(shouldShowThrobber ? UIMode.PROGRESS : UIMode.DISPLAY);
 
-        if (Tab.STATE_SUCCESS == tab.getState() && mTrackingProtectionEnabled) {
+        if (tab != null && Tab.STATE_SUCCESS == tab.getState() && mTrackingProtectionEnabled) {
             mActivity.showTrackingProtectionPromptIfApplicable();
         }
     }
 
-    private void updateUiMode(UIMode uiMode, EnumSet<UpdateFlags> flags) {
+    private void updateUiMode(UIMode uiMode) {
         if (mUiMode == uiMode) {
             return;
         }
 
         mUiMode = uiMode;
 
         // The "Throbber start" and "Throbber stop" log messages in this method
         // are needed by S1/S2 tests (http://mrcote.info/phonedash/#).
         // See discussion in Bug 804457. Bug 805124 tracks paring these down.
         if (mUiMode == UIMode.PROGRESS) {
             Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - Throbber start");
         } else {
             Log.i(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - Throbber stop");
         }
 
-        updatePageActions(flags);
+        updatePageActions();
     }
 
-    private void updatePageActions(EnumSet<UpdateFlags> flags) {
+    private void updatePageActions() {
         final boolean isShowingProgress = (mUiMode == UIMode.PROGRESS);
 
         mStop.setVisibility(isShowingProgress ? View.VISIBLE : View.GONE);
         mPageActionLayout.setVisibility(!isShowingProgress ? View.VISIBLE : View.GONE);
 
         // We want title to fill the whole space available for it when there are icons
         // being shown on the right side of the toolbar as the icons already have some
         // padding in them. This is just to avoid wasting space when icons are shown.
@@ -469,18 +466,16 @@ public class ToolbarDisplayLayout extend
      * are inflated.
      * @param view View to use as the anchor for the Site Identity popup.
      */
     void updateSiteIdentityAnchor(View view) {
         mSiteIdentityPopup.setAnchor(view);
     }
 
     void prepareForwardAnimation(PropertyAnimator anim, ForwardButtonAnimation animation, int width) {
-        mForwardAnim = anim;
-
         if (animation == ForwardButtonAnimation.HIDE) {
             // We animate these items individually, rather than this entire view,
             // so that we don't animate certain views, e.g. the stop button.
             anim.attach(mTitle,
                         PropertyAnimator.Property.TRANSLATION_X,
                         0);
             anim.attach(mSiteSecurity,
                         PropertyAnimator.Property.TRANSLATION_X,
@@ -499,18 +494,16 @@ public class ToolbarDisplayLayout extend
                         PropertyAnimator.Property.TRANSLATION_X,
                         width);
         }
     }
 
     void finishForwardAnimation() {
         ViewHelper.setTranslationX(mTitle, 0);
         ViewHelper.setTranslationX(mSiteSecurity, 0);
-
-        mForwardAnim = null;
     }
 
     void prepareStartEditingAnimation() {
         // Hide page actions/stop buttons immediately
         ViewHelper.setAlpha(mPageActionLayout, 0);
         ViewHelper.setAlpha(mStop, 0);
     }