1 /* 2 * Copyright 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 androidx.camera.testing.imagecapture 18 19 import androidx.annotation.IntDef 20 import androidx.annotation.RestrictTo 21 import androidx.camera.testing.fakes.FakeCameraCaptureResult 22 import androidx.camera.testing.fakes.FakeCameraControl 23 import androidx.camera.testing.imagecapture.CaptureResult.Companion.CAPTURE_STATUS_CANCELLED 24 import androidx.camera.testing.imagecapture.CaptureResult.Companion.CAPTURE_STATUS_FAILED 25 import androidx.camera.testing.imagecapture.CaptureResult.Companion.CAPTURE_STATUS_SUCCESSFUL 26 27 /** 28 * The capture result info used for a fake image capture completion. 29 * 30 * If [captureStatus] is [CAPTURE_STATUS_SUCCESSFUL], [cameraCaptureResult] is guaranteed to be 31 * non-null (`FakeCameraCaptureResult()` is used by default if user didn't provide any). 32 * 33 * If [captureStatus] is [CAPTURE_STATUS_FAILED] or [CAPTURE_STATUS_CANCELLED], 34 * [cameraCaptureResult] is usually null. 35 * 36 * @see FakeCameraControl.submitCaptureResult 37 */ 38 public class CaptureResult 39 private constructor( 40 public val captureStatus: @CaptureStatus Int, 41 public val cameraCaptureResult: FakeCameraCaptureResult? = null 42 ) { 43 /** 44 * The capture result status used in fake image capture completion. 45 * 46 * @see CaptureResult 47 */ 48 @Target(AnnotationTarget.TYPE) 49 @IntDef(CAPTURE_STATUS_SUCCESSFUL, CAPTURE_STATUS_FAILED, CAPTURE_STATUS_CANCELLED) 50 @Retention(AnnotationRetention.SOURCE) 51 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 52 public annotation class CaptureStatus 53 54 public companion object { 55 /** Represents a successful [CaptureStatus]. */ 56 public const val CAPTURE_STATUS_SUCCESSFUL: Int = 0 57 58 /** Represents a failed [CaptureStatus]. */ 59 public const val CAPTURE_STATUS_FAILED: Int = 1 60 61 /** Represents a canceled [CaptureStatus]. */ 62 public const val CAPTURE_STATUS_CANCELLED: Int = 2 63 64 /** Represents a successful [CaptureResult]. */ 65 @JvmStatic 66 @JvmOverloads successfulResultnull67 public fun successfulResult( 68 fakeCameraCaptureResult: FakeCameraCaptureResult = FakeCameraCaptureResult() 69 ): CaptureResult = 70 CaptureResult( 71 captureStatus = CAPTURE_STATUS_SUCCESSFUL, 72 cameraCaptureResult = fakeCameraCaptureResult 73 ) 74 75 /** Represents a failed [CaptureResult]. */ 76 @JvmStatic 77 public fun failedResult(): CaptureResult = 78 CaptureResult(captureStatus = CAPTURE_STATUS_FAILED) 79 80 /** Represents a cancelled [CaptureResult]. */ 81 @JvmStatic 82 public fun cancelledResult(): CaptureResult = 83 CaptureResult( 84 captureStatus = CAPTURE_STATUS_CANCELLED, 85 ) 86 } 87 } 88