Skip to content

Commit

Permalink
Merge pull request #4 from OutSystems/feat/RMET-2764/select-camera
Browse files Browse the repository at this point in the history
RMET-2764 OSBarcodeLib-Android - Select camera (back or front)
  • Loading branch information
alexgerardojacinto committed Nov 14, 2023
2 parents 1a3f2c7 + 4333275 commit e5f8f14
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The changes documented here do not include those from the original repository.

## [Unreleased]

### 13-11-2023
Android - Select Camera (Back or Front) (https://outsystemsrd.atlassian.net/browse/RMET-2764)

### 10-11-2023
Android - Use both libraries dynamically (https://outsystemsrd.atlassian.net/browse/RMET-2895)

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.outsystems</groupId>
<artifactId>osbarcode-android</artifactId>
<version>0.0.11</version>
<version>0.0.12</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ class OSBARCController {

companion object {
private const val SCAN_REQUEST_CODE = 112
private const val SCAN_INSTRUCTIONS = "SCAN_INSTRUCTIONS"
private const val CAMERA_DIRECTION = "CAMERA_DIRECTION"
private const val SCAN_ORIENTATION = "SCAN_ORIENTATION"
private const val SCAN_BUTTON = "SCAN_BUTTON"
private const val SCAN_BUTTON_TEXT = "SCAN_BUTTON_TEXT"
private const val SCAN_HINT = "SCAN_HINT"
private const val SCAN_LIBRARY = "SCAN_LIBRARY"
private const val SCAN_PARAMETERS = "SCAN_PARAMETERS"
private const val SCAN_RESULT = "scanResult"
private const val LOG_TAG = "OSBARCController"
}
Expand All @@ -33,16 +27,11 @@ class OSBARCController {
* @param parameters - object that contains all the barcode parameters to be used when scanning.
*/
fun scanCode(activity: Activity, parameters: OSBARCScanParameters) {
val scanningIntent = Intent(activity, OSBARCScannerActivity::class.java).apply {
putExtra(SCAN_INSTRUCTIONS, parameters.scanInstructions)
putExtra(CAMERA_DIRECTION, parameters.cameraDirection)
putExtra(SCAN_ORIENTATION, parameters.scanOrientation)
putExtra(SCAN_BUTTON, parameters.scanButton)
putExtra(SCAN_BUTTON_TEXT, parameters.scanText)
putExtra(SCAN_HINT, parameters.hint)
putExtra(SCAN_LIBRARY, parameters.androidScanningLibrary)
}
activity.startActivityForResult(scanningIntent, SCAN_REQUEST_CODE)
activity.startActivityForResult(
Intent(
activity, OSBARCScannerActivity::class.java
).putExtra(SCAN_PARAMETERS, parameters), SCAN_REQUEST_CODE
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.outsystems.plugins.barcode.model

import java.io.Serializable

/**
* Data class that represents the object with the scan parameters.
*/
Expand All @@ -11,4 +13,4 @@ data class OSBARCScanParameters(
val scanText: String?,
val hint: Int?,
val androidScanningLibrary: String?
)
) : Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.outsystems.plugins.barcode.controller.OSBARCScanLibraryFactory
import com.outsystems.plugins.barcode.controller.helper.OSBARCMLKitHelper
import com.outsystems.plugins.barcode.controller.helper.OSBARCZXingHelper
import com.outsystems.plugins.barcode.model.OSBARCError
import com.outsystems.plugins.barcode.model.OSBARCScanParameters
import com.outsystems.plugins.barcode.view.ui.theme.BarcodeScannerTheme
import java.lang.Exception

Expand All @@ -46,7 +47,8 @@ class OSBARCScannerActivity : ComponentActivity() {
private const val SCAN_SUCCESS_RESULT_CODE = -1
private const val SCAN_RESULT = "scanResult"
private const val LOG_TAG = "OSBARCScannerActivity"
private const val SCAN_LIBRARY = "SCAN_LIBRARY"
private const val SCAN_PARAMETERS = "SCAN_PARAMETERS"
private const val CAM_DIRECTION_FRONT = 2
}

/**
Expand All @@ -57,7 +59,7 @@ class OSBARCScannerActivity : ComponentActivity() {

setContent {
BarcodeScannerTheme {
ScanScreen()
ScanScreen(intent.extras?.getSerializable(SCAN_PARAMETERS) as OSBARCScanParameters)
}
}
}
Expand All @@ -67,7 +69,7 @@ class OSBARCScannerActivity : ComponentActivity() {
* as well as creating an instance of OSBARCBarcodeAnalyzer for image analysis.
*/
@Composable
fun ScanScreen() {
fun ScanScreen(parameters: OSBARCScanParameters) {
val lifecycleOwner = LocalLifecycleOwner.current
val context = LocalContext.current

Expand Down Expand Up @@ -102,7 +104,7 @@ class OSBARCScannerActivity : ComponentActivity() {
val previewView = PreviewView(context)
val preview = Preview.Builder().build()
val selector = CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_BACK) // temporary
.requireLensFacing(if (parameters.cameraDirection == CAM_DIRECTION_FRONT) CameraSelector.LENS_FACING_FRONT else CameraSelector.LENS_FACING_BACK)
.build()
preview.setSurfaceProvider(previewView.surfaceProvider)
val imageAnalysis = ImageAnalysis.Builder()
Expand All @@ -112,7 +114,7 @@ class OSBARCScannerActivity : ComponentActivity() {
ContextCompat.getMainExecutor(context),
OSBARCBarcodeAnalyzer(
OSBARCScanLibraryFactory.createScanLibraryWrapper(
intent.extras?.getString(SCAN_LIBRARY) ?: "",
parameters.androidScanningLibrary ?: "",
OSBARCZXingHelper(),
OSBARCMLKitHelper()
), // temporary
Expand Down

0 comments on commit e5f8f14

Please sign in to comment.