Guest User

Untitled

a guest
Feb 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. class BackgroundWithShadowDrawable(context: Context) : Drawable() {
  2. private val paint = Paint()
  3. private var pointer = BitmapFactory.decodeResource(context.resources, R.drawable.banner)
  4. private val margin: Float = context.resources.getDimension(R.dimen.balance_my_purchases_margin)
  5. private val bottomMargin: Float = context.resources.getDimension(R.dimen.notification_margin)
  6. private val cornerRadius: Float = context.resources.getDimension(R.dimen.notification_corner_radius)
  7.  
  8. init {
  9. paint.apply { setARGB(255, 255, 255, 255); setShadowLayer(margin, 0f, 0f, Color.parseColor("#4c000000")); }
  10.  
  11. val matrix = Matrix()
  12.  
  13. matrix.postRotate(180f)
  14.  
  15. pointer = Bitmap.createBitmap(pointer, 0, 0, pointer.width, pointer.height, matrix, true)
  16. }
  17.  
  18. override fun setAlpha(alpha: Int) {
  19. paint.alpha = alpha
  20. }
  21.  
  22. override fun getOpacity(): Int {
  23. return PixelFormat.TRANSLUCENT
  24. }
  25.  
  26. override fun setColorFilter(colorFilter: ColorFilter?) {
  27. paint.colorFilter = colorFilter
  28. }
  29.  
  30. override fun draw(canvas: Canvas?) {
  31. canvas?.drawRoundRect(RectF(margin, margin / 2, bounds.width() - margin, bounds.height() - bottomMargin), cornerRadius, cornerRadius, paint)
  32.  
  33. canvas?.drawBitmap(pointer, ((bounds.width() / 2) - bottomMargin * 1.5f), bounds.height() - bottomMargin,
  34. Paint().apply {
  35. setARGB(255, 255, 255, 255)
  36. setShadowLayer(margin * 3, 0f, 0f, Color.BLACK)
  37. })
  38.  
  39. }
  40. }
Add Comment
Please, Sign In to add comment