File tree Expand file tree Collapse file tree
app/src/main/java/io/github/sds100/keymapper Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -185,16 +185,18 @@ fun KeyMapAppBar(
185185 LaunchedEffect (state.groupName) {
186186 showDeleteGroupDialog = false
187187 error = null
188+ val endPosition = state.groupName.length
188189
189190 if (state.isEditingGroupName) {
190191 if (state.isNewGroup) {
191192 newName = TextFieldValue ()
192193 } else {
193- val endPosition = state.groupName.length
194-
195194 newName =
196195 TextFieldValue (state.groupName, selection = TextRange (endPosition))
197196 }
197+ } else {
198+ newName =
199+ TextFieldValue (state.groupName, selection = TextRange (endPosition))
198200 }
199201 }
200202
Original file line number Diff line number Diff line change @@ -209,39 +209,21 @@ class AndroidCameraAdapter(context: Context) : CameraAdapter {
209209
210210 try {
211211 val cameraId = getFlashlightCameraIdForLens(lens)
212+ val flashInfo = getFlashInfo(lens)
212213
213- if (cameraId == null ) {
214+ if (cameraId == null || flashInfo == null ) {
214215 return when (lens) {
215216 CameraLens .FRONT -> Error .FrontFlashNotFound
216217 CameraLens .BACK -> Error .BackFlashNotFound
217218 }
218219 }
219220
220- val maxStrength = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
221- getCharacteristicForLens(
222- lens,
223- CameraCharacteristics .FLASH_INFO_STRENGTH_MAXIMUM_LEVEL ,
224- )
225- } else {
226- null
227- }
228-
229- val defaultStrength =
230- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
231- getCharacteristicForLens(
232- lens,
233- CameraCharacteristics .FLASH_INFO_STRENGTH_DEFAULT_LEVEL ,
234- )
235- } else {
236- null
237- }
238-
239221 // try to find a camera with a flash
240- if (enabled && maxStrength != null && defaultStrength != null && Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
222+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU && enabled && flashInfo.supportsVariableStrength ) {
241223 val strength = if (strengthPercent == null ) {
242- defaultStrength
224+ flashInfo. defaultStrength
243225 } else {
244- (strengthPercent * maxStrength).toInt().coerceAtLeast(1 )
226+ (strengthPercent * flashInfo. maxStrength).toInt().coerceAtLeast(1 )
245227 }
246228 cameraManager.turnOnTorchWithStrengthLevel(cameraId, strength)
247229 } else {
You can’t perform that action at this time.
0 commit comments