Example usage for android.graphics.drawable Drawable copyBounds

List of usage examples for android.graphics.drawable Drawable copyBounds

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable copyBounds.

Prototype

@NonNull
public final Rect copyBounds() 

Source Link

Document

Return a copy of the drawable's bounds in a new Rect.

Usage

From source file:com.android.leanlauncher.WidgetPreviewLoader.java

private static void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h) {
    if (bitmap != null) {
        final Canvas c = new Canvas(bitmap);
        Rect oldBounds = d.copyBounds();
        d.setBounds(x, y, x + w, y + h);
        d.draw(c);//from  w ww  .ja  v a  2  s .c o  m
        d.setBounds(oldBounds); // Restore the bounds
        c.setBitmap(null);
    }
}

From source file:com.iangclifton.auid.horizontaliconview.HorizontalIconView.java

@Override
protected void onDraw(Canvas canvas) {
    if (mDrawables == null || mDrawables.isEmpty()) {
        return;//from w w w  .ja va  2  s. c  o m
    }

    final int width = getWidth();
    final int paddingBottom = getPaddingBottom();
    final int paddingLeft = getPaddingLeft();
    final int paddingTop = getPaddingTop();

    // Determine edges of visible content
    final int leftEdge = getScrollX();
    final int rightEdge = leftEdge + width;

    int left = paddingLeft;
    int top = paddingTop;
    mSkippedIconCount = 0;

    final int iconCount = mDrawables.size();
    for (int i = 0; i < iconCount; i++) {
        if (left + mIconSize < leftEdge) {
            // Icon is too far left to be seen
            left = left + mIconSize + mIconSpacing;
            mSkippedIconCount++;
            continue;
        }

        if (left > rightEdge) {
            // All remaining icons are right of the view
            break;
        }

        // Get a reference to the icon to be drawn
        final Drawable icon = mDrawables.get(i);
        icon.setBounds(left, top, left + mIconSize, top + mIconSize);
        icon.draw(canvas);

        // Icon was drawn, so track position
        final int drawnPosition = i - mSkippedIconCount;
        if (drawnPosition + 1 > mIconPositions.size()) {
            final Rect rect = icon.copyBounds();
            mIconPositions.add(rect);
        } else {
            final Rect rect = mIconPositions.get(drawnPosition);
            icon.copyBounds(rect);
        }

        // Update left position
        left = left + mIconSize + mIconSpacing;
    }

    if (mEdgeEffectLeft != null) {
        if (!mEdgeEffectLeft.isFinished()) {
            final int restoreCount = canvas.save();
            final int height = getHeight() - paddingTop - paddingBottom;

            canvas.rotate(270);
            canvas.translate(-height + paddingTop, Math.min(0, leftEdge));
            mEdgeEffectLeft.setSize(height, getWidth());
            if (mEdgeEffectLeft.draw(canvas)) {
                postInvalidateOnAnimation();
            }
            canvas.restoreToCount(restoreCount);
        }
        if (!mEdgeEffectRight.isFinished()) {
            final int restoreCount = canvas.save();
            final int height = getHeight() - paddingTop - paddingBottom;

            canvas.rotate(90);
            canvas.translate(-paddingTop, -(Math.max(mScrollRange, leftEdge) + width));
            mEdgeEffectRight.setSize(height, width);
            if (mEdgeEffectRight.draw(canvas)) {
                postInvalidateOnAnimation();
            }
            canvas.restoreToCount(restoreCount);
        }
    }
}

From source file:com.android.launcher2.AsyncTaskCallback.java

private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h, float scale) {
    if (bitmap != null) {
        Canvas c = new Canvas(bitmap);
        c.scale(scale, scale);//from   w ww  . ja v  a 2 s.c o  m
        Rect oldBounds = d.copyBounds();
        d.setBounds(x, y, x + w, y + h);
        d.draw(c);
        d.setBounds(oldBounds); // Restore the bounds
        c.setBitmap(null);
    }
}