List of usage examples for android.graphics Paint setARGB
public void setARGB(int a, int r, int g, int b)
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw cards with big single center suite * @param r application resources reference *//*w w w . jav a 2 s . com*/ private void drawBigCards(final Resources r) { final Bitmap[] bigSuit = new Bitmap[4]; final Bitmap[] suit = new Bitmap[4]; Canvas canvas; final String[] card_values = mResources.getStringArray(R.array.card_values); final Paint cardFrontPaint = new Paint(); final Paint cardBorderPaint = new Paint(); final Paint textPaintLeft = getTextPaint(mSuitsSize, Paint.Align.LEFT); Drawable drawable = ResourcesCompat.getDrawable(r, R.drawable.cardback, null); mCardHidden = Bitmap.createBitmap(Card.WIDTH, Card.HEIGHT, Bitmap.Config.ARGB_8888); canvas = new Canvas(mCardHidden); drawable.setBounds(0, 0, Card.WIDTH, Card.HEIGHT); drawable.draw(canvas); for (int i = 0; i < 4; i++) { suit[i] = Bitmap.createBitmap((int) mSuitsSizeHalf, (int) mSuitsSizeHalf, Bitmap.Config.ARGB_8888); canvas = new Canvas(suit[i]); drawSuit(i, canvas, mSuitsSizeHalf); } for (int i = 0; i < 4; i++) { bigSuit[i] = Bitmap.createBitmap((int) mSuitsSize, (int) mSuitsSize, Bitmap.Config.ARGB_8888); canvas = new Canvas(bigSuit[i]); drawSuit(i, canvas, mSuitsSize); } cardBorderPaint.setARGB(255, 0, 0, 0); cardFrontPaint.setARGB(255, 255, 255, 255); RectF rectf = new RectF(); for (int suitIdx = 0; suitIdx < 4; suitIdx++) { for (int valueIdx = 0; valueIdx < 13; valueIdx++) { mCardBitmap[suitIdx * 13 + valueIdx] = Bitmap.createBitmap(Card.WIDTH, Card.HEIGHT, Bitmap.Config.ARGB_8888); canvas = new Canvas(mCardBitmap[suitIdx * 13 + valueIdx]); drawCardBackground(rectf, canvas, cardBorderPaint, cardFrontPaint); drawCardValue(textPaintLeft, canvas, card_values[valueIdx], suit[suitIdx], suitIdx); // Middle canvas.drawBitmap(bigSuit[suitIdx], Card.WIDTH / 2 - mSuitsSizeHalf, Card.HEIGHT / 2 - mSuitsSizeHalf, mSuitPaint); } } }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Draw regular cards with suits representing values on card * @param r application resources reference *///from www .j ava2s . c om private void drawCards(final Resources r) { Paint cardFrontPaint = new Paint(); Paint cardBorderPaint = new Paint(); Bitmap[] suit = new Bitmap[4]; Bitmap[] revSuit = new Bitmap[4]; Bitmap[] smallSuit = new Bitmap[4]; Bitmap redJack; Bitmap redQueen; Bitmap redKing; Bitmap blackJack; Bitmap blackQueen; Bitmap blackKing; Canvas canvas; final int width = Card.WIDTH; final int height = Card.HEIGHT; final String[] card_values = mResources.getStringArray(R.array.card_values); final Paint textPaintLeft = getTextPaint(mSuitsSize, Paint.Align.LEFT); Drawable drawable = ResourcesCompat.getDrawable(r, R.drawable.cardback, null); mCardHidden = Bitmap.createBitmap(Card.WIDTH, Card.HEIGHT, Bitmap.Config.ARGB_8888); canvas = new Canvas(mCardHidden); drawable.setBounds(0, 0, Card.WIDTH, Card.HEIGHT); drawable.draw(canvas); for (int i = 0; i < 4; i++) { suit[i] = Bitmap.createBitmap((int) mSuitsSize, (int) mSuitsSize, Bitmap.Config.ARGB_8888); revSuit[i] = Bitmap.createBitmap((int) mSuitsSize, (int) mSuitsSize, Bitmap.Config.ARGB_8888); canvas = new Canvas(suit[i]); drawSuit(i, canvas, mSuitsSize); canvas = new Canvas(revSuit[i]); canvas.rotate(180, mSuitsSize / 2, mSuitsSize / 2); drawSuit(i, canvas, mSuitsSize); } for (int i = 0; i < 4; i++) { smallSuit[i] = Bitmap.createBitmap((int) mSuitsSizeHalf, (int) mSuitsSizeHalf, Bitmap.Config.ARGB_8888); canvas = new Canvas(smallSuit[i]); drawSuit(i, canvas, mSuitsSizeHalf); } final int faceWidth = width - 20; final int faceHeight = height / 2 - (int) mSuitsSize; blackJack = createFaceBitmap(r, R.drawable.blackjack, faceWidth, faceHeight); blackQueen = createFaceBitmap(r, R.drawable.blackqueen, faceWidth, faceHeight); blackKing = createFaceBitmap(r, R.drawable.blackking, faceWidth, faceHeight); redJack = createFaceBitmap(r, R.drawable.redjack, faceWidth, faceHeight); redQueen = createFaceBitmap(r, R.drawable.redqueen, faceWidth, faceHeight); redKing = createFaceBitmap(r, R.drawable.redking, faceWidth, faceHeight); cardBorderPaint.setARGB(255, 0, 0, 0); cardFrontPaint.setARGB(255, 255, 255, 255); RectF rectf = new RectF(); for (int suitIdx = 0; suitIdx < 4; suitIdx++) { for (int valueIdx = 0; valueIdx < 13; valueIdx++) { mCardBitmap[suitIdx * 13 + valueIdx] = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); canvas = new Canvas(mCardBitmap[suitIdx * 13 + valueIdx]); drawCardBackground(rectf, canvas, cardBorderPaint, cardFrontPaint); drawCardValue(textPaintLeft, canvas, card_values[valueIdx], smallSuit[suitIdx], suitIdx); if (valueIdx >= 10) { canvas.drawBitmap(suit[suitIdx], mSuitsSize, mSuitsSize, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], width - mSuitsSize * 2, height - mSuitsSize * 2, mSuitPaint); } final float height_7th = height / 7; final float height_9th = height / 9; // Columns final float width_5th = width / 5; final float[] suitX = { width_5th, width / 2 - mSuitsSizeHalf, width - width_5th - mSuitsSize }; // Rows final float[] suitY = { height_7th, // row 1 height_9th * 3, // row 2 height - (height_9th * 4) - mSuitsSizeHalf / 2, // row 4 height - (height_7th * 2) }; // row 5 // Center final float suitMidY = height / 2 - mSuitsSizeHalf; switch (valueIdx + 1) { case 1: canvas.drawBitmap(suit[suitIdx], suitX[1], suitMidY, mSuitPaint); break; case 2: canvas.drawBitmap(suit[suitIdx], suitX[1], suitY[0], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[1], suitY[3], mSuitPaint); break; case 3: canvas.drawBitmap(suit[suitIdx], suitX[1], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[1], suitMidY, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[1], suitY[3], mSuitPaint); break; case 4: canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint); break; case 5: canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[1], suitMidY, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint); break; case 6: canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[0], suitMidY, mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitMidY, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint); break; case 7: canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[0], suitMidY, mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitMidY, mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[1], (suitMidY + suitY[0]) / 2, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint); break; case 8: canvas.drawBitmap(suit[suitIdx], suitX[0], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitY[0], mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[0], suitMidY, mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[2], suitMidY, mSuitPaint); canvas.drawBitmap(suit[suitIdx], suitX[1], (suitMidY + suitY[0]) / 2, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[0], suitY[3], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[2], suitY[3], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[1], (suitY[3] + suitMidY) / 2, mSuitPaint); break; case 9: for (int i = 0; i < 4; i++) { canvas.drawBitmap(suit[suitIdx], suitX[(i % 2) * 2], suitY[i / 2], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[(i % 2) * 2], suitY[i / 2 + 2], mSuitPaint); } canvas.drawBitmap(suit[suitIdx], suitX[1], suitMidY, mSuitPaint); break; case 10: for (int i = 0; i < 4; i++) { canvas.drawBitmap(suit[suitIdx], suitX[(i % 2) * 2], suitY[i / 2], mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[(i % 2) * 2], suitY[i / 2 + 2], mSuitPaint); } canvas.drawBitmap(suit[suitIdx], suitX[1], (suitMidY + suitY[0]) / 2 - mSuitsSizeHalf, mSuitPaint); canvas.drawBitmap(revSuit[suitIdx], suitX[1], (suitY[3] + suitMidY) / 2 + mSuitsSizeHalf / 2, mSuitPaint); break; case Card.JACK: if ((suitIdx & 1) == 1) { drawFaceBitmap(canvas, redJack, mSuitsSizeHalf, mSuitsSize, mSuitPaint); } else { drawFaceBitmap(canvas, blackJack, mSuitsSizeHalf, mSuitsSize, mSuitPaint); } break; case Card.QUEEN: if ((suitIdx & 1) == 1) { drawFaceBitmap(canvas, redQueen, mSuitsSizeHalf, mSuitsSize, mSuitPaint); } else { drawFaceBitmap(canvas, blackQueen, mSuitsSizeHalf, mSuitsSize, mSuitPaint); } break; case Card.KING: if ((suitIdx & 1) == 1) { drawFaceBitmap(canvas, redKing, mSuitsSizeHalf, mSuitsSize, mSuitPaint); } else { drawFaceBitmap(canvas, blackKing, mSuitsSizeHalf, mSuitsSize, mSuitPaint); } break; } } } }