use of android.graphics.Canvas in project ShowcaseView by amlcurran.
the class StandardShowcaseDrawer method drawShowcase.
@Override
public void drawShowcase(Bitmap buffer, float x, float y, float scaleMultiplier) {
Canvas bufferCanvas = new Canvas(buffer);
bufferCanvas.drawCircle(x, y, showcaseRadius, eraserPaint);
int halfW = getShowcaseWidth() / 2;
int halfH = getShowcaseHeight() / 2;
int left = (int) (x - halfW);
int top = (int) (y - halfH);
showcaseDrawable.setBounds(left, top, left + getShowcaseWidth(), top + getShowcaseHeight());
showcaseDrawable.draw(bufferCanvas);
}
use of android.graphics.Canvas in project iosched by google.
the class BezelImageView method onDraw.
@Override
protected void onDraw(Canvas canvas) {
if (mBounds == null) {
return;
}
int width = mBounds.width();
int height = mBounds.height();
if (width == 0 || height == 0) {
return;
}
if (!mCacheValid || width != mCachedWidth || height != mCachedHeight) {
// Need to redraw the cache.
if (width == mCachedWidth && height == mCachedHeight) {
// Have a correct-sized bitmap cache already allocated. Just erase it.
mCacheBitmap.eraseColor(0);
} else {
// Allocate a new bitmap with the correct dimensions.
mCacheBitmap.recycle();
//noinspection AndroidLintDrawAllocation
mCacheBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
mCachedWidth = width;
mCachedHeight = height;
}
Canvas cacheCanvas = new Canvas(mCacheBitmap);
if (mMaskDrawable != null) {
int sc = cacheCanvas.save();
mMaskDrawable.draw(cacheCanvas);
mMaskedPaint.setColorFilter((mDesaturateOnPress && isPressed()) ? mDesaturateColorFilter : null);
cacheCanvas.saveLayer(mBoundsF, mMaskedPaint, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
super.onDraw(cacheCanvas);
cacheCanvas.restoreToCount(sc);
} else if (mDesaturateOnPress && isPressed()) {
int sc = cacheCanvas.save();
cacheCanvas.drawRect(0, 0, mCachedWidth, mCachedHeight, mBlackPaint);
mMaskedPaint.setColorFilter(mDesaturateColorFilter);
cacheCanvas.saveLayer(mBoundsF, mMaskedPaint, Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.FULL_COLOR_LAYER_SAVE_FLAG);
super.onDraw(cacheCanvas);
cacheCanvas.restoreToCount(sc);
} else {
super.onDraw(cacheCanvas);
}
if (mBorderDrawable != null) {
mBorderDrawable.draw(cacheCanvas);
}
}
// Draw from cache.
canvas.drawBitmap(mCacheBitmap, mBounds.left, mBounds.top, null);
}
use of android.graphics.Canvas in project iosched by google.
the class UIUtils method vectorToBitmap.
public static Bitmap vectorToBitmap(@NonNull Context context, @DrawableRes int drawableResId) {
VectorDrawableCompat vector = VectorDrawableCompat.create(context.getResources(), drawableResId, context.getTheme());
final Bitmap bitmap = Bitmap.createBitmap(vector.getIntrinsicWidth(), vector.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
vector.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
vector.draw(canvas);
return bitmap;
}
use of android.graphics.Canvas in project android-maps-utils by googlemaps.
the class IconGenerator method makeIcon.
/**
* Creates an icon with the current content and style.
* <p/>
* This method is useful if a custom view has previously been set, or if text content is not
* applicable.
*/
public Bitmap makeIcon() {
int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
mContainer.measure(measureSpec, measureSpec);
int measuredWidth = mContainer.getMeasuredWidth();
int measuredHeight = mContainer.getMeasuredHeight();
mContainer.layout(0, 0, measuredWidth, measuredHeight);
if (mRotation == 1 || mRotation == 3) {
measuredHeight = mContainer.getMeasuredWidth();
measuredWidth = mContainer.getMeasuredHeight();
}
Bitmap r = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
r.eraseColor(Color.TRANSPARENT);
Canvas canvas = new Canvas(r);
if (mRotation == 0) {
// do nothing
} else if (mRotation == 1) {
canvas.translate(measuredWidth, 0);
canvas.rotate(90);
} else if (mRotation == 2) {
canvas.rotate(180, measuredWidth / 2, measuredHeight / 2);
} else {
canvas.translate(0, measuredHeight);
canvas.rotate(270);
}
mContainer.draw(canvas);
return r;
}
use of android.graphics.Canvas in project gdk-compass-sample by googleglass.
the class CompassRenderer method repaint.
/**
* Repaints the compass.
*/
private synchronized void repaint() {
Canvas canvas = null;
try {
canvas = mHolder.lockCanvas();
} catch (RuntimeException e) {
Log.d(TAG, "lockCanvas failed", e);
}
if (canvas != null) {
canvas.drawColor(Color.BLACK);
mLayout.draw(canvas);
try {
mHolder.unlockCanvasAndPost(canvas);
} catch (RuntimeException e) {
Log.d(TAG, "unlockCanvasAndPost failed", e);
}
}
}
Aggregations