List of usage examples for android.graphics.drawable Drawable getIntrinsicWidth
public int getIntrinsicWidth()
From source file:github.madmarty.madsonic.util.ImageLoader.java
@SuppressWarnings("deprecation") private void setImage(View view, Drawable drawable, boolean crossfade) { if (view instanceof TextView) { // Cross-fading is not implemented for TextView since it's not in use. It would be easy to add it, though. TextView textView = (TextView) view; textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); } else if (view instanceof ImageView) { ImageView imageView = (ImageView) view; if (crossfade) { Drawable existingDrawable = imageView.getDrawable(); if (existingDrawable == null) { Bitmap emptyImage;//from w w w . ja v a 2s .c o m if (drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0) { emptyImage = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); } else { emptyImage = Bitmap.createBitmap(imageSizeDefault, imageSizeDefault, Bitmap.Config.ARGB_8888); } existingDrawable = new BitmapDrawable(emptyImage); } else { // Try to get rid of old transitions try { TransitionDrawable tmp = (TransitionDrawable) existingDrawable; int layers = tmp.getNumberOfLayers(); existingDrawable = tmp.getDrawable(layers - 1); } catch (Exception e) { // Do nothing, just means that the drawable is a flat image } } Drawable[] layers = new Drawable[] { existingDrawable, drawable }; TransitionDrawable transitionDrawable = new TransitionDrawable(layers); imageView.setImageDrawable(transitionDrawable); transitionDrawable.startTransition(250); } else { imageView.setImageDrawable(drawable); } } }
From source file:com.keylesspalace.tusky.activity.ComposeActivity.java
private void setStatusVisibility(String visibility) { statusVisibility = visibility;/*from w ww . j av a 2 s.co m*/ switch (visibility) { case "public": { floatingBtn.setText(R.string.action_send_public); floatingBtn.setCompoundDrawables(null, null, null, null); break; } case "private": { floatingBtn.setText(R.string.action_send); Drawable lock = AppCompatResources.getDrawable(this, R.drawable.send_private); if (lock != null) { lock.setBounds(0, 0, lock.getIntrinsicWidth(), lock.getIntrinsicHeight()); floatingBtn.setCompoundDrawables(null, null, lock, null); } break; } default: { floatingBtn.setText(R.string.action_send); floatingBtn.setCompoundDrawables(null, null, null, null); break; } } }
From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java
@Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Drawable d = mCurrentDrawable; int dw = 0;/*from w w w. ja va 2 s.c o m*/ int dh = 0; if (d != null) { dw = Math.max(mMinWidth, Math.min(mMaxWidth, d.getIntrinsicWidth())); dh = Math.max(mMinHeight, Math.min(mMaxHeight, d.getIntrinsicHeight())); } updateDrawableState(); dw += getPaddingLeft() + getPaddingRight(); dh += getPaddingTop() + getPaddingBottom(); if (IS_HONEYCOMB) { setMeasuredDimension(View.resolveSizeAndState(dw, widthMeasureSpec, 0), View.resolveSizeAndState(dh, heightMeasureSpec, 0)); } else { setMeasuredDimension(View.resolveSize(dw, widthMeasureSpec), View.resolveSize(dh, heightMeasureSpec)); } }
From source file:github.daneren2005.dsub.util.ImageLoader.java
private void setImage(View view, final Drawable drawable, boolean crossfade) { if (view instanceof TextView) { // Cross-fading is not implemented for TextView since it's not in use. It would be easy to add it, though. TextView textView = (TextView) view; textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); } else if (view instanceof ImageView) { final ImageView imageView = (ImageView) view; if (crossfade && drawable != null) { Drawable existingDrawable = imageView.getDrawable(); if (existingDrawable == null) { Bitmap emptyImage;//w w w . ja v a 2s . co m if (drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0) { emptyImage = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); } else { emptyImage = Bitmap.createBitmap(imageSizeDefault, imageSizeDefault, Bitmap.Config.ARGB_8888); } existingDrawable = new BitmapDrawable(context.getResources(), emptyImage); } else if (existingDrawable instanceof TransitionDrawable) { // This should only ever be used if user is skipping through many songs quickly TransitionDrawable tmp = (TransitionDrawable) existingDrawable; existingDrawable = tmp.getDrawable(tmp.getNumberOfLayers() - 1); } if (existingDrawable != null && drawable != null) { Drawable[] layers = new Drawable[] { existingDrawable, drawable }; final TransitionDrawable transitionDrawable = new TransitionDrawable(layers); imageView.setImageDrawable(transitionDrawable); transitionDrawable.startTransition(250); // Get rid of transition drawable after transition occurs handler.postDelayed(new Runnable() { @Override public void run() { // Only execute if still on same transition drawable if (imageView.getDrawable() == transitionDrawable) { imageView.setImageDrawable(drawable); } } }, 500L); } else { imageView.setImageDrawable(drawable); } } else { imageView.setImageDrawable(drawable); } } }
From source file:com.android.leanlauncher.WidgetPreviewLoader.java
public Bitmap generateWidgetPreview(AppWidgetProviderInfo info, int cellHSpan, int cellVSpan, int maxPreviewWidth, int maxPreviewHeight, Bitmap preview, int[] preScaledWidthOut) { // Load the preview image if possible if (maxPreviewWidth < 0) maxPreviewWidth = Integer.MAX_VALUE; Drawable drawable = null; if (info.previewImage != 0) { drawable = mManager.loadPreview(info); if (drawable != null) { drawable = mutateOnMainThread(drawable); } else {/* w ww . j av a2 s . c o m*/ Log.w(TAG, "Can't load widget preview drawable 0x" + Integer.toHexString(info.previewImage) + " for provider: " + info.provider); } } int previewWidth; int previewHeight; Bitmap defaultPreview = null; boolean widgetPreviewExists = (drawable != null); if (widgetPreviewExists) { previewWidth = drawable.getIntrinsicWidth(); previewHeight = drawable.getIntrinsicHeight(); } else { // Generate a preview image if we couldn't load one if (cellHSpan < 1) cellHSpan = 1; if (cellVSpan < 1) cellVSpan = 1; // This Drawable is not directly drawn, so there's no need to mutate it. BitmapDrawable previewDrawable = (BitmapDrawable) mContext.getResources() .getDrawable(R.drawable.widget_tile); final int previewDrawableWidth = previewDrawable.getIntrinsicWidth(); final int previewDrawableHeight = previewDrawable.getIntrinsicHeight(); previewWidth = previewDrawableWidth * cellHSpan; previewHeight = previewDrawableHeight * cellVSpan; defaultPreview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888); final Canvas c = mCachedAppWidgetPreviewCanvas.get(); c.setBitmap(defaultPreview); Paint p = mDefaultAppWidgetPreviewPaint.get(); if (p == null) { p = new Paint(); p.setShader(new BitmapShader(previewDrawable.getBitmap(), Shader.TileMode.REPEAT, Shader.TileMode.REPEAT)); mDefaultAppWidgetPreviewPaint.set(p); } final Rect dest = mCachedAppWidgetPreviewDestRect.get(); dest.set(0, 0, previewWidth, previewHeight); c.drawRect(dest, p); c.setBitmap(null); // Draw the icon in the top left corner int minOffset = (int) (mAppIconSize * WIDGET_PREVIEW_ICON_PADDING_PERCENTAGE); int smallestSide = Math.min(previewWidth, previewHeight); float iconScale = Math.min((float) smallestSide / (mAppIconSize + 2 * minOffset), 1f); try { Bitmap icon = mIconCache.getIconForComponent(info.configure, UserHandleCompat.myUserHandle()); if (icon != null) { int hoffset = (int) ((previewDrawableWidth - mAppIconSize * iconScale) / 2); int yoffset = (int) ((previewDrawableHeight - mAppIconSize * iconScale) / 2); renderBitmapIconOnPreview(icon, defaultPreview, hoffset, yoffset, (int) (mAppIconSize * iconScale), (int) (mAppIconSize * iconScale)); } } catch (Resources.NotFoundException ignored) { } } // Scale to fit width only - let the widget preview be clipped in the // vertical dimension float scale = 1f; if (preScaledWidthOut != null) { preScaledWidthOut[0] = previewWidth; } if (previewWidth > maxPreviewWidth) { scale = maxPreviewWidth / (float) previewWidth; } if (scale != 1f) { previewWidth = (int) (scale * previewWidth); previewHeight = (int) (scale * previewHeight); } // If a bitmap is passed in, we use it; otherwise, we create a bitmap of the right size if (preview == null) { preview = Bitmap.createBitmap(previewWidth, previewHeight, Config.ARGB_8888); } // Draw the scaled preview into the final bitmap int x = (preview.getWidth() - previewWidth) / 2; if (widgetPreviewExists) { renderDrawableToBitmap(drawable, preview, x, 0, previewWidth, previewHeight); } else { final Canvas c = mCachedAppWidgetPreviewCanvas.get(); final Rect src = mCachedAppWidgetPreviewSrcRect.get(); final Rect dest = mCachedAppWidgetPreviewDestRect.get(); c.setBitmap(preview); src.set(0, 0, defaultPreview.getWidth(), defaultPreview.getHeight()); dest.set(x, 0, x + previewWidth, previewHeight); Paint p = mCachedAppWidgetPreviewPaint.get(); if (p == null) { p = new Paint(); p.setFilterBitmap(true); mCachedAppWidgetPreviewPaint.set(p); } c.drawBitmap(defaultPreview, src, dest, p); c.setBitmap(null); } return preview; }
From source file:net.gsantner.opoc.util.ContextUtils.java
/** * Get a {@link Bitmap} out of a {@link Drawable} *///from w ww.j a v a2 s. c o m public Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = null; if (drawable instanceof VectorDrawableCompat || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && drawable instanceof VectorDrawable) || ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && drawable instanceof AdaptiveIconDrawable))) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { drawable = (DrawableCompat.wrap(drawable)).mutate(); } 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); } else if (drawable instanceof BitmapDrawable) { bitmap = ((BitmapDrawable) drawable).getBitmap(); } return bitmap; }
From source file:org.kymjs.aframe.ui.widget.HorizontalListView.java
public void setDivider(Drawable divider) { mDivider = divider;/* w w w. j a va2s.c o m*/ if (divider != null) { setDividerWidth(divider.getIntrinsicWidth()); } else { setDividerWidth(0); } }
From source file:cn.kangeqiu.kq.activity.GroupDetailsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ??groupid/*from w w w . ja v a2s.c o m*/ groupId = getIntent().getStringExtra("groupId"); group = EMGroupManager.getInstance().getGroup(groupId); roomId = getIntent().getStringExtra("roomId"); // we are not supposed to show the group if we don't find the group if (group == null) { finish(); return; } setContentView(R.layout.activity_group_details); shareUtil = new ShareUtils(this); instance = this; st = getResources().getString(R.string.people); clearAllHistory = (RelativeLayout) findViewById(R.id.clear_all_history); userGridview = (ExpandGridView) findViewById(R.id.gridview); loadingPB = (ProgressBar) findViewById(R.id.progressBar); exitBtn = (Button) findViewById(R.id.btn_exit_grp); deleteBtn = (Button) findViewById(R.id.btn_exitdel_grp); blacklistLayout = (RelativeLayout) findViewById(R.id.rl_blacklist); changeGroupNameLayout = (RelativeLayout) findViewById(R.id.rl_change_group_name); rl_switch_block_groupmsg = (RelativeLayout) findViewById(R.id.rl_switch_block_groupmsg); iv_switch_block_groupmsg = (ImageView) findViewById(R.id.iv_switch_block_groupmsg); iv_switch_unblock_groupmsg = (ImageView) findViewById(R.id.iv_switch_unblock_groupmsg); hourse_name = (TextView) findViewById(R.id.hourse_name); invite_number = (TextView) findViewById(R.id.invite_number); match_name = (TextView) findViewById(R.id.match_name); rl_chuiniu = (RelativeLayout) findViewById(R.id.rl_chuiniu); rl_guess = (RelativeLayout) findViewById(R.id.rl_guess); rl_match_name = (RelativeLayout) findViewById(R.id.rl_match_name); member_sum = (TextView) findViewById(R.id.member_sum); rl_chuiniu.setOnClickListener(this); rl_guess.setOnClickListener(this); rl_switch_block_groupmsg.setOnClickListener(this); Drawable referenceDrawable = getResources().getDrawable(R.drawable.smiley_add_btn); referenceWidth = referenceDrawable.getIntrinsicWidth(); referenceHeight = referenceDrawable.getIntrinsicHeight(); if (group.getOwner() == null || "".equals(group.getOwner()) || !group.getOwner().equals(EMChatManager.getInstance().getCurrentUser())) { exitBtn.setVisibility(View.GONE); deleteBtn.setVisibility(View.GONE); blacklistLayout.setVisibility(View.GONE); // changeGroupNameLayout.setVisibility(View.GONE); changeGroupNameLayout.setClickable(false); changeGroupNameLayout.setFocusable(false); findViewById(R.id.hourse_name_right).setVisibility(View.INVISIBLE); } // if (EMChatManager.getInstance().getCurrentUser().equals(group.getOwner())) { exitBtn.setVisibility(View.GONE); deleteBtn.setVisibility(View.VISIBLE); findViewById(R.id.hourse_name_right).setVisibility(View.VISIBLE); findViewById(R.id.match_right).setVisibility(View.VISIBLE); changeGroupNameLayout.setOnClickListener(this); rl_match_name.setOnClickListener(this); } // ((TextView) // findViewById(R.id.group_name)).setText(group.getGroupName() // + "(" + group.getAffiliationsCount() + st); List<String> members = new ArrayList<String>(); members.addAll(group.getMembers()); adapter = new GridAdapter(this, R.layout.grid); userGridview.setAdapter(adapter); // ???group updateGroup(); // OnTouchListener userGridview.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (adapter.isInDeleteMode) { adapter.isInDeleteMode = false; adapter.notifyDataSetChanged(); return true; } break; default: break; } return false; } }); clearAllHistory.setOnClickListener(this); blacklistLayout.setOnClickListener(this); initDate(); }
From source file:com.fa.mastodon.activity.ComposeActivity.java
private void addLockToSendButton() { floatingBtn.setText(R.string.action_send); Drawable lock = AppCompatResources.getDrawable(this, R.drawable.send_private); if (lock != null) { lock.setBounds(0, 0, lock.getIntrinsicWidth(), lock.getIntrinsicHeight()); floatingBtn.setCompoundDrawables(null, null, lock, null); }/* ww w.j a v a 2 s . c om*/ }
From source file:com.ycl.framework.photoview.PhotoViewAttacher.java
/** * Calculate Matrix for FIT_CENTER/*from ww w.j a va 2 s. co m*/ * * @param d - Drawable being displayed */ private void updateBaseMatrix(Drawable d) { ImageView imageView = getImageView(); if (null == imageView || null == d) { return; } final float viewWidth = getImageViewWidth(imageView); final float viewHeight = getImageViewHeight(imageView); final int drawableWidth = d.getIntrinsicWidth(); final int drawableHeight = d.getIntrinsicHeight(); mBaseMatrix.reset(); final float widthScale = viewWidth / drawableWidth; final float heightScale = viewHeight / drawableHeight; if (mScaleType == ScaleType.CENTER) { mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F, (viewHeight - drawableHeight) / 2F); } else if (mScaleType == ScaleType.CENTER_CROP) { float scale = Math.max(widthScale, heightScale); mBaseMatrix.postScale(scale, scale); mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F, (viewHeight - drawableHeight * scale) / 2F); } else if (mScaleType == ScaleType.CENTER_INSIDE) { float scale = Math.min(1.0f, Math.min(widthScale, heightScale)); mBaseMatrix.postScale(scale, scale); mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F, (viewHeight - drawableHeight * scale) / 2F); } else { RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight); RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight); switch (mScaleType) { case FIT_CENTER: mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER); break; case FIT_START: mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START); break; case FIT_END: mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END); break; case FIT_XY: mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL); break; default: break; } } resetMatrix(); }