Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FilipeLipan/f86274b1ee6ff738076152c5580af3d6 to your computer and use it in GitHub Desktop.
Save FilipeLipan/f86274b1ee6ff738076152c5580af3d6 to your computer and use it in GitHub Desktop.
cloud background view
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