Guest User

Untitled

a guest
Jun 22nd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. private fun writeCloud(text: String): BitmapDrawable {
  2. // Draw bitmap
  3. val drawable = ContextCompat.getDrawable(context, R.drawable.ic_cloud)
  4. val bitmap = Bitmap.createBitmap(drawable?.intrinsicWidth ?: 68f.toPx.toInt(),
  5. drawable?.intrinsicHeight ?: 48f.toPx.toInt(), Bitmap.Config.ARGB_8888)
  6. val textPaint = TextPaint().apply {
  7. style = Paint.Style.FILL
  8. color = Color.BLACK
  9. flags = Paint.ANTI_ALIAS_FLAG
  10. xfermode = PorterDuffXfermode(PorterDuff.Mode.XOR)
  11. textSize = resources.getDimension(R.dimen.CloudSeekBar_thumbTextSize)
  12. typeface = Typeface.create(typeface, Typeface.BOLD)
  13. }
  14. val canvas = Canvas(bitmap)
  15. drawable?.setBounds(0, 0, canvas.width, canvas.height)
  16. drawable?.draw(canvas)
  17.  
  18. // Draw text
  19. val bounds = canvas.clipBounds
  20. val textWidth = textPaint.measureText(text)
  21. canvas.drawText(text,
  22. bounds.centerX() - textWidth / 2f,
  23. (bitmap.height + resources.getDimensionPixelSize(R.dimen.CloudSeekBar_thumbHorizontalPadding)) / 2f,
  24. textPaint)
  25.  
  26. return BitmapDrawable(resources, bitmap)
  27. }
Add Comment
Please, Sign In to add comment