Skip to content

Commit

Permalink
Merge branch 'release/1.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
G00fY2 committed Aug 11, 2022
2 parents a4b3e26 + 07607be commit cb6ebc2
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 32 deletions.
6 changes: 3 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ ij_kotlin_name_count_to_use_star_import_for_members=2147483647
ij_kotlin_imports_layout=*,java.**,javax.**,kotlin.**,^

[*.xml]
ij_continuation_indent_size = 4
ij_xml_keep_line_breaks = true
ij_xml_space_inside_empty_tag = false
ij_continuation_indent_size=4
ij_xml_keep_line_breaks=true
ij_xml_space_inside_empty_tag=false
37 changes: 27 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Android Jetpack CameraX for communicating with the camera and showing the preview
- ML Kit Vision API for best, fully on-device barcode recognition and decoding

> **Note**: On Google I/O 2022 the [Google code scanner](https://developers.google.com/ml-kit/code-scanner) was announced. You should consider using it instead of quickie unbundled. If you don't have access to the Play Services or want to ship the latest ML Kit model then quickie bundled should still be preferred.
## Download [![Maven Central](https://img.shields.io/maven-central/v/io.github.g00fy2.quickie/quickie-unbundled)](https://search.maven.org/search?q=g:io.github.g00fy2.quickie)
There are two different flavors available on `mavenCentral()`:

Expand All @@ -18,32 +20,47 @@ There are two different flavors available on `mavenCentral()`:
| V3 model is used (faster, more accurate) | Currently V1 model will be downloaded
```kotlin
// bundled:
implementation("io.github.g00fy2.quickie:quickie-bundled:1.5.0")
implementation("io.github.g00fy2.quickie:quickie-bundled:1.5.1")

// unbundled:
implementation("io.github.g00fy2.quickie:quickie-unbundled:1.5.0")
implementation("io.github.g00fy2.quickie:quickie-unbundled:1.5.1")
```

## Quick Start

#### View-based
To use the QR scanner simply register the `ScanQRCode()` ActivityResultContract together with a callback during `init` or `onCreate()` lifecycle of your Activity/Fragment and use the returned ActivityResultLauncher to launch the QR scanner Activity.
```kotlin
val scanQrCode = registerForActivityResult(ScanQRCode(), ::handleResult)
val scanQrCodeLauncher = registerForActivityResult(ScanQRCode()) { result ->
// handle QRResult
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.button.setOnClickListener { scanQrCode.launch(null) }
binding.button.setOnClickListener { scanQrCodeLauncher.launch(null) }
}

fun handleResult(result: QRResult) {
```
⚠️ **You can't register the ActivityResultContract inside the OnClickListener lambda. This will fail since the code gets executed after the onCreate lifecycle!**

Check out the [sample](https://github.com/G00fY2/quickie/tree/develop/sample) inside this repo or visit the official [Activity Result API documentation](https://developer.android.com/training/basics/intents/result) for more information.

#### Jetpack Compose
Use the `rememberLauncherForActivityResult()` API to register the `ScanQRCode()` ActivityResultContract together with a callback in your composable:
```kotlin
@Composable
fun GetQRCodeExample() {
val scanQrCodeLauncher = rememberLauncherForActivityResult(ScanQRCode()) { result ->
// handle QRResult
}

Button(onClick = { scanQrCodeLauncher.launch(null) }) {
}
```
Check out the official [Compose Activity Result documentation](https://developer.android.com/jetpack/compose/libraries#activity_result) for more information.

### Responses
The callback you add to the `registerForActivityResult` will receive a subclass of the sealed `QRResult` class:
The activity result is a subclass of the sealed `QRResult` class:

1. `QRSuccess` when ML Kit successfully detected a QR code
* wraps a `QRContent` object
Expand Down Expand Up @@ -128,7 +145,7 @@ Thanks to everyone who contributed to quickie!
## License
The MIT License (MIT)
Copyright (C) 2021 Thomas Wirth
Copyright (C) 2022 Thomas Wirth
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
Expand Down
8 changes: 5 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Set the build VMs heap size.
# Ensure important default jvmargs aren't overwritten. See https://github.com/gradle/gradle/issues/19750
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
# Controls whether Gradle should print a welcome message
org.gradle.welcome=never
# Allow usage of AndroidX instead of the old support libraries.
android.useAndroidX=true
# Use R8 in full mode instead of ProGuard compatibility mode.
android.enableR8.fullMode=true
# Set the build VMs heap size.
# Ensure important default jvmargs aren't overwritten. See https://github.com/gradle/gradle/issues/19750
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
# Enables namespacing of each library's R class so that its R class includes only the resources declared in the library
# itself and none from the library's dependencies
android.nonTransitiveRClass=true
14 changes: 7 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[versions]
quickie = "1.5.0"
quickie = "1.5.1"

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

androidGradle = "7.2.1"
kotlin = "1.7.0"
androidGradle = "7.2.2"
kotlin = "1.7.10"

appcompat = "1.4.2"
appcompat = "1.5.0"

cameraX = "1.1.0"

Expand All @@ -18,11 +18,11 @@ barcodeScanningGms = "18.0.0"

materialDesign = "1.6.1"

detekt = "1.21.0-RC2"
detekt = "1.21.0"
gradleVersions = "0.42.0"
dokka = "1.7.0"
dokka = "1.7.10"

junit = "5.8.2"
junit = "5.9.0"

[libraries]
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
14 changes: 8 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import io.github.g00fy2.quickie.extensions.toQuickieContentType

public class ScanCustomCode : ActivityResultContract<ScannerConfig, QRResult>() {

override fun createIntent(context: Context, input: ScannerConfig?): Intent {
override fun createIntent(context: Context, input: ScannerConfig): Intent {
return Intent(context, QRScannerActivity::class.java).apply {
putExtra(EXTRA_CONFIG, input?.toParcelableConfig())
putExtra(EXTRA_CONFIG, input.toParcelableConfig())
}
}

Expand Down

0 comments on commit cb6ebc2

Please sign in to comment.