That fuck shit the fascists are using
at master 56 lines 1.3 kB view raw
1package org.tm.archive.conversation 2 3import android.graphics.Canvas 4import android.graphics.Color 5import android.graphics.Path 6import android.graphics.Region 7import android.graphics.drawable.ColorDrawable 8import android.graphics.drawable.Drawable 9import android.graphics.drawable.LayerDrawable 10import org.tm.archive.util.Projection 11 12/** 13 * Drawable which clips out the given projection 14 */ 15class ClipProjectionDrawable(wrapped: Drawable) : LayerDrawable(arrayOf(wrapped)) { 16 17 constructor() : this(ColorDrawable(Color.TRANSPARENT)) 18 19 init { 20 setId(0, 0) 21 } 22 23 private val clipPath = Path() 24 private var projections: List<Projection> = listOf() 25 26 fun setWrappedDrawable(drawable: Drawable) { 27 setDrawableByLayerId(0, drawable) 28 } 29 30 fun setProjections(projections: Set<Projection>) { 31 this.projections = projections.toList() 32 invalidateSelf() 33 } 34 35 fun clearProjections() { 36 this.projections = listOf() 37 invalidateSelf() 38 } 39 40 override fun draw(canvas: Canvas) { 41 if (projections.isNotEmpty()) { 42 canvas.save() 43 clipPath.rewind() 44 45 projections.forEach { 46 it.applyToPath(clipPath) 47 } 48 49 canvas.clipPath(clipPath, Region.Op.DIFFERENCE) 50 super.draw(canvas) 51 canvas.restore() 52 } else { 53 super.draw(canvas) 54 } 55 } 56}