Example usage for android.graphics.drawable ColorDrawable draw

List of usage examples for android.graphics.drawable ColorDrawable draw

Introduction

In this page you can find the example usage for android.graphics.drawable ColorDrawable draw.

Prototype

@Override
    public void draw(Canvas canvas) 

Source Link

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static int getColor(final ColorDrawable colorDrawable) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        final Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        final Canvas canvas = new Canvas(bitmap);
        colorDrawable.draw(canvas);
        return bitmap.getPixel(0, 0);
    } else {/*  w w  w  . j a v a  2  s  .co  m*/
        return colorDrawable.getColor();
    }
}

From source file:Main.java

public static int colorDrawableGetColor(ColorDrawable d) {
    try {//from   w  ww . j av  a  2  s .  c  om
        Method getColor = d.getClass().getMethod("getColor");
        return (Integer) getColor.invoke(d);
    } catch (NoSuchMethodException ignore) {
    } catch (InvocationTargetException ignore) {
    } catch (IllegalAccessException ignore) {
    } catch (ClassCastException ignore) {
    }

    // For some reason the following doesn't work on Android 15, but the above does, and the below
    // works for Android <= 10, so the function as a whole works but is a dirty hack.

    Bitmap b = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    d.draw(new Canvas(b));
    return b.getPixel(0, 0);
}

From source file:com.ecom.consumer.customviews.HorizontalListView.java

@Override
protected void dispatchDraw(Canvas canvas) {
    canvas.save();/*w  w w .jav a2 s  .  com*/
    super.dispatchDraw(canvas);

    if (outRect != null && !mIsBeingDragged) {
        ColorDrawable drawable = new ColorDrawable(0x884193C9);// 77318fd5new
        // ColorDrawable(0x440000ff
        // &
        // Color.BLUE);
        drawable.setBounds(outRect);
        drawable.draw(canvas);
    }
    outRect = null;
    drawEdgeGlow(canvas);
    canvas.restore();
}

From source file:com.marlonjones.voidlauncher.CellLayout.java

@Override
protected void onDraw(Canvas canvas) {
    if (!mIsDragTarget) {
        return;// ww w  .ja  va  2s  .co m
    }

    // When we're large, we are either drawn in a "hover" state (ie when dragging an item to
    // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f)
    // When we're small, we are either drawn normally or in the "accepts drops" state (during
    // a drag). However, we also drag the mini hover background *over* one of those two
    // backgrounds
    if (mBackgroundAlpha > 0.0f) {
        mBackground.draw(canvas);
    }

    final Paint paint = mDragOutlinePaint;
    for (int i = 0; i < mDragOutlines.length; i++) {
        final float alpha = mDragOutlineAlphas[i];
        if (alpha > 0) {
            final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
            paint.setAlpha((int) (alpha + .5f));
            canvas.drawBitmap(b, null, mDragOutlines[i], paint);
        }
    }

    if (DEBUG_VISUALIZE_OCCUPIED) {
        int[] pt = new int[2];
        ColorDrawable cd = new ColorDrawable(Color.RED);
        cd.setBounds(0, 0, mCellWidth, mCellHeight);
        for (int i = 0; i < mCountX; i++) {
            for (int j = 0; j < mCountY; j++) {
                if (mOccupied.cells[i][j]) {
                    cellToPoint(i, j, pt);
                    canvas.save();
                    canvas.translate(pt[0], pt[1]);
                    cd.draw(canvas);
                    canvas.restore();
                }
            }
        }
    }

    for (int i = 0; i < mFolderBackgrounds.size(); i++) {
        FolderIcon.PreviewBackground bg = mFolderBackgrounds.get(i);
        cellToPoint(bg.delegateCellX, bg.delegateCellY, mTempLocation);
        canvas.save();
        canvas.translate(mTempLocation[0], mTempLocation[1]);
        bg.drawBackground(canvas, mFolderBgPaint);
        if (!bg.isClipping) {
            bg.drawBackgroundStroke(canvas, mFolderBgPaint);
        }
        canvas.restore();
    }

    if (mFolderLeaveBehind.delegateCellX >= 0 && mFolderLeaveBehind.delegateCellY >= 0) {
        cellToPoint(mFolderLeaveBehind.delegateCellX, mFolderLeaveBehind.delegateCellY, mTempLocation);
        canvas.save();
        canvas.translate(mTempLocation[0], mTempLocation[1]);
        mFolderLeaveBehind.drawLeaveBehind(canvas, mFolderBgPaint);
        canvas.restore();
    }
}

From source file:com.codemx.launcher3.CellLayout.java

