Bug 1054371 - Part 3: Ged rid of separate paint instance for private mode (r=mcomella)
authorLucas Rocha <lucasr@mozilla.com>
Thu, 21 Aug 2014 17:14:27 +0100
changeset 200832 5a6f622fbc202dcd7ba651827cf7afcba06bfebf
parent 200831 772202e2424d62bd7d7330323ddc05a6460d584b
child 200833 32dc1b927463603620de3868dff7de0a55906aee
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmcomella
bugs1054371
milestone34.0a1
Bug 1054371 - Part 3: Ged rid of separate paint instance for private mode (r=mcomella)
mobile/android/base/toolbar/BackButton.java
mobile/android/base/toolbar/ForwardButton.java
--- a/mobile/android/base/toolbar/BackButton.java
+++ b/mobile/android/base/toolbar/BackButton.java
@@ -15,37 +15,40 @@ import android.graphics.Shader;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.StateListDrawable;
 import android.util.AttributeSet;
 
 public class BackButton extends ShapedButton { 
     private Path mPath;
     private Path mBorderPath;
     private Paint mBorderPaint;
-    private Paint mBorderPrivatePaint;
     private final float mBorderWidth;
 
     public BackButton(Context context, AttributeSet attrs) {
         super(context, attrs);
 
         mBorderWidth = getResources().getDimension(R.dimen.nav_button_border_width);
 
         // Paint to draw the border.
         mBorderPaint = new Paint();
         mBorderPaint.setAntiAlias(true);
-        mBorderPaint.setColor(0xFFB5B5B5);
         mBorderPaint.setStrokeWidth(mBorderWidth);
         mBorderPaint.setStyle(Paint.Style.STROKE);
 
-        mBorderPrivatePaint = new Paint(mBorderPaint);
-        mBorderPrivatePaint.setColor(0xFF363B40);
-
         // Path is masked.
         mPath = new Path();
         mBorderPath = new Path();
+
+        setPrivateMode(false);
+    }
+
+    @Override
+    public void setPrivateMode(boolean isPrivate) {
+        super.setPrivateMode(isPrivate);
+        mBorderPaint.setColor(isPrivate ? 0xFF363B40 : 0xFFB5B5B5);
     }
 
     @Override
     protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
         super.onSizeChanged(width, height, oldWidth, oldHeight);
 
         mPath.reset();
         mPath.addCircle(width/2, height/2, width/2 - mBorderWidth, Path.Direction.CW);
@@ -54,17 +57,17 @@ public class BackButton extends ShapedBu
         mBorderPath.addCircle(width/2, height/2, (width/2) - mBorderWidth, Path.Direction.CW);
     }
 
     @Override
     public void draw(Canvas canvas) {
         mCanvasDelegate.draw(canvas, mPath, getWidth(), getHeight());
 
         // Draw the border on top.
-        canvas.drawPath(mBorderPath, isPrivateMode() ? mBorderPrivatePaint : mBorderPaint);
+        canvas.drawPath(mBorderPath, mBorderPaint);
     }
 
     // The drawable is constructed as per @drawable/url_bar_nav_button.
     @Override
     public void onLightweightThemeChanged() {
         final Drawable drawable = mTheme.getDrawable(this);
         if (drawable == null)
             return;
--- a/mobile/android/base/toolbar/ForwardButton.java
+++ b/mobile/android/base/toolbar/ForwardButton.java
@@ -14,52 +14,55 @@ import android.graphics.Path;
 import android.graphics.Shader;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.StateListDrawable;
 import android.util.AttributeSet;
 
 public class ForwardButton extends ShapedButton { 
     private Path mBorderPath;
     private Paint mBorderPaint;
-    private Paint mBorderPrivatePaint;
     private final float mBorderWidth;
 
     public ForwardButton(Context context, AttributeSet attrs) {
         super(context, attrs);
 
         mBorderWidth = getResources().getDimension(R.dimen.nav_button_border_width);
 
         // Paint to draw the border.
         mBorderPaint = new Paint();
         mBorderPaint.setAntiAlias(true);
-        mBorderPaint.setColor(0xFFB5B5B5);
         mBorderPaint.setStrokeWidth(mBorderWidth);
         mBorderPaint.setStyle(Paint.Style.STROKE);
 
-        mBorderPrivatePaint = new Paint(mBorderPaint);
-        mBorderPrivatePaint.setColor(0xFF363B40);
+        mBorderPath = new Path();
+
+        setPrivateMode(false);
+    }
 
-        mBorderPath = new Path();
+    @Override
+    public void setPrivateMode(boolean isPrivate) {
+        super.setPrivateMode(isPrivate);
+        mBorderPaint.setColor(isPrivate ? 0xFF363B40 : 0xFFBFBFBF);
     }
 
     @Override
     protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
         super.onSizeChanged(width, height, oldWidth, oldHeight);
 
         mBorderPath.reset();
         mBorderPath.moveTo(width - mBorderWidth, 0);
         mBorderPath.lineTo(width - mBorderWidth, height);
     }
 
     @Override
     public void draw(Canvas canvas) {
         super.draw(canvas);
 
         // Draw the border on top.
-        canvas.drawPath(mBorderPath, isPrivateMode() ? mBorderPrivatePaint : mBorderPaint);
+        canvas.drawPath(mBorderPath, mBorderPaint);
     }
 
     // The drawable is constructed as per @drawable/url_bar_nav_button.
     @Override
     public void onLightweightThemeChanged() {
         final Drawable drawable = mTheme.getDrawable(this);
         if (drawable == null)
             return;