Skip to content

Commit

Permalink
Merge branch 'release/1.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
G00fY2 committed Jan 8, 2023
2 parents d3d625d + 3f3bf42 commit 41f69c6
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 25 deletions.
4 changes: 1 addition & 3 deletions detekt.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
complexity:
ComplexMethod:
CyclomaticComplexMethod:
ignoreSingleWhenExpression: true
LongParameterList:
ignoreAnnotated: ['Parcelize']
Expand All @@ -15,8 +15,6 @@ formatting:
active: false
FinalNewline:
insertFinalNewLine: false
ParameterListWrapping:
indentSize: 2

performance:
SpreadOperator:
Expand Down
18 changes: 9 additions & 9 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
[versions]
quickie = "1.5.2"
quickie = "1.6.0"

androidconfig-minSdk = "21"
androidconfig-compileSdk = "32"
androidconfig-targetSdk = "32"
androidconfig-buildTools = "32.0.0"
androidconfig-compileSdk = "33"
androidconfig-targetSdk = "33"
androidconfig-buildTools = "33.0.1"

androidGradle = "7.3.1"
kotlin = "1.7.20"
kotlin = "1.7.21"

appcompat = "1.5.1"

cameraX = "1.1.0"
cameraX = "1.2.0"

barcodeScanning = "17.0.2"
barcodeScanning = "17.0.3"
barcodeScanningGms = "18.1.0"

materialDesign = "1.7.0"

detekt = "1.21.0"
gradleVersions = "0.43.0"
detekt = "1.22.0"
gradleVersions = "0.44.0"
dokka = "1.7.20"

junit = "5.9.1"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 8 additions & 4 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,10 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
Expand Down Expand Up @@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ internal class QROverlayView @JvmOverloads constructor(
}
}

fun setCloseVisibilityAndOnClick(visible: Boolean, action: () -> Unit = {}) {
binding.closeImageView.visibility = if (visible) View.VISIBLE else View.GONE
binding.closeImageView.setOnClickListener { action() }
if (visible) binding.closeImageView.setTintAndStateAwareBackground()
}

