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:com.chaotix.applerefurbwatcher.helpers.ImageDownloader.java

private void setButtonBitmap(Button imageView, Bitmap bitmap) {
    Drawable drawable = new BitmapDrawable(resources, bitmap);
    drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
    imageView.setCompoundDrawables(drawable, null, null, null);
}

From source file:com.abhinavjhanwar.android.egg.neko.Cat.java

private void slowDraw(Canvas canvas, int x, int y, int w, int h) {
    for (int i = 0; i < D.drawingOrder.length; i++) {
        final Drawable d = D.drawingOrder[i];
        if (d != null) {
            d.setBounds(x, y, x + w, y + h);
            d.draw(canvas);//from   w  w  w .  ja  va  2s  .  c  o  m
        }
    }

}

From source file:nl.privacybarometer.privacyvandaag.adapter.FeedsCursorAdapter.java

@Override
protected void bindChildView(View view, Context context, Cursor cursor) {
    view.findViewById(R.id.indicator).setVisibility(View.INVISIBLE);

    TextView textView = ((TextView) view.findViewById(android.R.id.text1));
    // if FetchMode is 99 then DO-NOT-REFRESH feed channel. activeFeedChannel = false;
    boolean activeFeedChannel = !(cursor.getInt(mFetchModePos) == FETCHMODE_DO_NOT_FETCH);

    // Use icons in package instead of fetching favicons from internet. See comment below.
    Drawable mDrawable;
    int mIconResourceId = cursor.getInt(mIconId);
    if (mIconResourceId > 0) {
        mDrawable = ContextCompat.getDrawable(context, mIconResourceId);
    } else {/*ww w  .j  a  v  a  2  s .c om*/
        mDrawable = ContextCompat.getDrawable(context, R.drawable.logo_icon_pv);
    }
    mDrawable.setBounds(0, 0, 50, 50); // define the size of the drawable
    textView.setCompoundDrawables(mDrawable, null, null, null);

    //  Code not needed since we no longer use favicons retrieved from the internet,
    //but use the logo's included in the resource directory of the app using the code above.
    /*
        final long feedId = cursor.getLong(mIdPos);
        Bitmap bitmap = UiUtils.getFaviconBitmap(feedId, cursor, mIconPos);
        if ((bitmap != null) && (activeFeedChannel)) {   // if a favicon is available, show it next to the feed name.
            textView.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(context.getResources(), bitmap), null, null, null);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
        }
    */
    textView.setText((cursor.isNull(mNamePos) ? cursor.getString(mLinkPos) : cursor.getString(mNamePos)));
    // if FetchMode is 99 then DO-NOT-REFRESH is active. Add remark and change style
    if (activeFeedChannel) {
        textView.setTextColor(ACTIVE_TEXT_COLOR);
    } else { // inactive feed channel. Is not refreshed.
        textView.append(" - niet volgen");
        textView.setTextColor(DO_NOT_FETCH_COLOR_TEXT_COLOR);
    }
}

From source file:com.example.administrator.mengbaofushiji.extras.SlidingTabLayout.java

private void populateTabStrip() {
    removeOldSelection(); // add those two lines
    oldSelection = null;/*from  w  ww . j a v  a 2 s.  c o m*/
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;
        if (mTabViewLayoutId != 0) {
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        if (mTabViewTextViewImgs != null && mTabViewTextViewImgs.length > 0) {
            Drawable drawable = getResources().getDrawable(mTabViewTextViewImgs[i]);
            /// ??,??.
            drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
            tabTitleView.setCompoundDrawables(drawable, null, null, null);
        }
        tabView.setOnClickListener(tabClickListener);
        mTabStrip.addView(tabView);
    }
}

From source file:com.tct.mail.browse.SubjectAndFolderView.java

