Skip to content

Commit

Permalink
feat: update button according to flashlight state
Browse files Browse the repository at this point in the history
Context: We need to use different images to represent the on and off state.

References: https://outsystemsrd.atlassian.net/browse/RMET-2759
  • Loading branch information
alexgerardojacinto committed Nov 14, 2023
1 parent a377eb6 commit ac6c8bc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,26 @@ import androidx.camera.core.ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST
import androidx.camera.core.Preview
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.camera.view.PreviewView
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Info
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.ButtonDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.content.ContextCompat
import com.outsystems.plugins.barcode.R
import com.outsystems.plugins.barcode.controller.OSBARCBarcodeAnalyzer
import com.outsystems.plugins.barcode.controller.OSBARCScanLibraryFactory
import com.outsystems.plugins.barcode.controller.helper.OSBARCMLKitHelper
Expand Down Expand Up @@ -210,18 +213,27 @@ class OSBARCScannerActivity : ComponentActivity() {
@Composable
fun TorchButton() {
var isFlashlightOn by remember { mutableStateOf(false) }
val onIcon = painterResource(id = R.drawable.flash_on)
val offIcon = painterResource(id = R.drawable.flash_off)

Button(
onClick = {
toggleFlashlight(isFlashlightOn)
isFlashlightOn = !isFlashlightOn
},
modifier = Modifier,
colors = ButtonDefaults.buttonColors(
containerColor = if (isFlashlightOn) Color.White else Color.Black
),
shape = CircleShape
) {
Icon(
imageVector = Icons.Default.Info,
contentDescription = "Torch"
val icon = if (isFlashlightOn) onIcon else offIcon
Image(
painter = icon,
contentDescription = null
)
}

}

private fun hasCameraPermission(context: Context): Boolean {
Expand Down
10 changes: 10 additions & 0 deletions src/main/res/drawable/flash_off.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="12dp"
android:height="23dp"
android:viewportWidth="12"
android:viewportHeight="23">
<path
android:pathData="M11.854,5.866C12.015,6.045 12.046,6.241 11.948,6.455L4.715,21.951C4.599,22.174 4.412,22.286 4.153,22.286C4.117,22.286 4.055,22.277 3.965,22.259C3.814,22.214 3.7,22.129 3.624,22.004C3.548,21.879 3.528,21.746 3.564,21.603L6.202,10.781L0.765,12.134C0.729,12.143 0.675,12.147 0.604,12.147C0.443,12.147 0.305,12.098 0.189,12C0.028,11.866 -0.03,11.692 0.015,11.478L2.707,0.429C2.742,0.304 2.814,0.201 2.921,0.121C3.028,0.04 3.153,0 3.296,0H7.689C7.858,0 8.001,0.056 8.117,0.167C8.233,0.279 8.291,0.411 8.291,0.563C8.291,0.634 8.269,0.714 8.224,0.804L5.934,7.004L11.238,5.692C11.309,5.674 11.363,5.665 11.399,5.665C11.568,5.665 11.72,5.732 11.854,5.866L11.854,5.866Z"
android:fillColor="#ffffff"
android:fillType="evenOdd"/>
</vector>
10 changes: 10 additions & 0 deletions src/main/res/drawable/flash_on.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="14dp"
android:height="25dp"
android:viewportWidth="14"
android:viewportHeight="25">
<path
android:pathData="M13.128,6.495C13.306,6.693 13.341,6.91 13.232,7.147L5.224,24.304C5.096,24.551 4.888,24.675 4.602,24.675C4.562,24.675 4.493,24.665 4.394,24.645C4.226,24.596 4.1,24.502 4.016,24.363C3.932,24.225 3.91,24.077 3.949,23.918L6.87,11.937L0.85,13.435C0.811,13.444 0.751,13.45 0.672,13.45C0.494,13.45 0.341,13.395 0.212,13.286C0.034,13.138 -0.03,12.945 0.02,12.708L3,0.475C3.04,0.336 3.119,0.222 3.237,0.133C3.356,0.044 3.494,0 3.653,0H8.516C8.704,0 8.862,0.062 8.991,0.185C9.119,0.309 9.184,0.455 9.184,0.623C9.184,0.702 9.159,0.791 9.11,0.89L6.574,7.755L12.446,6.302C12.525,6.282 12.584,6.272 12.624,6.272C12.812,6.272 12.98,6.347 13.128,6.495L13.128,6.495Z"
android:fillColor="#4F575E"
android:fillType="evenOdd"/>
</vector>

0 comments on commit ac6c8bc

Please sign in to comment.