Skip to content

Commit 3613d96

Browse files
committed
Merge branch 'release/1.1.2' into main
2 parents 30e800c + e46480a commit 3613d96

File tree

12 files changed

+59
-39
lines changed

12 files changed

+59
-39
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ There are two different flavors available on `mavenCentral()`:
1818
| V2 model is used (possibly faster, more accurate) | currently V1 model will be downloaded
1919
```kotlin
2020
// bundled:
21-
implementation("io.github.g00fy2.quickie:quickie-bundled:1.1.1")
21+
implementation("io.github.g00fy2.quickie:quickie-bundled:1.1.2")
2222

2323
// unbundled:
24-
implementation("io.github.g00fy2.quickie:quickie-unbundled:1.1.1")
24+
implementation("io.github.g00fy2.quickie:quickie-unbundled:1.1.2")
2525
```
2626

2727
## Quick Start
@@ -61,7 +61,7 @@ Currently, supported subtypes are:
6161
See the ML Kit [Barcode documentation](https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/Barcode#nested-class-summary) for further details.
6262

6363
### Customization
64-
Use the `ScanCustomCode()` ActivityResultContract to create a configurable barcode scan. When launching the ActivityResultLauncher pass in a `ScannerConfig` object. You can set the supported `BarcodeFormat` list, `overlayStringRes` and `overlayDrawableRes` resource ID.
64+
Use the `ScanCustomCode()` ActivityResultContract to create a configurable barcode scan. When launching the ActivityResultLauncher pass in a `ScannerConfig` object. You can set the supported `BarcodeFormat` list, `overlayStringRes` and `overlayDrawableRes` resource ID and control the `hapticSuccessFeedback`.
6565

6666
<details>
6767
<summary>BarcodeFormat options</summary>
@@ -96,6 +96,7 @@ override fun onCreate(savedInstanceState: Bundle?) {
9696
setBarcodeFormats(listOf(BarcodeFormat.FORMAT_CODE_128))
9797
setOverlayStringRes(R.string.scan_barcode)
9898
setOverlayDrawableRes(R.drawable.ic_scan_barcode)
99+
setHapticSuccessFeedback(false)
99100
}
100101
)
101102
}

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object Versions {
1111
const val appcompat = "1.3.0"
1212

1313
const val cameraX = "1.0.0"
14-
const val cameraView = "1.0.0-alpha24"
14+
const val cameraView = "1.0.0-alpha25"
1515

1616
const val materialDesign = "1.3.0"
1717

gradle/wrapper/gradle-wrapper.jar

333 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ case "`uname`" in
7272
Darwin* )
7373
darwin=true
7474
;;
75-
MINGW* )
75+
MSYS* | MINGW* )
7676
msys=true
7777
;;
7878
NONSTOP* )

quickie/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dependencies {
4343
}
4444

4545
group = "io.github.g00fy2.quickie"
46-
version = "1.1.1"
46+
version = "1.1.2"
4747

4848
tasks.register<Jar>("androidJavadocJar") {
4949
archiveClassifier.set("javadoc")

quickie/src/main/kotlin/io/github/g00fy2/quickie/QROverlayView.kt

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package io.github.g00fy2.quickie
33
import android.content.Context
44
import android.content.res.Resources.NotFoundException
55
import android.graphics.Bitmap
6-
import android.graphics.Bitmap.Config.ARGB_8888
76
import android.graphics.Canvas
87
import android.graphics.Color
98
import android.graphics.Paint
@@ -16,7 +15,6 @@ import android.util.TypedValue
1615
import android.view.LayoutInflater
1716
import android.view.View
1817
import android.widget.FrameLayout
19-
import androidx.appcompat.widget.AppCompatTextView
2018
import androidx.core.content.ContextCompat
2119
import androidx.core.content.res.ResourcesCompat
2220
import androidx.core.graphics.ColorUtils
@@ -39,14 +37,14 @@ internal class QROverlayView @JvmOverloads constructor(
3937
color = Color.TRANSPARENT
4038
xfermode = PorterDuffXfermode(CLEAR)
4139
}
42-
private val radius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, OUT_RADIUS, resources.displayMetrics)
43-
private val innerRadius =
44-
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, OUT_RADIUS - STROKE_WIDTH, resources.displayMetrics)
45-
private val titleTextView: AppCompatTextView
40+
private val outerRadius = OUT_RADIUS.toPx()
41+
private val innerRadius = (OUT_RADIUS - STROKE_WIDTH).toPx()
42+
private val titleTextView = QuickieTextviewBinding.inflate(LayoutInflater.from(context), this, true).root
43+
private val outerFrame = RectF()
44+
private val innerFrame = RectF()
4645
private var maskBitmap: Bitmap? = null
4746
private var maskCanvas: Canvas? = null
48-
private var outerFrame = RectF()
49-
private var innerFrame = RectF()
47+
5048
var isHighlighted = false
5149
set(value) {
5250
field = value
@@ -55,24 +53,21 @@ internal class QROverlayView @JvmOverloads constructor(
5553

5654
init {
5755
setWillNotDraw(false)
58-
titleTextView = QuickieTextviewBinding.inflate(LayoutInflater.from(context), this, true).root
5956
}
6057

6158
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
6259
super.onLayout(changed, left, top, right, bottom)
6360

6461
if (maskBitmap == null && width > 0 && height > 0) {
65-
maskBitmap = Bitmap.createBitmap(width, height, ARGB_8888).apply {
66-
maskCanvas = Canvas(this)
67-
}
62+
maskBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888).apply { maskCanvas = Canvas(this) }
6863
calculateFrameAndTitlePos()
6964
}
7065
}
7166

