Bug 864958 - Tint the progress bar in private browsing mode. r=mhaigh
authorMichael Comella <michael.l.comella@gmail.com>
Thu, 25 Jun 2015 14:00:15 -0700
changeset 268453 7ca978706f30f459f9df8724b670f9ff18d3a15a
parent 268452 d11dd076d026b89ec71fc576e3e490960d01fb22
child 268454 1f597787c8d0bde5e2b0da6f56a4ed8daf1ca85a
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-esr52@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhaigh
bugs864958
milestone41.0a1
Bug 864958 - Tint the progress bar in private browsing mode. r=mhaigh Note: the tinted view is only a single color while the original asset contains gradients.
mobile/android/base/BrowserApp.java
mobile/android/base/toolbar/ToolbarProgressView.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -472,16 +472,18 @@ public class BrowserApp extends GeckoApp
             case LOCATION_CHANGE:
                 // fall through
             case SELECTED:
                 if (Tabs.getInstance().isSelectedTab(tab)) {
                     updateHomePagerForTab(tab);
                 }
 
                 mHideDynamicToolbarOnActionModeEnd = false;
+
+                mProgressView.setPrivateMode(tab.isPrivate());
                 break;
             case START:
                 if (Tabs.getInstance().isSelectedTab(tab)) {
                     invalidateOptionsMenu();
 
                     if (mDynamicToolbar.isEnabled()) {
                         mDynamicToolbar.setVisible(true, VisibilityTransition.ANIMATE);
                     }
--- a/mobile/android/base/toolbar/ToolbarProgressView.java
+++ b/mobile/android/base/toolbar/ToolbarProgressView.java
@@ -12,67 +12,70 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.mozilla.gecko.toolbar;
 
 import org.mozilla.gecko.AppConstants.Versions;
+import org.mozilla.gecko.R;
+import org.mozilla.gecko.widget.ThemedImageView;
 
 import android.content.Context;
 import android.graphics.Canvas;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.os.Handler;
 import android.os.Message;
 import android.util.AttributeSet;
 import android.view.View;
 import android.view.animation.Animation;
-import android.widget.ImageView;
 
 /**
  * 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 {
+public class ToolbarProgressView extends ThemedImageView {
     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 int mTargetProgress;
     private int mIncrement;
     private Rect mBounds;
     private Handler mHandler;
     private int mCurrentProgress;
 
+    private PorterDuffColorFilter mPrivateBrowsingColorFilter;
+
     public ToolbarProgressView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         init(context);
     }
 
     public ToolbarProgressView(Context context, AttributeSet attrs) {
         super(context, attrs);
         init(context);
     }
 
-    public ToolbarProgressView(Context context) {
-        super(context);
-        init(context);
-    }
-
     private void init(Context ctx) {
         mBounds = new Rect(0,0,0,0);
         mTargetProgress = 0;
 
+        mPrivateBrowsingColorFilter =
+                new PorterDuffColorFilter(R.color.private_browsing_purple, PorterDuff.Mode.SRC_IN);
+
         mHandler = new Handler() {
             @Override
             public void handleMessage(Message msg) {
                 switch (msg.what) {
                     case MSG_UPDATE:
                         mCurrentProgress = Math.min(mTargetProgress, mCurrentProgress + mIncrement);
 
                         updateBounds();
@@ -181,9 +184,21 @@ public class ToolbarProgressView extends
 
         return progressPercentage * MAX_PROGRESS / 100;
     }
 
     private void updateBounds() {
         mBounds.right = getWidth() * mCurrentProgress / MAX_PROGRESS;
         invalidate();
     }
+
+    @Override
+    public void setPrivateMode(final boolean isPrivate) {
+        super.setPrivateMode(isPrivate);
+
+        // Note: android:tint is better but ColorStateLists are not supported until API 21.
+        if (isPrivate) {
+            setColorFilter(mPrivateBrowsingColorFilter);
+        } else {
+            clearColorFilter();
+        }
+    }
 }