android.graphics.drawable.BitmapDrawable#setBounds()源码实例Demo

下面列出了android.graphics.drawable.BitmapDrawable#setBounds() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: UltimateAndroid   文件: DynamicListView.java
/**
 * Creates the hover cell with the appropriate bitmap and of appropriate
 * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every
 * single time an invalidate call is made.
 */
private BitmapDrawable getAndAddHoverView(View v) {
    int w = v.getWidth();
    int h = v.getHeight();
    int top = v.getTop();
    int left = v.getLeft();

    Bitmap b = getBitmapFromView(v);

    BitmapDrawable drawable = new BitmapDrawable(getResources(), b);

    mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h);
    mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds);

    drawable.setBounds(mHoverCellCurrentBounds);

    return drawable;
}
 
源代码2 项目: LiveGiftLayout   文件: AnimatedGifDrawable.java
public AnimatedGifDrawable(InputStream source, UpdateListener listener) {
	mListener = listener;
	GifDecoder decoder = new GifDecoder();
	decoder.read(source);
	// Iterate through the gif frames, add each as animation frame
	for (int i = 0; i < decoder.getFrameCount(); i++) {
		Bitmap bitmap = decoder.getFrame(i);
		BitmapDrawable drawable = new BitmapDrawable(bitmap);
		// Explicitly set the bounds in order for the frames to display
		drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
		addFrame(drawable, decoder.getDelay(i));
		if (i == 0) {
			// Also set the bounds for this container drawable
			setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
		}
	}
}
 
源代码3 项目: coursera-android   文件: ContactInfoListAdapter.java
public ContactInfoListAdapter(Context context, int layout, Cursor c,
		int flags) {

	super(context, layout, c, flags);

	mContentResolver = context.getContentResolver();

	mApplicationContext = context.getApplicationContext();

	// Default thumbnail bitmap for when contact has no thubnail
	mNoPictureBitmap = (BitmapDrawable) context.getResources().getDrawable(
			R.drawable.ic_contact_picture);
	mBitmapSize = (int) context.getResources().getDimension(
			R.dimen.textview_height);
	mNoPictureBitmap.setBounds(0, 0, mBitmapSize, mBitmapSize);

}
 
源代码4 项目: android-discourse   文件: UrlImageGetter.java
@Override
public Drawable getDrawable(String source) {
    source = checkUrl(source);
    UrlDrawable urlDrawable = new UrlDrawable();

    ImageContainer ic = mImageLoader.getForImageSpan(this, source, mTextView, new ImageCallback(mCtx.getResources(), urlDrawable));
    // TODO 当帖子滚动屏幕外的时候 如何和ImageView一样 取消前面没用的下载请求???
    if (ic != null && ic.getBitmap() != null) {
        BitmapDrawable drawable = new BitmapDrawable(mCtx.getResources(), ic.getBitmap());
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        return drawable;
    }
    if (ic != null) {
        mImageContainers.add(ic);
    }
    // get the actual source
    // ImageGetterAsyncTask asyncTask = new ImageGetterAsyncTask(urlDrawable);
    // asyncTask.execute(source);

    // return reference to URLDrawable where I will change with actual image from
    // the src tag
    return urlDrawable;
}
 
源代码5 项目: Android_framework   文件: WebActivity.java
@Override
    protected void onHandleMessageFromFragment(Message msg) {
        if (msg.what == 1){
            isLoading = true;
            refresh.setBackgroundResource(R.mipmap.ic_refresh_close);
        }else if (msg.what == 2){
            isLoading = false;
            refresh.setBackgroundResource(R.mipmap.ic_refresh);
        }else if (msg.what == 3){
            int newProgress = (int) msg.obj;
            if (newProgress == 100)
                pb_bar.setVisibility(View.GONE);
            else
                pb_bar.setVisibility(View.VISIBLE);
            pb_bar.setProgress(newProgress);
        }else if (msg.what == 4){
            Bitmap icon = (Bitmap) msg.obj;
            BitmapDrawable drawable = new BitmapDrawable(getResources(), icon);
            drawable.setBounds(0, 0, CommonUtils.dp2px(20), CommonUtils.dp2px(20));
//            setTitle.setCompoundDrawables(drawable, null, null, null);
        }else if (msg.what == 5){
            String title = (String) msg.obj;
            titles.add(" "+title);
            setTitle(" " + title);
        }
    }
 
