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:io.mapsquare.osmcontributor.utils.core.ArpiInitializer.java

/**
 * Pre-compute the different PoiTypes bitmaps icons for the ArpiGL fragment and view.
 *//*from w  w w .  ja  va  2  s.co m*/
public void precomputeArpiBitmaps() {
    try {
        if (!ArpiGlInstaller.getInstance(application.getApplicationContext()).isInstalled()) {
            ArpiGlInstaller.getInstance(application.getApplicationContext()).install();

            Map<Long, PoiType> poiTypes = poiManager.loadPoiTypes();

            for (Map.Entry<Long, PoiType> entry : poiTypes.entrySet()) {
                Integer id = bitmapHandler.getIconDrawableId(entry.getValue());
                if (id != null && id > 0) {
                    Drawable d = application.getApplicationContext().getResources().getDrawableForDensity(id,
                            DisplayMetrics.DENSITY_XXHIGH);
                    int width = d.getIntrinsicWidth();
                    int height = d.getIntrinsicHeight();
                    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
                    Canvas c = new Canvas(bitmap);
                    d.setBounds(0, 0, width, height);
                    d.draw(c);

                    File dest = new File(application.getApplicationContext().getFilesDir(),
                            ArpiGlInstaller.INSTALLATION_DIR + "/" + ArpiGlInstaller.TEXTURE_ICONS_SUBDIR + "/"
                                    + entry.getValue().getIcon() + ".png");
                    dest.getParentFile().mkdirs();

                    if (dest.exists()) {
                        dest.delete();
                    }
                    dest.createNewFile();
                    OutputStream stream = new FileOutputStream(dest);
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                    stream.close();
                    bitmap.recycle();
                }
            }
        }
    } catch (IOException | JSONException e) {
        Timber.e("Error while initializing ArpiGl library: {}", e.getMessage());
    }
}

From source file:com.darly.im.ui.CCPActivityBase.java

/**
 *
 * @param padding/*from w  w w  .  j  av  a 2s .  c  om*/
 * @param iconRes
 * @return
 */
private VerticalImageSpan getTitleIconTips(int padding, int iconRes) {
    Drawable drawable = mActionBarActivity.getResources().getDrawable(iconRes);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    VerticalImageSpan imageSpan = new VerticalImageSpan(drawable);
    imageSpan.setPadding((drawable.getIntrinsicHeight() - padding) / 2);
    return imageSpan;
}

From source file:de.mrapp.android.util.BitmapUtil.java

/**
 * Creates and returns a bitmap from a specific drawable.
 *
 * @param drawable//  w  w  w.j a v  a2s . com
 *         The drawable, which should be converted, as an instance of the class {@link
 *         Drawable}. The drawable may not be null
 * @return The bitmap, which has been created, as an instance of the class {@link Bitmap}
 */
public static Bitmap drawableToBitmap(@NonNull final Drawable drawable) {
    ensureNotNull(drawable, "The drawable may not be null");

    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;

        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }

    Bitmap bitmap;

    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    } else {
        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:android.support.design.internal.NavigationMenuItemView.java

@Override
public void setIcon(Drawable icon) {
    if (icon != null) {
        if (mHasIconTintList) {
            Drawable.ConstantState state = icon.getConstantState();
            icon = DrawableCompat.wrap(state == null ? icon : state.newDrawable()).mutate();
            DrawableCompat.setTintList(icon, mIconTintList);
        }/*  w  ww  .  j  a v a 2s .c om*/
        icon.setBounds(0, 0, mIconSize, mIconSize);
    } else if (mNeedsEmptyIcon) {
        if (mEmptyDrawable == null) {
            mEmptyDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.navigation_empty_icon,
                    getContext().getTheme());
            if (mEmptyDrawable != null) {
                mEmptyDrawable.setBounds(0, 0, mIconSize, mIconSize);
            }
        }
        icon = mEmptyDrawable;
    }
    TextViewCompat.setCompoundDrawablesRelative(mTextView, icon, null, null, null);
}

From source file:org.mozilla.gecko.toolbar.SiteIdentityPopup.java

private void setSecurityStateIcon(int resource, int factor) {
    final Drawable stateIcon = ContextCompat.getDrawable(mContext, resource);
    stateIcon.setBounds(0, 0, stateIcon.getIntrinsicWidth() / factor, stateIcon.getIntrinsicHeight() / factor);
    mSecurityState.setCompoundDrawables(stateIcon, null, null, null);
    mSecurityState/*from w  w  w . ja v  a 2s.c  om*/
            .setCompoundDrawablePadding((int) mResources.getDimension(R.dimen.doorhanger_drawable_padding));
}

From source file:org.addhen.smssync.presentation.view.ui.fragment.ListWebServiceFragment.java

