List of usage examples for android.graphics.drawable Drawable draw
public abstract void draw(@NonNull Canvas canvas);
From source file:com.google.samples.apps.topeka.widget.AvatarView.java
@Override protected void onDraw(@NonNull Canvas canvas) { super.onDraw(canvas); if (mChecked) { Drawable border = ContextCompat.getDrawable(getContext(), R.drawable.selector_avatar); border.setBounds(0, 0, getWidth(), getHeight()); border.draw(canvas); }//from w ww .ja v a 2s . c o m }
From source file:de.geeksfactory.opacclient.ui.AccountDividerItemDecoration.java
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { 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.ViewHolder vh = parent.getChildViewHolder(child); if (!isDecorated(child, parent)) continue; if (!(vh instanceof AccountAdapter.ViewHolder)) continue; final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); final int top = child.getBottom() + params.bottomMargin; final Drawable drawable = (((AccountAdapter.ViewHolder) vh).isCoversHidden() ? mDividerWithoutInset : mDividerWithInset);/*from w ww. j a v a2 s .c om*/ final int bottom = top + drawable.getIntrinsicHeight(); drawable.setBounds(left, top, right, bottom); drawable.draw(c); } }
From source file:de.bahnhoefe.deutschlands.bahnhofsfotos.notification.NearbyBahnhofWithPhotoNotificationManager.java
/** * Construct a Bitmap object from a given drawable resource ID. * * @param id the resource ID denoting a drawable resource * @return the Bitmap. May be null./*w w w . j ava 2 s. com*/ */ @Nullable private Bitmap getBitmapFromResource(int id) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Drawable vectorDrawable = context.getDrawable(id); int h = 400; int w = 400; vectorDrawable.setBounds(0, 0, w, h); Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bm); canvas.drawColor(Color.WHITE); vectorDrawable.draw(canvas); return bm; } else return null; }
From source file:com.silentcircle.contacts.calllognew.CallTypeIconsView.java
@Override protected void onDraw(Canvas canvas) { int left = 0; for (Integer callType : mCallTypes) { final Drawable drawable = getCallTypeDrawable(callType); final int right = left + drawable.getIntrinsicWidth(); drawable.setBounds(left, 0, right, drawable.getIntrinsicHeight()); drawable.draw(canvas); left = right + mResources.iconMargin; }//from w ww. ja va 2s. c o m // If showing the video call icon, draw it scaled appropriately. // if (mShowVideo) { // final Drawable drawable = mResources.videoCall; // final int right = left + mResources.videoCall.getIntrinsicWidth(); // drawable.setBounds(left, 0, right, mResources.videoCall.getIntrinsicHeight()); // drawable.draw(canvas); // } }
From source file:com.freshdigitable.udonroad.MediaImageView.java
public MediaImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setContentDescription(getResources().getString(R.string.tweet_media_descs)); setVisibility(GONE);//from w ww.j av a2s .c o m if (playIcon == null) { final Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.ld_play_icon); playIcon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(playIcon); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); } }
From source file:com.jaspersoft.android.jaspermobile.util.resource.viewbinder.CustomBitmapProcessor.java
public Bitmap convertToBitmap(Drawable drawable) { int widthPixels = drawable.getIntrinsicWidth(); int heightPixels = drawable.getIntrinsicHeight(); Bitmap mutableBitmap = Bitmap.createBitmap(widthPixels, heightPixels, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(mutableBitmap); drawable.setBounds(0, 0, widthPixels, heightPixels); drawable.draw(canvas); return mutableBitmap; }
From source file:lewa.support.v7.internal.widget.ListViewCompat.java
protected void drawSelectorCompat(Canvas canvas) { if (!mSelectorRect.isEmpty()) { final Drawable selector = getSelector(); selector.setBounds(mSelectorRect); selector.draw(canvas); }//w ww. j av a 2s .com }
From source file:com.creationgroundmedia.nytimessearch.adapters.ArticlesAdapter.java
private Bitmap bitmapFromResource(int resId) { Drawable sendIcon = ContextCompat.getDrawable(mContext, resId); Bitmap bitmap = Bitmap.createBitmap(sendIcon.getIntrinsicWidth(), sendIcon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);//from ww w. j ava 2 s .c o m Canvas canvas = new Canvas(bitmap); sendIcon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); sendIcon.draw(canvas); return bitmap; }
From source file:com.maxleap.mall.widget.FlexibleDividerDecoration.java
@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { int lastChildPosition = -1; int childCount = mShowLastDivider ? parent.getChildCount() : parent.getChildCount() - 1; for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); int childPosition = parent.getChildAdapterPosition(child); if (childPosition < lastChildPosition) { // Avoid remaining divider when animation starts continue; }//ww w. j a v a 2 s . co m lastChildPosition = childPosition; if (ViewCompat.getAlpha(child) < 1) { // Avoid remaining divider when animation starts continue; } if (mVisibilityProvider.shouldHideDivider(childPosition, parent)) { continue; } Rect bounds = getDividerBound(childPosition, parent, child); switch (mDividerType) { case DRAWABLE: Drawable drawable = mDrawableProvider.drawableProvider(childPosition, parent); drawable.setBounds(bounds); drawable.draw(c); break; case PAINT: mPaint = mPaintProvider.dividerPaint(childPosition, parent); c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint); break; case COLOR: mPaint.setColor(mColorProvider.dividerColor(childPosition, parent)); mPaint.setStrokeWidth(mSizeProvider.dividerSize(childPosition, parent)); c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint); break; } } }
From source file:com.s8launch.cheil.facetracker.MultiTrackerActivity.java
public Bitmap getBitmapFromView(View view) { view.setBackgroundColor(Color.TRANSPARENT); //Define a bitmap with the same size as the view Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); //Bind a canvas to it Canvas canvas = new Canvas(returnedBitmap); //Get the view's background Drawable bgDrawable = view.getBackground(); if (bgDrawable != null) //has background drawable, then draw it on the canvas bgDrawable.draw(canvas); else//www .jav a 2s. c om //does not have background drawable, then draw white background on the canvas canvas.drawColor(Color.WHITE); // draw the view on the canvas view.draw(canvas); //return the bitmap return returnedBitmap; }