1 /*
<lambda>null2  * Copyright (C) 2024 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 platform.test.motion.view
18 
19 import android.graphics.Rect
20 import android.graphics.drawable.Drawable
21 import android.graphics.drawable.GradientDrawable
22 import platform.test.motion.golden.DataPoint
23 import platform.test.motion.golden.FeatureCapture
24 import platform.test.motion.golden.asDataPoint
25 
26 /** Common, generic [FeatureCapture] implementations for [Drawable]s. */
27 object DrawableFeatureCaptures {
28     val bounds = FeatureCapture<Drawable, Rect>("bounds") { it.bounds.asDataPoint() }
29     val alpha = FeatureCapture<Drawable, Int>("alpha") { it.alpha.asDataPoint() }
30     val cornerRadii =
31         FeatureCapture<GradientDrawable, CornerRadii>("cornerRadii") {
32             DataPoint.of(
33                 it.cornerRadii?.let { rawValues -> CornerRadii(rawValues) },
34                 DataPointTypes.cornerRadii
35             )
36         }
37 }
38 
39 /**
40  * Wrapper type for [GradientDrawable.getCornerRadii], to provide equality checks on [rawValues].
41  *
42  * TODO(b/322324387): This is temporary until figuring out how to best implement custom equality
43  *   checks.
44  */
45 class CornerRadii(rawValues: FloatArray) {
46     val rawValues = rawValues.clone()
equalsnull47     override fun equals(other: Any?): Boolean {
48         if (this === other) return true
49 
50         val otherRawValues = (other as? CornerRadii)?.rawValues ?: return false
51         return rawValues.contentEquals(otherRawValues)
52     }
53 
hashCodenull54     override fun hashCode(): Int {
55         return rawValues.contentHashCode()
56     }
57 }
58