@Override
protected void onDraw(Canvas canvas) {
    if (!mIsDragTarget) {
        return;//from  w w w . j a  v  a  2s . c o m
    }

    // When we're large, we are either drawn in a "hover" state (ie when dragging an item to
    // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f)
    // When we're small, we are either drawn normally or in the "accepts drops" state (during
    // a drag). However, we also drag the mini hover background *over* one of those two
    // backgrounds
    if (mBackgroundAlpha > 0.0f) {
        mBackground.draw(canvas);
    }

    final Paint paint = mDragOutlinePaint;
    for (int i = 0; i < mDragOutlines.length; i++) {
        final float alpha = mDragOutlineAlphas[i];
        if (alpha > 0) {
            final Rect r = mDragOutlines[i];
            mTempRect.set(r);
            Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale());
            final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
            paint.setAlpha((int) (alpha + .5f));
            canvas.drawBitmap(b, null, mTempRect, paint);
        }
    }

    if (DEBUG_VISUALIZE_OCCUPIED) {
        int[] pt = new int[2];
        ColorDrawable cd = new ColorDrawable(Color.RED);
        cd.setBounds(0, 0, mCellWidth, mCellHeight);
        for (int i = 0; i < mCountX; i++) {
            for (int j = 0; j < mCountY; j++) {
                if (mOccupied[i][j]) {
                    cellToPoint(i, j, pt);
                    canvas.save();
                    canvas.translate(pt[0], pt[1]);
                    cd.draw(canvas);
                    canvas.restore();
                }
            }
        }
    }

    int previewOffset = FolderIcon.FolderRingAnimator.sPreviewSize;

    // The folder outer / inner ring image(s)
    DeviceProfile grid = mLauncher.getDeviceProfile();
    for (int i = 0; i < mFolderOuterRings.size(); i++) {
        FolderIcon.FolderRingAnimator fra = mFolderOuterRings.get(i);

        Drawable d;
        int width, height;
        cellToPoint(fra.mCellX, fra.mCellY, mTempLocation);
        View child = getChildAt(fra.mCellX, fra.mCellY);

        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop()
                    + grid.folderBackgroundOffset;

            // Draw outer ring, if it exists
            if (FolderIcon.HAS_OUTER_RING) {
                d = FolderIcon.FolderRingAnimator.sSharedOuterRingDrawable;
                width = (int) (fra.getOuterRingSize() * getChildrenScale());
                height = width;
                canvas.save();
                canvas.translate(centerX - width / 2, centerY - height / 2);
                d.setBounds(0, 0, width, height);
                d.draw(canvas);
                canvas.restore();
            }

            // Draw inner ring
            d = FolderIcon.FolderRingAnimator.sSharedInnerRingDrawable;
            width = (int) (fra.getInnerRingSize() * getChildrenScale());
            height = width;
            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }

    if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) {
        Drawable d = FolderIcon.sSharedFolderLeaveBehind;
        int width = d.getIntrinsicWidth();
        int height = d.getIntrinsicHeight();

        cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation);
        View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]);
        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop()
                    + grid.folderBackgroundOffset;

            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }
}

From source file:com.lite.android.launcher3.CellLayout.java

@Override
protected void onDraw(Canvas canvas) {
    if (!mIsDragTarget) {
        return;//from w ww  . j ava 2s.  c  om
    }

    // When we're large, we are either drawn in a "hover" state (ie when dragging an item to
    // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f)
    // When we're small, we are either drawn normally or in the "accepts drops" state (during
    // a drag). However, we also drag the mini hover background *over* one of those two
    // backgrounds
    if (mBackgroundAlpha > 0.0f) {
        mBackground.draw(canvas);
    }

    final Paint paint = mDragOutlinePaint;
    for (int i = 0; i < mDragOutlines.length; i++) {
        final float alpha = mDragOutlineAlphas[i];
        if (alpha > 0) {
            final Rect r = mDragOutlines[i];
            mTempRect.set(r);
            Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale());
            final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
            paint.setAlpha((int) (alpha + .5f));
            canvas.drawBitmap(b, null, mTempRect, paint);
        }
    }

    if (DEBUG_VISUALIZE_OCCUPIED) {
        int[] pt = new int[2];
        ColorDrawable cd = new ColorDrawable(Color.RED);
        cd.setBounds(0, 0, mCellWidth, mCellHeight);
        for (int i = 0; i < mCountX; i++) {
            for (int j = 0; j < mCountY; j++) {
                if (mOccupied[i][j]) {
                    cellToPoint(i, j, pt);
                    canvas.save();
                    canvas.translate(pt[0], pt[1]);
                    cd.draw(canvas);
                    canvas.restore();
                }
            }
        }
    }

    int previewOffset = FolderRingAnimator.sPreviewSize;

    // The folder outer / inner ring image(s)
    DeviceProfile grid = mLauncher.getDeviceProfile();
    for (int i = 0; i < mFolderOuterRings.size(); i++) {
        FolderRingAnimator fra = mFolderOuterRings.get(i);

        Drawable d;
        int width, height;
        cellToPoint(fra.mCellX, fra.mCellY, mTempLocation);
        View child = getChildAt(fra.mCellX, fra.mCellY);

        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop()
                    + grid.folderBackgroundOffset;

            // Draw outer ring, if it exists
            if (FolderIcon.HAS_OUTER_RING) {
                d = FolderRingAnimator.sSharedOuterRingDrawable;
                width = (int) (fra.getOuterRingSize() * getChildrenScale());
                height = width;
                canvas.save();
                canvas.translate(centerX - width / 2, centerY - height / 2);
                d.setBounds(0, 0, width, height);
                d.draw(canvas);
                canvas.restore();
            }

            // Draw inner ring
            d = FolderRingAnimator.sSharedInnerRingDrawable;
            if (d != null) {
                width = (int) (fra.getInnerRingSize() * getChildrenScale());
                height = width;
                canvas.save();
                canvas.translate(centerX - width / 2, centerY - width / 2);
                d.setBounds(0, 0, width, height);
                d.draw(canvas);
                canvas.restore();
            }
        }
    }

    if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) {
        Drawable d = FolderIcon.sSharedFolderLeaveBehind;
        int width = d.getIntrinsicWidth();
        int height = d.getIntrinsicHeight();

        cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation);
        View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]);
        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop()
                    + grid.folderBackgroundOffset;

            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }
}