private void processImageResponse(String id, ImageResponse response) {
    if (response != null) {
        Bitmap bitmap = response.getBitmap();
        if (bitmap != null) {
            BitmapDrawable drawable = new BitmapDrawable(UserSettingsFragment.this.getResources(), bitmap);
            drawable.setBounds(0, 0,
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_width),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_height));
            userProfilePic = drawable;
            userProfilePicID = id;
            connectedStateLabel.setCompoundDrawables(null, drawable, null, null);
            connectedStateLabel.setTag(response.getRequest().getImageUri());
        }
    }
}
 
源代码7 项目: Slide   文件: DragSortRecycler.java
private BitmapDrawable createFloatingBitmap(View v) {
    floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
    floatingItemBounds = new Rect(floatingItemStatingBounds);

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

    BitmapDrawable retDrawable = new BitmapDrawable(v.getResources(), bitmap);
    retDrawable.setBounds(floatingItemBounds);

    return retDrawable;
}
 
源代码8 项目: coursera-android   文件: ContactInfoListAdapter.java
public ContactInfoListAdapter(Context context, @SuppressWarnings("SameParameterValue") int layout, Cursor c,
							  @SuppressWarnings("SameParameterValue") int flags) {

	super(context, layout, c, flags);

	mApplicationContext = context.getApplicationContext();

	// default thumbnail photo
	mNoPictureBitmap = (BitmapDrawable) context.getResources().getDrawable(
			R.drawable.ic_contact_picture, context.getTheme());
	mBitmapSize = (int) context.getResources().getDimension(
			R.dimen.textview_height);
	mNoPictureBitmap.setBounds(0, 0, mBitmapSize, mBitmapSize);

}
 
源代码9 项目: mappwidget   文件: TextPopup.java
public void setIcon(BitmapDrawable theDrawable)
{
    if (theDrawable != null) {
        theDrawable.setBounds(0,0, (int) (theDrawable.getBitmap().getWidth()),
                                    (int)(theDrawable.getBitmap().getHeight()));
    }
    
    text.setCompoundDrawables(null, null, theDrawable, null);
}
 
/**
 * Constructor
 *
 * @param res                {@link Resources} instance.
 * @param bitmapOuter        {@link Bitmap} which represents the outer non-movable part of the joystick.
 * @param bitmapInnerDefault {@link Bitmap} which represents the default inner movable part of the joystick.
 * @param bitmapInnerPressed {@link Bitmap} which represents the pressed inner movable part of the joystick.
 * @param rectOuter          {@link Rect} which represents the outer joystick bounds.
 * @param rectInner          {@link Rect} which represents the inner joystick bounds.
 * @param joystick           Identifier for which joystick this is.
 */
public InputOverlayDrawableJoystick(Resources res, Bitmap bitmapOuter,
        Bitmap bitmapInnerDefault, Bitmap bitmapInnerPressed,
        Rect rectOuter, Rect rectInner, int joystick)
{
  axisIDs[0] = joystick + 1; // Up
  axisIDs[1] = joystick + 2; // Down
  axisIDs[2] = joystick + 3; // Left
  axisIDs[3] = joystick + 4; // Right
  mJoystickType = joystick;

  mOuterBitmap = new BitmapDrawable(res, bitmapOuter);
  mDefaultStateInnerBitmap = new BitmapDrawable(res, bitmapInnerDefault);
  mPressedStateInnerBitmap = new BitmapDrawable(res, bitmapInnerPressed);
  mBoundsBoxBitmap = new BitmapDrawable(res, bitmapOuter);
  mWidth = bitmapOuter.getWidth();
  mHeight = bitmapOuter.getHeight();

  setBounds(rectOuter);
  mDefaultStateInnerBitmap.setBounds(rectInner);
  mPressedStateInnerBitmap.setBounds(rectInner);
  mVirtBounds = getBounds();
  mOrigBounds = mOuterBitmap.copyBounds();
  mBoundsBoxBitmap.setAlpha(0);
  mBoundsBoxBitmap.setBounds(getVirtBounds());
  SetInnerBounds();
}
 
