Bug 1054371 - Part 2: Only fetch border width once in back/forward buttons (r=mcomella)
authorLucas Rocha <lucasr@mozilla.com>
Thu, 21 Aug 2014 17:14:26 +0100
changeset 200831 772202e2424d62bd7d7330323ddc05a6460d584b
parent 200830 4f7230c805113a7cb17ee158e54bbef45502c76c
child 200832 5a6f622fbc202dcd7ba651827cf7afcba06bfebf
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmcomella
bugs1054371
milestone34.0a1
Bug 1054371 - Part 2: Only fetch border width once in back/forward buttons (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
@@ -16,47 +16,47 @@ import android.graphics.drawable.Drawabl
 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();
     }
 
     @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, Path.Direction.CW);
-
-        float borderWidth = getContext().getResources().getDimension(R.dimen.nav_button_border_width);
-        mBorderPaint.setStrokeWidth(borderWidth);
-        mBorderPrivatePaint.setStrokeWidth(borderWidth);
+        mPath.addCircle(width/2, height/2, width/2 - mBorderWidth, Path.Direction.CW);
 
         mBorderPath.reset();
-        mBorderPath.addCircle(width/2, height/2, (width/2) - borderWidth, Path.Direction.CW);
+        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);
--- a/mobile/android/base/toolbar/ForwardButton.java
+++ b/mobile/android/base/toolbar/ForwardButton.java
@@ -15,43 +15,43 @@ 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();
     }
 
     @Override
     protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
         super.onSizeChanged(width, height, oldWidth, oldHeight);
 
-        float borderWidth = getContext().getResources().getDimension(R.dimen.nav_button_border_width);
-        mBorderPaint.setStrokeWidth(borderWidth);
-        mBorderPrivatePaint.setStrokeWidth(borderWidth);
-
         mBorderPath.reset();
-        mBorderPath.moveTo(width - borderWidth, 0);
-        mBorderPath.lineTo(width - borderWidth, height);
+        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);