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:android.support.v7.internal.view.menu.ActionMenuItemView.java

public void setIcon(Drawable icon) {
    mIcon = icon;/*from   w  ww .  ja va  2 s  . co  m*/
    if (icon != null) {
        int width = icon.getIntrinsicWidth();
        int height = icon.getIntrinsicHeight();
        if (width > mMaxIconSize) {
            final float scale = (float) mMaxIconSize / width;
            width = mMaxIconSize;
            height *= scale;
        }
        if (height > mMaxIconSize) {
            final float scale = (float) mMaxIconSize / height;
            height = mMaxIconSize;
            width *= scale;
        }
        icon.setBounds(0, 0, width, height);
    }
    setCompoundDrawables(icon, null, null, null);

    updateTextButtonVisibility();
}

From source file:ir.besteveryeverapp.ui.Cells.DrawerProfileCell.java

@Override
protected void onDraw(Canvas canvas) {
    int pic = SkinMan.currentSkin.actionPicture();
    Drawable backgroundDrawable = pic != 0 ? ContextCompat.getDrawable(getContext(), pic)
            : ApplicationLoader.getCachedWallpaper();
    int color = ApplicationLoader.getServiceMessageColor();
    if (currentColor != color) {
        currentColor = color;//w w  w  .j  a  v  a2 s  .c o m
        shadowView.getDrawable()
                .setColorFilter(new PorterDuffColorFilter(color | 0xff000000, PorterDuff.Mode.MULTIPLY));
    }

    if (ApplicationLoader.isCustomTheme() || pic != 0 && backgroundDrawable != null) {
        phoneTextView.setTextColor(0xffffffff);
        shadowView.setVisibility(VISIBLE);
        if (backgroundDrawable instanceof ColorDrawable) {
            backgroundDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
            backgroundDrawable.draw(canvas);
        } else if (backgroundDrawable instanceof BitmapDrawable) {
            Bitmap bitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
            float scaleX = (float) getMeasuredWidth() / (float) bitmap.getWidth();
            float scaleY = (float) getMeasuredHeight() / (float) bitmap.getHeight();
            float scale = scaleX < scaleY ? scaleY : scaleX;
            int width = (int) (getMeasuredWidth() / scale);
            int height = (int) (getMeasuredHeight() / scale);
            int x = (bitmap.getWidth() - width) / 2;
            int y = (bitmap.getHeight() - height) / 2;
            srcRect.set(x, y, x + width, y + height);
            destRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
            canvas.drawBitmap(bitmap, srcRect, destRect, paint);
        }
    } else {
        shadowView.setVisibility(INVISIBLE);
        phoneTextView.setTextColor(0xffc2e5ff);
        super.onDraw(canvas);
    }
}

From source file:com.android.leanlauncher.IconCache.java

private Bitmap makeDefaultIcon(UserHandleCompat user) {
    Drawable unbadged = getFullResDefaultActivityIcon();
    Drawable d = mUserManager.getBadgedDrawableForUser(unbadged, user);
    Bitmap b = Bitmap.createBitmap(Math.max(d.getIntrinsicWidth(), 1), Math.max(d.getIntrinsicHeight(), 1),
            Bitmap.Config.ARGB_8888);/*from w ww.j ava2s  . c  o  m*/
    Canvas c = new Canvas(b);
    d.setBounds(0, 0, b.getWidth(), b.getHeight());
    d.draw(c);
    c.setBitmap(null);
    return b;
}

From source file:com.ibm.mil.readyapps.physio.fragments.PainLocationFragment.java

/**
 * Places a marker on the bodyLayout in the given location.
 *
 * @param x x location to place the marker.
 * @param y y location to place the marker.
 *//*from www .  j  av a2  s .c  o m*/
private void placePointer(int x, int y) {

    y -= getYOffset();

    //Log.d("PLACE_POINTER", "Placing pointer at: " + x + ", " + y);

    Drawable pointer_im = getResources().getDrawable(R.drawable.pointer_3x);
    pointer_im.setBounds(0, 0, 44, 65);
    ImageView new_pointer = new ImageView(getActivity());
    new_pointer.setImageDrawable(pointer_im);
    new_pointer.setLayoutParams(setLayoutParams(x, y));
    bodyLayout.addView(new_pointer);

    pointers.add(new_pointer);
}

From source file:com.urgoo.message.activities.MainActivity.java

/**
 * ?/*from w w w . j av a2  s  .  c  o  m*/
 */
