List of usage examples for android.graphics.drawable Drawable setBounds
public void setBounds(int left, int top, int right, int bottom)
From source file:com.linkbubble.util.Util.java
/** * Returns a bitmap suitable for the all apps view. *///from w ww . j a v a2 s. c o m static Bitmap createIconBitmap(Drawable icon, Context context) { synchronized (sCanvas) { // we share the statics :-( if (sIconWidth == -1) { initStatics(context); } int width = sIconWidth; int height = sIconHeight; if (icon instanceof PaintDrawable) { PaintDrawable painter = (PaintDrawable) icon; painter.setIntrinsicWidth(width); painter.setIntrinsicHeight(height); } else if (icon instanceof BitmapDrawable) { // Ensure the bitmap has a density. BitmapDrawable bitmapDrawable = (BitmapDrawable) icon; Bitmap bitmap = bitmapDrawable.getBitmap(); if (bitmap.getDensity() == Bitmap.DENSITY_NONE) { bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics()); } } int sourceWidth = icon.getIntrinsicWidth(); int sourceHeight = icon.getIntrinsicHeight(); if (sourceWidth > 0 && sourceHeight > 0) { // There are intrinsic sizes. if (width < sourceWidth || height < sourceHeight) { // It's too big, scale it down. final float ratio = (float) sourceWidth / sourceHeight; if (sourceWidth > sourceHeight) { height = (int) (width / ratio); } else if (sourceHeight > sourceWidth) { width = (int) (height * ratio); } } else if (sourceWidth < width && sourceHeight < height) { // Don't scale up the icon width = sourceWidth; height = sourceHeight; } } // no intrinsic size --> use default size int textureWidth = sIconTextureWidth; int textureHeight = sIconTextureHeight; final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, Bitmap.Config.ARGB_8888); final Canvas canvas = sCanvas; canvas.setBitmap(bitmap); final int left = (textureWidth - width) / 2; final int top = (textureHeight - height) / 2; @SuppressWarnings("all") // suppress dead code warning final boolean debug = false; if (debug) { // draw a big box for the icon for debugging canvas.drawColor(sColors[sColorIndex]); if (++sColorIndex >= sColors.length) sColorIndex = 0; Paint debugPaint = new Paint(); debugPaint.setColor(0xffcccc00); canvas.drawRect(left, top, left + width, top + height, debugPaint); } sOldBounds.set(icon.getBounds()); icon.setBounds(left, top, left + width, top + height); icon.draw(canvas); icon.setBounds(sOldBounds); canvas.setBitmap(null); return bitmap; } }
From source file:com.android.calendar.EventInfoFragment.java
private void updateCustomAppButton() { buttonSetup: {/*from w ww. j av a 2 s .c o m*/ final Button launchButton = (Button) mView.findViewById(R.id.launch_custom_app_button); if (launchButton == null) break buttonSetup; final String customAppPackage = mEventCursor.getString(EVENT_INDEX_CUSTOM_APP_PACKAGE); final String customAppUri = mEventCursor.getString(EVENT_INDEX_CUSTOM_APP_URI); if (TextUtils.isEmpty(customAppPackage) || TextUtils.isEmpty(customAppUri)) break buttonSetup; PackageManager pm = mContext.getPackageManager(); if (pm == null) break buttonSetup; ApplicationInfo info; try { info = pm.getApplicationInfo(customAppPackage, 0); if (info == null) break buttonSetup; } catch (NameNotFoundException e) { break buttonSetup; } Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mEventId); final Intent intent = new Intent(CalendarContract.ACTION_HANDLE_CUSTOM_EVENT, uri); intent.setPackage(customAppPackage); intent.putExtra(CalendarContract.EXTRA_CUSTOM_APP_URI, customAppUri); intent.putExtra(EXTRA_EVENT_BEGIN_TIME, mStartMillis); // See if we have a taker for our intent if (pm.resolveActivity(intent, 0) == null) break buttonSetup; Drawable icon = pm.getApplicationIcon(info); if (icon != null) { Drawable[] d = launchButton.getCompoundDrawables(); icon.setBounds(0, 0, mCustomAppIconSize, mCustomAppIconSize); launchButton.setCompoundDrawables(icon, d[1], d[2], d[3]); } CharSequence label = pm.getApplicationLabel(info); if (label != null && label.length() != 0) { launchButton.setText(label); } else if (icon == null) { // No icon && no label. Hide button? break buttonSetup; } // Launch custom app launchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { startActivityForResult(intent, 0); } catch (ActivityNotFoundException e) { // Shouldn't happen as we checked it already setVisibilityCommon(mView, R.id.launch_custom_app_container, View.GONE); } } }); setVisibilityCommon(mView, R.id.launch_custom_app_container, View.VISIBLE); return; } setVisibilityCommon(mView, R.id.launch_custom_app_container, View.GONE); return; }
From source file:com.facebook.litho.LayoutState.java
void createDisplayList(LayoutOutput output) { ThreadUtils.assertMainThread();// w w w .j a v a2 s .c o m final Component component = output.getComponent(); ComponentsSystrace.beginSection("createDisplayList: " + component.getSimpleName()); final ComponentLifecycle lifecycle = component.getLifecycle(); final DisplayList displayList = DisplayList.createDisplayList(lifecycle.getClass().getSimpleName()); if (displayList == null) { ComponentsSystrace.endSection(); return; } final ComponentContext context = mContext; Drawable drawable = (Drawable) ComponentsPools.acquireMountContent(context, lifecycle.getId()); if (drawable == null) { drawable = (Drawable) lifecycle.createMountContent(context); } final LayoutOutput clickableOutput = findInteractiveRoot(this, output); boolean isStateEnabled = false; if (clickableOutput != null && clickableOutput.getNodeInfo() != null) { final NodeInfo nodeInfo = clickableOutput.getNodeInfo(); if (nodeInfo.hasTouchEventHandlers() || nodeInfo.getFocusState() == FOCUS_SET_TRUE) { isStateEnabled = true; } } if (isStateEnabled) { drawable.setState(DRAWABLE_STATE_ENABLED); } else { drawable.setState(DRAWABLE_STATE_NOT_ENABLED); } lifecycle.mount(context, drawable, component); lifecycle.bind(context, drawable, component); final Rect rect = mDisplayListCreateRect; output.getMountBounds(rect); drawable.setBounds(0, 0, rect.width(), rect.height()); try { final Canvas canvas = displayList.start(rect.width(), rect.height()); drawable.draw(canvas); displayList.end(canvas); displayList.setBounds(rect.left, rect.top, rect.right, rect.bottom); output.setDisplayList(displayList); } catch (DisplayListException e) { // Display list creation failed. Make sure the DisplayList for this output is set // to null. output.setDisplayList(null); } lifecycle.unbind(context, drawable, component); lifecycle.unmount(context, drawable, component); ComponentsPools.release(context, lifecycle, drawable); ComponentsSystrace.endSection(); }
From source file:com.android.ex.chips.RecipientEditTextView.java
private MoreImageSpan createMoreSpan(final int count) { final String moreText = String.format(mMoreItem.getText().toString(), count); final TextPaint morePaint = new TextPaint(getPaint()); morePaint.setTextSize(mMoreItem.getTextSize()); morePaint.setColor(mMoreItem.getCurrentTextColor()); final int width = (int) morePaint.measureText(moreText) + mMoreItem.getPaddingLeft() + mMoreItem.getPaddingRight(); final int height = getLineHeight(); final Bitmap drawable = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(drawable); int adjustedHeight = height; final Layout layout = getLayout(); if (layout != null) adjustedHeight -= layout.getLineDescent(0); canvas.drawText(moreText, 0, moreText.length(), 0, adjustedHeight, morePaint); final Drawable result = new BitmapDrawable(getResources(), drawable); result.setBounds(0, 0, width, height); return new MoreImageSpan(result); }
From source file:com.android.ex.chips.RecipientEditTextView.java
private DrawableRecipientChip constructChipSpan(final RecipientEntry contact, final boolean pressed, final boolean leaveIconSpace) throws NullPointerException { if (mChipBackground == null) throw new NullPointerException("Unable to render any chips as setChipDimensions was not called."); final TextPaint paint = getPaint(); final float defaultSize = paint.getTextSize(); final int defaultColor = paint.getColor(); Bitmap tmpBitmap;/*from ww w .ja v a 2 s . c o m*/ if (pressed) tmpBitmap = createSelectedChip(contact, paint); else tmpBitmap = createUnselectedChip(contact, paint, leaveIconSpace); // Pass the full text, un-ellipsized, to the chip. final Drawable result = new BitmapDrawable(getResources(), tmpBitmap); result.setBounds(0, 0, tmpBitmap.getWidth(), tmpBitmap.getHeight()); final DrawableRecipientChip recipientChip = new VisibleRecipientChip(result, contact); // Return text to the original size. paint.setTextSize(defaultSize); paint.setColor(defaultColor); return recipientChip; }
From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.java
@Override public void draw(Canvas c) { super.draw(c); final boolean isLayoutRtl = isLayoutRtlSupport(); Drawable shadowDrawable; if (isLayoutRtl) { shadowDrawable = mShadowDrawableRight; } else {/*from w w w . j av a 2 s . c o m*/ shadowDrawable = mShadowDrawableLeft; } final View shadowView = getChildCount() > 1 ? getChildAt(1) : null; if (shadowView == null || shadowDrawable == null) { // No need to draw a shadow if we don't have one. return; } final int top = shadowView.getTop(); final int bottom = shadowView.getBottom(); final int shadowWidth = shadowDrawable.getIntrinsicWidth(); final int left; final int right; if (isLayoutRtlSupport()) { left = shadowView.getRight(); right = left + shadowWidth; } else { right = shadowView.getLeft(); left = right - shadowWidth; } shadowDrawable.setBounds(left, top, right, bottom); shadowDrawable.draw(c); }
From source file:com.android.ex.chips.RecipientEditTextView.java
private Bitmap createUnselectedChip(final RecipientEntry contact, final TextPaint paint, final boolean leaveBlankIconSpacer) { // Ellipsize the text so that it takes AT MOST the entire width of the // autocomplete text entry area. Make sure to leave space for padding // on the sides. final int height = (int) mChipHeight; int iconWidth = height; final float[] widths = new float[1]; paint.getTextWidths(" ", widths); final float availableWidth = calculateAvailableWidth(); final String chipDisplayText = createChipDisplayText(contact); final CharSequence ellipsizedText = ellipsizeText(chipDisplayText, paint, availableWidth - iconWidth - widths[0]); // Make sure there is a minimum chip width so the user can ALWAYS // tap a chip without difficulty. final int width = Math.max(iconWidth * 2, (int) Math.floor(paint.measureText(ellipsizedText, 0, ellipsizedText.length())) + mChipPadding * 2 + iconWidth);/*from ww w . j a v a 2 s . c om*/ // Create the background of the chip. final Bitmap tmpBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(tmpBitmap); final Drawable background = getChipBackground(contact); if (background != null) { background.setBounds(0, 0, width, height); background.draw(canvas); // Don't draw photos for recipients that have been typed in OR generated on the fly. final long contactId = contact.getContactId(); final boolean drawPhotos = isPhoneQuery() ? contactId != RecipientEntry.INVALID_CONTACT : contactId != RecipientEntry.INVALID_CONTACT && contactId != RecipientEntry.GENERATED_CONTACT && !TextUtils.isEmpty(contact.getDisplayName()); if (drawPhotos) { byte[] photoBytes = contact.getPhotoBytes(); // There may not be a photo yet if anything but the first contact address // was selected. if (photoBytes == null && contact.getPhotoThumbnailUri() != null) { // TODO: cache this in the recipient entry? getAdapter().fetchPhoto(contact, contact.getPhotoThumbnailUri()); photoBytes = contact.getPhotoBytes(); } Bitmap photo; if (photoBytes != null) photo = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.length); else // TODO: can the scaled down default photo be cached? photo = mDefaultContactPhoto; // Draw the photo on the left side. if (photo != null) { final RectF src = new RectF(0, 0, photo.getWidth(), photo.getHeight()); final Rect backgroundPadding = new Rect(); mChipBackground.getPadding(backgroundPadding); final RectF dst = new RectF(width - iconWidth + backgroundPadding.left, 0 + backgroundPadding.top, width - backgroundPadding.right, height - backgroundPadding.bottom); final Matrix matrix = new Matrix(); matrix.setRectToRect(src, dst, Matrix.ScaleToFit.FILL); canvas.drawBitmap(photo, matrix, paint); } } else if (!leaveBlankIconSpacer || isPhoneQuery()) iconWidth = 0; paint.setColor(ContextCompat.getColor(getContext(), android.R.color.black)); // Vertically center the text in the chip. canvas.drawText(ellipsizedText, 0, ellipsizedText.length(), mChipPadding, getTextYOffset((String) ellipsizedText, paint, height), paint); } else Log.w(TAG, "Unable to draw a background for the chips as it was never set"); return tmpBitmap; }
From source file:cw.kop.autobackground.LiveWallpaperService.java
@SuppressLint("NewApi") private void startNotification(boolean useNotification) { if (useNotification) { normalView = new RemoteViews(getPackageName(), R.layout.notification_layout); normalView.setInt(R.id.notification_container, "setBackgroundColor", AppSettings.getNotificationColor()); normalView.setImageViewResource(R.id.notification_icon, R.drawable.app_icon); normalView.setTextViewText(R.id.notification_title, AppSettings.getNotificationTitle()); normalView.setInt(R.id.notification_title, "setTextColor", AppSettings.getNotificationTitleColor()); normalView.setTextViewText(R.id.notification_summary, AppSettings.getNotificationSummary()); normalView.setInt(R.id.notification_summary, "setTextColor", AppSettings.getNotificationSummaryColor()); Drawable coloredImageOne = LiveWallpaperService.this.getResources() .getDrawable(AppSettings.getNotificationOptionDrawable(0)); Drawable coloredImageTwo = LiveWallpaperService.this.getResources() .getDrawable(AppSettings.getNotificationOptionDrawable(1)); Drawable coloredImageThree = LiveWallpaperService.this.getResources() .getDrawable(AppSettings.getNotificationOptionDrawable(2)); coloredImageOne.mutate().setColorFilter(AppSettings.getNotificationOptionColor(0), PorterDuff.Mode.MULTIPLY); coloredImageTwo.mutate().setColorFilter(AppSettings.getNotificationOptionColor(1), PorterDuff.Mode.MULTIPLY); coloredImageThree.mutate().setColorFilter(AppSettings.getNotificationOptionColor(2), PorterDuff.Mode.MULTIPLY); Bitmap mutableBitmapOne = Bitmap.createBitmap(coloredImageOne.getIntrinsicWidth(), coloredImageOne.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvasOne = new Canvas(mutableBitmapOne); coloredImageOne.setBounds(0, 0, coloredImageOne.getIntrinsicWidth(), coloredImageOne.getIntrinsicHeight()); coloredImageOne.draw(canvasOne); Bitmap mutableBitmapTwo = Bitmap.createBitmap(coloredImageTwo.getIntrinsicWidth(), coloredImageTwo.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvasTwo = new Canvas(mutableBitmapTwo); coloredImageTwo.setBounds(0, 0, coloredImageTwo.getIntrinsicWidth(), coloredImageTwo.getIntrinsicHeight()); coloredImageTwo.draw(canvasTwo); Bitmap mutableBitmapThree = Bitmap.createBitmap(coloredImageThree.getIntrinsicWidth(), coloredImageThree.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvasThree = new Canvas(mutableBitmapThree); coloredImageThree.setBounds(0, 0, coloredImageThree.getIntrinsicWidth(), coloredImageThree.getIntrinsicHeight()); coloredImageThree.draw(canvasThree); if (AppSettings.useNotificationGame()) { if (setupGameTiles()) { bigView = new RemoteViews(getPackageName(), R.layout.notification_game); tileIds = new int[] { R.id.notification_game_tile_0, R.id.notification_game_tile_1, R.id.notification_game_tile_2, R.id.notification_game_tile_3, R.id.notification_game_tile_4, R.id.notification_game_tile_5, R.id.notification_game_tile_6, R.id.notification_game_tile_7, R.id.notification_game_tile_8, R.id.notification_game_tile_9 }; bigView.setOnClickPendingIntent(tileIds[0], pendingTile0); bigView.setOnClickPendingIntent(tileIds[1], pendingTile1); bigView.setOnClickPendingIntent(tileIds[2], pendingTile2); bigView.setOnClickPendingIntent(tileIds[3], pendingTile3); bigView.setOnClickPendingIntent(tileIds[4], pendingTile4); bigView.setOnClickPendingIntent(tileIds[5], pendingTile5); bigView.setOnClickPendingIntent(tileIds[6], pendingTile6); bigView.setOnClickPendingIntent(tileIds[7], pendingTile7); bigView.setOnClickPendingIntent(tileIds[8], pendingTile8); bigView.setOnClickPendingIntent(tileIds[9], pendingTile9); } else { bigView = new RemoteViews(getPackageName(), R.layout.notification_big_layout); closeNotificationDrawer(LiveWallpaperService.this); Toast.makeText(LiveWallpaperService.this, "Not enough images to create game", Toast.LENGTH_LONG) .show();//w w w . j a v a 2s. c o m AppSettings.setUseNotificationGame(false); } } else { bigView = new RemoteViews(getPackageName(), R.layout.notification_big_layout); } bigView.setInt(R.id.notification_big_container, "setBackgroundColor", AppSettings.getNotificationColor()); bigView.setImageViewResource(R.id.notification_big_icon, R.drawable.app_icon); bigView.setTextViewText(R.id.notification_big_title, AppSettings.getNotificationTitle()); bigView.setInt(R.id.notification_big_title, "setTextColor", AppSettings.getNotificationTitleColor()); bigView.setTextViewText(R.id.notification_big_summary, AppSettings.getNotificationSummary()); bigView.setInt(R.id.notification_big_summary, "setTextColor", AppSettings.getNotificationSummaryColor()); bigView.setImageViewBitmap(R.id.notification_button_one_image, mutableBitmapOne); bigView.setImageViewBitmap(R.id.notification_button_two_image, mutableBitmapTwo); bigView.setImageViewBitmap(R.id.notification_button_three_image, mutableBitmapThree); bigView.setTextViewText(R.id.notification_button_one_text, AppSettings.getNotificationOptionTitle(0)); bigView.setInt(R.id.notification_button_one_text, "setTextColor", AppSettings.getNotificationOptionColor(0)); bigView.setTextViewText(R.id.notification_button_two_text, AppSettings.getNotificationOptionTitle(1)); bigView.setInt(R.id.notification_button_two_text, "setTextColor", AppSettings.getNotificationOptionColor(1)); bigView.setTextViewText(R.id.notification_button_three_text, AppSettings.getNotificationOptionTitle(2)); bigView.setInt(R.id.notification_button_three_text, "setTextColor", AppSettings.getNotificationOptionColor(2)); if (getIntentForNotification(AppSettings.getNotificationIconAction()) != null) { normalView.setOnClickPendingIntent(R.id.notification_icon, getIntentForNotification(AppSettings.getNotificationIconAction())); bigView.setOnClickPendingIntent(R.id.notification_big_icon, getIntentForNotification(AppSettings.getNotificationIconAction())); } else { normalView.setOnClickPendingIntent(R.id.notification_icon, pendingAppIntent); bigView.setOnClickPendingIntent(R.id.notification_big_icon, pendingAppIntent); } notificationBuilder = new Notification.Builder(this).setContent(normalView) .setSmallIcon(R.drawable.notification_icon).setOngoing(true); if (Build.VERSION.SDK_INT >= 16) { if (AppSettings.useNotificationGame()) { notificationBuilder.setPriority(Notification.PRIORITY_MAX); } else { notificationBuilder.setPriority(Notification.PRIORITY_MIN); } if (getIntentForNotification(AppSettings.getNotificationOptionTitle(0)) != null) { bigView.setOnClickPendingIntent(R.id.notification_button_one, getIntentForNotification(AppSettings.getNotificationOptionTitle(0))); } if (getIntentForNotification(AppSettings.getNotificationOptionTitle(1)) != null) { bigView.setOnClickPendingIntent(R.id.notification_button_two, getIntentForNotification(AppSettings.getNotificationOptionTitle(1))); } if (getIntentForNotification(AppSettings.getNotificationOptionTitle(2)) != null) { bigView.setOnClickPendingIntent(R.id.notification_button_three, getIntentForNotification(AppSettings.getNotificationOptionTitle(2))); } } else { notificationBuilder.setContentTitle(AppSettings.getNotificationTitle()); notificationBuilder.setContentText(AppSettings.getNotificationSummary()); notificationBuilder.addAction(AppSettings.getNotificationOptionDrawable(0), AppSettings.getNotificationOptionTitle(0), getIntentForNotification(AppSettings.getNotificationOptionTitle(0))); notificationBuilder.addAction(AppSettings.getNotificationOptionDrawable(1), AppSettings.getNotificationOptionTitle(1), getIntentForNotification(AppSettings.getNotificationOptionTitle(1))); notificationBuilder.addAction(AppSettings.getNotificationOptionDrawable(2), AppSettings.getNotificationOptionTitle(2), getIntentForNotification(AppSettings.getNotificationOptionTitle(2))); } pushNotification(); if (FileHandler.getCurrentBitmapFile() != null) { notifyChangeImage(); } } else { notificationManager.cancel(NOTIFICATION_ID); } }
From source file:cnedu.ustcjd.widget.MultiSlider.java
/** * @param gap If set to {@link Integer#MIN_VALUE}, this will be ignored and *///from w ww. ja va 2 s. c o m private void setThumbPos(int w, int h, Drawable thumb, Drawable prevThumb, Drawable range, float scale, int gap, int thumbOffset, int optThumbOffset) { final int available = getAvailable(); int thumbWidth = thumb.getIntrinsicWidth(); int thumbHeight = thumb.getIntrinsicHeight(); int prevLeft = thumb.getBounds().left; //todo change available before also float scaleOffset = getScaleSize() > 0 ? (float) mScaleMin / (float) getScaleSize() : 0; int thumbPos = (int) (scale * available - scaleOffset * available + 0.5f); int topBound, bottomBound; if (gap == Integer.MIN_VALUE) { Rect oldBounds = thumb.getBounds(); topBound = oldBounds.top; bottomBound = oldBounds.bottom; } else { topBound = gap; bottomBound = gap + thumbHeight; } // Canvas will be translated, so 0,0 is where we start drawing final int left = (isLayoutRtl() && mMirrorForRtl) ? available - thumbPos - optThumbOffset : thumbPos + optThumbOffset; thumb.setBounds(left, topBound, left + thumbWidth, bottomBound); w -= getPaddingRight() + getPaddingLeft(); h -= getPaddingTop() + getPaddingBottom(); int right = w; int bottom = h; int leftRange = 0; if (prevThumb != null) { leftRange = prevThumb.getBounds().left; } if (range != null) { range.setBounds(leftRange, 0, left, bottom); } invalidate(); }
From source file:org.mdc.chess.ChessBoard.java
protected final void drawPiece(Canvas canvas, int xCrd, int yCrd, int p) { if (blindMode) { return;//from w w w . ja v a 2s .co m } /*String psb, psw; boolean rotate = false; switch (p) { default: case Piece.EMPTY: psb = null; psw = null; break; case Piece.WKING: psb = "H"; psw = "k"; break; case Piece.WQUEEN: psb = "I"; psw = "l"; break; case Piece.WROOK: psb = "J"; psw = "m"; break; case Piece.WBISHOP: psb = "K"; psw = "n"; break; case Piece.WKNIGHT: psb = "L"; psw = "o"; break; case Piece.WPAWN: psb = "M"; psw = "p"; break; case Piece.BKING: psb = "N"; psw = "q"; rotate = true; break; case Piece.BQUEEN: psb = "O"; psw = "r"; rotate = true; break; case Piece.BROOK: psb = "P"; psw = "s"; rotate = true; break; case Piece.BBISHOP: psb = "Q"; psw = "t"; rotate = true; break; case Piece.BKNIGHT: psb = "R"; psw = "u"; rotate = true; break; case Piece.BPAWN: psb = "S"; psw = "v"; rotate = true; break; } if (psb != null) { if (pieceXDelta < 0) { Rect bounds = new Rect(); blackPiecePaint.getTextBounds("H", 0, 1, bounds); pieceXDelta = (sqSize - (bounds.left + bounds.right)) / 2; pieceYDelta = (sqSize - (bounds.top + bounds.bottom)) / 2; } rotate ^= flipped; rotate = false; // Disabled for now if (rotate) { canvas.save(); canvas.rotate(180, xCrd + sqSize * 0.5f, yCrd + sqSize * 0.5f); } xCrd += pieceXDelta; yCrd += pieceYDelta; canvas.drawText(psw, xCrd, yCrd, whitePiecePaint); canvas.drawText(psb, xCrd, yCrd, blackPiecePaint); if (rotate) canvas.restore(); }*/ Drawable dr; switch (p) { default: case Piece.EMPTY: dr = null; // don't do anything break; case Piece.WKING: dr = ContextCompat.getDrawable(getContext(), R.drawable.ic_white_king); break; case Piece.WQUEEN: dr = ContextCompat.getDrawable(getContext(), R.drawable.ic_white_queen); break; case Piece.WROOK: dr = ContextCompat.getDrawable(getContext(), R.drawable.ic_white_rook); break; case Piece.WBISHOP: dr = ContextCompat.getDrawable(getContext(), R.drawable.ic_white_bishop); break; case Piece.WKNIGHT: dr = ContextCompat.getDrawable(getContext(), R.drawable.ic_white_knight); break; case Piece.WPAWN: dr = ContextCompat.getDrawable(getContext(), R.drawable.ic_white_pawn); break; case Piece.BKING: dr = ContextCompat.getDrawable(getContext(), R.drawable.ic_black_king); break; case Piece.BQUEEN: dr = ContextCompat.getDrawable(getContext(), R.drawable.ic_black_queen); break; case Piece.BROOK: dr = ContextCompat.getDrawable(getContext(), R.drawable.ic_black_rook); break; case Piece.BBISHOP: dr = ContextCompat.getDrawable(getContext(), R.drawable.ic_black_bishop); break; case Piece.BKNIGHT: dr = ContextCompat.getDrawable(getContext(), R.drawable.ic_black_knight); break; case Piece.BPAWN: dr = ContextCompat.getDrawable(getContext(), R.drawable.ic_black_pawn); break; } if (dr != null) { if (pieceXDelta < 0) { Rect bounds = new Rect(); blackPiecePaint.getTextBounds("H", 0, 1, bounds); pieceXDelta = (sqSize - (bounds.left + bounds.right)) / 2; pieceYDelta = (sqSize - (bounds.top + bounds.bottom)) / 2; } xCrd += pieceXDelta; //yCrd += pieceYDelta; dr.setBounds(xCrd, yCrd, xCrd + sqSize, yCrd + sqSize); dr.draw(canvas); } }