1 /* <lambda>null2 * Copyright 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.graphics.lowlatency 18 19 import android.graphics.Canvas 20 import android.graphics.ColorFilter 21 import android.graphics.Paint 22 import android.graphics.PixelFormat 23 import android.graphics.drawable.Drawable 24 25 class LinesDrawable : Drawable() { 26 27 private var mLines: FloatArray? = null 28 private val mPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { strokeWidth = 5f } 29 30 var strokeWidth: Float 31 get() = mPaint.strokeWidth 32 set(value) { 33 mPaint.strokeWidth = value 34 } 35 36 override fun draw(canvas: Canvas) { 37 mLines?.let { lines -> 38 for (i in lines.indices step 4) { 39 canvas.drawLine(lines[i], lines[i + 1], lines[i + 2], lines[i + 3], mPaint) 40 } 41 } 42 } 43 44 fun setLines(lines: FloatArray) { 45 mLines = lines 46 invalidateSelf() 47 } 48 49 fun setColor(color: Int) { 50 mPaint.color = color 51 invalidateSelf() 52 } 53 54 override fun setAlpha(alpha: Int) { 55 mPaint.alpha = alpha 56 invalidateSelf() 57 } 58 59 override fun setColorFilter(colorFilter: ColorFilter?) { 60 mPaint.colorFilter = colorFilter 61 invalidateSelf() 62 } 63 64 @Suppress("OVERRIDE_DEPRECATION") // b/407504449 65 override fun getOpacity(): Int = PixelFormat.TRANSLUCENT 66 } 67