1 /* 2 * 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 package com.google.jetpackcamera.feature.preview.quicksettings 17 18 import androidx.annotation.DrawableRes 19 import androidx.annotation.StringRes 20 import androidx.compose.material.icons.Icons 21 import androidx.compose.material.icons.filled.AspectRatio 22 import androidx.compose.material.icons.filled.Cameraswitch 23 import androidx.compose.material.icons.filled.FlashAuto 24 import androidx.compose.material.icons.filled.FlashOff 25 import androidx.compose.material.icons.filled.FlashOn 26 import androidx.compose.material.icons.filled.HdrOff 27 import androidx.compose.material.icons.filled.HdrOn 28 import androidx.compose.material.icons.filled.Nightlight 29 import androidx.compose.material.icons.filled.PictureInPicture 30 import androidx.compose.material.icons.outlined.Nightlight 31 import androidx.compose.runtime.Composable 32 import androidx.compose.ui.graphics.painter.Painter 33 import androidx.compose.ui.graphics.vector.ImageVector 34 import androidx.compose.ui.graphics.vector.rememberVectorPainter 35 import androidx.compose.ui.res.painterResource 36 import com.google.jetpackcamera.feature.preview.R 37 38 interface QuickSettingsEnum { 39 @Composable getPainternull40 fun getPainter(): Painter { 41 val iconResId = getDrawableResId() 42 val iconVector = getImageVector() 43 require((iconResId == null).xor(iconVector == null)) { 44 "UI Item should have exactly one of iconResId or iconVector set." 45 } 46 return iconResId?.let { painterResource(it) } 47 ?: iconVector?.let { 48 rememberVectorPainter( 49 it 50 ) 51 }!! // !! allowed because we've checked null 52 } 53 54 @DrawableRes getDrawableResIdnull55 fun getDrawableResId(): Int? 56 57 fun getImageVector(): ImageVector? 58 59 @StringRes 60 fun getTextResId(): Int 61 62 @StringRes 63 fun getDescriptionResId(): Int 64 } 65 66 enum class CameraLensFace : QuickSettingsEnum { 67 FRONT { 68 override fun getDrawableResId() = null 69 override fun getImageVector() = Icons.Filled.Cameraswitch 70 override fun getTextResId() = R.string.quick_settings_front_camera_text 71 override fun getDescriptionResId() = R.string.quick_settings_front_camera_description 72 }, 73 BACK { 74 override fun getDrawableResId() = null 75 override fun getImageVector() = Icons.Filled.Cameraswitch 76 override fun getTextResId() = R.string.quick_settings_back_camera_text 77 override fun getDescriptionResId() = R.string.quick_settings_back_camera_description 78 } 79 } 80 81 enum class CameraFlashMode : QuickSettingsEnum { 82 OFF { getDrawableResIdnull83 override fun getDrawableResId() = null 84 override fun getImageVector() = Icons.Filled.FlashOff 85 override fun getTextResId() = R.string.quick_settings_flash_off 86 override fun getDescriptionResId() = R.string.quick_settings_flash_off_description 87 }, 88 AUTO { 89 override fun getDrawableResId() = null 90 override fun getImageVector() = Icons.Filled.FlashAuto 91 override fun getTextResId() = R.string.quick_settings_flash_auto 92 override fun getDescriptionResId() = R.string.quick_settings_flash_auto_description 93 }, 94 ON { getDrawableResIdnull95 override fun getDrawableResId() = null 96 override fun getImageVector() = Icons.Filled.FlashOn 97 override fun getTextResId() = R.string.quick_settings_flash_on 98 override fun getDescriptionResId() = R.string.quick_settings_flash_on_description 99 }, 100 LOW_LIGHT_BOOST_INACTIVE { 101 override fun getDrawableResId() = null 102 override fun getImageVector() = Icons.Outlined.Nightlight 103 override fun getTextResId() = R.string.quick_settings_flash_llb 104 override fun getDescriptionResId() = R.string.quick_settings_flash_llb_description 105 }, 106 LOW_LIGHT_BOOST_ACTIVE { getDrawableResIdnull107 override fun getDrawableResId() = null 108 override fun getImageVector() = Icons.Filled.Nightlight 109 override fun getTextResId() = R.string.quick_settings_flash_llb 110 override fun getDescriptionResId() = R.string.quick_settings_flash_llb_description 111 } 112 } 113 114 enum class CameraAspectRatio : QuickSettingsEnum { 115 THREE_FOUR { 116 override fun getDrawableResId() = null 117 override fun getImageVector() = Icons.Filled.AspectRatio 118 override fun getTextResId() = R.string.quick_settings_aspect_ratio_3_4 119 override fun getDescriptionResId() = R.string.quick_settings_aspect_ratio_3_4_description 120 }, 121 NINE_SIXTEEN { 122 override fun getDrawableResId() = null 123 override fun getImageVector() = Icons.Filled.AspectRatio 124 override fun getTextResId() = R.string.quick_settings_aspect_ratio_9_16 125 override fun getDescriptionResId() = R.string.quick_settings_aspect_ratio_9_16_description 126 }, 127 ONE_ONE { 128 override fun getDrawableResId() = null 129 override fun getImageVector() = Icons.Filled.AspectRatio 130 override fun getTextResId() = R.string.quick_settings_aspect_ratio_1_1 131 override fun getDescriptionResId() = R.string.quick_settings_aspect_ratio_1_1_description 132 } 133 } 134 135 enum class CameraStreamConfig : QuickSettingsEnum { 136 MULTI_STREAM { getDrawableResIdnull137 override fun getDrawableResId() = R.drawable.multi_stream_icon 138 override fun getImageVector() = null // this icon is not available 139 override fun getTextResId() = R.string.quick_settings_capture_mode_multi 140 override fun getDescriptionResId() = R.string.quick_settings_capture_mode_multi_description 141 }, 142 SINGLE_STREAM { 143 override fun getDrawableResId() = R.drawable.single_stream_capture_icon 144 override fun getImageVector() = null // this icon is not available 145 override fun getTextResId() = R.string.quick_settings_capture_mode_single 146 override fun getDescriptionResId() = R.string.quick_settings_capture_mode_single_description 147 } 148 } 149 150 enum class CameraDynamicRange : QuickSettingsEnum { 151 SDR { getDrawableResIdnull152 override fun getDrawableResId() = null 153 override fun getImageVector() = Icons.Filled.HdrOff 154 override fun getTextResId() = R.string.quick_settings_dynamic_range_sdr 155 override fun getDescriptionResId() = R.string.quick_settings_dynamic_range_sdr_description 156 }, 157 HDR { 158 override fun getDrawableResId() = null 159 override fun getImageVector() = Icons.Filled.HdrOn 160 override fun getTextResId() = R.string.quick_settings_dynamic_range_hdr 161 override fun getDescriptionResId() = R.string.quick_settings_dynamic_range_hdr_description 162 } 163 } 164 165 enum class CameraConcurrentCameraMode : QuickSettingsEnum { 166 OFF { getDrawableResIdnull167 override fun getDrawableResId() = R.drawable.picture_in_picture_off_icon 168 override fun getImageVector() = null 169 override fun getTextResId() = R.string.quick_settings_concurrent_camera_off 170 override fun getDescriptionResId() = 171 R.string.quick_settings_concurrent_camera_off_description 172 }, 173 DUAL { 174 override fun getDrawableResId() = null 175 override fun getImageVector() = Icons.Filled.PictureInPicture 176 override fun getTextResId() = R.string.quick_settings_concurrent_camera_dual 177 override fun getDescriptionResId() = 178 R.string.quick_settings_concurrent_camera_dual_description 179 } 180 } 181