From source file:com.android.launcher3.CellLayout.java

@Override
protected void onDraw(Canvas canvas) {
    if (!mIsDragTarget) {
        return;/*from  w  w  w . j  av a 2 s . c  o  m*/
    }

    // When we're large, we are either drawn in a "hover" state (ie when dragging an item to
    // a neighboring page) or with just a normal background (if backgroundAlpha > 0.0f)
    // When we're small, we are either drawn normally or in the "accepts drops" state (during
    // a drag). However, we also drag the mini hover background *over* one of those two
    // backgrounds
    if (mBackgroundAlpha > 0.0f) {
        mBackground.draw(canvas);
    }

    final Paint paint = mDragOutlinePaint;
    for (int i = 0; i < mDragOutlines.length; i++) {
        final float alpha = mDragOutlineAlphas[i];
        if (alpha > 0) {
            final Rect r = mDragOutlines[i];
            mTempRect.set(r);
            Utilities.scaleRectAboutCenter(mTempRect, getChildrenScale());
            final Bitmap b = (Bitmap) mDragOutlineAnims[i].getTag();
            paint.setAlpha((int) (alpha + .5f));
            canvas.drawBitmap(b, null, mTempRect, paint);
        }
    }

    if (DEBUG_VISUALIZE_OCCUPIED) {
        int[] pt = new int[2];
        ColorDrawable cd = new ColorDrawable(Color.RED);
        cd.setBounds(0, 0, mCellWidth, mCellHeight);
        for (int i = 0; i < mCountX; i++) {
            for (int j = 0; j < mCountY; j++) {
                if (mOccupied[i][j]) {
                    cellToPoint(i, j, pt);
                    canvas.save();
                    canvas.translate(pt[0], pt[1]);
                    cd.draw(canvas);
                    canvas.restore();
                }
            }
        }
    }

    int previewOffset = FolderRingAnimator.sPreviewSize;

    // The folder outer / inner ring image(s)
    DeviceProfile grid = mLauncher.getDeviceProfile();
    for (int i = 0; i < mFolderOuterRings.size(); i++) {
        FolderRingAnimator fra = mFolderOuterRings.get(i);

        Drawable d;
        int width, height;
        cellToPoint(fra.mCellX, fra.mCellY, mTempLocation);
        View child = getChildAt(fra.mCellX, fra.mCellY);

        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop()
                    + grid.folderBackgroundOffset;

            // Draw outer ring, if it exists
            if (FolderIcon.HAS_OUTER_RING) {
                d = FolderRingAnimator.sSharedOuterRingDrawable;
                width = (int) (fra.getOuterRingSize() * getChildrenScale());
                height = width;
                canvas.save();
                canvas.translate(centerX - width / 2, centerY - height / 2);
                d.setBounds(0, 0, width, height);
                d.draw(canvas);
                canvas.restore();
            }

            // Draw inner ring
            d = FolderRingAnimator.sSharedInnerRingDrawable;
            width = (int) (fra.getInnerRingSize() * getChildrenScale());
            height = width;
            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }

    if (mFolderLeaveBehindCell[0] >= 0 && mFolderLeaveBehindCell[1] >= 0) {
        Drawable d = FolderIcon.sSharedFolderLeaveBehind;
        int width = d.getIntrinsicWidth();
        int height = d.getIntrinsicHeight();

        cellToPoint(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1], mTempLocation);
        View child = getChildAt(mFolderLeaveBehindCell[0], mFolderLeaveBehindCell[1]);
        if (child != null) {
            int centerX = mTempLocation[0] + mCellWidth / 2;
            int centerY = mTempLocation[1] + previewOffset / 2 + child.getPaddingTop()
                    + grid.folderBackgroundOffset;

            canvas.save();
            canvas.translate(centerX - width / 2, centerY - width / 2);
            d.setBounds(0, 0, width, height);
            d.draw(canvas);
            canvas.restore();
        }
    }
}