Created
June 20, 2018 16:24
-
-
Save FilipeLipan/f86274b1ee6ff738076152c5580af3d6 to your computer and use it in GitHub Desktop.
cloud background view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun writeCloud(text: String): BitmapDrawable { | |
// Draw bitmap | |
val drawable = ContextCompat.getDrawable(context, R.drawable.ic_cloud) | |
val bitmap = Bitmap.createBitmap(drawable?.intrinsicWidth ?: 68f.toPx.toInt(), | |
drawable?.intrinsicHeight ?: 48f.toPx.toInt(), Bitmap.Config.ARGB_8888) | |
val textPaint = TextPaint().apply { | |
style = Paint.Style.FILL | |
color = Color.BLACK | |
flags = Paint.ANTI_ALIAS_FLAG | |
xfermode = PorterDuffXfermode(PorterDuff.Mode.XOR) | |
textSize = resources.getDimension(R.dimen.CloudSeekBar_thumbTextSize) | |
typeface = Typeface.create(typeface, Typeface.BOLD) | |
} | |
val canvas = Canvas(bitmap) | |
drawable?.setBounds(0, 0, canvas.width, canvas.height) | |
drawable?.draw(canvas) | |
// Draw text | |
val bounds = canvas.clipBounds | |
val textWidth = textPaint.measureText(text) | |
canvas.drawText(text, | |
bounds.centerX() - textWidth / 2f, | |
(bitmap.height + resources.getDimensionPixelSize(R.dimen.CloudSeekBar_thumbHorizontalPadding)) / 2f, | |
textPaint) | |
return BitmapDrawable(resources, bitmap) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment