diff --git a/kbarcode/src/androidTest/java/uk/co/brightec/kbarcode/BarcodeViewTest.kt b/kbarcode/src/androidTest/java/uk/co/brightec/kbarcode/BarcodeViewTest.kt index f33aa39..b251596 100644 --- a/kbarcode/src/androidTest/java/uk/co/brightec/kbarcode/BarcodeViewTest.kt +++ b/kbarcode/src/androidTest/java/uk/co/brightec/kbarcode/BarcodeViewTest.kt @@ -334,15 +334,16 @@ internal class BarcodeViewTest { @Test fun centerInside_viewEqualWidthTaller_portrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_INSIDE + val previewScaleType = BarcodeView.CENTER_INSIDE whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 100, 250) doReturn(true).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -355,15 +356,16 @@ internal class BarcodeViewTest { @Test fun centerInside_viewEqualWidthShorter_portrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_INSIDE + val previewScaleType = BarcodeView.CENTER_INSIDE whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 100, 150) doReturn(true).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -376,15 +378,16 @@ internal class BarcodeViewTest { @Test fun centerInside_viewEqualHeightWider_portrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_INSIDE + val previewScaleType = BarcodeView.CENTER_INSIDE whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 150, 200) doReturn(true).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -397,15 +400,16 @@ internal class BarcodeViewTest { @Test fun centerInside_viewEqualHeightNarrower_portrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_INSIDE + val previewScaleType = BarcodeView.CENTER_INSIDE whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 50, 200) doReturn(true).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -418,15 +422,16 @@ internal class BarcodeViewTest { @Test fun centerInside_viewEqualWidthTaller_notPortrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_INSIDE + val previewScaleType = BarcodeView.CENTER_INSIDE whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 250, 100) doReturn(false).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -439,15 +444,16 @@ internal class BarcodeViewTest { @Test fun centerInside_viewEqualWidthShorter_notPortrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_INSIDE + val previewScaleType = BarcodeView.CENTER_INSIDE whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 150, 100) doReturn(false).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -460,15 +466,16 @@ internal class BarcodeViewTest { @Test fun centerInside_viewEqualHeightWider_notPortrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_INSIDE + val previewScaleType = BarcodeView.CENTER_INSIDE whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 200, 150) doReturn(false).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -481,15 +488,16 @@ internal class BarcodeViewTest { @Test fun centerInside_viewEqualHeightNarrower_notPortrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_INSIDE + val previewScaleType = BarcodeView.CENTER_INSIDE whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 200, 50) doReturn(false).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -502,15 +510,16 @@ internal class BarcodeViewTest { @Test fun centerCrop_viewEqualWidthTaller_portrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_CROP + val previewScaleType = BarcodeView.CENTER_CROP whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 100, 250) doReturn(true).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -523,15 +532,16 @@ internal class BarcodeViewTest { @Test fun centerCrop_viewEqualWidthShorter_portrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_CROP + val previewScaleType = BarcodeView.CENTER_CROP whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 100, 150) doReturn(true).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -544,15 +554,16 @@ internal class BarcodeViewTest { @Test fun centerCrop_viewEqualHeightWider_portrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_CROP + val previewScaleType = BarcodeView.CENTER_CROP whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 150, 200) doReturn(true).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -565,15 +576,16 @@ internal class BarcodeViewTest { @Test fun centerCrop_viewEqualHeightNarrower_portrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_CROP + val previewScaleType = BarcodeView.CENTER_CROP whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 50, 200) doReturn(true).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -586,15 +598,16 @@ internal class BarcodeViewTest { @Test fun centerCrop_viewEqualWidthTaller_notPortrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_CROP + val previewScaleType = BarcodeView.CENTER_CROP whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 250, 100) doReturn(false).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -607,15 +620,16 @@ internal class BarcodeViewTest { @Test fun centerCrop_viewEqualWidthShorter_notPortrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_CROP + val previewScaleType = BarcodeView.CENTER_CROP whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 150, 100) doReturn(false).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -628,15 +642,16 @@ internal class BarcodeViewTest { @Test fun centerCrop_viewEqualHeightWider_notPortrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_CROP + val previewScaleType = BarcodeView.CENTER_CROP whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 200, 150) doReturn(false).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN @@ -649,15 +664,16 @@ internal class BarcodeViewTest { @Test fun centerCrop_viewEqualHeightNarrower_notPortrait__calculateRectForChild__isCorrect() { // GIVEN - val scaleType = BarcodeView.CENTER_CROP + val previewScaleType = BarcodeView.CENTER_CROP whenever(barcodeScanner.getOutputSize()).thenReturn(Size(200, 100)) val viewRect = Rect(0, 0, 200, 50) doReturn(false).whenever(barcodeView).isPortraitMode() // WHEN val result = barcodeView.calculateRectForChild( - scaleType = scaleType, left = viewRect.left, top = viewRect.top, right = viewRect.right, - bottom = viewRect.bottom + previewScaleType = previewScaleType, + left = viewRect.left, top = viewRect.top, + right = viewRect.right, bottom = viewRect.bottom ) // THEN diff --git a/kbarcode/src/main/java/uk/co/brightec/kbarcode/BarcodeScanner.kt b/kbarcode/src/main/java/uk/co/brightec/kbarcode/BarcodeScanner.kt index 07ea73d..0242889 100644 --- a/kbarcode/src/main/java/uk/co/brightec/kbarcode/BarcodeScanner.kt +++ b/kbarcode/src/main/java/uk/co/brightec/kbarcode/BarcodeScanner.kt @@ -155,8 +155,8 @@ public class BarcodeScanner internal constructor( frameProcessor.barcodesSort = comparator } - override fun setPreviewScaleType(@BarcodeView.ScaleType scaleType: Int) { - Timber.v("ScaleType has no affect on ${BarcodeScanner::class.java.simpleName}") + override fun setPreviewScaleType(@BarcodeView.PreviewScaleType previewScaleType: Int) { + Timber.v("PreviewScaleType has no affect on ${BarcodeScanner::class.java.simpleName}") } @Throws(IllegalArgumentException::class) diff --git a/kbarcode/src/main/java/uk/co/brightec/kbarcode/BarcodeView.kt b/kbarcode/src/main/java/uk/co/brightec/kbarcode/BarcodeView.kt index b4e755f..5f380d9 100644 --- a/kbarcode/src/main/java/uk/co/brightec/kbarcode/BarcodeView.kt +++ b/kbarcode/src/main/java/uk/co/brightec/kbarcode/BarcodeView.kt @@ -55,7 +55,7 @@ public class BarcodeView @JvmOverloads constructor( private val surfaceView = SurfaceView(context) - @ScaleType + @PreviewScaleType private var _previewScaleType: Int = CENTER_INSIDE set(value) { field = value @@ -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_previewScaleType, 0) - setPreviewScaleType(previewScaleTypeAttrConvert(attrScaleType)) + val attrPreviewScaleType = getInteger(R.styleable.BarcodeView_previewScaleType, 0) + setPreviewScaleType(previewScaleTypeAttrConvert(attrPreviewScaleType)) val attrClearFocusDelay = getInteger( R.styleable.BarcodeView_clearFocusDelay, CLEAR_FOCUS_DELAY_DEFAULT.toInt() @@ -187,8 +187,8 @@ public class BarcodeView @JvmOverloads constructor( barcodeScanner.setBarcodesSort(comparator) } - override fun setPreviewScaleType(scaleType: Int) { - _previewScaleType = scaleType + override fun setPreviewScaleType(previewScaleType: Int) { + _previewScaleType = previewScaleType } override fun setClearFocusDelay(delay: Long) { @@ -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 + previewScaleType = _previewScaleType, left = left, top = top, right = right, bottom = bottom ) for (i in 0 until childCount) { @@ -262,7 +262,7 @@ public class BarcodeView @JvmOverloads constructor( @VisibleForTesting internal fun calculateRectForChild( - @ScaleType scaleType: Int, + @PreviewScaleType previewScaleType: Int, left: Int, top: Int, right: Int, @@ -293,13 +293,13 @@ public class BarcodeView @JvmOverloads constructor( var childWidth = layoutWidth var childHeight = (layoutWidth.toFloat() / width.toFloat() * height).toInt() - if (scaleType == CENTER_INSIDE) { + if (previewScaleType == CENTER_INSIDE) { // If height is too tall using fit width, do fit height instead. if (childHeight > layoutHeight) { childHeight = layoutHeight childWidth = (layoutHeight.toFloat() / height.toFloat() * width).toInt() } - } else if (scaleType == CENTER_CROP) { + } else if (previewScaleType == CENTER_CROP) { // If height is too short using fit width, do fit height instead. if (childHeight < layoutHeight) { childHeight = layoutHeight @@ -355,5 +355,5 @@ public class BarcodeView @JvmOverloads constructor( CENTER_CROP ) @Retention(AnnotationRetention.SOURCE) - public annotation class ScaleType + public annotation class PreviewScaleType } diff --git a/kbarcode/src/main/java/uk/co/brightec/kbarcode/KBarcode.kt b/kbarcode/src/main/java/uk/co/brightec/kbarcode/KBarcode.kt index 70f29b5..db34681 100644 --- a/kbarcode/src/main/java/uk/co/brightec/kbarcode/KBarcode.kt +++ b/kbarcode/src/main/java/uk/co/brightec/kbarcode/KBarcode.kt @@ -43,7 +43,7 @@ public class KBarcode { public fun setBarcodesSort(comparator: Comparator?) - public fun setPreviewScaleType(@BarcodeView.ScaleType scaleType: Int) + public fun setPreviewScaleType(@BarcodeView.PreviewScaleType previewScaleType: Int) public fun setClearFocusDelay(delay: Long) diff --git a/kbarcode/src/main/java/uk/co/brightec/kbarcode/Options.kt b/kbarcode/src/main/java/uk/co/brightec/kbarcode/Options.kt index 6943468..93925eb 100644 --- a/kbarcode/src/main/java/uk/co/brightec/kbarcode/Options.kt +++ b/kbarcode/src/main/java/uk/co/brightec/kbarcode/Options.kt @@ -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 previewScaleType: Int, + @BarcodeView.PreviewScaleType val previewScaleType: Int, val clearFocusDelay: Long ) { @@ -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 previewScaleType: Int = BarcodeView.CENTER_INSIDE, + @BarcodeView.PreviewScaleType private var previewScaleType: Int = BarcodeView.CENTER_INSIDE, private var clearFocusDelay: Long = BarcodeView.CLEAR_FOCUS_DELAY_DEFAULT ) { @@ -50,8 +50,10 @@ public data class Options( this.barcodesSort = barcodesSort } - public fun previewScaleType(@BarcodeView.ScaleType scaleType: Int): Builder = apply { - this.previewScaleType = scaleType + public fun previewScaleType( + @BarcodeView.PreviewScaleType previewScaleType: Int + ): Builder = apply { + this.previewScaleType = previewScaleType } public fun clearFocusDelay(clearFocusDelay: Long): Builder = apply { diff --git a/kbarcode/src/test/java/uk/co/brightec/kbarcode/KBarcodeScannerTest.kt b/kbarcode/src/test/java/uk/co/brightec/kbarcode/KBarcodeScannerTest.kt index cedb963..690ff5a 100644 --- a/kbarcode/src/test/java/uk/co/brightec/kbarcode/KBarcodeScannerTest.kt +++ b/kbarcode/src/test/java/uk/co/brightec/kbarcode/KBarcodeScannerTest.kt @@ -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.previewScaleType) + verify(barcodeScanner).setPreviewScaleType(options.previewScaleType) verify(barcodeScanner).setClearFocusDelay(options.clearFocusDelay) } @@ -94,7 +94,7 @@ internal class KBarcodeScannerTest { // no-op } - override fun setScaleType(scaleType: Int) { + override fun setPreviewScaleType(previewScaleType: Int) { // no-op }