1 /* 2 * Copyright 2023 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.view.internal; 18 19 import androidx.camera.core.ImageCapture; 20 import androidx.camera.view.CameraController; 21 import androidx.camera.view.PreviewView; 22 import androidx.camera.view.ScreenFlashView; 23 24 import org.jspecify.annotations.NonNull; 25 import org.jspecify.annotations.Nullable; 26 27 import java.util.Objects; 28 29 /** 30 * Internal data class that encapsulates an {@link ImageCapture.ScreenFlash} and its 31 * provider. 32 */ 33 public class ScreenFlashUiInfo { 34 /** 35 * Since {@link ImageCapture.ScreenFlash} can be created from either the 36 * {@link ScreenFlashView} set by user or the one internally used in {@link PreviewView}, 37 * {@link CameraController} needs to know where exactly the control is from so that it can 38 * prioritize the user-set one when both are available. 39 */ 40 public enum ProviderType { 41 PREVIEW_VIEW, 42 SCREEN_FLASH_VIEW 43 } 44 45 private final @NonNull ProviderType mProviderType; 46 47 private final ImageCapture.@Nullable ScreenFlash mScreenFlash; 48 ScreenFlashUiInfo(@onNull ProviderType providerType, ImageCapture.@Nullable ScreenFlash screenFlash)49 public ScreenFlashUiInfo(@NonNull ProviderType providerType, 50 ImageCapture.@Nullable ScreenFlash screenFlash) { 51 mProviderType = providerType; 52 mScreenFlash = screenFlash; 53 } 54 getProviderType()55 public @NonNull ProviderType getProviderType() { 56 return mProviderType; 57 } 58 getScreenFlash()59 public ImageCapture.@Nullable ScreenFlash getScreenFlash() { 60 return mScreenFlash; 61 } 62 63 @Override equals(Object o)64 public boolean equals(Object o) { 65 if (this == o) return true; 66 if (!(o instanceof ScreenFlashUiInfo)) return false; 67 ScreenFlashUiInfo that = (ScreenFlashUiInfo) o; 68 return mProviderType == that.mProviderType && Objects.equals(mScreenFlash, 69 that.mScreenFlash); 70 } 71 72 @Override hashCode()73 public int hashCode() { 74 return Objects.hash(mProviderType, mScreenFlash); 75 } 76 } 77