List of usage examples for android.graphics.drawable Drawable draw
public abstract void draw(@NonNull Canvas canvas);
From source file:org.ciasaboark.tacere.manager.NotificationManagerWrapper.java
private Bitmap createMarkerIcon(Drawable backgroundImage, String text, int width, int height) { Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); // Create a canvas, that will draw on to canvasBitmap. Canvas imageCanvas = new Canvas(canvasBitmap); // Draw the image to our canvas backgroundImage.draw(imageCanvas); // Set up the paint for use with our Canvas TextPaint textPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG | TextPaint.LINEAR_TEXT_FLAG); textPaint.setTextAlign(TextPaint.Align.CENTER); textPaint.setTypeface(Typeface.DEFAULT); textPaint.setTextSize(100f);// www .j a v a2s . c o m textPaint.setColor(context.getResources().getColor(android.R.color.white)); int xPos = (imageCanvas.getWidth() / 2); int yPos = (int) ((imageCanvas.getHeight() / 2) - ((textPaint.descent() + textPaint.ascent()) / 2)); Rect r = new Rect(); textPaint.getTextBounds(text, 0, text.length(), r); // yPos += (Math.abs(r.height()))/2; // Draw the text on top of our image imageCanvas.drawText(text, xPos, yPos, textPaint); // Combine background and text to a LayerDrawable LayerDrawable layerDrawable = new LayerDrawable( new Drawable[] { backgroundImage, new BitmapDrawable(canvasBitmap) }); Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); layerDrawable.setBounds(0, 0, width, height); layerDrawable.draw(new Canvas(newBitmap)); return newBitmap; }
From source file:com.handmark.pulltorefresh.library.internal.LoadingLayout.java
private void rotateArrow() { final Drawable drawable = mHeaderArrow.getDrawable(); final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888);//from w w w . j a v a2s . com final Canvas canvas = new Canvas(bitmap); canvas.save(); canvas.rotate(180.0f, canvas.getWidth() / 2.0f, canvas.getHeight() / 2.0f); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); canvas.restore(); mHeaderArrow.setImageBitmap(bitmap); }
From source file:com.iangclifton.auid.horizontaliconview.HorizontalIconView.java
@Override protected void onDraw(Canvas canvas) { if (mDrawables == null || mDrawables.isEmpty()) { return;// w w w. j av a 2 s . c o m } final int width = getWidth(); final int paddingBottom = getPaddingBottom(); final int paddingLeft = getPaddingLeft(); final int paddingTop = getPaddingTop(); // Determine edges of visible content final int leftEdge = getScrollX(); final int rightEdge = leftEdge + width; int left = paddingLeft; int top = paddingTop; mSkippedIconCount = 0; final int iconCount = mDrawables.size(); for (int i = 0; i < iconCount; i++) { if (left + mIconSize < leftEdge) { // Icon is too far left to be seen left = left + mIconSize + mIconSpacing; mSkippedIconCount++; continue; } if (left > rightEdge) { // All remaining icons are right of the view break; } // Get a reference to the icon to be drawn final Drawable icon = mDrawables.get(i); icon.setBounds(left, top, left + mIconSize, top + mIconSize); icon.draw(canvas); // Icon was drawn, so track position final int drawnPosition = i - mSkippedIconCount; if (drawnPosition + 1 > mIconPositions.size()) { final Rect rect = icon.copyBounds(); mIconPositions.add(rect); } else { final Rect rect = mIconPositions.get(drawnPosition); icon.copyBounds(rect); } // Update left position left = left + mIconSize + mIconSpacing; } if (mEdgeEffectLeft != null) { if (!mEdgeEffectLeft.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - paddingTop - paddingBottom; canvas.rotate(270); canvas.translate(-height + paddingTop, Math.min(0, leftEdge)); mEdgeEffectLeft.setSize(height, getWidth()); if (mEdgeEffectLeft.draw(canvas)) { postInvalidateOnAnimation(); } canvas.restoreToCount(restoreCount); } if (!mEdgeEffectRight.isFinished()) { final int restoreCount = canvas.save(); final int height = getHeight() - paddingTop - paddingBottom; canvas.rotate(90); canvas.translate(-paddingTop, -(Math.max(mScrollRange, leftEdge) + width)); mEdgeEffectRight.setSize(height, width); if (mEdgeEffectRight.draw(canvas)) { postInvalidateOnAnimation(); } canvas.restoreToCount(restoreCount); } } }
From source file:com.github.pedrovgs.nox.NoxView.java
/** * Draws a NoxItem drawable during the onDraw method given a canvas object and all the * information needed to draw the Drawable passed as parameter. *//*w ww .j ava2 s .c o m*/ private void drawNoxItemDrawable(Canvas canvas, int left, int top, Drawable drawable) { if (drawable != null) { int itemSize = (int) noxConfig.getNoxItemSize(); drawable.setBounds(left, top, left + itemSize, top + itemSize); drawable.draw(canvas); } }
From source file:com.android.contacts.ShortcutIntentBuilder.java
private Bitmap generateQuickContactIcon(Drawable photo) { // Setup the drawing classes Bitmap bitmap = Bitmap.createBitmap(mIconSize, mIconSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); // Copy in the photo Rect dst = new Rect(0, 0, mIconSize, mIconSize); photo.setBounds(dst);//from ww w . j a va2 s . co m photo.draw(canvas); // Don't put a rounded border on an icon for O if (BuildCompat.isAtLeastO()) { return bitmap; } // Draw the icon with a rounded border RoundedBitmapDrawable roundedDrawable = RoundedBitmapDrawableFactory.create(mResources, bitmap); roundedDrawable.setAntiAlias(true); roundedDrawable.setCornerRadius(mIconSize / 2); Bitmap roundedBitmap = Bitmap.createBitmap(mIconSize, mIconSize, Bitmap.Config.ARGB_8888); canvas.setBitmap(roundedBitmap); roundedDrawable.setBounds(dst); roundedDrawable.draw(canvas); canvas.setBitmap(null); return roundedBitmap; }
From source file:org.totschnig.myexpenses.util.Utils.java
public static Bitmap getTintedBitmapForTheme(Context context, int drawableResId, int themeResId) { Context wrappedContext = new ContextThemeWrapper(context, themeResId); Drawable d = AppCompatDrawableManager.get().getDrawable(wrappedContext, drawableResId); Bitmap b = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); d.setBounds(0, 0, c.getWidth(), c.getHeight()); d.draw(c); return b;//from w w w.j a v a 2 s . com }
From source file:android.support.v7.preference.PreferenceDialogFragmentCompat.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Fragment rawFragment = getTargetFragment(); if (!(rawFragment instanceof DialogPreference.TargetFragment)) { throw new IllegalStateException("Target fragment must implement TargetFragment" + " interface"); }/* w w w .ja v a2 s .c om*/ final DialogPreference.TargetFragment fragment = (DialogPreference.TargetFragment) rawFragment; final String key = getArguments().getString(ARG_KEY); if (savedInstanceState == null) { mPreference = (DialogPreference) fragment.findPreference(key); mDialogTitle = mPreference.getDialogTitle(); mPositiveButtonText = mPreference.getPositiveButtonText(); mNegativeButtonText = mPreference.getNegativeButtonText(); mDialogMessage = mPreference.getDialogMessage(); mDialogLayoutRes = mPreference.getDialogLayoutResource(); final Drawable icon = mPreference.getDialogIcon(); if (icon == null || icon instanceof BitmapDrawable) { mDialogIcon = (BitmapDrawable) icon; } else { final Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bitmap); icon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); icon.draw(canvas); mDialogIcon = new BitmapDrawable(getResources(), bitmap); } } else { mDialogTitle = savedInstanceState.getCharSequence(SAVE_STATE_TITLE); mPositiveButtonText = savedInstanceState.getCharSequence(SAVE_STATE_POSITIVE_TEXT); mNegativeButtonText = savedInstanceState.getCharSequence(SAVE_STATE_NEGATIVE_TEXT); mDialogMessage = savedInstanceState.getCharSequence(SAVE_STATE_MESSAGE); mDialogLayoutRes = savedInstanceState.getInt(SAVE_STATE_LAYOUT, 0); final Bitmap bitmap = savedInstanceState.getParcelable(SAVE_STATE_ICON); if (bitmap != null) { mDialogIcon = new BitmapDrawable(getResources(), bitmap); } } }
From source file:com.github.magiepooh.recycleritemdecoration.HorizontalItemDecoration.java
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { int top = parent.getPaddingTop(); int bottom = parent.getHeight() - parent.getPaddingBottom(); boolean isReverse = ((LinearLayoutManager) parent.getLayoutManager()).getReverseLayout(); int childCount = parent.getChildCount(); for (int i = 0; i <= childCount - 1; i++) { View child = parent.getChildAt(i); int childViewType = parent.getLayoutManager().getItemViewType(child); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); // last position if (isLastPosition(child, parent)) { if (mLastDrawable != null) { int left, right; if (isReverse) { right = child.getLeft() - params.leftMargin; left = right - mLastDrawable.getIntrinsicWidth(); } else { left = child.getRight() + params.rightMargin; right = left + mLastDrawable.getIntrinsicWidth(); }//from ww w .j av a 2s .co m mLastDrawable.setBounds(left, top, right, bottom); mLastDrawable.draw(c); } return; } // specific view type Drawable drawable = mDividerViewTypeMap.get(childViewType); if (drawable != null) { int left, right; if (isReverse) { right = child.getLeft() - params.leftMargin; left = right - drawable.getIntrinsicWidth(); } else { left = child.getRight() + params.rightMargin; right = left + drawable.getIntrinsicWidth(); } drawable.setBounds(left, top, right, bottom); drawable.draw(c); } // first position if (isFirstPosition(child, parent)) { if (mFirstDrawable != null) { int left, right; if (isReverse) { left = child.getRight() + params.rightMargin; right = left + mFirstDrawable.getIntrinsicWidth(); } else { right = child.getLeft() - params.leftMargin; left = right - mFirstDrawable.getIntrinsicWidth(); } mFirstDrawable.setBounds(left, top, right, bottom); mFirstDrawable.draw(c); } } } }
From source file:com.lee.sdk.widget.viewpager.PointPageIndicator.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (null != mViewPager) { if (mViewPager instanceof CircularViewPager) { mPointCount = ((CircularViewPager) mViewPager).getCount(); } else {/*ww w .ja v a2 s.co m*/ mPointCount = mViewPager.getAdapter().getCount(); } } if (mPointCount <= 0) { return; } final int count = mPointCount; final int margin = mPointMargin; final int height = getHeight(); final int width = getWidth(); final int selIndex = mPosition; final Rect normalRc = mNormalPointRect; final Rect selectRc = mSelectPointRect; final Drawable dNormal = mNormalDrawable; final Drawable dSelect = mSelectDrawable; int left = (width - (margin * (count - 1) + normalRc.width() * (count - 1) + selectRc.width())) / 2; int top = 0; for (int index = 0; index < count; ++index) { if (index == selIndex) { if (null != dSelect) { top = (height - selectRc.height()) / 2; selectRc.offsetTo(left, top); dSelect.setBounds(selectRc); dSelect.draw(canvas); } left += (selectRc.width() + margin); } else { if (null != dNormal) { top = (height - normalRc.height()) / 2; normalRc.offsetTo(left, top); dNormal.setBounds(normalRc); dNormal.draw(canvas); } left += (normalRc.width() + margin); } } }
From source file:com.camnter.easyrecyclerviewsidebar.EasyRecyclerViewSidebar.java
private Bitmap drawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) ((BitmapDrawable) drawable).getBitmap(); int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap bitmap = this.createBitmapSafely(width, height, Bitmap.Config.ARGB_8888, 1); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, width, height); drawable.draw(canvas); return bitmap; }