private void drawSwipeListItemBackground(Canvas c, int dX, View itemView, int actionState) {
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        // Fade out the view as it is swiped out of the parent's bounds
        final float alpha = 2.0f - Math.abs(dX) / (float) itemView.getWidth();
        ViewHelper.setAlpha(itemView, alpha);
        ViewHelper.setTranslationX(itemView, dX);

        Drawable d;
        // Swiping right
        if (dX > 0) {
            d = ContextCompat.getDrawable(getAppContext(), R.drawable.swipe_right_publish_list_item_background);
            d.setBounds(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom());
        } else { // Swiping left
            d = ContextCompat.getDrawable(getAppContext(), R.drawable.swipe_left_publish_list_item_background);
            d.setBounds(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom());
        }//  w  w  w.  j  a v a 2 s .  com
        d.draw(c);
    }
}

From source file:com.vuze.android.remote.activity.LoginActivity.java

private void setupGuideText(TextView tvLoginGuide) {
    AndroidUtilsUI.linkify(tvLoginGuide);
    CharSequence text = tvLoginGuide.getText();

    SpannableStringBuilder ss = new SpannableStringBuilder(text);
    String string = text.toString();

    new SpanBubbles().setSpanBubbles(ss, string, "|", tvLoginGuide.getPaint(),
            AndroidUtilsUI.getStyleColor(this, R.attr.login_text_color),
            AndroidUtilsUI.getStyleColor(this, R.attr.login_textbubble_color),
            AndroidUtilsUI.getStyleColor(this, R.attr.login_text_color));

    int indexOf = string.indexOf("@@");
    if (indexOf >= 0) {
        int style = ImageSpan.ALIGN_BASELINE;
        int newHeight = tvLoginGuide.getBaseline();
        if (newHeight <= 0) {
            newHeight = tvLoginGuide.getLineHeight();
            style = ImageSpan.ALIGN_BOTTOM;
            if (newHeight <= 0) {
                newHeight = 20;//from www. jav  a2 s.  co m
            }
        }
        Drawable drawable = ContextCompat.getDrawable(this, R.drawable.guide_icon);
        int oldWidth = drawable.getIntrinsicWidth();
        int oldHeight = drawable.getIntrinsicHeight();
        int newWidth = (oldHeight > 0) ? (oldWidth * newHeight) / oldHeight : newHeight;
        drawable.setBounds(0, 0, newWidth, newHeight);

        ImageSpan imageSpan = new ImageSpan(drawable, style);
        ss.setSpan(imageSpan, indexOf, indexOf + 2, 0);
    }

    tvLoginGuide.setText(ss);
}

From source file:at.flack.MailMainActivity.java

public Bitmap convertToBitmap(Drawable drawable, int widthPixels, int heightPixels) {
    Bitmap mutableBitmap = Bitmap.createBitmap(widthPixels, heightPixels, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(mutableBitmap);
    drawable.setBounds(0, 0, widthPixels, heightPixels);
    drawable.draw(canvas);/*from   w w  w .  j  a  va  2  s .c o m*/

    return mutableBitmap;
}

From source file:es.usc.citius.servando.calendula.activities.CalendarActivity.java

public CharSequence addPickupList(CharSequence msg, List<PickupInfo> pks) {

    Paint textPaint = new Paint();
    //obviously, we have to set textSize into Paint object
    textPaint.setTextSize(getResources().getDimensionPixelOffset(R.dimen.medium_font_size));
    Paint.FontMetricsInt fontMetrics = textPaint.getFontMetricsInt();

    for (PickupInfo p : pks) {
        Patient patient = pickupUtils.getPatient(p);
        int color = patient.color();
        String str = "       " + p.medicine().name() + " (" + dtf2.format(p.from().toDate()) + " - "
                + dtf2.format(p.to().toDate()) + ")\n";
        Spannable text = new SpannableString(str);
        text.setSpan(new ForegroundColorSpan(color), 0, str.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        Drawable d = getResources().getDrawable(AvatarMgr.res(patient.avatar()));
        d.setBounds(0, 0, fontMetrics.bottom, fontMetrics.bottom);
        ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
        text.setSpan(span, 0, 5, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        msg = TextUtils.concat(msg, text);
    }// w w w  .j  a  va 2  s. c o  m
    return msg;
}

From source file:com.lepin.activity.MyLoveCarActivity.java

/**
 * ???/*w  w  w  . j  a  v a  2s  .c om*/
 */
public void setVisible(boolean b) {
    if (b == true) {
        mlTitleEdit.setVisibility(View.GONE);
        Drawable drawable = getResources().getDrawable(R.drawable.arrow);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        mlType.setCompoundDrawables(null, null, drawable, null);
        mlSave.setVisibility(View.VISIBLE);
        mlEditShow.setVisibility(View.VISIBLE);
        mlSafeLayout.setVisibility(View.GONE);
    } else {
        mlTitleEdit.setVisibility(View.VISIBLE);
        mlType.setCompoundDrawables(null, null, null, null);
        mlSave.setVisibility(View.INVISIBLE);
        mlEditShow.setVisibility(View.GONE);
        mlSafeLayout.setVisibility(View.VISIBLE);
    }
}