Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ fun GenericBarcodeExample(
modifier = Modifier
.align(Alignment.CenterHorizontally)
.width(300.dp)
.height(300.dp),
.height(100.dp),
type = barcodeType,
value = value
value = value,
width = 300.dp,
height = 100.dp,
)
Text(
modifier = Modifier.fillMaxWidth(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ import kotlinx.coroutines.withContext
*
* @param modifier the modifier to be applied to the layout
* @param showProgress true will show the progress indicator. Defaults to true.
* @param resolutionFactor multiplied by 128 to get the resolution, in px, for the bitmap
* @param resolutionFactor multiplied on the width/height to get the resolution, in px, for the bitmap
* @param width for the generated bitmap multiplied by the resolutionFactor
* @param height for the generated bitmap multiplied by the resolutionFactor
* @param type the type of barcode to render
* @param value the value of the barcode to show
*/
@Composable
fun Barcode(
modifier: Modifier = Modifier,
showProgress: Boolean = true,
resolutionFactor: Int = 10,
resolutionFactor: Int = 1,
width: Dp = 128.dp,
height: Dp = 128.dp,
type: BarcodeType,
value: String
) {
Expand All @@ -49,8 +53,8 @@ fun Barcode(
withContext(Dispatchers.Default) {
barcodeBitmap.value = try {
type.getImageBitmap(
width = 128 * resolutionFactor,
height = 128 * resolutionFactor,
width = (width.value * resolutionFactor).toInt(),
height = (height.value * resolutionFactor).toInt(),
value = value
)
} catch (e: Exception) {
Expand Down Expand Up @@ -82,37 +86,3 @@ fun Barcode(
}
}
}

/**
* Barcode asynchronously creates a barcode bitmap in the background and then displays
* the barcode via an Image composable. A progress indicator shows, optionally, until
* the barcode value has been encoded to a bitmap.
*
* Note: if the barcode is not a valid format, the spinner will continue forever.
*
* @param modifier the modifier to be applied to the layout
* @param width the width desired for the barcode
* @param height the height desired for the barcode
* @param showProgress true will show the progress indicator. Defaults to true.
* @param type the type of barcode to render
* @param value the value of the barcode to show
*/
@Deprecated("Please set desired height and width on the modifier")
@Composable
fun Barcode(
Comment on lines -101 to -102
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not remove this until v2 please

modifier: Modifier = Modifier,
width: Dp = 50.dp,
height: Dp = 50.dp,
showProgress: Boolean = true,
type: BarcodeType,
value: String
) {
Barcode(
modifier = modifier
.width(width = width)
.height(height = height),
showProgress = showProgress,
type = type,
value = value
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum class BarcodeType(private val barcodeFormat: BarcodeFormat) {
for (y in 0 until height) {
val offset = y * width
for (x in 0 until width) {
pixels[offset + x] = if (get(x, y)) android.graphics.Color.BLACK else android.graphics.Color.WHITE
pixels[offset + x] = if (get(x, y)) android.graphics.Color.BLACK else android.graphics.Color.TRANSPARENT
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also be nice to have the main color being passed from the barcode view and not be black all the time :)

}
}
setPixels(pixels, 0, width, 0, 0, width, height)
Expand Down