public void setFolders(ConversationViewHeaderCallbacks callbacks, Account account, Conversation conv) {
    mVisibleFolders = true;/* w w w. j a va  2  s. c  o  m*/
    final BidiFormatter bidiFormatter = getBidiFormatter();
    if (TextUtils.isEmpty(mSubject)) {
        mSubject = conv.subject;
    }
    final SpannableStringBuilder sb = new SpannableStringBuilder(bidiFormatter.unicodeWrap(mSubject));
    sb.append('\u0020');
    final Settings settings = account.settings;
    final int start = sb.length();
    if (settings.importanceMarkersEnabled && conv.isImportant()) {
        sb.append(".\u0020");
        sb.setSpan(new DynamicDrawableSpan(DynamicDrawableSpan.ALIGN_BASELINE) {
            @Override
            public Drawable getDrawable() {
                Drawable d = getContext().getResources()
                        .getDrawable(R.drawable.ic_email_caret_none_important_unread);
                d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
                return d;
            }
        }, start, start + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    }

    //TS: yanhua.chen 2015-12-22 EMAIL BUGFIX_1178365 MOD_S
    //        mFolderDisplayer.loadConversationFolders(conv, null /* ignoreFolder */, -1 /* ignoreFolderType */);
    //        mFolderDisplayer.appendFolderSpans(sb, bidiFormatter);

    //        final int end = sb.length();
    //        sb.setSpan(new ChangeLabelsSpan(callbacks), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    setText(sb);
    //TS: yanhua.chen 2015-11-4 EMAIL BUGFIX_851207 MOD_S
    //        if(isNeedMove()){
    //            setMovementMethod(LinkMovementMethod.getInstance());
    //        }
    //TS: yanhua.chen 2015-11-4 EMAIL BUGFIX_851207 MOD_E
    //TS: yanhua.chen 2015-12-22 EMAIL BUGFIX_1178365 MOD_E
}

From source file:cc.solart.turbo.decoration.LinearDividerItemDecoration.java

public void drawHorizontalDividers(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final Drawable divider = getDivider(parent, params.getViewAdapterPosition());
        final int left = child.getRight() + params.rightMargin + Math.round(ViewCompat.getTranslationX(child));
        final int right = left + divider.getIntrinsicHeight();

        mDividerOffsets.put(params.getViewAdapterPosition(), divider.getIntrinsicHeight());

        divider.setBounds(left, top, right, bottom);
        divider.draw(c);//from   w  w w  . ja v  a 2 s  .co  m
    }
}

From source file:com.google.android.gms.samples.wallet.CartDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_cart_detail, container, false);

    ItemInfo itemInfo = Constants.ITEMS_FOR_SALE[mItemId];

    TextView itemName = (TextView) view.findViewById(R.id.text_item_name);
    itemName.setText(itemInfo.name);//from   ww w.  j  ava2 s.c  o  m

    Drawable itemImage = getResources().getDrawable(itemInfo.imageResourceId);
    int imageSize = getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size);
    int actualWidth = itemImage.getIntrinsicWidth();
    int actualHeight = itemImage.getIntrinsicHeight();
    int scaledHeight = imageSize;
    int scaledWidth = (int) (((float) actualWidth / actualHeight) * scaledHeight);
    itemImage.setBounds(0, 0, scaledWidth, scaledHeight);
    itemName.setCompoundDrawables(itemImage, null, null, null);

    TextView itemPrice = (TextView) view.findViewById(R.id.text_item_price);
    itemPrice.setText(Util.formatPrice(getActivity(), itemInfo.priceMicros));
    TextView shippingCost = (TextView) view.findViewById(R.id.text_shipping_price);
    TextView tax = (TextView) view.findViewById(R.id.text_tax_price);
    TextView total = (TextView) view.findViewById(R.id.text_total_price);
    if ((mItemId == Constants.PROMOTION_ITEM) && getApplication().isAddressValidForPromo()) {
        shippingCost.setText(Util.formatPrice(getActivity(), 0L));
    } else {
        shippingCost.setText(Util.formatPrice(getActivity(), itemInfo.shippingPriceMicros));
    }

    tax.setText(Util.formatPrice(getActivity(), itemInfo.taxMicros));
    total.setText(Util.formatPrice(getActivity(), itemInfo.getTotalPrice()));

    return view;
}

From source file:cc.solart.turbo.decoration.LinearDividerItemDecoration.java

public void drawVerticalDividers(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final Drawable divider = getDivider(parent, params.getViewAdapterPosition());
        final int top = child.getBottom() + params.bottomMargin + Math.round(ViewCompat.getTranslationY(child));
        final int bottom = top + divider.getIntrinsicHeight();

        mDividerOffsets.put(params.getViewAdapterPosition(), divider.getIntrinsicHeight());

        divider.setBounds(left, top, right, bottom);
        divider.draw(c);/*from  ww w  . j a  v a2  s .c  o m*/
    }
}

From source file:com.hippo.gl.glrenderer.XmlResourceTexture.java

@Override
protected Bitmap onGetBitmap() {
    Drawable drawable = ContextCompat.getDrawable(mContext, mResId);

    int width = mWidth;
    int height = mHeight;
    if (width <= 0) {
        width = drawable.getIntrinsicWidth();
    }/*from w  ww.ja  va 2 s .co  m*/
    if (height <= 0) {
        height = drawable.getIntrinsicHeight();
    }
    if (width <= 0) {
        width = 1;
    }
    if (height <= 0) {
        height = 1;
    }

    drawable.setBounds(0, 0, width, height);

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.draw(canvas);

    return bitmap;
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

public static Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bd = (BitmapDrawable) drawable;
        return bd.getBitmap();
    }/*from  w  ww . j  av a 2s  .  c o  m*/
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    drawable.draw(canvas);
    return bitmap;
}