Bug 1054371 - Part 2: Only fetch border width once in back/forward buttons (r=mcomella)
--- 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);