Java Code Examples for android.graphics.drawable.ColorDrawable#draw()

The following examples show how to use android.graphics.drawable.ColorDrawable#draw() . 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: IcsColorDrawable.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
public IcsColorDrawable(ColorDrawable drawable) {
    Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bitmap);
    drawable.draw(c);
    this.color = bitmap.getPixel(0, 0);
    bitmap.recycle();
}
 
Example 2
Source File: Coloring.java    From DrawMe with Apache License 2.0 5 votes vote down vote up
@ColorInt
public static int getDrawableColor(ColorDrawable colorDrawable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return colorDrawable.getColor();
    } else {
        // http://stackoverflow.com/questions/15982044/get-activity-background-color-in-android-api-level-8
        Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
        Canvas canvas = new Canvas(bitmap);
        colorDrawable.draw(canvas);
        final int color = bitmap.getPixel(0, 0);
        bitmap.recycle();
        return color;
    }
}
 
Example 3
Source File: ViewUtil.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static int getColorDrawableColor(ColorDrawable drawable) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
        Canvas canvas = new Canvas(bitmap);
        drawable.draw(canvas);
        int pix = bitmap.getPixel(0, 0);
        bitmap.recycle();
        return pix;
    } else {
        return drawable.getColor();
    }
}
 
Example 4
Source File: IcsColorDrawable.java    From zen4android with MIT License 5 votes vote down vote up
public IcsColorDrawable(ColorDrawable drawable) {
    Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bitmap);
    drawable.draw(c);
    this.color = bitmap.getPixel(0, 0);
    bitmap.recycle();
}
 
Example 5
Source File: IcsColorDrawable.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
public IcsColorDrawable(ColorDrawable drawable) {
    Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bitmap);
    drawable.draw(c);
    this.color = bitmap.getPixel(0, 0);
    bitmap.recycle();
}
 
Example 6
Source File: IcsColorDrawable.java    From Libraries-for-Android-Developers with MIT License 5 votes vote down vote up
public IcsColorDrawable(ColorDrawable drawable) {
    Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bitmap);
    drawable.draw(c);
    this.color = bitmap.getPixel(0, 0);
    bitmap.recycle();
}
 
Example 7
Source File: CellLayout.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    if (!mIsDragTarget) {
        return;
    }

    // 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(mLauncher, canvas);
        if (!bg.isClipping) {
            bg.drawBackgroundStroke(mLauncher, canvas);
        }
        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);
        canvas.restore();
    }
}