Created
January 2, 2016 13:37
-
-
Save xiprox/6026aed4d8b1e3a995f1 to your computer and use it in GitHub Desktop.
A ShowcaseDrawer that draws showcase circle with the greater side of a view divided by 2 as its radius value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.res.Resources; | |
import android.graphics.Bitmap; | |
import android.graphics.Canvas; | |
import android.graphics.Paint; | |
import android.graphics.PorterDuff; | |
import android.graphics.PorterDuffXfermode; | |
import android.view.View; | |
import com.github.amlcurran.showcaseview.MaterialShowcaseDrawer; | |
/** | |
* A {@link com.github.amlcurran.showcaseview.ShowcaseDrawer} that draws showcase circle with the | |
* greater side of a view divided by 2 as its radius value. | |
*/ | |
public class ViewBasedRadiusShowcaseDrawer extends MaterialShowcaseDrawer { | |
private float mRadius; | |
private Paint mEraserPaint; | |
public ViewBasedRadiusShowcaseDrawer(Resources resources, View view) { | |
super(resources); | |
mRadius = Math.max(view.getHeight(), view.getWidth()) / 2; | |
mEraserPaint = new Paint(); | |
mEraserPaint.setColor(0xFFFFFF); | |
mEraserPaint.setAlpha(0); | |
mEraserPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY)); | |
mEraserPaint.setAntiAlias(true); | |
} | |
@Override | |
public void drawShowcase(Bitmap buffer, float x, float y, float scaleMultiplier) { | |
Canvas bufferCanvas = new Canvas(buffer); | |
bufferCanvas.drawCircle(x, y, mRadius, mEraserPaint); | |
} | |
@Override | |
public int getShowcaseWidth() { | |
return (int) (mRadius * 2); | |
} | |
@Override | |
public int getShowcaseHeight() { | |
return (int) (mRadius * 2); | |
} | |
@Override | |
public float getBlockedRadius() { | |
return mRadius; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment