Example usage for android.graphics.drawable Drawable getMinimumWidth

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

Introduction

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

Prototype

public int getMinimumWidth() 

Source Link

Document

Returns the minimum width suggested by this Drawable.

Usage

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);/*ww w . ja  v  a 2 s  .co  m*/

    return bitmap;
}

From source file:Main.java

public static Bitmap toBitmap(Drawable drawable) {
    int w = drawable.getMinimumWidth();
    int h = drawable.getMinimumHeight();
    if (w <= 0 || h <= 0) {
        return null;
    }//from w  w w  .jav a 2s  .  c  o  m
    Rect bounds = drawable.getBounds();
    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    drawable.draw(canvas);
    drawable.setBounds(bounds);
    return bitmap;
}

From source file:Main.java

public static Drawable toGreyDrawable(Drawable drawable) {
    int w = drawable.getMinimumWidth();
    int h = drawable.getMinimumHeight();
    if (w <= 0 || h <= 0) {
        return drawable;
    }//www  .j av  a 2s  . c o  m
    Rect bounds = drawable.getBounds();
    Bitmap grey = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(grey);
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    drawable.setColorFilter(new ColorMatrixColorFilter(cm));
    drawable.setBounds(0, 0, w, h);
    drawable.draw(c);
    drawable.clearColorFilter();
    drawable.setBounds(bounds);
    BitmapDrawable bd = new BitmapDrawable(grey);
    bd.setBounds(0, 0, w, h);
    return bd;
}

From source file:Main.java

public static Drawable getDrawable(@Nullable Context context, @Nullable int id) {
    Drawable draw = context.getResources().getDrawable(id);
    draw.setBounds(0, 0, draw.getMinimumWidth(), draw.getMinimumHeight());
    return draw;//w  w  w  . ja v  a2s.co  m
}

From source file:Main.java

public static Drawable toGrey(Drawable drawable) {
    int w = drawable.getMinimumWidth();
    int h = drawable.getMinimumHeight();
    if (w <= 0 || h <= 0) {
        return drawable;
    }/*w  ww.j  a v a 2s .  c o m*/
    Rect bounds = drawable.getBounds();
    Bitmap grey = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(grey);
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    drawable.setColorFilter(new ColorMatrixColorFilter(cm));
    drawable.setBounds(0, 0, w, h);
    drawable.draw(c);
    drawable.clearColorFilter();
    drawable.setBounds(bounds);
    BitmapDrawable bd = new BitmapDrawable(grey);
    bd.setBounds(0, 0, w, h);
    return bd;
}

From source file:Main.java

public static Drawable getDrawable(Context context, int R_ID) {
    Drawable brawable = context.getResources().getDrawable(R_ID);
    brawable.setBounds(0, 0, brawable.getMinimumWidth(), brawable.getMinimumHeight());
    return brawable;
}

From source file:Main.java

public static Drawable getCompoundDrawable(@NonNull Context context, @DrawableRes int resId) {
    Drawable drawable = context.getResources().getDrawable(resId);
    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    return drawable;
}

From source file:Main.java

public static void textViewSetImg(Context context, TextView tv, int resId) {
    Drawable drawable = context.getResources().getDrawable(resId);
    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    tv.setCompoundDrawables(drawable, null, null, null);
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static void setTvLeftPic(Context context, int resId, TextView tv) {
    Drawable drawable = context.getResources().getDrawable(resId);
    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    tv.setCompoundDrawables(drawable, null, null, null);
}

From source file:Main.java

public static void setRightCheckBoxDrawable(Context context, int drawableId, CheckBox box) {
    Drawable drawable = context.getResources().getDrawable(drawableId); // /
    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    box.setCompoundDrawables(null, null, drawable, null);
}