1 /* 2 * Copyright (C) 2022 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 com.android.systemui.shared.shadow 18 19 import android.graphics.Canvas 20 import android.graphics.Color 21 import android.widget.TextView 22 23 object DoubleShadowTextHelper { 24 data class ShadowInfo( 25 val blur: Float, 26 val offsetX: Float = 0f, 27 val offsetY: Float = 0f, 28 val alpha: Float 29 ) 30 applyShadowsnull31 fun applyShadows( 32 keyShadowInfo: ShadowInfo, 33 ambientShadowInfo: ShadowInfo, 34 view: TextView, 35 canvas: Canvas, 36 onDrawCallback: () -> Unit 37 ) { 38 // We enhance the shadow by drawing the shadow twice 39 view.paint.setShadowLayer( 40 ambientShadowInfo.blur, 41 ambientShadowInfo.offsetX, 42 ambientShadowInfo.offsetY, 43 Color.argb(ambientShadowInfo.alpha, 0f, 0f, 0f) 44 ) 45 onDrawCallback() 46 canvas.save() 47 canvas.clipRect( 48 view.scrollX, 49 view.scrollY + view.extendedPaddingTop, 50 view.scrollX + view.width, 51 view.scrollY + view.height 52 ) 53 54 view.paint.setShadowLayer( 55 keyShadowInfo.blur, 56 keyShadowInfo.offsetX, 57 keyShadowInfo.offsetY, 58 Color.argb(keyShadowInfo.alpha, 0f, 0f, 0f) 59 ) 60 onDrawCallback() 61 canvas.restore() 62 } 63 } 64