源代码11 项目: Abelana-Android   文件: UserSettingsFragment.java
private void processImageResponse(String id, ImageResponse response) {
    if (response != null) {
        Bitmap bitmap = response.getBitmap();
        if (bitmap != null) {
            BitmapDrawable drawable = new BitmapDrawable(UserSettingsFragment.this.getResources(), bitmap);
            drawable.setBounds(0, 0,
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_width),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_height));
            userProfilePic = drawable;
            userProfilePicID = id;
            connectedStateLabel.setCompoundDrawables(null, drawable, null, null);
            connectedStateLabel.setTag(response.getRequest().getImageUri());
        }
    }
}
 
源代码12 项目: RichText   文件: ImageWrapper.java
Drawable getDrawable(Resources resources) {
    if (gifDrawable == null) {
        BitmapDrawable bitmapDrawable = new BitmapDrawable(resources, bitmap);
        bitmapDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
        return bitmapDrawable;
    } else {
        return gifDrawable;
    }
}
 
源代码13 项目: BoardView   文件: BoardView.java
private BitmapDrawable getAndAddHoverView(View v, float scale){
    int w = v.getWidth();
    int h = v.getHeight();
    int top = v.getTop();
    int left = v.getLeft();

    Bitmap b = getBitmapWithBorder(v,scale);
    BitmapDrawable drawable = new BitmapDrawable(getResources(),b);
    mHoverCellOriginalBounds = new Rect(left,top,left+w,top+h);
    mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds);
    drawable.setBounds(mHoverCellCurrentBounds);
    return drawable;
}
 
源代码14 项目: rox-android   文件: DragSortRecycler.java
private BitmapDrawable createFloatingBitmap(View v)
{
    floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(),v.getRight(), v.getBottom());
    floatingItemBounds = new Rect(floatingItemStatingBounds);

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

    BitmapDrawable retDrawable = new BitmapDrawable(v.getResources(), bitmap);
    retDrawable.setBounds(floatingItemBounds);

    return retDrawable;
}
 
源代码15 项目: toktok-android   文件: NewMessageActivity.java
private void createMiniContact(@NonNull final NewMessageRecyclerAdapter adapter) {
    CharSequence friendsList = "";

    for (final Friend friend : adapter.getSelectedFriends()) {
        SpannableStringBuilder sb = new SpannableStringBuilder();
        LinearLayout miniContact = createContactTextView(friend.userName);
        BitmapDrawable bd = convertViewToDrawable(miniContact);
        bd.setBounds(0, 0, bd.getIntrinsicWidth() * 3, bd.getIntrinsicHeight() * 3);

        sb.append(friend.userName).append(" ");
        sb.setSpan(new ImageSpan(bd),
                sb.length() - (friend.userName.length() + 1),
                sb.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mSelectedMini.setMovementMethod(LinkMovementMethod.getInstance());
        sb.setSpan(new ClickableSpan() {
            @Override
            public void onClick(View widget) {
                int i = 0;

                for (Friend item : adapter.getItems()) {
                    if (item.id == friend.id) {
                        adapter.selectItem(i);
                        selectItem(i);
                    }
                    i += 1;
                }
            }
        }, sb.length() - (friend.userName.length() + 1), sb.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        friendsList = TextUtils.concat(friendsList, sb);
    }

    mSelectedMini.setText(friendsList);
}
 
源代码16 项目: coursera-android   文件: ContactInfoListAdapter.java
public ContactInfoListAdapter(Context context, int layout, Cursor c,
		int flags) {

	super(context, layout, c, flags);

	mApplicationContext = context.getApplicationContext();

	// default thumbnail photo
	mNoPictureBitmap = (BitmapDrawable) context.getResources().getDrawable(
			R.drawable.ic_contact_picture);
	mBitmapSize = (int) context.getResources().getDimension(
			R.dimen.textview_height);
	mNoPictureBitmap.setBounds(0, 0, mBitmapSize, mBitmapSize);

}
 
源代码17 项目: Klyph   文件: UserSettingsFragment.java
private void processImageResponse(String id, ImageResponse response) {
    if (response != null) {
        Bitmap bitmap = response.getBitmap();
        if (bitmap != null) {
            BitmapDrawable drawable = new BitmapDrawable(UserSettingsFragment.this.getResources(), bitmap);
            drawable.setBounds(0, 0,
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_width),
                    getResources().getDimensionPixelSize(R.dimen.com_facebook_usersettingsfragment_profile_picture_height));
            userProfilePic = drawable;
            userProfilePicID = id;
            connectedStateLabel.setCompoundDrawables(null, drawable, null, null);
            connectedStateLabel.setTag(response.getRequest().getImageUri());
        }
    }
}
 
源代码18 项目: ALLGO   文件: DynamicListView.java
/**
 * Creates the hover cell with the appropriate bitmap and of appropriate
 * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every
 * single time an invalidate call is made.
 */
private BitmapDrawable getAndAddHoverView(View v) {

	int w = v.getWidth();
	int h = v.getHeight();
	int top = v.getTop();
	int left = v.getLeft();

	Bitmap b = getBitmapFromView(v);

	BitmapDrawable drawable = new BitmapDrawable(getResources(), b);

	mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h);
	mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds);

	drawable.setBounds(mHoverCellCurrentBounds);

	return drawable;
}
 
