Bug 962103 - Fix progress bar visibility on pre-Honeycomb devices. r=lucasr, a=sledru
authorBrian Nicholson <bnicholson@mozilla.com>
Tue, 18 Mar 2014 10:36:23 -0700
changeset 192247 c26670dd4bd6080760b524738e0f5cf087b47fca
parent 192246 2bdbf9223e1ddc89f0563c4b4c49d7b4f6ecbd86
child 192248 c16340f255c20798d515ddc52ac6838c02a24262
push id474
push userasasaki@mozilla.com
push dateMon, 02 Jun 2014 21:01:02 +0000
treeherdermozilla-release@967f4cf1b31c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr, sledru
bugs962103
milestone30.0a2
Bug 962103 - Fix progress bar visibility on pre-Honeycomb devices. r=lucasr, a=sledru
mobile/android/base/toolbar/ToolbarProgressView.java
--- a/mobile/android/base/toolbar/ToolbarProgressView.java
+++ b/mobile/android/base/toolbar/ToolbarProgressView.java
@@ -15,37 +15,40 @@
  */
 
 package org.mozilla.gecko.toolbar;
 
 import android.content.Context;
 import android.graphics.Canvas;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
+import android.os.Build;
 import android.os.Handler;
 import android.os.Message;
 import android.util.AttributeSet;
-import android.util.Log;
 import android.widget.ImageView;
 import android.view.View;
+import android.view.animation.Animation;
 
 /**
  * Progress view used for page loads.
  *
  * Because we're given limited information about the page load progress, the
  * bar also includes incremental animation between each step to improve
  * perceived performance.
  */
 public class ToolbarProgressView extends ImageView {
     private static final int MAX_PROGRESS = 10000;
     private static final int MSG_UPDATE = 0;
     private static final int MSG_HIDE = 1;
     private static final int STEPS = 10;
     private static final int DELAY = 40;
 
+    private static final boolean PRE_HONEYCOMB = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB;
+
     private int mTargetProgress;
     private int mIncrement;
     private Rect mBounds;
     private Handler mHandler;
     private int mCurrentProgress;
 
     public ToolbarProgressView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
@@ -88,16 +91,37 @@ public class ToolbarProgressView extends
                         break;
                 }
             }
 
         };
     }
 
     @Override
+    public void setVisibility(int visibility) {
+        // On GB/Froyo, setting the visibility to GONE/HIDDEN alone does not
+        // work with translations. Calling clearAnimation acts as a workaround.
+        if (PRE_HONEYCOMB && visibility != VISIBLE) {
+            clearAnimation();
+        }
+
+        super.setVisibility(visibility);
+    }
+
+    @Override
+    public void setAnimation(Animation animation) {
+        // On GB/Froyo, setting the animation after hiding the view causes it
+        // to reappear. As a workaround, disallow setAnimation from being
+        // called if the view is not shown.
+        if (PRE_HONEYCOMB && isShown()) {
+            super.setAnimation(animation);
+        }
+    }
+
+    @Override
     public void onLayout(boolean f, int l, int t, int r, int b) {
         mBounds.left = 0;
         mBounds.right = (r - l) * mCurrentProgress / MAX_PROGRESS;
         mBounds.top = 0;
         mBounds.bottom = b - t;
     }
 
     @Override