diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index c176ba11..3d3dcaa2 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -15,6 +15,8 @@ Make sure to get working code on a personal branch with tests and sanity checks ```shell ./gradlew detektBundledDebug detektUnbundledDebug ./gradlew test +./gradlew :sample:lintBundledDebug +./gradlew :sample:lintUnbundledDebug ./gradlew :sample:assembleBundledDebug ./gradlew :sample:assembleUnbundledDebug ``` diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d0adebfd..0cc12b65 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,6 +37,19 @@ jobs: - name: Run bundled and unbundled unit tests run: ./gradlew test + android_lint: + name: Android lint + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '17' + - name: Run Android lint + run: ./gradlew :sample:lintBundledDebug :sample:lintUnbundledDebug + build_bundled: name: Build bundled debug runs-on: ubuntu-latest diff --git a/README.md b/README.md index 7089f084..b11cb328 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,10 @@ There are two different flavors available on `mavenCentral()`: ```kotlin // bundled: -implementation("io.github.g00fy2.quickie:quickie-bundled:1.9.0") +implementation("io.github.g00fy2.quickie:quickie-bundled:1.10.0") // unbundled: -implementation("io.github.g00fy2.quickie:quickie-unbundled:1.9.0") +implementation("io.github.g00fy2.quickie:quickie-unbundled:1.10.0") ``` ## Quick Start @@ -116,6 +116,7 @@ override fun onCreate(savedInstanceState: Bundle?) { setShowCloseButton(true) // show or hide (default) close button setHorizontalFrameRatio(2.2f) // set the horizontal overlay ratio (default is 1 / square frame) setUseFrontCamera(true) // use the front camera + setKeepScreenOn(true) // keep the device's screen turned on } ) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4b9f6138..d9d1a1c9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,28 +1,28 @@ [versions] -quickie = "1.9.0" +quickie = "1.10.0" androidconfig-minSdk = "21" androidconfig-compileSdk = "34" androidconfig-targetSdk = "33" androidconfig-buildTools = "34.0.0" -androidGradle = "8.2.0" -kotlin = "1.9.21" +androidGradle = "8.4.0" +kotlin = "1.9.23" appcompat = "1.6.1" -core = "1.12.0" +core = "1.13.1" -cameraX = "1.3.0" +cameraX = "1.3.3" barcodeScanning = "17.2.0" barcodeScanningGms = "18.3.0" -materialDesign = "1.10.0" +materialDesign = "1.12.0" -detekt = "1.23.4" -dokka = "1.9.10" +detekt = "1.23.6" +dokka = "1.9.20" -junit = "5.10.1" +junit = "5.10.2" [libraries] androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index d64cd491..e6441136 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1af9e093..b82aa23a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew.bat b/gradlew.bat index 6689b85b..7101f8e4 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/quickie/src/main/AndroidManifest.xml b/quickie/src/main/AndroidManifest.xml index db4b4096..cf62fb9d 100644 --- a/quickie/src/main/AndroidManifest.xml +++ b/quickie/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ - + + android:theme="@style/QuickieScannerActivity" + tools:ignore="DiscouragedApi"/> diff --git a/quickie/src/main/kotlin/io/github/g00fy2/quickie/QRResult.kt b/quickie/src/main/kotlin/io/github/g00fy2/quickie/QRResult.kt index dc7e38bb..4d2ea2d5 100644 --- a/quickie/src/main/kotlin/io/github/g00fy2/quickie/QRResult.kt +++ b/quickie/src/main/kotlin/io/github/g00fy2/quickie/QRResult.kt @@ -14,12 +14,12 @@ public sealed class QRResult { /** * Activity got cancelled by the user. */ - public object QRUserCanceled : QRResult() + public data object QRUserCanceled : QRResult() /** * Camera permission was not granted. */ - public object QRMissingPermission : QRResult() + public data object QRMissingPermission : QRResult() /** * Error while setting up CameraX or while MLKit analysis. diff --git a/quickie/src/main/kotlin/io/github/g00fy2/quickie/QRScannerActivity.kt b/quickie/src/main/kotlin/io/github/g00fy2/quickie/QRScannerActivity.kt index eeff7712..79401434 100644 --- a/quickie/src/main/kotlin/io/github/g00fy2/quickie/QRScannerActivity.kt +++ b/quickie/src/main/kotlin/io/github/g00fy2/quickie/QRScannerActivity.kt @@ -10,6 +10,7 @@ import android.util.Size import android.view.HapticFeedbackConstants import android.view.KeyEvent import android.view.View +import android.view.WindowManager import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ContextThemeWrapper @@ -195,6 +196,8 @@ internal class QRScannerActivity : AppCompatActivity() { showTorchToggle = it.showTorchToggle useFrontCamera = it.useFrontCamera showCloseButton = it.showCloseButton + + if (it.keepScreenOn) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) } } diff --git a/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ParcelableScannerConfig.kt b/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ParcelableScannerConfig.kt index 78e1e427..3f9d34b0 100644 --- a/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ParcelableScannerConfig.kt +++ b/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ParcelableScannerConfig.kt @@ -13,4 +13,5 @@ internal class ParcelableScannerConfig( val horizontalFrameRatio: Float, val useFrontCamera: Boolean, val showCloseButton: Boolean, + val keepScreenOn: Boolean, ) : Parcelable \ No newline at end of file diff --git a/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ScannerConfig.kt b/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ScannerConfig.kt index 03e6bbb5..dc4f2945 100644 --- a/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ScannerConfig.kt +++ b/quickie/src/main/kotlin/io/github/g00fy2/quickie/config/ScannerConfig.kt @@ -16,6 +16,7 @@ public class ScannerConfig internal constructor( internal val horizontalFrameRatio: Float, internal val useFrontCamera: Boolean, internal val showCloseButton: Boolean, + internal val keepScreenOn: Boolean, ) { public class Builder { @@ -27,6 +28,7 @@ public class ScannerConfig internal constructor( private var horizontalFrameRatio: Float = 1f private var useFrontCamera: Boolean = false private var showCloseButton: Boolean = false + private var keepScreenOn: Boolean = false /** * Set a list of interested barcode formats. List must not be empty. @@ -71,19 +73,25 @@ public class ScannerConfig internal constructor( */ public fun setShowCloseButton(enable: Boolean): Builder = apply { showCloseButton = enable } + /** + * Keep the device's screen turned on as long as the scanner is visible. + */ + public fun setKeepScreenOn(enable: Boolean): Builder = apply { keepScreenOn = enable } + /** * Build the BarcodeConfig required by the ScanBarcode ActivityResultContract. */ public fun build(): ScannerConfig = ScannerConfig( - barcodeFormats.map { it.value }.toIntArray(), - overlayStringRes, - overlayDrawableRes, - hapticSuccessFeedback, - showTorchToggle, - horizontalFrameRatio, - useFrontCamera, - showCloseButton, + formats = barcodeFormats.map { it.value }.toIntArray(), + stringRes = overlayStringRes, + drawableRes = overlayDrawableRes, + hapticFeedback = hapticSuccessFeedback, + showTorchToggle = showTorchToggle, + horizontalFrameRatio = horizontalFrameRatio, + useFrontCamera = useFrontCamera, + showCloseButton = showCloseButton, + keepScreenOn = keepScreenOn, ) } diff --git a/quickie/src/main/kotlin/io/github/g00fy2/quickie/extensions/ScannerConfigExtensions.kt b/quickie/src/main/kotlin/io/github/g00fy2/quickie/extensions/ScannerConfigExtensions.kt index 7d24d8d3..b2cfc837 100644 --- a/quickie/src/main/kotlin/io/github/g00fy2/quickie/extensions/ScannerConfigExtensions.kt +++ b/quickie/src/main/kotlin/io/github/g00fy2/quickie/extensions/ScannerConfigExtensions.kt @@ -13,4 +13,5 @@ internal fun ScannerConfig.toParcelableConfig() = horizontalFrameRatio = horizontalFrameRatio, useFrontCamera = useFrontCamera, showCloseButton = showCloseButton, + keepScreenOn = keepScreenOn, ) \ No newline at end of file diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 12b2df95..04d55c05 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -34,6 +34,12 @@ android { buildConfig = true viewBinding = true } + lint { + abortOnError = true + warningsAsErrors = true + checkDependencies = true + disable.add("RtlEnabled") + } } dependencies { diff --git a/sample/src/main/kotlin/io/github/g00fy2/quickiesample/MainActivity.kt b/sample/src/main/kotlin/io/github/g00fy2/quickiesample/MainActivity.kt index 1142eee8..acf21d6a 100644 --- a/sample/src/main/kotlin/io/github/g00fy2/quickiesample/MainActivity.kt +++ b/sample/src/main/kotlin/io/github/g00fy2/quickiesample/MainActivity.kt @@ -49,6 +49,7 @@ class MainActivity : AppCompatActivity() { 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 + setKeepScreenOn(true) // keep the device's screen turned on } ) } diff --git a/sample/src/main/kotlin/io/github/g00fy2/quickiesample/quicksettingstile/QuickieTileService.kt b/sample/src/main/kotlin/io/github/g00fy2/quickiesample/quicksettingstile/QuickieTileService.kt index f5f4d72f..1c8943eb 100644 --- a/sample/src/main/kotlin/io/github/g00fy2/quickiesample/quicksettingstile/QuickieTileService.kt +++ b/sample/src/main/kotlin/io/github/g00fy2/quickiesample/quicksettingstile/QuickieTileService.kt @@ -1,5 +1,6 @@ package io.github.g00fy2.quickiesample.quicksettingstile +import android.app.PendingIntent import android.content.ComponentName import android.content.Intent import android.os.Build @@ -7,6 +8,8 @@ import android.os.IBinder import android.service.quicksettings.Tile import android.service.quicksettings.TileService import androidx.annotation.RequiresApi +import androidx.core.service.quicksettings.PendingIntentActivityWrapper +import androidx.core.service.quicksettings.TileServiceCompat import io.github.g00fy2.quickiesample.MainActivity // optional service to allow launching the sample app from the quick settings @@ -28,12 +31,15 @@ class QuickieTileService : TileService() { override fun onClick() { super.onClick() - @Suppress("DEPRECATION") - startActivityAndCollapse( - Intent(this, MainActivity::class.java).apply { - addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) - putExtra(MainActivity.OPEN_SCANNER, true) - } + + val intent = Intent(this, MainActivity::class.java).apply { + addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK) + putExtra(MainActivity.OPEN_SCANNER, true) + } + + TileServiceCompat.startActivityAndCollapse( + this, + PendingIntentActivityWrapper(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT, true) ) } } \ No newline at end of file