源代码19 项目: android-discourse   文件: UrlImageGetter.java
@Override
public void onResponse(ImageContainer response, boolean isImmediate) {
    if (mTextView.getTag(R.id.poste_image_getter) == UrlImageGetter.this && response.getBitmap() != null) {
        BitmapDrawable drawable = new BitmapDrawable(mRes, response.getBitmap());
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        String src = response.getRequestUrl();
        // redraw the image by invalidating the container
        // 由于下面重新设置了ImageSpan,所以这里invalidate就不必要了吧
        // urlDrawable.invalidateSelf();
        // UrlImageGetter.this.mTextView.invalidate();

        // TODO 这种方式基本完美解决显示图片问题, blog?
        // 把提取到下面显示的图片在放出来? 然后点击任何图片 进入到 帖子图片浏览界面。。?
        TextView v = UrlImageGetter.this.mTextView;
        CharSequence text = v.getText();
        if (!(text instanceof Spannable)) {
            return;
        }
        Spannable spanText = (Spannable) text;
        @SuppressWarnings("unchecked") ArrayList<String> imgs = (ArrayList<String>) v.getTag(R.id.poste_image_data);
        ImageSpan[] imageSpans = spanText.getSpans(0, spanText.length(), ImageSpan.class);
        L.i("%b X Recycled %b src: %s", isImmediate, response.getBitmap().isRecycled(), src);
        for (ImageSpan imgSpan : imageSpans) {
            int start = spanText.getSpanStart(imgSpan);
            int end = spanText.getSpanEnd(imgSpan);
            L.i("%d-%d :%s", start, end, imgSpan.getSource());
            String url = imgSpan.getSource();
            url = checkUrl(url);
            if (src.equals(url)) {
                spanText.removeSpan(imgSpan);
                ImageSpan is = new ImageSpan(drawable, src, ImageSpan.ALIGN_BASELINE);
                spanText.setSpan(is, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (imgs != null && imgs.contains(src)) {
                ImageClickableSpan ics = new ImageClickableSpan(src);
                spanText.setSpan(ics, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

        }
        v.setText(spanText);
    }

}
 
源代码20 项目: Ninja   文件: DynamicGridView.java
/**
 * Creates the hover cell with the appropriate bitmap and of appropriate
 * size. The hover cell's BitmapDrawable is drawn on top of the bitmap every
 * single time an invalidate call is made.
 */
private BitmapDrawable getAndAddHoverView(View v) {

    int w = v.getWidth();
    int h = v.getHeight();
    int top = v.getTop();
    int left = v.getLeft();

    Bitmap b = getBitmapFromView(v);

    BitmapDrawable drawable = new BitmapDrawable(getResources(), b);

    mHoverCellOriginalBounds = new Rect(left, top, left + w, top + h);
    mHoverCellCurrentBounds = new Rect(mHoverCellOriginalBounds);

    drawable.setBounds(mHoverCellCurrentBounds);

    return drawable;
}