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 18 19 import android.graphics.Bitmap 20 import platform.test.motion.filmstrip.Filmstrip 21 import platform.test.motion.filmstrip.MotionScreenshot 22 import platform.test.motion.filmstrip.VideoRenderer 23 import platform.test.motion.golden.TimeSeries 24 25 /** 26 * The motion recorded while an animation is playing. 27 * 28 * @param timeSeries recorded time series. 29 * @param screenshots screenshot of the animation per `frameId` in [timeSeries]. 30 */ 31 class RecordedMotion 32 internal constructor( 33 internal val testClassName: String, 34 internal val testMethodName: String, 35 val timeSeries: TimeSeries, 36 screenshots: List<Bitmap>?, 37 ) { 38 /** Visual filmstrip of the animation. */ 39 val filmstrip: Filmstrip? 40 /** Renders the screenshots as an MP4 video. */ 41 val videoRenderer: VideoRenderer? 42 43 init { 44 if (screenshots != null) { 45 val motionScreenshots = 46 timeSeries.frameIds.zip(screenshots) { frameId, bitmap -> 47 MotionScreenshot(frameId, bitmap) 48 } 49 filmstrip = Filmstrip(motionScreenshots) 50 videoRenderer = VideoRenderer(motionScreenshots) 51 } else { 52 filmstrip = null 53 videoRenderer = null 54 } 55 } 56 57 companion object { 58 fun MotionTestRule<*>.create(timeSeries: TimeSeries, screenshots: List<Bitmap>?) = 59 RecordedMotion( 60 checkNotNull(testClassName), 61 checkNotNull(testMethodName), 62 timeSeries, 63 screenshots, 64 ) 65 } 66 } 67