If you think the Android project Calma listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.espian.showcaseview.drawing;
/*www.java2s.com*/import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.Log;
import com.github.espiandev.showcaseview.R;
/**
* Created by curraa01 on 13/10/2013.
*/publicclass ClingDrawerImpl implements ClingDrawer {
private Paint mEraser;
private Drawable mShowcaseDrawable;
private Rect mShowcaseRect;
public ClingDrawerImpl(Resources resources, int showcaseColor) {
PorterDuffXfermode mBlender = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
mEraser = new Paint();
mEraser.setColor(0xFFFFFF);
mEraser.setAlpha(0);
mEraser.setXfermode(mBlender);
mEraser.setAntiAlias(true);
mShowcaseDrawable = resources.getDrawable(R.drawable.cling_bleached);
mShowcaseDrawable.setColorFilter(showcaseColor, PorterDuff.Mode.MULTIPLY);
}
@Override
publicvoid drawShowcase(Canvas canvas, float x, float y, float scaleMultiplier, float radius) {
Matrix mm = new Matrix();
mm.postScale(scaleMultiplier, scaleMultiplier, x, y);
canvas.setMatrix(mm);
canvas.drawCircle(x, y, radius, mEraser);
mShowcaseDrawable.setBounds(mShowcaseRect);
mShowcaseDrawable.draw(canvas);
canvas.setMatrix(new Matrix());
}
@Override
publicint getShowcaseWidth() {
return mShowcaseDrawable.getIntrinsicWidth();
}
@Override
publicint getShowcaseHeight() {
return mShowcaseDrawable.getIntrinsicHeight();
}
/**
* Creates a {@link android.graphics.Rect} which represents the area the showcase covers. Used
* to calculate where best to place the text
*
* @return true if voidedArea has changed, false otherwise.
*/publicboolean calculateShowcaseRect(float x, float y) {
if (mShowcaseRect == null) {
mShowcaseRect = new Rect();
}
int cx = (int) x, cy = (int) y;
int dw = getShowcaseWidth();
int dh = getShowcaseHeight();
if (mShowcaseRect.left == cx - dw / 2) {
return false;
}
Log.d("ShowcaseView", "Recalculated");
mShowcaseRect.left = cx - dw / 2;
mShowcaseRect.top = cy - dh / 2;
mShowcaseRect.right = cx + dw / 2;
mShowcaseRect.bottom = cy + dh / 2;
return true;
}
@Override
public Rect getShowcaseRect() {
return mShowcaseRect;
}
}