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 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);
}

From source file:Main.java

private static Bitmap drawToBitmap(Resources resources, int drawableResourceID, Bitmap bitmap) {
    Drawable drawable = resources.getDrawable(drawableResourceID);
    drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
    drawable.draw(new Canvas(bitmap));
    return bitmap;
}

From source file:Main.java

/**
 * //from w ww.j  a v a2 s  .c  o  m
 * @param context
 * @param id
 * @return
 */
public static Drawable getDrawables(Context context, int id) {
    Drawable drawable = getResources(context).getDrawable(id);
    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());

    return drawable;
}

From source file:Main.java

public static void updateTextViewIconRight(Context context, View view, int resourceId) {
    if (view != null && view instanceof TextView) {
        Drawable drawable = context.getResources().getDrawable(resourceId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        ((TextView) view).setCompoundDrawables(null, null, drawable, null);
        ((TextView) view).setCompoundDrawablePadding(2);
        view.setVisibility(View.VISIBLE);
    }//  www  .j a va  2  s . c o  m
}

From source file:Main.java

public static void updateLeft(Context context, View view, int resourceId) {
    if (view != null && view instanceof TextView) {
        Drawable drawable = context.getResources().getDrawable(resourceId);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        ((TextView) view).setCompoundDrawables(drawable, null, null, null);
    }/*from  w  w  w  .j a  v  a 2  s  .c  o m*/
}

From source file:Main.java

public static void changeImageButton(Context context, ImageButton button, int resId, int width, int height) {
    Drawable icon;
    icon = context.getResources().getDrawable(resId);
    icon.setBounds(0, 0, width, height);
    Bitmap iconBitmap = ((BitmapDrawable) icon).getBitmap();
    Bitmap bitmapResized = Bitmap.createScaledBitmap(iconBitmap, width, height, false);
    button.setImageBitmap(bitmapResized);

}

From source file:Main.java

public static void updateRightImgTitle(Activity activity, int viewId, int txtRes, int imgRes) {
    View view = activity.findViewById(viewId);
    if (view == null) {
        return;//from  w w w.j ava  2s. co  m
    }
    if (view instanceof TextView) {
        view.setVisibility(View.VISIBLE);
        ((TextView) view).setText(activity.getString(txtRes));
        Drawable drawable = activity.getResources().getDrawable(imgRes);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        ((TextView) view).setCompoundDrawables(null, drawable, null, null);
    }
}

From source file:Main.java

/**
 * @param c/*  ww  w. j a v a 2 s  .co m*/
 * @return
 */
public static ImageGetter getImageGetter(final Context c) {
    return new ImageGetter() {

        public Drawable getDrawable(String source) {
            System.out.println("source =" + source);
            Integer resID = c.getResources().getIdentifier(source, "drawable", c.getPackageName());
            Drawable d = c.getResources().getDrawable(resID);
            d.setBounds(0, 0, 24, 24);
            return d;
        }
    };
}

From source file:Main.java

/**
 * @param c/*from w w  w . j  a  v  a2  s.  c  o m*/
 * @return
 */
public static ImageGetter getImageGetter(final Context c) {
    return new ImageGetter() {

        @Override
        public Drawable getDrawable(String source) {
            System.out.println("source =" + source);
            Integer resID = c.getResources().getIdentifier(source, "drawable", c.getPackageName());
            Drawable d = c.getResources().getDrawable(resID);
            d.setBounds(0, 0, 24, 24);
            return d;
        }
    };
}

From source file:Main.java

public static Drawable getDrawable(Context context, String name) {
    Drawable drawable = context.getResources().getDrawable(getResourceId(context, name));
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    return drawable;
}