fun setTorchVisibilityAndOnClick(visible: Boolean, action: (Boolean) -> Unit = {}) {
binding.torchImageView.visibility = if (visible) View.VISIBLE else View.GONE
binding.torchImageView.setOnClickListener { action(!it.isSelected) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal class QRScannerActivity : AppCompatActivity() {
private var barcodeFormats = intArrayOf(Barcode.FORMAT_QR_CODE)
private var hapticFeedback = true
private var showTorchToggle = false
private var showCloseButton = false
private var useFrontCamera = false
internal var errorDialog: Dialog? = null
set(value) {
Expand Down Expand Up @@ -82,10 +83,20 @@ internal class QRScannerActivity : AppCompatActivity() {
}

private fun startCamera() {
val cameraProviderFuture = ProcessCameraProvider.getInstance(this)
val cameraProviderFuture = try {
ProcessCameraProvider.getInstance(this)
} catch (e: Exception) {
onFailure(e)
return
}

cameraProviderFuture.addListener({
val cameraProvider = cameraProviderFuture.get()
val cameraProvider = try {
cameraProviderFuture.get()
} catch (e: Exception) {
onFailure(e)
return@addListener
}

val preview = Preview.Builder().build().also { it.setSurfaceProvider(binding.previewView.surfaceProvider) }
val imageAnalysis = ImageAnalysis.Builder()
Expand All @@ -107,14 +118,14 @@ internal class QRScannerActivity : AppCompatActivity() {
}

cameraProvider.unbindAll()

val cameraSelector =
if (useFrontCamera) CameraSelector.DEFAULT_FRONT_CAMERA else CameraSelector.DEFAULT_BACK_CAMERA

try {
val cameraSelector = if (useFrontCamera) {
CameraSelector.DEFAULT_FRONT_CAMERA
} else {
CameraSelector.DEFAULT_BACK_CAMERA
}
val camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageAnalysis)
binding.overlayView.visibility = View.VISIBLE
binding.overlayView.setCloseVisibilityAndOnClick(showCloseButton) { finish() }
if (showTorchToggle && camera.cameraInfo.hasFlashUnit()) {
binding.overlayView.setTorchVisibilityAndOnClick(true) { camera.cameraControl.enableTorch(it) }
camera.cameraInfo.torchState.observe(this) { binding.overlayView.setTorchState(it == TorchState.ON) }
Expand All @@ -131,6 +142,7 @@ internal class QRScannerActivity : AppCompatActivity() {
private fun onSuccess(result: Barcode) {
binding.overlayView.isHighlighted = true
if (hapticFeedback) {
@Suppress("DEPRECATION")
binding.overlayView.performHapticFeedback(
HapticFeedbackConstants.KEYBOARD_TAP,
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING or HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING
Expand Down Expand Up @@ -165,6 +177,7 @@ internal class QRScannerActivity : AppCompatActivity() {
}

private fun applyScannerConfig() {
@Suppress("DEPRECATION")
intent?.getParcelableExtra<ParcelableScannerConfig>(EXTRA_CONFIG)?.let {
barcodeFormats = it.formats
binding.overlayView.setCustomText(it.stringRes)
Expand All @@ -173,6 +186,7 @@ internal class QRScannerActivity : AppCompatActivity() {
hapticFeedback = it.hapticFeedback
showTorchToggle = it.showTorchToggle
useFrontCamera = it.useFrontCamera
showCloseButton = it.showCloseButton
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ internal class ParcelableScannerConfig(
val showTorchToggle: Boolean,
val horizontalFrameRatio: Float,
val useFrontCamera: Boolean,
val showCloseButton: Boolean,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.annotation.StringRes
/**
* Builder for ScannerConfig used in ScanBarcode ActivityResultContract.
*/
@Suppress("LongParameterList")
public class ScannerConfig internal constructor(
internal val formats: IntArray,
internal val stringRes: Int,
Expand All @@ -14,6 +15,7 @@ public class ScannerConfig internal constructor(
internal val showTorchToggle: Boolean,
internal val horizontalFrameRatio: Float,
internal val useFrontCamera: Boolean,
internal val showCloseButton: Boolean,
) {

public class Builder {
Expand All @@ -24,6 +26,7 @@ public class ScannerConfig internal constructor(
private var showTorchToggle: Boolean = false
private var horizontalFrameRatio: Float = 1f
private var useFrontCamera: Boolean = false
private var showCloseButton: Boolean = false

/**
* Set a list of interested barcode formats. List must not be empty.
Expand Down Expand Up @@ -63,6 +66,11 @@ public class ScannerConfig internal constructor(
*/
public fun setUseFrontCamera(enable: Boolean): Builder = apply { useFrontCamera = enable }

/**
* Show or hide (default) close button.
*/
public fun setShowCloseButton(enable: Boolean): Builder = apply { showCloseButton = enable }

/**
* Build the BarcodeConfig required by the ScanBarcode ActivityResultContract.
*/
Expand All @@ -75,6 +83,7 @@ public class ScannerConfig internal constructor(
showTorchToggle,
horizontalFrameRatio,
useFrontCamera,
showCloseButton,
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("DEPRECATION")

package io.github.g00fy2.quickie.extensions

import android.content.Intent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ internal fun ScannerConfig.toParcelableConfig() =
showTorchToggle = showTorchToggle,
horizontalFrameRatio = horizontalFrameRatio,
useFrontCamera = useFrontCamera,
showCloseButton = showCloseButton,
)
26 changes: 26 additions & 0 deletions quickie/src/main/res/drawable/quickie_ic_close.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2021 Thomas Wirth
Copyright (C) 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This file has been modified by Thomas Wirth by replacing the fillColor.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24.0dp"
android:height="24.0dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M18.3,5.71a0.996,0.996 0,0 0,-1.41 0L12,10.59 7.11,5.7A0.996,0.996 0,1 0,5.7 7.11L10.59,12 5.7,16.89a0.996,0.996 0,1 0,1.41 1.41L12,13.41l4.89,4.89a0.996,0.996 0,1 0,1.41 -1.41L13.41,12l4.89,-4.89c0.38,-0.38 0.38,-1.02 0,-1.4z"
android:fillColor="@color/quickie_white"/>
</vector>
15 changes: 14 additions & 1 deletion quickie/src/main/res/layout/quickie_overlay_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,26 @@
app:drawableTopCompat="@drawable/quickie_ic_qrcode"
/>

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/close_image_view"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="top|start"
android:layout_margin="12dp"
android:background="@drawable/quickie_bg_round"
android:padding="12dp"
android:visibility="gone"
app:srcCompat="@drawable/quickie_ic_close"
tools:visibility="visible"
/>

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/torch_image_view"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="top|end"
android:layout_margin="12dp"
android:background="@drawable/quickie_bg_torch"
android:background="@drawable/quickie_bg_round"
android:padding="12dp"
android:visibility="gone"
app:srcCompat="@drawable/quickie_ic_torch"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class MainActivity : AppCompatActivity() {
setOverlayDrawableRes(R.drawable.ic_scan_barcode) // drawable resource used for the scanner overlay
setHapticSuccessFeedback(false) // enable (default) or disable haptic feedback when a barcode was detected
setShowTorchToggle(true) // show or hide (default) torch/flashlight toggle button
setShowCloseButton(true) // show or hide (default) close button
setHorizontalFrameRatio(2.2f) // set the horizontal overlay ratio (default is 1 / square frame)
setUseFrontCamera(false) // use the front camera
}
Expand Down

0 comments on commit 41f69c6

Please sign in to comment.