private void initView() {
    unreadAddressLable = (TextView) findViewById(R.id.unread_address_number);
    mTabs = new Button[4];

    Drawable drawable;
    mTabs[0] = (Button) findViewById(R.id.btn_address_list);
    drawable = getResources().getDrawable(R.drawable.em_tab_contact_list_bg1);
    drawable.setBounds(0, 0, Util.dp2px(MainActivity.this, 20), Util.dp2px(MainActivity.this, 20));
    mTabs[0].setCompoundDrawables(null, drawable, null, null);

    mTabs[1] = (Button) findViewById(R.id.btn_conversation);
    drawable = getResources().getDrawable(R.drawable.em_tab_chat_bg);
    drawable.setBounds(0, 0, Util.dp2px(MainActivity.this, 20), Util.dp2px(MainActivity.this, 20));
    mTabs[1].setCompoundDrawables(null, drawable, null, null);

    mTabs[2] = (Button) findViewById(R.id.btn_service);
    drawable = getResources().getDrawable(R.drawable.urgoo_tab_service_bg);
    drawable.setBounds(0, 0, Util.dp2px(MainActivity.this, 20), Util.dp2px(MainActivity.this, 20));
    mTabs[2].setCompoundDrawables(null, drawable, null, null);

    mTabs[3] = (Button) findViewById(R.id.btn_setting);
    drawable = getResources().getDrawable(R.drawable.em_tab_profile_bg);
    drawable.setBounds(0, 0, Util.dp2px(MainActivity.this, 20), Util.dp2px(MainActivity.this, 20));
    mTabs[3].setCompoundDrawables(null, drawable, null, null);
    // tab?
    mTabs[0].setSelected(true);
}

From source file:com.ibm.mil.readyapps.physio.fragments.PainLocationFragment.java

/**
 * Switches the look of the FRONT and BACK buttons to make them the ADD and DELETE buttons
 * and visa-versa.//from ww w  .  j  a v a 2s  .c  om
 */
private void swapButtons() {

    if (zoomed) {

        Drawable l_pointer = getResources().getDrawable(R.drawable.pointerlight_3x);
        l_pointer.setBounds(0, 0, 44, 65);
        frontBtn.setCompoundDrawables(l_pointer, null, null, null);
        frontBtn.setLayoutParams(new LinearLayout.LayoutParams((int) dipToPixels(37), (int) dipToPixels(34)));
        frontBtn.setTextColor(getResources().getColor(R.color.ready_dark_gray));
        frontBtn.setText("+");

        backBtn.setTextColor(getResources().getColor(R.color.ready_dark_gray));
        backBtn.setText(getResources().getText(R.string.delete));

    } else {

        frontBtn.setCompoundDrawables(null, null, null, null);
        frontBtn.setBackgroundColor(Color.WHITE);
        frontBtn.setLayoutParams(new LinearLayout.LayoutParams(dipToPixels(80), dipToPixels(34)));
        frontBtn.setText(getResources().getText(R.string.front));
        backBtn.setText(getResources().getText(R.string.back));
        if (front) {
            frontBtn.setTextColor(pageColor);
        } else {
            backBtn.setTextColor(pageColor);
        }

    }

}

From source file:com.appsimobile.appsii.module.weather.WeatherActivity.java

void showDrawable(Drawable drawable, boolean isImmediate) {
    mBackgroundImage.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    if (isImmediate) {
        int w = drawable.getIntrinsicWidth();
        int viewWidth = mBackgroundImage.getWidth();
        float factor = viewWidth / (float) w;
        int h = (int) (drawable.getIntrinsicHeight() * factor);
        drawable.setBounds(0, 0, w, h);
        mBackgroundImage.setImageDrawable(drawable);
    } else {/*from  w w  w. j a  v  a  2 s  .c om*/
        Drawable current = mBackgroundImage.getDrawable();
        if (current == null)
            current = new ColorDrawable(Color.TRANSPARENT);
        TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { current, drawable });
        transitionDrawable.setCrossFadeEnabled(true);
        mBackgroundImage.setImageDrawable(transitionDrawable);
        transitionDrawable.startTransition(500);
    }

}

From source file:github.madmarty.madsonic.util.Util.java

public static Bitmap createBitmapFromDrawable(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    }/*w  ww  . ja v  a 2 s . co  m*/

    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}

From source file:com.kmagic.solitaire.DrawMaster.java

/**
 * Create a face card bitmap from resources
 * @param r application resources reference
 * @param id drawable resource id (R.drawable.id)
 * @param width width of the bitmap//from   w  w w.  j  ava  2s  .c o  m
 * @param height height of the bitmap
 * @return bitmap of the face card resource
 */
private Bitmap createFaceBitmap(final Resources r, final int id, final int width, final int height) {
    Drawable drawable = ResourcesCompat.getDrawable(r, id, null);
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, width, height);
    drawable.draw(canvas);
    return (bitmap);
}

From source file:vc908.stickerfactory.ui.advancedrecyclerview.swipeable.RemovingItemDecorator.java

private void fillSwipingItemBackground(Canvas c, Drawable drawable, int height) {
    final Rect bounds = mSwipingItemBounds;
    final int translationX = mInitialTranslationX;
    final int translationY = mTranslationY;

    if (height < 0) {
        height = bounds.height();//www  .  j  a v  a2 s.  c  om
    }

    if ((height == 0) || (drawable == null)) {
        return;
    }

    final int savedCount = c.save();

    c.clipRect(bounds.left + translationX, bounds.top + translationY, bounds.right + translationX,
            bounds.top + translationY + height);

    // c.drawColor(0xffff0000); // <-- debug

    c.translate(bounds.left + translationX, bounds.top + translationY - (bounds.height() - height) / 2);
    drawable.setBounds(0, 0, bounds.width(), bounds.height());

    drawable.draw(c);

    c.restoreToCount(savedCount);
}