Example usage for android.graphics.drawable InsetDrawable getIntrinsicHeight

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

Introduction

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

Prototype

@Override
    public int getIntrinsicHeight() 

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/*from   ww  w.j  av  a 2s  .  c om*/
 * @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);
}