List of usage examples for android.graphics.drawable Drawable getIntrinsicHeight
public int getIntrinsicHeight()
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 .j a va 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:net.osmand.plus.views.controls.DynamicListView.java
/** * dispatchDraw gets invoked when all the child views are about to be drawn. * By overriding this method, the hover cell (BitmapDrawable) can be drawn * over the listview's items whenever the listview is redrawn. *//* ww w . j a va 2 s . c o m*/ @Override protected void dispatchDraw(@NonNull Canvas canvas) { super.dispatchDraw(canvas); if (mHoverCell != null) { mHoverCell.draw(canvas); } // Draw dividers StableArrayAdapter stableAdapter = getStableAdapter(); if (getDivider() == null && stableAdapter != null && stableAdapter.hasDividers()) { List<Drawable> dividers = stableAdapter.getDividers(); final int count = getChildCount(); final int first = getFirstVisiblePosition(); final int headerCount = getHeaderViewsCount(); final int itemCount = getCount(); final int footerLimit = (itemCount - getFooterViewsCount()); final Rect bounds = new Rect(); bounds.left = getPaddingLeft(); bounds.right = getRight() - getLeft() - getPaddingRight(); final int listBottom = getBottom() - getTop() + getScrollY(); for (int i = 0; i < count; i++) { final int itemIndex = (first + i); final boolean isHeader = (itemIndex < headerCount); final boolean isFooter = (itemIndex >= footerLimit); if (!isHeader && !isFooter && itemIndex < dividers.size()) { Drawable divider = dividers.get(itemIndex - headerCount); if (divider != null) { final View child = getChildAt(i); int bottom = child.getBottom(); final boolean isLastItem = (i == (count - 1)); if (bottom < listBottom && !isLastItem) { final int nextIndex = (itemIndex + 1); if (nextIndex >= headerCount && nextIndex < footerLimit) { bounds.top = bottom; bounds.bottom = bottom + divider.getIntrinsicHeight(); drawDivider(canvas, divider, bounds); } } } } } } }
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 {//from w ww . j av a2 s .co 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:com.example.stickablelistview.StickListView.java
/** * Sets the drawable that will be drawn between each item in the list. If the drawable does * not have an intrinsic width, you should also call {@link #setDividerWidth(int)} * * @param divider The drawable to use.//from www . j a va2 s .c o m */ public void setDivider(Drawable divider) { mDivider = divider; if (divider != null) { setDividerHeight(divider.getIntrinsicHeight()); } else { setDividerHeight(0); } }
From source file:com.cm.beer.util.DrawableManager.java
/** * /* ww w.j a v a2s. co m*/ * @param urlString * @return */ public byte[] fetchDrawableAsByteArray(String urlString) { byte[] bitmapdata = null; if (mDrawableCache.containsKey(urlString)) { if (Logger.isLogEnabled()) Logger.log("Returning Drawable from Cache:" + urlString); SoftReference<Drawable> softReference = mDrawableCache.get(urlString); if ((softReference == null) || (softReference.get() == null)) { mDrawableCache.remove(urlString); if (Logger.isLogEnabled()) Logger.log("fetchDrawable():Soft Reference has been Garbage Collected:" + urlString); } else { Drawable drawable = softReference.get(); Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); bitmapdata = stream.toByteArray(); } } if (Logger.isLogEnabled()) Logger.log("image url:" + urlString); try { // prevents multithreaded fetches for the same image mLockCache.put(urlString, urlString); if (Logger.isLogEnabled()) Logger.log("Begin Downloading:" + urlString); InputStream is = fetch(urlString); if (Logger.isLogEnabled()) Logger.log("End Downloading:" + urlString); Drawable drawable = Drawable.createFromStream(is, "src"); mDrawableCache.put(urlString, new SoftReference<Drawable>(drawable)); mLockCache.remove(urlString); if (Logger.isLogEnabled()) Logger.log("got a thumbnail drawable: " + drawable.getBounds() + ", " + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", " + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth()); Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); bitmapdata = stream.toByteArray(); } catch (Throwable e) { Log.e(this.getClass().getName(), "fetchDrawable failed", e); return null; } return bitmapdata; }
From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java
@Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Drawable d = mCurrentDrawable; int dw = 0;// w ww. j a v a 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: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); }//from w w w . j av a2 s.c o m }
From source file:radialdemo.RadialMenuWidget.java
private void animateOuterWedges(int animation_direction) { boolean animationComplete = false; // Wedge 2//from w w w.ja v a2s .co m float slice2 = 360 / wedgeQty2; float start_slice2 = 270 - (slice2 / 2); // calculates where to put the images double rSlice2 = (2 * Math.PI) / wedgeQty2; double rStart2 = (2 * Math.PI) * (0.75) - (rSlice2 / 2); this.Wedges2 = new RadialMenuWedge[wedgeQty2]; this.iconRect2 = new Rect[wedgeQty2]; Wedge2Shown = true; int wedgeSizeChange = (r2MaxSize - r2MinSize) / animateSections; if (animation_direction == ANIMATE_OUT) { if (r2MinSize + r2VariableSize + wedgeSizeChange < r2MaxSize) { r2VariableSize += wedgeSizeChange; } else { animateOuterOut = false; r2VariableSize = r2MaxSize - r2MinSize; animationComplete = true; } // animates text size change this.animateTextSize = (textSize / animateSections) * (r2VariableSize / wedgeSizeChange); // calculates new wedge sizes for (int i = 0; i < Wedges2.length; i++) { this.Wedges2[i] = new RadialMenuWedge(xPosition, yPosition, r2MinSize, r2MinSize + r2VariableSize, (i * slice2) + start_slice2, slice2); float xCenter = (float) (Math.cos(((rSlice2 * i) + (rSlice2 * 0.5)) + rStart2) * (r2MinSize + r2VariableSize + r2MinSize) / 2) + xPosition; float yCenter = (float) (Math.sin(((rSlice2 * i) + (rSlice2 * 0.5)) + rStart2) * (r2MinSize + r2VariableSize + r2MinSize) / 2) + yPosition; int h = MaxIconSize; int w = MaxIconSize; if (wedge2Data.getChildren().get(i).getIcon() != 0) { Drawable drawable = getResources().getDrawable(wedge2Data.getChildren().get(i).getIcon()); h = getIconSize(drawable.getIntrinsicHeight(), MinIconSize, MaxIconSize); w = getIconSize(drawable.getIntrinsicWidth(), MinIconSize, MaxIconSize); } if (r2VariableSize < h) { h = r2VariableSize; } if (r2VariableSize < w) { w = r2VariableSize; } this.iconRect2[i] = new Rect((int) xCenter - w / 2, (int) yCenter - h / 2, (int) xCenter + w / 2, (int) yCenter + h / 2); int widthOffset = MaxSize; if (widthOffset < this.textRect.width() / 2) { widthOffset = this.textRect.width() / 2 + scalePX(3); } this.textBoxRect.set((xPosition - (widthOffset)), (int) (yPosition - (r2MinSize + r2VariableSize) - headerBuffer - this.textRect.height() - scalePX(3)), (xPosition + (widthOffset)), (yPosition - (r2MinSize + r2VariableSize) - headerBuffer + scalePX(3))); this.headerTextBottom = yPosition - (r2MinSize + r2VariableSize) - headerBuffer - this.textRect.bottom; } } else if (animation_direction == ANIMATE_IN) { if (r2MinSize < r2MaxSize - r2VariableSize - wedgeSizeChange) { r2VariableSize += wedgeSizeChange; } else { animateOuterIn = false; r2VariableSize = r2MaxSize; animationComplete = true; } // animates text size change this.animateTextSize = textSize - ((textSize / animateSections) * (r2VariableSize / wedgeSizeChange)); for (int i = 0; i < Wedges2.length; i++) { this.Wedges2[i] = new RadialMenuWedge(xPosition, yPosition, r2MinSize, r2MaxSize - r2VariableSize, (i * slice2) + start_slice2, slice2); float xCenter = (float) (Math.cos(((rSlice2 * i) + (rSlice2 * 0.5)) + rStart2) * (r2MaxSize - r2VariableSize + r2MinSize) / 2) + xPosition; float yCenter = (float) (Math.sin(((rSlice2 * i) + (rSlice2 * 0.5)) + rStart2) * (r2MaxSize - r2VariableSize + r2MinSize) / 2) + yPosition; int h = MaxIconSize; int w = MaxIconSize; if (wedge2Data.getChildren().get(i).getIcon() != 0) { Drawable drawable = getResources().getDrawable(wedge2Data.getChildren().get(i).getIcon()); h = getIconSize(drawable.getIntrinsicHeight(), MinIconSize, MaxIconSize); w = getIconSize(drawable.getIntrinsicWidth(), MinIconSize, MaxIconSize); } if (r2MaxSize - r2MinSize - r2VariableSize < h) { h = r2MaxSize - r2MinSize - r2VariableSize; } if (r2MaxSize - r2MinSize - r2VariableSize < w) { w = r2MaxSize - r2MinSize - r2VariableSize; } this.iconRect2[i] = new Rect((int) xCenter - w / 2, (int) yCenter - h / 2, (int) xCenter + w / 2, (int) yCenter + h / 2); // computes header text box int heightOffset = r2MaxSize - r2VariableSize; int widthOffset = MaxSize; if (MaxSize > r2MaxSize - r2VariableSize) { heightOffset = MaxSize; } if (widthOffset < this.textRect.width() / 2) { widthOffset = this.textRect.width() / 2 + scalePX(3); } this.textBoxRect.set((xPosition - (widthOffset)), (int) (yPosition - (heightOffset) - headerBuffer - this.textRect.height() - scalePX(3)), (xPosition + (widthOffset)), (yPosition - (heightOffset) - headerBuffer + scalePX(3))); this.headerTextBottom = yPosition - (heightOffset) - headerBuffer - this.textRect.bottom; } } if (animationComplete == true) { r2VariableSize = 0; this.animateTextSize = textSize; if (animation_direction == ANIMATE_IN) { Wedge2Shown = false; } } invalidate(); // re-draws the picture }
From source file:com.hippo.ehviewer.ui.scene.DownloadsScene.java
@Nullable @Override//from w w w . j av a 2 s. c o m public View onCreateView3(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.scene_download, container, false); View content = ViewUtils.$$(view, R.id.content); mRecyclerView = (EasyRecyclerView) ViewUtils.$$(content, R.id.recycler_view); FastScroller fastScroller = (FastScroller) ViewUtils.$$(content, R.id.fast_scroller); mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout); TextView tip = (TextView) ViewUtils.$$(view, R.id.tip); mViewTransition = new ViewTransition(content, tip); Context context = getContext2(); Assert.assertNotNull(content); Resources resources = context.getResources(); Drawable drawable = DrawableManager.getDrawable(context, R.drawable.big_download); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); tip.setCompoundDrawables(null, drawable, null, null); mAdapter = new DownloadAdapter(); mAdapter.setHasStableIds(true); mRecyclerView.setAdapter(mAdapter); mLayoutManager = new AutoStaggeredGridLayoutManager(0, StaggeredGridLayoutManager.VERTICAL); mLayoutManager.setColumnSize(resources.getDimensionPixelOffset(Settings.getDetailSizeResId())); mLayoutManager.setStrategy(AutoStaggeredGridLayoutManager.STRATEGY_MIN_SIZE); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, false)); mRecyclerView.setDrawSelectorOnTop(true); mRecyclerView.hasFixedSize(); mRecyclerView.setClipToPadding(false); mRecyclerView.setOnItemClickListener(this); mRecyclerView.setOnItemLongClickListener(this); mRecyclerView.setChoiceMode(EasyRecyclerView.CHOICE_MODE_MULTIPLE_CUSTOM); mRecyclerView.setCustomCheckedListener(new DownloadChoiceListener()); // Cancel change animation RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator(); if (itemAnimator instanceof SimpleItemAnimator) { ((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false); } int interval = resources.getDimensionPixelOffset(R.dimen.gallery_list_interval); int paddingH = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_h); int paddingV = resources.getDimensionPixelOffset(R.dimen.gallery_list_margin_v); MarginItemDecoration decoration = new MarginItemDecoration(interval, paddingH, paddingV, paddingH, paddingV); mRecyclerView.addItemDecoration(decoration); decoration.applyPaddings(mRecyclerView); if (mInitPosition >= 0) { mRecyclerView.scrollToPosition(mInitPosition); mInitPosition = -1; } fastScroller.attachToRecyclerView(mRecyclerView); HandlerDrawable handlerDrawable = new HandlerDrawable(); handlerDrawable.setColor(ResourcesUtils.getAttrColor(context, R.attr.colorAccent)); fastScroller.setHandlerDrawable(handlerDrawable); fastScroller.setOnDragHandlerListener(this); mFabLayout.setExpanded(false, false); mFabLayout.setHidePrimaryFab(true); mFabLayout.setAutoCancel(false); mFabLayout.setOnClickFabListener(this); addAboveSnackView(mFabLayout); updateView(); guide(); return view; }