Skip to content

Commit

Permalink
fix an API15 issue where inflating crossview inside an action bar men…
Browse files Browse the repository at this point in the history
…u item would fail with a null pointer exception on the local variable mPaint
  • Loading branch information
Collin Flynn authored and Collin Flynn committed May 12, 2015
1 parent e36928b commit 64b2ab7
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class CrossView extends View {
private float mArcLengthLeft;
private float mArcLengthRight;

private Paint mPaint = new Paint();
private Paint mPaint;
private int mColor = DEFAULT_COLOR;
private RectF mRect;
private PathMeasure mPathMeasure;
Expand Down Expand Up @@ -169,11 +169,13 @@ public void setPaddingRelative(int start, int top, int end, int bottom) {

public void setColor(int argb) {
mColor = argb;
if (mPaint == null) {
mPaint = new Paint();
}
mPaint.setColor(argb);
invalidate();
}


/**
* Tell this view to switch states from cross to plus, or back, using the default animation duration.
* @return an integer flag that represents the new state after toggling.
Expand Down Expand Up @@ -253,6 +255,7 @@ private void setPercent(float percent) {
* or an operating system callback like {@link #onLayout(boolean, int, int, int, int)}.
*/
private void init() {
mPaint = new Paint();
mRect = new RectF();
mRect.left = getPaddingLeft();
mRect.right = getWidth() - getPaddingRight();
Expand Down

0 comments on commit 64b2ab7

Please sign in to comment.