This file contains hidden or 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
// To load an image into an ImageView, use the load extension function. | |
imageView.load("https://www.example.com/image.jpg") | |
// Coil supports urls, uris, resources, drawables, bitmaps, files, and more. | |
imageView.load(R.drawable.image) | |
imageView.load(File("/path/to/image.jpg")) | |
imageView.load("content://com.android.externalstorage/image.jpg") | |
// Requests can be configured with an optional trailing lambda. | |
imageView.load("https://www.example.com/image.jpg") { |
This file contains hidden or 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
imageView.load("https://www.example.com/image.jpg") { | |
listener( | |
onSuccess = { /** Handle success. */ }, | |
onError = { /** Handle error. */ } | |
) | |
} | |
// Call this inside of your coroutine scope. | |
// This will throw an error inside of the scope if it fails. | |
val drawable = Coil.get("https://www.example.com/image.jpg") |
This file contains hidden or 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
open class ForwardingPainter( | |
private val delegate: Painter, | |
private var alpha: Float = DefaultAlpha, | |
private var colorFilter: ColorFilter? = null, | |
) : Painter() { | |
override val intrinsicSize get() = delegate.intrinsicSize | |
override fun applyAlpha(alpha: Float): Boolean { | |
if (alpha == DefaultAlpha) { |
This file contains hidden or 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
/** | |
* Create and return a new [Painter] that wraps [painter] with its [alpha], [colorFilter], or [onDraw] overwritten. | |
*/ | |
fun forwardingPainter( | |
painter: Painter, | |
alpha: Float = DefaultAlpha, | |
colorFilter: ColorFilter? = null, | |
onDraw: DrawScope.(ForwardingDrawInfo) -> Unit = DefaultOnDraw, | |
): Painter = ForwardingPainter(painter, alpha, colorFilter, onDraw) |
OlderNewer