Java Code Examples for android.graphics.drawable.Drawable#setBounds()
The following examples show how to use
android.graphics.drawable.Drawable#setBounds() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmileyUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 6 votes |
public static SpannableStringBuilder replaceSmileyCode2Smiley(Context context, String input) { if (TextUtils.isEmpty(input)) { return new SpannableStringBuilder(""); } Pattern pattern = Pattern.compile("ddddd", Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(input); SpannableStringBuilder ssb = new SpannableStringBuilder(input); while (matcher.find()) { String found = matcher.group(); EmoticonBean bean = EmojiDb.getEmojiByUnicode(context, found); if (bean != null) { Drawable drawable = ImageLoader.getInstance(context).getDrawable(bean.getIconUri()); if (drawable != null) { int itemHeight = drawable.getIntrinsicHeight(); int itemWidth = drawable.getIntrinsicWidth(); drawable.setBounds(0, 0, itemHeight, itemWidth); VerticalImageSpan imageSpan = new VerticalImageSpan(drawable); ssb.setSpan(imageSpan, matcher.start(), matcher.end(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } } } return ssb; }
Example 2
Source File: SelectableRoundedImageView.java From Expert-Android-Programming with MIT License | 6 votes |
public static Bitmap drawableToBitmap1(Drawable drawable) { if (drawable == null) { return null; } if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } Bitmap bitmap; int width = Math.max(drawable.getIntrinsicWidth(), 2); int height = Math.max(drawable.getIntrinsicHeight(), 2); try { bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); } catch (IllegalArgumentException e) { MyLg.e(TAG, "Error " + e.getMessage()); e.printStackTrace(); bitmap = null; } return bitmap; }
Example 3
Source File: BaseEffectBridgeWrapper.java From AndroidTVWidget with Apache License 2.0 | 6 votes |
/** * 绘制外部阴影. */ public void onDrawShadow(Canvas canvas) { Drawable drawableShadow = getShadowDrawable(); if (drawableShadow != null) { RectF shadowPaddingRect = getDrawShadowRect(); int width = getMainUpView().getWidth(); int height = getMainUpView().getHeight(); Rect padding = new Rect(); drawableShadow.getPadding(padding); // int left = (int)Math.rint(shadowPaddingRect.left); int right = (int)Math.rint(shadowPaddingRect.right); int bottom = (int)Math.rint(shadowPaddingRect.bottom); int top = (int)Math.rint(shadowPaddingRect.top); // drawableShadow.setBounds(-padding.left - (left), -padding.top - (top), width + padding.right + (right), height + padding.bottom + (bottom)); drawableShadow.draw(canvas); } }
Example 4
Source File: EasyRatingBar.java From NovelReader with MIT License | 5 votes |
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Drawable normalDrawable = getDrawable(mNormalWeak,mNormalRes); Drawable selectDrawable = getDrawable(mSelectWeak,mSelectRes); //绘制的半径 int radius = Math.min(mRoomWidth, mRoomHeight)/2 - mInterval; //进行绘制 for (int i=0; i<mRateCount; ++i){ int roomWidthCenter = 0; if (i == 0){ roomWidthCenter = mRoomWidth/2-mInterval; } else if (i==mRateCount-1){ roomWidthCenter = mRoomWidth/2 + mRoomWidth*i + mInterval; } else { roomWidthCenter = mRoomWidth/2 + mRoomWidth*i; } int roomHeightCenter = mRoomHeight /2; canvas.save(); canvas.translate(roomWidthCenter,roomHeightCenter); //绘制正常图片 normalDrawable.setBounds(-radius,-radius,radius,radius); normalDrawable.draw(canvas); //绘制选中图片 if (i < mCurrentRate){ selectDrawable.setBounds(-radius,-radius,radius,radius); selectDrawable.draw(canvas); } canvas.restore(); } }
Example 5
Source File: ItemizedOverlay.java From android_frameworks_mapsv1 with Apache License 2.0 | 5 votes |
@OriginalApi protected static Drawable boundCenter(Drawable ballon) { int width = ballon.getIntrinsicWidth(); int halfWidth = width / 2; int height = ballon.getIntrinsicHeight(); int halfHeight = height / 2; ballon.setBounds(-halfWidth, -halfHeight, width - halfWidth, height - halfHeight); return ballon; }
Example 6
Source File: PlayListAdapter.java From Musicoco with Apache License 2.0 | 5 votes |
private void setSelectItem(ViewHolder holder) { Drawable drawable; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { drawable = context.getDrawable(R.drawable.ic_volume_up_black_24dp); if (drawable != null) { drawable.setTint(accentC); } } else { drawable = context.getResources().getDrawable(R.drawable.ic_volume_up_black_24dp); } if (drawable != null) { drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); holder.number.setCompoundDrawables(drawable, null, null, null); holder.number.setText(""); } holder.name.setTextColor(accentC); holder.arts.setTextColor(accentC); holder.number.setTextColor(accentC); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { holder.remove.getDrawable().setTint(accentC); } }
Example 7
Source File: HelpUtils.java From browser with GNU General Public License v2.0 | 5 votes |
/** * * @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; }
Example 8
Source File: LetvVipActivity.java From letv with Apache License 2.0 | 5 votes |
private void updateVipUI(boolean isSeniorVip) { boolean z = false; this.mIsSeniorVip = isSeniorVip; if (isSeniorVip) { this.mIsOneKeySignWithAlipayFlag = this.mAllScreenSignFlag; setFragmentArguments(this.mSuperVipFragment, this.mIsOneKeySignWithAlipayFlag, isSeniorVip); showFragmentIfNeeded(this.mSuperVipFragment); ImageDownloader.getInstance().download(this.mProductImageView, this.mSuperVipFragment.getmVipProductBean().mMobilePic); this.mSuperVipButton.setBackgroundResource(2130838846); this.mMobileDevicesVipButton.setBackgroundResource(2130838839); this.mMobileDevicesVipButton.setTextColor(getResources().getColor(2131493223)); this.mSuperVipButton.setTextColor(getResources().getColor(2131493377)); this.mVipImageView.setBackgroundResource(2130838990); Drawable drawable = getResources().getDrawable(2130839188); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); this.mSuperVipTipTv.setCompoundDrawables(drawable, null, null, null); this.mVipNameTv.setText(getString(2131101134)); PreferencesManager instance = PreferencesManager.getInstance(); if (this.mMobileSignFlag == 1 || this.mAllScreenSignFlag == 1) { z = true; } instance.setAlipayAutoOpenStatus(z); return; } this.mIsOneKeySignWithAlipayFlag = this.mMobileSignFlag; setFragmentArguments(this.mMobileDevicesVipFragment, this.mIsOneKeySignWithAlipayFlag, isSeniorVip); showFragmentIfNeeded(this.mMobileDevicesVipFragment); ImageDownloader.getInstance().download(this.mProductImageView, this.mMobileDevicesVipFragment.getmVipProductBean().mMobilePic, 2130838798, ScaleType.FIT_XY); this.mSuperVipButton.setBackgroundResource(2130838845); this.mMobileDevicesVipButton.setBackgroundResource(2130838840); this.mMobileDevicesVipButton.setTextColor(getResources().getColor(2131493377)); this.mSuperVipButton.setTextColor(getResources().getColor(2131493223)); this.mVipImageView.setBackgroundResource(2130838611); drawable = getResources().getDrawable(2130839198); drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); this.mSuperVipTipTv.setCompoundDrawables(drawable, null, null, null); this.mVipNameTv.setText(getString(2131101101)); }
Example 9
Source File: CircleImageView.java From AndJie with GNU General Public License v2.0 | 5 votes |
private Bitmap getBitmapFromDrawable(Drawable drawable) { if (drawable == null) { return null; } if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } try { Bitmap bitmap; if (drawable instanceof ColorDrawable) { bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG); } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG); } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; } catch (OutOfMemoryError e) { return null; } }
Example 10
Source File: CustomRatingBar.java From QuickDevFramework with Apache License 2.0 | 5 votes |
private static Bitmap drawableToBitmap(Drawable drawable) { int w = drawable.getIntrinsicWidth(); int h = drawable.getIntrinsicHeight(); Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565; Bitmap bitmap = Bitmap.createBitmap(w, h, config); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, w, h); drawable.draw(canvas); return bitmap; }
Example 11
Source File: BitmapUtils.java From JianshuApp with GNU General Public License v3.0 | 5 votes |
public static Bitmap toBitmap(Drawable drawable) { int w = drawable.getIntrinsicWidth(); int h = drawable.getIntrinsicHeight(); Bitmap bitmap = Bitmap.createBitmap(w, h, drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, w, h); drawable.draw(canvas); return bitmap; }
Example 12
Source File: Utils.java From KUAS-AP-Material with MIT License | 5 votes |
public static Bitmap convertDrawableToBitmap(Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } 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; }
Example 13
Source File: LauncherIconHelper.java From HgLauncher with GNU General Public License v3.0 | 5 votes |
/** * Adds a shadow to a Bitmap. * <p> * TODO: Make this return Drawable for our use case. * * @param drawable Drawable that should be used as the foreground layer * of the shadow. * @param dstHeight Height of the returned bitmap. * @param dstWidth Width of the returned bitmap. * @param color Colour of the drawn shadow. * @param size Size of the drawn shadow. * @param dx Shadow x direction. * @param dy Shadow y direction. * * @return Bitmap with resulting shadow. * * @author schwiz (https://stackoverflow.com/a/24579764) */ private static Bitmap addShadow(final Drawable drawable, final int dstHeight, final int dstWidth, int color, int size, float dx, float dy) { final Bitmap bm = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(bm); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); final Bitmap mask = Bitmap.createBitmap(dstWidth, dstHeight, Bitmap.Config.ALPHA_8); final Matrix scaleToFit = new Matrix(); final RectF src = new RectF(0, 0, bm.getWidth(), bm.getHeight()); final RectF dst = new RectF(0, 0, dstWidth - dx, dstHeight - dy); scaleToFit.setRectToRect(src, dst, Matrix.ScaleToFit.FILL); final Matrix dropShadow = new Matrix(scaleToFit); dropShadow.postTranslate(dx, dy); final Canvas maskCanvas = new Canvas(mask); final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); maskCanvas.drawBitmap(bm, scaleToFit, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT)); maskCanvas.drawBitmap(bm, dropShadow, paint); final BlurMaskFilter filter = new BlurMaskFilter(size, BlurMaskFilter.Blur.SOLID); paint.reset(); paint.setAntiAlias(true); paint.setColor(color); paint.setMaskFilter(filter); paint.setFilterBitmap(true); final Bitmap ret = Bitmap.createBitmap(dstWidth, dstHeight, Bitmap.Config.ARGB_8888); final Canvas retCanvas = new Canvas(ret); retCanvas.drawBitmap(mask, 0, 0, paint); retCanvas.drawBitmap(bm, scaleToFit, null); mask.recycle(); return ret; }
Example 14
Source File: ImageUtils.java From wakao-app with MIT License | 5 votes |
/** * 将Drawable转化为Bitmap * * @param drawable * @return */ public static Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap bitmap = Bitmap.createBitmap(width, height, drawable .getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, width, height); drawable.draw(canvas); return bitmap; }
Example 15
Source File: BBCodeReader.java From AndFChat with GNU General Public License v3.0 | 5 votes |
@Override public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) { ImageView image = new ImageView(context); image.setImageBitmap(resource); // Possibly runOnUiThread() Drawable dImage = image.getDrawable(); dImage.setBounds(0, 0, dImage.getIntrinsicWidth(), dImage.getIntrinsicHeight()); icon.addState(new int[]{android.R.attr.state_last}, dImage); icon.setState(new int[]{android.R.attr.state_last}); Ln.i("Does this even happen?"); }
Example 16
Source File: ContactEditText.java From material with Apache License 2.0 | 5 votes |
public void setImageDrawable(Drawable drawable) { if(drawable == null) return; if (drawable instanceof BitmapDrawable) setImage(((BitmapDrawable) drawable).getBitmap()); else{ Bitmap bm = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bm); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); setImage(bm); } }
Example 17
Source File: LockscreenAppBar.java From GravityBox with Apache License 2.0 | 4 votes |
private Drawable createBadgeDrawable(Drawable d, int count) { if (d == null) return null; NumberFormat f = NumberFormat.getIntegerInstance(); String countStr = count > 99 ? "99+" : f.format(count); Bitmap b = Utils.drawableToBitmap(d); b = b.copy(Bitmap.Config.ARGB_8888, true); Canvas c = new Canvas(b); Paint p = new Paint(); p.setTextAlign(Paint.Align.CENTER); p.setColor(Color.WHITE); p.setAntiAlias(true); p.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, mResources.getDisplayMetrics())); Drawable bg = mGbResources.getDrawable(R.drawable.ic_notification_overlay, null); final int w = b.getWidth(); final int h = b.getHeight(); final Rect r = new Rect(); p.getTextBounds(countStr, 0, countStr.length(), r); final int tw = r.right - r.left; final int th = r.bottom - r.top; bg.getPadding(r); int dw = r.left + tw + r.right; if (dw < bg.getMinimumWidth()) { dw = bg.getMinimumWidth(); } int x = w-r.right-((dw-r.right-r.left)/2); int dh = r.top + th + r.bottom; if (dh < bg.getMinimumHeight()) { dh = bg.getMinimumHeight(); } if (dw < dh) dw = dh; int y = h-r.bottom-((dh-r.top-th-r.bottom)/2); bg.setBounds(w-dw, h-dh, w, h); bg.draw(c); c.drawText(countStr, x, y, p); return new BitmapDrawable(mResources, b); }
Example 18
Source File: MusicPlayerService.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public void onCreate() { audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) { NotificationCenter.getInstance(a).addObserver(this, NotificationCenter.messagePlayingDidSeek); NotificationCenter.getInstance(a).addObserver(this, NotificationCenter.messagePlayingPlayStateChanged); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mediaSession = new MediaSession(this, "telegramAudioPlayer"); playbackState = new PlaybackState.Builder(); albumArtPlaceholder = Bitmap.createBitmap(AndroidUtilities.dp(102), AndroidUtilities.dp(102), Bitmap.Config.ARGB_8888); Drawable placeholder = getResources().getDrawable(R.drawable.nocover_big); placeholder.setBounds(0, 0, albumArtPlaceholder.getWidth(), albumArtPlaceholder.getHeight()); placeholder.draw(new Canvas(albumArtPlaceholder)); mediaSession.setCallback(new MediaSession.Callback() { @Override public void onPlay() { MediaController.getInstance().playMessage(MediaController.getInstance().getPlayingMessageObject()); } @Override public void onPause() { MediaController.getInstance().pauseMessage(MediaController.getInstance().getPlayingMessageObject()); } @Override public void onSkipToNext() { MediaController.getInstance().playNextMessage(); } @Override public void onSkipToPrevious() { MediaController.getInstance().playPreviousMessage(); } @Override public void onStop() { //stopSelf(); } }); mediaSession.setActive(true); } super.onCreate(); }
Example 19
Source File: LatinKeyboard.java From hackerskeyboard with Apache License 2.0 | 4 votes |
private void setDefaultBounds(Drawable drawable) { drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); }
Example 20
Source File: AroundCircleView.java From Pas with Apache License 2.0 | 4 votes |
private Bitmap getBitmapFromDrawable(Drawable drawable) { if (drawable == null) { return null; } if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } try { Bitmap bitmap; if (drawable instanceof ColorDrawable) { bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG); } else { // 为0就自己加上需要的 要改不 就 传值 变化 或者 这里可以先测量一下? if (drawable.getIntrinsicWidth() <= 0) { int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); measure(w, h); int height = getMeasuredHeight(); int width = getMeasuredWidth(); System.out.println(height + "---" + width); bitmap = Bitmap .createBitmap(width, height, BITMAP_CONFIG); } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG); } } Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return bitmap; } catch (OutOfMemoryError e) { return null; } }