Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Part ways from the use of deprecated parameters of Region.Op class.
Browse files Browse the repository at this point in the history
- LEARNER-7662
- Using Region.Op.DIFFERENCE instead of Region.Op.XOR now because in our
case it is giving the same results in clipping.
  • Loading branch information
farhan committed Mar 2, 2020
1 parent b5cf07c commit bf99bf7
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.os.Build;
import android.support.annotation.NonNull;
import android.util.AttributeSet;

Expand Down Expand Up @@ -108,7 +109,13 @@ protected void onDraw(Canvas canvas) {
mRectF.set((float) canvas.getWidth() / 2 - radius, (float) canvas.getHeight() / 2 - radius, (float) canvas.getWidth() / 2 + radius, (float) canvas.getHeight() / 2 + radius);
circleSelectionPath.reset();
circleSelectionPath.addOval(mRectF, Path.Direction.CW);
canvas.clipPath(circleSelectionPath, Region.Op.XOR);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
canvas.clipOutPath(circleSelectionPath);
} else {
canvas.clipPath(circleSelectionPath, Region.Op.XOR);
}

canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), backgroundPaint);
// Canvas did not save and called restore due to which app crashes, so we have to save first then call restore
canvas.save();
Expand Down

0 comments on commit bf99bf7

Please sign in to comment.