public static Bitmap drawableToBitmap (Drawable drawable) { Bitmap bitmap = null; if (drawable instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; if(bitmapDrawable.getBitmap() != null) { return bitmapDrawable.getBitmap(); } } if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; }
int bottom = top + divider.getIntrinsicHeight(); divider.setBounds(left, top, right, bottom); divider.draw(c);
public static void drawRightAlignItem(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) { final int top = child.getTop() - params.topMargin; final int bottom = child.getBottom() + params.bottomMargin; final int left = child.getRight() + params.rightMargin; final int right = left + drawable.getIntrinsicWidth(); drawable.setBounds(left, top, right, bottom); drawable.draw(canvas); }
void drawTintedTarget() { final Drawable icon = target.icon; if (!shouldTintTarget || icon == null) { tintedTarget = null; return; } if (tintedTarget != null) return; tintedTarget = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(tintedTarget); icon.setColorFilter(new PorterDuffColorFilter( outerCirclePaint.getColor(), PorterDuff.Mode.SRC_ATOP)); icon.draw(canvas); icon.setColorFilter(null); }
public static Bitmap drawableToBitmap (Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable)drawable).getBitmap(); } int width = drawable.getIntrinsicWidth(); width = width > 0 ? width : 1; int height = drawable.getIntrinsicHeight(); height = height > 0 ? height : 1; Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; }
public static void drawBottomAlignItem(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) { final int left = child.getLeft() - params.leftMargin; final int right = child.getRight() + params.rightMargin; final int top = child.getBottom() + params.bottomMargin; final int bottom = top + drawable.getIntrinsicHeight(); drawable.setBounds(left, top, right, bottom); drawable.draw(canvas); }
int px = getResources().getDimensionPixelSize(R.dimen.map_dot_marker_size); mDotMarkerBitmap = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(mDotMarkerBitmap); Drawable shape = getResources().getDrawable(R.drawable.map_dot_red); shape.setBounds(0, 0, mDotMarkerBitmap.getWidth(), mDotMarkerBitmap.getHeight()); shape.draw(canvas);
public static void drawLeftAlignItem(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) { final int top = child.getTop() - params.topMargin; final int bottom = child.getBottom() + params.bottomMargin; final int left = child.getLeft() - params.leftMargin - drawable.getIntrinsicWidth(); final int right = left + drawable.getIntrinsicWidth(); drawable.setBounds(left, top, right, bottom); drawable.draw(canvas); }
/** * @return the original Bitmap source that will be drawn as a circular image */ @Nullable private Bitmap getBitmapForView() { Drawable drawable = getDrawable(); if (drawable == null) { return null; } if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } else { int w = drawable.getIntrinsicWidth(); int h = drawable.getIntrinsicHeight(); Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); drawable.draw(new Canvas(bm)); return bm; } }
public static void drawRight(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) { final int top = child.getTop() - params.topMargin - drawable.getIntrinsicHeight(); final int bottom = child.getBottom() + params.bottomMargin + drawable.getIntrinsicHeight(); final int left = child.getRight() + params.rightMargin; final int right = left + drawable.getIntrinsicWidth(); drawable.setBounds(left, top, right, bottom); drawable.draw(canvas); }
public void drawVertical(Canvas c, RecyclerView parent) { final int left = parent.getPaddingLeft(); final int right = parent.getWidth() - parent.getPaddingRight(); final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child .getLayoutParams(); final int top = child.getBottom() + params.bottomMargin; final int bottom = top + mDivider.getIntrinsicHeight(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } }
void drawOverscrollHeader(Canvas canvas, Drawable drawable, Rect bounds) { final int height = drawable.getMinimumHeight(); canvas.save(); canvas.clipRect(bounds); final int span = bounds.bottom - bounds.top; if (span < height) { bounds.top = bounds.bottom - height; } drawable.setBounds(bounds); drawable.draw(canvas); canvas.restore(); }
public void drawVertical(Canvas c, RecyclerView parent) { final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child .getLayoutParams(); final int top = child.getTop() - params.topMargin; final int bottom = child.getBottom() + params.bottomMargin; final int left = child.getRight() + params.rightMargin; final int right = left + mDivider.getIntrinsicWidth(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } }
public static void drawBottom(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) { final int left = child.getLeft() - params.leftMargin - drawable.getIntrinsicWidth(); final int right = child.getRight() + params.rightMargin + drawable.getIntrinsicWidth(); final int top = child.getBottom() + params.bottomMargin; final int bottom = top + drawable.getIntrinsicHeight(); drawable.setBounds(left, top, right, bottom); drawable.draw(canvas); }
public static void drawTopAlignItem(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) { final int left = child.getLeft() - params.leftMargin; final int right = child.getRight() + params.rightMargin; final int top = child.getTop() - params.topMargin - drawable.getIntrinsicHeight(); final int bottom = top + drawable.getIntrinsicHeight(); drawable.setBounds(left, top, right, bottom); drawable.draw(canvas); }
void drawOverscrollFooter(Canvas canvas, Drawable drawable, Rect bounds) { final int height = drawable.getMinimumHeight(); canvas.save(); canvas.clipRect(bounds); final int span = bounds.bottom - bounds.top; if (span < height) { bounds.bottom = bounds.top + height; } drawable.setBounds(bounds); drawable.draw(canvas); canvas.restore(); }
public void drawVertical(Canvas c, RecyclerView parent) { final int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { final View child = parent.getChildAt(i); final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child .getLayoutParams(); final int top = child.getTop() - params.topMargin; final int bottom = child.getBottom() + params.bottomMargin; final int left = child.getRight() + params.rightMargin; final int right = left + mDivider.getIntrinsicWidth(); mDivider.setBounds(left, top, right, bottom); mDivider.draw(c); } }
public static void drawLeft(Canvas canvas, Drawable drawable, View child, ViewGroup.MarginLayoutParams params) { final int top = child.getTop() - params.topMargin - drawable.getIntrinsicHeight(); final int bottom = child.getBottom() + params.bottomMargin + drawable.getIntrinsicHeight(); final int left = child.getLeft() - params.leftMargin - drawable.getIntrinsicWidth(); final int right = left + drawable.getIntrinsicWidth(); drawable.setBounds(left, top, right, bottom); drawable.draw(canvas); }
@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { int left=parent.getPaddingLeft(); int right=parent.getWidth()-parent.getPaddingRight(); int childCount=parent.getChildCount(); for (int i=0; i<childCount-1; i++) { View child=parent.getChildAt(i); RecyclerView.LayoutParams params= (RecyclerView.LayoutParams)child.getLayoutParams(); int top=child.getBottom()+params.bottomMargin; int bottom=top+divider.getIntrinsicHeight(); divider.setBounds(left, top, right, bottom); divider.draw(c); } } }