Skip to content

Commit

Permalink
some perf improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
connyduck committed Jul 20, 2018
1 parent 2b631b4 commit d97dc44
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ void init() {
circleView.setLayoutParams(circleViewLayoutParams);

circleView.setColors(secondaryColor, primaryColor);
circleView.getLayoutParams().height = circleSize;
circleView.getLayoutParams().width = circleSize;

addView(circleView);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import android.animation.ArgbEvaluator;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
Expand All @@ -36,9 +35,6 @@ public class CircleView extends View {
private Paint circlePaint = new Paint();
private Paint maskPaint = new Paint();

private Bitmap tempBitmap;
private Canvas tempCanvas;

private float outerCircleRadiusProgress = 0f;
private float innerCircleRadiusProgress = 0f;

Expand Down Expand Up @@ -66,28 +62,23 @@ public CircleView(Context context, AttributeSet attrs, int defStyleAttr, int def
}

private void init() {
setLayerType(View.LAYER_TYPE_HARDWARE, null);
circlePaint.setStyle(Paint.Style.FILL);
circlePaint.setAntiAlias(true);
maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
maskPaint.setAntiAlias(true);

}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
maxCircleSize = w / 2;
tempBitmap = Bitmap.createBitmap(getWidth(), getWidth(), Bitmap.Config.ARGB_8888);
tempCanvas = new Canvas(tempBitmap);
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
tempCanvas.drawColor(0xffffff, PorterDuff.Mode.CLEAR);
tempCanvas.drawCircle(getWidth() / 2, getHeight() / 2, outerCircleRadiusProgress * maxCircleSize, circlePaint);
tempCanvas.drawCircle(getWidth() / 2, getHeight() / 2, innerCircleRadiusProgress * (maxCircleSize+1), maskPaint);
canvas.drawBitmap(tempBitmap, 0, 0, null);
canvas.drawCircle(getWidth() / 2, getHeight() / 2, outerCircleRadiusProgress * maxCircleSize, circlePaint);
canvas.drawCircle(getWidth() / 2, getHeight() / 2, innerCircleRadiusProgress * (maxCircleSize+1), maskPaint);
}

public void setColors(int startColor, int endColor) {
Expand Down

0 comments on commit d97dc44

Please sign in to comment.