List of usage examples for android.graphics.drawable Drawable setBounds
public void setBounds(@NonNull Rect bounds)
From source file:Main.java
private static Drawable createPlaceholder(Drawable original) { Drawable placeholder = new ColorDrawable(); placeholder.setBounds(original.getBounds()); return placeholder; }
From source file:Main.java
/** * Copies various properties from one drawable to the other. * @param to drawable to copy properties to * @param from drawable to copy properties from *//* w ww .ja v a 2s .c o m*/ public static void copyProperties(Drawable to, Drawable from) { if (from == null || to == null || to == from) { return; } to.setBounds(from.getBounds()); to.setChangingConfigurations(from.getChangingConfigurations()); to.setLevel(from.getLevel()); to.setVisible(from.isVisible(), /* restart */false); to.setState(from.getState()); }
From source file:Main.java
private static Bitmap toBitmap(Drawable drawable, int width, int height) { Bitmap bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas c = new Canvas(bmp); drawable.setBounds(new Rect(0, 0, width, height)); drawable.draw(c);//from w ww . j a v a2s. c o m return bmp; }
From source file:Main.java
public static Bitmap asBitmap(Drawable drawable, int minWidth, int minHeight) { final Rect tmpRect = new Rect(); drawable.copyBounds(tmpRect);//from w w w .j a v a 2s . co m if (tmpRect.isEmpty()) { tmpRect.set(0, 0, Math.max(minWidth, drawable.getIntrinsicWidth()), Math.max(minHeight, drawable.getIntrinsicHeight())); drawable.setBounds(tmpRect); } Bitmap bitmap = Bitmap.createBitmap(tmpRect.width(), tmpRect.height(), Bitmap.Config.ARGB_8888); drawable.draw(new Canvas(bitmap)); return bitmap; }
From source file:com.stepstone.stepper.internal.util.TintUtil.java
/** * Tints a drawable with the provided color state list * @param drawable drawable to tint//from w w w . j ava 2 s. c o m * @param color tint color state list * @return tinted drawable */ public static Drawable tintDrawable(@Nullable Drawable drawable, ColorStateList color) { if (drawable != null) { drawable = DrawableCompat.unwrap(drawable); Rect bounds = drawable.getBounds(); drawable = DrawableCompat.wrap(drawable); // bounds can be all set to zeros when inflating vector drawables in Android Support Library 23.3.0... if (bounds.right == 0 || bounds.bottom == 0) { if (drawable.getIntrinsicHeight() != -1 && drawable.getIntrinsicWidth() != -1) { bounds.right = drawable.getIntrinsicWidth(); bounds.bottom = drawable.getIntrinsicHeight(); } else { Log.w(TAG, "Cannot tint drawable because its bounds cannot be determined!"); return DrawableCompat.unwrap(drawable); } } DrawableCompat.setTintList(drawable, color); drawable.setBounds(bounds); } return drawable; }
From source file:com.open.file.manager.IconLoader.java
/** * Load icon for conflict dialog/*www.j av a 2 s .c om*/ * @param current * @return icon drawable */ public Drawable loadConflictico(File current) { Drawable icodraw; Bitmap iconbm; iconbm = getIcon(current); icodraw = new BitmapDrawable(mycont.getResources(), iconbm); icodraw.setBounds(new Rect(0, 0, iconbm.getWidth(), iconbm.getHeight())); return icodraw; }
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);/*from w w w . j av a 2s . co m*/ } }
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; }/*from w w w . ja va 2s . c o 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:android.support.v7.internal.widget.ListViewCompat.java
protected void drawSelectorCompat(Canvas canvas) { if (!mSelectorRect.isEmpty()) { final Drawable selector = getSelector(); if (selector != null) { selector.setBounds(mSelectorRect); selector.draw(canvas);//from ww w . j a va 2s.c o m } } }
From source file:com.bobomee.android.tab_navigator.recyclerview.FlexibleDividerDecoration.java
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { RecyclerView.Adapter adapter = parent.getAdapter(); if (adapter == null) { return;/*from w w w .ja v a 2s. c o m*/ } int itemCount = adapter.getItemCount(); int lastDividerOffset = getLastDividerOffset(parent); int validChildCount = parent.getChildCount(); int lastChildPosition = -1; for (int i = 0; i < validChildCount; i++) { View child = parent.getChildAt(i); int childPosition = parent.getChildAdapterPosition(child); if (childPosition < lastChildPosition) { // Avoid remaining divider when animation starts continue; } lastChildPosition = childPosition; if (!mShowLastDivider && childPosition >= itemCount - lastDividerOffset) { // Don't draw divider for last line if mShowLastDivider = false continue; } if (wasDividerAlreadyDrawn(childPosition, parent)) { // No need to draw divider again as it was drawn already by previous column continue; } int groupIndex = getGroupIndex(childPosition, parent); if (mVisibilityProvider.shouldHideDivider(groupIndex, parent)) { continue; } Rect bounds = getDividerBound(groupIndex, parent, child); switch (mDividerType) { case DRAWABLE: Drawable drawable = mDrawableProvider.drawableProvider(groupIndex, parent); drawable.setBounds(bounds); drawable.draw(c); break; case PAINT: mPaint = mPaintProvider.dividerPaint(groupIndex, parent); c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint); break; case COLOR: mPaint.setColor(mColorProvider.dividerColor(groupIndex, parent)); mPaint.setStrokeWidth(mSizeProvider.dividerSize(groupIndex, parent)); c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint); break; } } }