<lambda>null1package com.airbnb.lottie.snapshots 2 3 import android.content.Context 4 import android.util.AttributeSet 5 import android.util.Log 6 import android.widget.FrameLayout 7 import androidx.core.view.children 8 import com.airbnb.lottie.FontAssetDelegate 9 import com.airbnb.lottie.ImageAssetDelegate 10 import com.airbnb.lottie.LottieAnimationView 11 import com.airbnb.lottie.LottieComposition 12 import com.airbnb.lottie.snapshots.databinding.FilmStripViewBinding 13 import com.airbnb.lottie.snapshots.utils.viewBinding 14 import kotlin.math.round 15 16 class FilmStripView @JvmOverloads constructor( 17 context: Context, 18 attrs: AttributeSet? = null, 19 defStyleAttr: Int = 0 20 ) : FrameLayout(context, attrs, defStyleAttr) { 21 private val binding: FilmStripViewBinding by viewBinding() 22 23 private val animationViews = binding.gridLayout.children.filterIsInstance<LottieAnimationView>() 24 25 fun setComposition(composition: LottieComposition, name: String) { 26 animationViews.forEachIndexed { i, view -> 27 view.setComposition(composition) 28 val progress = (i / 8f).round(decimals = 2) 29 view.progress = progress 30 Log.d("FilmStripView", "$name $i $progress -> ${view.progress}") 31 } 32 } 33 34 fun setImageAssetDelegate(delegate: ImageAssetDelegate?) { 35 animationViews.forEach { it.setImageAssetDelegate(delegate) } 36 // Enable bitmap rescaling for the first 4 views so both APIs get test coverage. 37 animationViews.forEachIndexed { i, av -> av.maintainOriginalImageBounds = i <= 4 } 38 } 39 40 fun setFontAssetDelegate(delegate: FontAssetDelegate?) { 41 animationViews.forEach { it.setFontAssetDelegate(delegate) } 42 } 43 44 fun setApplyingOpacityToLayersEnabled(isApplyingOpacityToLayersEnabled: Boolean) { 45 animationViews.forEach { it.setApplyingOpacityToLayersEnabled(isApplyingOpacityToLayersEnabled) } 46 } 47 48 fun setOutlineMasksAndMattes(outline: Boolean) { 49 animationViews.forEach { it.setOutlineMasksAndMattes(outline) } 50 } 51 52 private fun Float.round(decimals: Int): Float { 53 var multiplier = 1f 54 repeat(decimals) { multiplier *= 10 } 55 return round(this * multiplier) / multiplier 56 } 57 }