Example usage for android.graphics.drawable InsetDrawable getIntrinsicWidth

List of usage examples for android.graphics.drawable InsetDrawable getIntrinsicWidth

Introduction

In this page you can find the example usage for android.graphics.drawable InsetDrawable getIntrinsicWidth.

Prototype

@Override
    public int getIntrinsicWidth() 

Source Link

Usage

From source file:com.forrestguice.suntimeswidget.SuntimesUtils.java

/**
 * @param context context used to get resources
 * @param resourceID drawable resource ID to an InsetDrawable
 * @param fillColor fill color to apply to drawable
 * @param strokeColor stroke color to apply to drawable
 * @param strokePx width of stroke/*w  ww .  j  av  a2 s . co  m*/
 * @return a Bitmap of the drawable
 */
public static Bitmap insetDrawableToBitmap(Context context, int resourceID, int fillColor, int strokeColor,
        int strokePx) {
    Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), resourceID, null);
    InsetDrawable inset = (InsetDrawable) drawable;

    int w = 1, h = 1;
    if (inset != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Drawable wrapped = inset.getDrawable();
            if (wrapped != null) {
                w = wrapped.getIntrinsicWidth();
                h = wrapped.getIntrinsicHeight();
            }
        } else {
            w = inset.getIntrinsicWidth();
            h = inset.getIntrinsicHeight();
        }
    }

    Drawable tinted = tintDrawable(inset, fillColor, strokeColor, strokePx);
    return drawableToBitmap(context, tinted, w, h, true);
}