List of usage examples for android.graphics.drawable Drawable getIntrinsicWidth
public int getIntrinsicWidth()
From source file:com.xxxifan.devbox.core.util.ViewUtils.java
public static Bitmap toBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); }/* w ww . j a v a 2 s . com*/ Bitmap 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; }
From source file:com.stepstone.stepper.internal.util.TintUtil.java
/** * Tints a drawable with the provided color state list * @param drawable drawable to tint/* www . j a va 2 s.co 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.destin.sehaikun.DrawableUtils.java
public static Bitmap getBitmapFromDrawable(Drawable drawable) { if (drawable == null) { return null; }//from w w w . java2 s .com if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } try { Bitmap bitmap; if (drawable instanceof ColorDrawable) { bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888); } 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; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:jahirfiquitiva.iconshowcase.utilities.utils.Utils.java
public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap;/*from w w w . j a v a2s . c o m*/ 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); } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); return bitmap; }
From source file:com.tr4android.support.extension.widget.CircleImageView.java
/** * Helper for creating a bitmap from a drawable * * @param drawable The drawable which should be converted to a bitmap * @return the bitmap containing the drawable *///from w w w .j av a 2 s.c om public static Bitmap getBitmapFromDrawable(Drawable drawable) { if (drawable == null) return null; if (drawable instanceof BitmapDrawable) { Log.w(LOG_TAG, "For better performance consider using setImageBitmap() instead!"); return ((BitmapDrawable) drawable).getBitmap(); } else { Bitmap bitmap = Bitmap.createBitmap(Math.max(2, drawable.getIntrinsicWidth()), Math.max(2, drawable.getIntrinsicHeight()), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; } }
From source file:it.cdpaf.helper.DrawableManager.java
public static Drawable fetchDrawable(String urlString, Context ctx) { if (drawableMap.containsKey(urlString)) { Log.d(ctx.getClass().getSimpleName(), "DRAWABLE MANAGER FD:" + "RIUSO: " + urlString + " Size:" + drawableMap.size()); return drawableMap.get(urlString); }/*ww w .j a v a2 s. c om*/ Log.d(ctx.getClass().getSimpleName(), "image url:" + urlString); try { InputStream is = fetch(urlString, ctx); Drawable drawable = Drawable.createFromStream(is, "src"); if (drawable != null) { drawableMap.put(urlString, drawable); Log.d(ctx.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", " + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", " + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth()); } else { Log.w(ctx.getClass().getSimpleName(), "could not get thumbnail"); } return drawable; } catch (MalformedURLException e) { Log.e(ctx.getClass().getSimpleName(), "MALFORMEDURL EXC fetchDrawable failed", e); return null; } catch (IOException e) { Log.e(ctx.getClass().getSimpleName(), "IO EXCP fetchDrawable failed", e); return null; } }
From source file:de.gebatzens.sia.SettingsActivity.java
public static CustomTabsIntent createCustomTab(Activity activity, String url) { Drawable d = ContextCompat.getDrawable(activity, R.drawable.ic_arrow_back); Bitmap bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); d.draw(canvas);// w ww. ja va2 s . c o m CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder() .setToolbarColor(SIAApp.SIA_APP.school.getColor()).setSecondaryToolbarColor(Color.RED) .setCloseButtonIcon(bitmap).setShowTitle(true).build(); customTabsIntent.launchUrl(activity, Uri.parse(url)); return customTabsIntent; }
From source file:com.battlelancer.seriesguide.util.Utils.java
/** * Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the * text. Use null if you do not want a Drawable there. The Drawables' bounds will be set to * their intrinsic bounds./*from w w w . j a va 2 s . c o m*/ */ public static void setCompoundDrawablesRelativeWithIntrinsicBounds(Button button, Drawable left, Drawable top, Drawable right, Drawable bottom) { if (left != null) { left.setBounds(0, 0, left.getIntrinsicWidth(), left.getIntrinsicHeight()); } if (right != null) { right.setBounds(0, 0, right.getIntrinsicWidth(), right.getIntrinsicHeight()); } if (top != null) { top.setBounds(0, 0, top.getIntrinsicWidth(), top.getIntrinsicHeight()); } if (bottom != null) { bottom.setBounds(0, 0, bottom.getIntrinsicWidth(), bottom.getIntrinsicHeight()); } button.setCompoundDrawables(left, top, right, bottom); }
From source file:org.bottiger.podcast.utils.UIUtils.java
public static Bitmap getBitmapFromVectorDrawable(Context context, int drawableId) { Drawable drawable = ContextCompat.getDrawable(context, drawableId); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { drawable = (DrawableCompat.wrap(drawable)).mutate(); }//from ww w. j a va2 s . c o m Bitmap 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; }
From source file:io.jawg.osmcontributor.ui.utils.BitmapHandler.java
public static Bitmap drawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); }//from w w w . j a v a 2 s . co m Bitmap 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; }