Example usage for android.graphics.drawable Drawable setBounds

List of usage examples for android.graphics.drawable Drawable setBounds

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable setBounds.

Prototype

public void setBounds(int left, int top, int right, int bottom) 

Source Link

Document

Specify a bounding rectangle for the Drawable.

Usage

From source file:Main.java

public static Drawable getImgageDrawable(Context context, String iconStr) {
    int pos = iconStr.indexOf(".");
    if (pos != -1) {
        iconStr = iconStr.substring(0, pos);
    }/*from  w ww .j av  a2  s. c  om*/
    if (!iconCacheHashMap.containsKey(iconStr)) {
        int res = context.getResources().getIdentifier(iconStr, "drawable", context.getPackageName());
        if (res == 0) {
            return null;
        } else {
            Drawable drawable = context.getResources().getDrawable(res);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            iconCacheHashMap.put(iconStr, drawable);
        }
    }
    return iconCacheHashMap.get(iconStr);
}

From source file:com.nextgis.woody.util.UiUtil.java

public static Drawable tintIcon(Drawable drawable, int color) {
    Drawable result = DrawableCompat.wrap(drawable);
    result.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    DrawableCompat.setTint(result, color);
    return result;
}

From source file:Main.java

/**
 * Get the {@link Drawable} identified by {@code drawableId} and set its bounds
 * with the dimensions identified by {@code widthDimenId} and {@code heightDimenId}.
 * @param ctx Context//from   w  w  w.j av  a 2s .c  o  m
 * @param drawableId Identifier of the drawable.
 * @param widthDimenId Identifier of the resource to use as the width.
 * @param heightDimenId Identifier of the resource to use as the height.
 * @return The {@link Drawable} identified by {@code drawableId} bounded to {@code widthDimenId} and {@code heightDimenId}.
 */
public static Drawable boundedDrawable(Context ctx, int drawableId, int widthDimenId, int heightDimenId) {
    Drawable retVal;
    Resources res = ctx.getResources();
    retVal = res.getDrawable(drawableId);
    retVal.setBounds(0, 0, res.getDimensionPixelSize(widthDimenId), res.getDimensionPixelSize(heightDimenId));
    return retVal;
}

From source file:Main.java

public static Drawable boundCenterBottom(Drawable drawable, int i, int j) {
    int k = drawable.getIntrinsicWidth();
    int l = drawable.getIntrinsicHeight();
    drawable.setBounds(i + -k / 2, j + -l, i + k / 2, j);
    return drawable;
}

From source file:Main.java

public static Drawable getDrawableIcon(Context context, int drawableIcon, int size) {
    Drawable drawable;
    drawable = ContextCompat.getDrawable(context, drawableIcon);
    if (drawable != null)
        drawable.setBounds(0, 0, size, size);
    return drawable;
}

From source file:Main.java

public static Bitmap convertBitmap(Drawable drawable, int width, int height) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);/*  w  w  w. j a  v  a  2  s  .  com*/
    return bitmap;
}

From source file:Main.java

public static Bitmap DrawToBitmap(Drawable dw) {
    Bitmap bitmap = Bitmap.createBitmap(dw.getMinimumWidth(), dw.getMinimumHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    dw.setBounds(0, 0, dw.getMinimumWidth(), dw.getMinimumHeight());
    dw.draw(canvas);/*from w  ww  .j  a v a 2  s. co  m*/

    return bitmap;
}

From source file:com.achep.acdisplay.graphics.IconFactory.java

@NonNull
private static Bitmap createEmptyIcon(@NonNull Resources res, int size) {
    Paint paint = new Paint();
    paint.setAntiAlias(true);/*from  w ww . j a  va 2s .  co m*/
    paint.setColor(0xDDCCCCCC); // white gray

    final float radius = size / 2f;

    Bitmap icon = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(icon);
    canvas.drawCircle(radius, radius, radius, paint);

    Drawable drawable = res.getDrawable(R.drawable.ic_action_warning_white);
    drawable.setBounds(0, 0, size, size);
    drawable.draw(canvas);

    return icon;
}

From source file:Main.java

public static Bitmap convertToBitmap(Drawable drawable, int width, int height) {
    Bitmap outputBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(outputBitmap);

    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);/*from w w  w  . ja v  a 2s .com*/

    return outputBitmap;
}

From source file:Main.java

public static Bitmap drawableToBitmap(Drawable drawable, int width, int height) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);/* www.  j a  v  a2 s. c  o m*/
    return bitmap;
}