Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
task/scale-type-rename: Renamed the scaleType attribute to previewSca…
Browse files Browse the repository at this point in the history
…leType.

This clarifies more precisely what this attribute does. It also means
KBarcode shouldn't clash with camerax lib should you have both
installed.
  • Loading branch information
alistairsykes committed Jun 17, 2021
1 parent 3ae08af commit 793c2f3
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class ProgrammaticActivity :
)
)
.barcodesSort(null)
.scaleType(BarcodeView.CENTER_INSIDE)
.previewScaleType(BarcodeView.CENTER_INSIDE)
.clearFocusDelay(BarcodeView.CLEAR_FOCUS_DELAY_DEFAULT)
.build()
)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_xml.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:scaleType="centerInside"
app:previewScaleType="centerInside"
app:sort="none"
app:clearFocusDelay="2000"/>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_viewfinder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:scaleType="centerCrop"
app:previewScaleType="centerCrop"
app:sort="central" />

<View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public class BarcodeScanner internal constructor(
frameProcessor.barcodesSort = comparator
}

override fun setScaleType(@BarcodeView.ScaleType scaleType: Int) {
override fun setPreviewScaleType(@BarcodeView.ScaleType scaleType: Int) {
Timber.v("ScaleType has no affect on ${BarcodeScanner::class.java.simpleName}")
}

Expand Down
14 changes: 7 additions & 7 deletions kbarcode/src/main/java/uk/co/brightec/kbarcode/BarcodeView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class BarcodeView @JvmOverloads constructor(
private val surfaceView = SurfaceView(context)

@ScaleType
private var previewScaleType: Int = CENTER_INSIDE
private var _previewScaleType: Int = CENTER_INSIDE
set(value) {
field = value
requestLayout()
Expand Down Expand Up @@ -97,8 +97,8 @@ public class BarcodeView @JvmOverloads constructor(
setMinBarcodeWidth(attrMinBarcodeWidth)
val attrSort = getInteger(R.styleable.BarcodeView_sort, 0)
setBarcodesSort(sortAttrConvert(attrSort))
val attrScaleType = getInteger(R.styleable.BarcodeView_scaleType, 0)
setScaleType(scaleTypeAttrConvert(attrScaleType))
val attrScaleType = getInteger(R.styleable.BarcodeView_previewScaleType, 0)
setPreviewScaleType(previewScaleTypeAttrConvert(attrScaleType))
val attrClearFocusDelay = getInteger(
R.styleable.BarcodeView_clearFocusDelay,
CLEAR_FOCUS_DELAY_DEFAULT.toInt()
Expand Down Expand Up @@ -187,8 +187,8 @@ public class BarcodeView @JvmOverloads constructor(
barcodeScanner.setBarcodesSort(comparator)
}

override fun setScaleType(scaleType: Int) {
previewScaleType = scaleType
override fun setPreviewScaleType(scaleType: Int) {
_previewScaleType = scaleType
}

override fun setClearFocusDelay(delay: Long) {
Expand All @@ -197,7 +197,7 @@ public class BarcodeView @JvmOverloads constructor(

override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
val childRect = calculateRectForChild(
scaleType = previewScaleType, left = left, top = top, right = right, bottom = bottom
scaleType = _previewScaleType, left = left, top = top, right = right, bottom = bottom
)

for (i in 0 until childCount) {
Expand Down Expand Up @@ -254,7 +254,7 @@ public class BarcodeView @JvmOverloads constructor(
}

@VisibleForTesting
internal fun scaleTypeAttrConvert(attr: Int) = when (attr) {
internal fun previewScaleTypeAttrConvert(attr: Int) = when (attr) {
0 -> CENTER_INSIDE
1 -> CENTER_CROP
else -> CENTER_INSIDE
Expand Down
4 changes: 2 additions & 2 deletions kbarcode/src/main/java/uk/co/brightec/kbarcode/KBarcode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class KBarcode {

public fun setBarcodesSort(comparator: Comparator<Barcode>?)

public fun setScaleType(@BarcodeView.ScaleType scaleType: Int)
public fun setPreviewScaleType(@BarcodeView.ScaleType scaleType: Int)

public fun setClearFocusDelay(delay: Long)

Expand All @@ -53,7 +53,7 @@ public class KBarcode {
setBarcodeFormats(options.barcodeFormats)
setMinBarcodeWidth(options.minBarcodeWidth)
setBarcodesSort(options.barcodesSort)
setScaleType(options.scaleType)
setPreviewScaleType(options.previewScaleType)
setClearFocusDelay(options.clearFocusDelay)
}
}
Expand Down
14 changes: 7 additions & 7 deletions kbarcode/src/main/java/uk/co/brightec/kbarcode/Options.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public data class Options(
val barcodeFormats: IntArray = intArrayOf(Barcode.FORMAT_ALL_FORMATS),
@Px val minBarcodeWidth: Int? = null,
val barcodesSort: BarcodeComparator? = null,
@BarcodeView.ScaleType val scaleType: Int,
@BarcodeView.ScaleType val previewScaleType: Int,
val clearFocusDelay: Long
) {

Expand All @@ -22,7 +22,7 @@ public data class Options(
private var barcodeFormats: IntArray = intArrayOf(Barcode.FORMAT_ALL_FORMATS),
@Px private var minBarcodeWidth: Int? = null,
private var barcodesSort: BarcodeComparator? = null,
@BarcodeView.ScaleType private var scaleType: Int = BarcodeView.CENTER_INSIDE,
@BarcodeView.ScaleType private var previewScaleType: Int = BarcodeView.CENTER_INSIDE,
private var clearFocusDelay: Long = BarcodeView.CLEAR_FOCUS_DELAY_DEFAULT
) {

Expand Down Expand Up @@ -50,8 +50,8 @@ public data class Options(
this.barcodesSort = barcodesSort
}

public fun scaleType(@BarcodeView.ScaleType scaleType: Int): Builder = apply {
this.scaleType = scaleType
public fun previewScaleType(@BarcodeView.ScaleType scaleType: Int): Builder = apply {
this.previewScaleType = scaleType
}

public fun clearFocusDelay(clearFocusDelay: Long): Builder = apply {
Expand All @@ -64,7 +64,7 @@ public data class Options(
barcodeFormats = barcodeFormats,
minBarcodeWidth = minBarcodeWidth,
barcodesSort = barcodesSort,
scaleType = scaleType,
previewScaleType = previewScaleType,
clearFocusDelay = clearFocusDelay
)
}
Expand All @@ -80,7 +80,7 @@ public data class Options(
if (!barcodeFormats.contentEquals(other.barcodeFormats)) return false
if (minBarcodeWidth != other.minBarcodeWidth) return false
if (barcodesSort != other.barcodesSort) return false
if (scaleType != other.scaleType) return false
if (previewScaleType != other.previewScaleType) return false
if (clearFocusDelay != other.clearFocusDelay) return false

return true
Expand All @@ -92,7 +92,7 @@ public data class Options(
result = 31 * result + barcodeFormats.contentHashCode()
result = 31 * result + minBarcodeWidth.hashCode()
result = 31 * result + (barcodesSort?.hashCode() ?: 0)
result = 31 * result + scaleType.hashCode()
result = 31 * result + previewScaleType.hashCode()
result = 31 * result + clearFocusDelay.hashCode()
return result
}
Expand Down
2 changes: 1 addition & 1 deletion kbarcode/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<enum name="none" value="0" />
<enum name="central" value="1" />
</attr>
<attr name="scaleType" format="enum">
<attr name="previewScaleType" format="enum">
<enum name="centerInside" value="0" />
<enum name="centerCrop" value="1" />
</attr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class KBarcodeScannerTest {
on { barcodeFormats } doReturn intArrayOf(1, 2, 3)
on { minBarcodeWidth } doReturn -2
on { barcodesSort } doReturn mock()
on { scaleType } doReturn -3
on { previewScaleType } doReturn -3
on { clearFocusDelay } doReturn 1234L
}

Expand All @@ -44,7 +44,7 @@ internal class KBarcodeScannerTest {
verify(barcodeScanner).setBarcodeFormats(options.barcodeFormats)
verify(barcodeScanner).setMinBarcodeWidth(options.minBarcodeWidth)
verify(barcodeScanner).setBarcodesSort(options.barcodesSort)
verify(barcodeScanner).setScaleType(options.scaleType)
verify(barcodeScanner).setScaleType(options.previewScaleType)
verify(barcodeScanner).setClearFocusDelay(options.clearFocusDelay)
}

Expand Down

0 comments on commit 793c2f3

Please sign in to comment.