Created
June 25, 2018 16:54
-
-
Save cyrilmottier/5082114dd684fa204ab5165bcd4cf2bd to your computer and use it in GitHub Desktop.
This file contains 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
return object : Drawable() { | |
private val paint = Paint() | |
init { | |
val scaledWidth = RAINBOW_WIDTH * context.resources.displayMetrics.density | |
val y1 = (Math.sin(2 * RAINBOW_ANGLE) / 2 * scaledWidth).toFloat() | |
val x1 = (scaledWidth - Math.tan(RAINBOW_ANGLE) * y1).toFloat() | |
paint.shader = LinearGradient( | |
0f, 0f, | |
x1, y1, | |
colors, stops, | |
Shader.TileMode.REPEAT | |
) | |
} | |
override fun draw(canvas: Canvas) { | |
canvas.drawRect(bounds, paint) | |
} | |
override fun setAlpha(alpha: Int) {} | |
override fun getOpacity() = PixelFormat.OPAQUE | |
override fun setColorFilter(colorFilter: ColorFilter?) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment