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 }
101 
102 enum class CameraAspectRatio : QuickSettingsEnum {
103     THREE_FOUR {
104         override fun getDrawableResId() = null
105         override fun getImageVector() = Icons.Filled.AspectRatio
106         override fun getTextResId() = R.string.quick_settings_aspect_ratio_3_4
107         override fun getDescriptionResId() = R.string.quick_settings_aspect_ratio_3_4_description
108     },
109     NINE_SIXTEEN {
110         override fun getDrawableResId() = null
111         override fun getImageVector() = Icons.Filled.AspectRatio
112         override fun getTextResId() = R.string.quick_settings_aspect_ratio_9_16
113         override fun getDescriptionResId() = R.string.quick_settings_aspect_ratio_9_16_description
114     },
115     ONE_ONE {
116         override fun getDrawableResId() = null
117         override fun getImageVector() = Icons.Filled.AspectRatio
118         override fun getTextResId() = R.string.quick_settings_aspect_ratio_1_1
119         override fun getDescriptionResId() = R.string.quick_settings_aspect_ratio_1_1_description
120     }
121 }
122 
123 enum class CameraCaptureMode : QuickSettingsEnum {
124     MULTI_STREAM {
getDrawableResIdnull125         override fun getDrawableResId() = R.drawable.multi_stream_icon
126         override fun getImageVector() = null // this icon is not available
127         override fun getTextResId() = R.string.quick_settings_capture_mode_multi
128         override fun getDescriptionResId() = R.string.quick_settings_capture_mode_multi_description
129     },
130     SINGLE_STREAM {
131         override fun getDrawableResId() = R.drawable.single_stream_capture_icon
132         override fun getImageVector() = null // this icon is not available
133         override fun getTextResId() = R.string.quick_settings_capture_mode_single
134         override fun getDescriptionResId() = R.string.quick_settings_capture_mode_single_description
135     }
136 }
137 
138 enum class CameraDynamicRange : QuickSettingsEnum {
139     SDR {
getDrawableResIdnull140         override fun getDrawableResId() = null
141         override fun getImageVector() = Icons.Filled.HdrOff
142         override fun getTextResId() = R.string.quick_settings_dynamic_range_sdr
143         override fun getDescriptionResId() = R.string.quick_settings_dynamic_range_sdr_description
144     },
145     HDR {
146         override fun getDrawableResId() = null
147         override fun getImageVector() = Icons.Filled.HdrOn
148         override fun getTextResId() = R.string.quick_settings_dynamic_range_hdr
149         override fun getDescriptionResId() = R.string.quick_settings_dynamic_range_hdr_description
150     }
151 }
152 
153 enum class CameraLowLightBoost : QuickSettingsEnum {
154 
155     ENABLED {
getDrawableResIdnull156         override fun getDrawableResId() = null
157         override fun getImageVector() = Icons.Filled.Nightlight
158         override fun getTextResId() = R.string.quick_settings_lowlightboost_enabled
159         override fun getDescriptionResId() =
160             R.string.quick_settings_lowlightboost_enabled_description
161     },
162 
163     DISABLED {
164         override fun getDrawableResId() = null
165         override fun getImageVector() = Icons.Outlined.Nightlight
166         override fun getTextResId() = R.string.quick_settings_lowlightboost_disabled
167         override fun getDescriptionResId() =
168             R.string.quick_settings_lowlightboost_disabled_description
169     }
170 }
171 
172 enum class CameraConcurrentCameraMode : QuickSettingsEnum {
173     OFF {
getDrawableResIdnull174         override fun getDrawableResId() = R.drawable.picture_in_picture_off_icon
175         override fun getImageVector() = null
176         override fun getTextResId() = R.string.quick_settings_concurrent_camera_off
177         override fun getDescriptionResId() =
178             R.string.quick_settings_concurrent_camera_off_description
179     },
180     DUAL {
181         override fun getDrawableResId() = null
182         override fun getImageVector() = Icons.Filled.PictureInPicture
183         override fun getTextResId() = R.string.quick_settings_concurrent_camera_dual
184         override fun getDescriptionResId() =
185             R.string.quick_settings_concurrent_camera_dual_description
186     }
187 }
188