$path = 'app\src\main\kotlin\com\bodycamera\twentyfoulabs\camera\M530CameraActivity.kt' $lines = Get-Content $path $result = New-Object System.Collections.Generic.List[string] $addedVariable = $false $addedButtonDeclaration = $false $addedButtonUi = $false $replacedSelector = $false $replacedState = $false foreach ($line in $lines) { # --------------------------------------------------------- # 1. Variable para saber que camara usa el preview # --------------------------------------------------------- if (-not $addedVariable -and $line -match 'private var lastTouchActionMs = 0L') { $result.Add($line) $result.Add(' private var frontPreviewUsesFrontCamera = true') $addedVariable = $true continue } # --------------------------------------------------------- # 2. Declaracion del boton # --------------------------------------------------------- if (-not $addedButtonDeclaration -and $line -match 'private lateinit var closeButton: Button') { $result.Add($line) $result.Add(' private lateinit var switchCameraButton: Button') $addedButtonDeclaration = $true continue } # --------------------------------------------------------- # 3. Insertar boton antes de captureButton # --------------------------------------------------------- if (-not $addedButtonUi -and $line -match '^\s*captureButton = Button\(this\)\.apply') { $result.Add(' switchCameraButton = Button(this).apply {') $result.Add(' text = "CAMBIAR"') $result.Add(' setTextColor(Color.WHITE)') $result.Add(' textSize = 12f') $result.Add(' setTypeface(typeface, Typeface.BOLD)') $result.Add(' gravity = Gravity.CENTER') $result.Add(' minWidth = 0') $result.Add(' minHeight = 0') $result.Add(' setPadding(dp(8), 0, dp(8), 0)') $result.Add(' background = circleDrawable(0xB0000000.toInt(), Color.WHITE, dp(1))') $result.Add(' visibility = if (mode == MODE_FRONT_PREVIEW) View.VISIBLE else View.GONE') $result.Add(' elevation = dp(12).toFloat()') $result.Add('') $result.Add(' setOnClickListener {') $result.Add(' if (mode == MODE_FRONT_PREVIEW) {') $result.Add(' frontPreviewUsesFrontCamera = !frontPreviewUsesFrontCamera') $result.Add(' startCamera()') $result.Add(' }') $result.Add(' }') $result.Add(' }') $result.Add('') $result.Add(' root.addView(') $result.Add(' switchCameraButton,') $result.Add(' FrameLayout.LayoutParams(dp(110), dp(48), Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL).apply {') $result.Add(' bottomMargin = dp(76)') $result.Add(' }') $result.Add(' )') $result.Add('') $result.Add($line) $addedButtonUi = $true continue } # --------------------------------------------------------- # 4. Selector dinamico frontal/posterior SOLO para preview # --------------------------------------------------------- if (-not $replacedSelector -and $line -match 'CameraSelector\.DEFAULT_FRONT_CAMERA') { $result.Add(' if (frontPreviewUsesFrontCamera)') $result.Add(' CameraSelector.DEFAULT_FRONT_CAMERA') $result.Add(' else') $result.Add(' CameraSelector.DEFAULT_BACK_CAMERA,') $replacedSelector = $true continue } # --------------------------------------------------------- # 5. Cambiar mensaje segun camara # --------------------------------------------------------- if (-not $replacedState -and $line -match 'stateText\.text = "Camara frontal lista"') { $result.Add(' stateText.text = if (frontPreviewUsesFrontCamera)') $result.Add(' "Camara frontal lista"') $result.Add(' else') $result.Add(' "Camara posterior lista"') $replacedState = $true continue } $result.Add($line) } Set-Content -Path $path -Value $result -Encoding UTF8 Write-Host "" Write-Host "==========================================" Write-Host "CAMBIO DE CAMARA AGREGADO" Write-Host "==========================================" Write-Host "Variable: $addedVariable" Write-Host "Declaracion boton: $addedButtonDeclaration" Write-Host "UI boton: $addedButtonUi" Write-Host "Selector: $replacedSelector" Write-Host "Estado: $replacedState" Write-Host ""