7267
override fun onDraw(canvas: Canvas) {
7368
strokePaint.color = if (isHighlighted) highlightedStrokeColor else strokeColor
7469
maskCanvas!!.drawColor(backgroundColor)
75-
maskCanvas!!.drawRoundRect(outerFrame, radius, radius, strokePaint)
70+
maskCanvas!!.drawRoundRect(outerFrame, outerRadius, outerRadius, strokePaint)
7671
maskCanvas!!.drawRoundRect(innerFrame, innerRadius, innerRadius, transparentPaint)
7772
canvas.drawBitmap(maskBitmap!!, 0f, 0f, alphaPaint)
7873
super.onDraw(canvas)
@@ -102,7 +97,7 @@ internal class QROverlayView @JvmOverloads constructor(
10297
val centralY = height / 2
10398
val minLength = min(centralX, centralY)
10499
val strokeLength = minLength - (minLength * FRAME_MARGIN_RATIO)
105-
val strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, STROKE_WIDTH, resources.displayMetrics)
100+
val strokeWidth = STROKE_WIDTH.toPx()
106101
outerFrame.set(
107102
centralX - strokeLength,
108103
centralY - strokeLength,
@@ -136,7 +131,7 @@ internal class QROverlayView @JvmOverloads constructor(
136131
}
137132

138133
private fun Drawable.limitDrawableSize(): Drawable {
139-
val heightLimit = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, ICON_MAX_HEIGHT, resources.displayMetrics)
134+
val heightLimit = ICON_MAX_HEIGHT.toPx()
140135
val scale = heightLimit / minimumHeight
141136
if (scale < 1) {
142137
setBounds(0, 0, (minimumWidth * scale).roundToInt(), (minimumHeight * scale).roundToInt())
@@ -146,6 +141,8 @@ internal class QROverlayView @JvmOverloads constructor(
146141
return this
147142
}
148143

144+
private fun Float.toPx() = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this, resources.displayMetrics)
145+
149146
companion object {
150147
private const val BACKGROUND_ALPHA = 0.77 * 255
151148
private const val STROKE_WIDTH = 4f

quickie/src/main/kotlin/io/github/g00fy2/quickie/QRScannerActivity.kt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.g00fy2.quickie
22

3-
import android.Manifest
3+
import android.Manifest.permission.CAMERA
44
import android.app.Activity
55
import android.content.Intent
66
import android.content.pm.PackageManager
@@ -32,6 +32,7 @@ internal class QRScannerActivity : AppCompatActivity() {
3232
private lateinit var binding: QuickieScannerActivityBinding
3333
private lateinit var analysisExecutor: ExecutorService
3434
private var barcodeFormats = intArrayOf(Barcode.FORMAT_QR_CODE)
35+
private var hapticFeedback = true
3536

3637
override fun onCreate(savedInstanceState: Bundle?) {
3738
super.onCreate(savedInstanceState)
@@ -99,10 +100,12 @@ internal class QRScannerActivity : AppCompatActivity() {
99100

100101
private fun onSuccess(result: Barcode) {
101102
binding.overlayView.isHighlighted = true
102-
binding.overlayView.performHapticFeedback(
103-
HapticFeedbackConstants.KEYBOARD_TAP,
104-
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING or HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING
105-
)
103+
if (hapticFeedback) {
104+
binding.overlayView.performHapticFeedback(
105+
HapticFeedbackConstants.KEYBOARD_TAP,
106+
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING or HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING
107+
)
108+
}
106109
setResult(
107110
Activity.RESULT_OK,
108111
Intent().apply {
@@ -122,9 +125,7 @@ internal class QRScannerActivity : AppCompatActivity() {
122125
private fun setupEdgeToEdgeUI() {
123126
WindowCompat.setDecorFitsSystemWindows(window, false)
124127
ViewCompat.setOnApplyWindowInsetsListener(binding.overlayView) { v, insets ->
125-
insets.getInsets(WindowInsetsCompat.Type.systemBars()).let {
126-
v.setPadding(it.left, it.top, it.right, it.bottom)
127-
}
128+
insets.getInsets(WindowInsetsCompat.Type.systemBars()).let { v.setPadding(it.left, it.top, it.right, it.bottom) }
128129
WindowInsetsCompat.CONSUMED
129130
}
130131
}
@@ -133,17 +134,15 @@ internal class QRScannerActivity : AppCompatActivity() {
133134
intent?.getParcelableExtra<ParcelableScannerConfig>(EXTRA_CONFIG)?.let {
134135
barcodeFormats = it.formats
135136
binding.overlayView.setCustomTextAndIcon(it.stringRes, it.drawableRes)
137+
hapticFeedback = it.hapticFeedback
136138
}
137139
}
138140

139141
private fun requestCameraPermissionIfMissing(onResult: ((Boolean) -> Unit)) {
140-
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
142+
if (ContextCompat.checkSelfPermission(this, CAMERA) == PackageManager.PERMISSION_GRANTED) {
141143
onResult(true)
142144
} else {
143-
// register the activity result here is allowed since we call this in onCreate only
144-
registerForActivityResult(ActivityResultContracts.RequestPermission()) {
145-
onResult(it)
146-
}.launch(Manifest.permission.CAMERA)
145+
registerForActivityResult(ActivityResultContracts.RequestPermission()) { onResult(it) }.launch(CAMERA)
147146
}
148147
}
149148

quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ParcelableScannerConfig.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ import android.os.Parcelable
44
import kotlinx.parcelize.Parcelize
55

66
@Parcelize
7-
internal class ParcelableScannerConfig(val formats: IntArray, val stringRes: Int, val drawableRes: Int) : Parcelable
7+
internal class ParcelableScannerConfig(
8+
val formats: IntArray,
9+
val stringRes: Int,
10+
val drawableRes: Int,
11+
val hapticFeedback: Boolean
12+
) : Parcelable

quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ScannerConfig.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ import androidx.annotation.StringRes
99
public class ScannerConfig internal constructor(
1010
internal val formats: IntArray,
1111
internal val stringRes: Int,
12-
internal val drawableRes: Int
12+
internal val drawableRes: Int,
13+
internal val hapticFeedback: Boolean,
1314
) {
1415

1516
public class Builder {
1617
private var barcodeFormats: List<BarcodeFormat> = listOf(BarcodeFormat.FORMAT_ALL_FORMATS)
1718
private var overlayStringRes: Int = 0
1819
private var overlayDrawableRes: Int = 0
20+
private var hapticSuccessFeedback: Boolean = true
1921

2022
/**
2123
* Set a list of interested barcode formats. List must not be empty.
@@ -34,11 +36,21 @@ public class ScannerConfig internal constructor(
3436
public fun setOverlayDrawableRes(@DrawableRes drawableRes: Int): Builder =
3537
apply { overlayDrawableRes = drawableRes }
3638

39+
/**
40+
* Enable (default) or disable haptic feedback when a barcode code was detected.
41+
*/
42+
public fun setHapticSuccessFeedback(enable: Boolean): Builder = apply { hapticSuccessFeedback = enable }
43+
3744
/**
3845
* Build the BarcodeConfig required by the ScanBarcode ActivityResultContract.
3946
*/
4047
public fun build(): ScannerConfig =
41-
ScannerConfig(barcodeFormats.map { it.value }.toIntArray(), overlayStringRes, overlayDrawableRes)
48+
ScannerConfig(
49+
barcodeFormats.map { it.value }.toIntArray(),
50+
overlayStringRes,
51+
overlayDrawableRes,
52+
hapticSuccessFeedback
53+
)
4254
}
4355

4456
public companion object {

0 commit comments

Comments
 (0)