diff --git a/.editorconfig b/.editorconfig index c19a0660..8cf061c0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,10 +15,5 @@ ij_kotlin_name_count_to_use_star_import=2147483647 ij_kotlin_name_count_to_use_star_import_for_members=2147483647 # ktlint -# Comma-separated list of rules to disable (Since 0.34.0) -# Note that rules in any ruleset other than the standard ruleset will need to be prefixed by the ruleset identifier. -# noinspection EditorConfigKeyCorrectness -disabled_rules=final-newline -# Defines the imports layout. There are predefined layouts like "ascii" or "idea", as well as a custom layout. # noinspection EditorConfigKeyCorrectness kotlin_imports_layout=idea \ No newline at end of file diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 349a8e7b..3bdce8e0 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -13,26 +13,27 @@ on: jobs: ktlint: name: Run ktlint - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - name: Setup java - uses: actions/setup-java@v1 - with: - java-version: 11 - name: Run ktlintCheck run: ./gradlew ktlintCheck - build: - name: Build debug app - runs-on: ubuntu-latest + build_bundled: + name: Build bundled debug apps + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - - name: Setup java - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Build debug sample app - run: ./gradlew :activity-sample:assembleBundledDebug :advanced-sample:assembleBundledDebug :fragment-sample:assembleBundledDebug \ No newline at end of file + - name: Build debug bundled sample app + run: ./gradlew :activity-sample:assembleBundledDebug :advanced-sample:assembleBundledDebug :fragment-sample:assembleBundledDebug + + build_unbundled: + name: Build unbundled debug apps + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + - name: Build debug unbundled sample app + run: ./gradlew :activity-sample:assembleUnbundledDebug :advanced-sample:assembleUnbundledDebug :fragment-sample:assembleUnbundledDebug \ No newline at end of file diff --git a/README.md b/README.md index 44804d04..f2a25d04 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,10 @@ There are two different flavors available on `jcenter()`: | V2 barcode model is used (possibly faster, more accurate) | currently V1 will be downloaded ```kotlin // bundled: -implementation("com.g00fy2.quickie:quickie-bundled:0.4.0") +implementation("com.g00fy2.quickie:quickie-bundled:0.5.0") // unbundled: -implementation("com.g00fy2.quickie:quickie-unbundled:0.4.0") +implementation("com.g00fy2.quickie:quickie-unbundled:0.5.0") ``` ## Quick Start @@ -67,11 +67,11 @@ The library is designed to behave and look as generic as possible. Currently it' ![Image](https://raw.githubusercontent.com/G00fY2/Quickie/gh-pages/media/quickie-device-demo.png) ## Release state -**quickie** relies on Google Jetpack libraries which are in pre-release state. CameraX has no stable release version yet and the Activity Result API is part of the latest AndroidX Activity and Fragment beta releases. Here is what Google says about this release state: -* Beta releases are functionally stable and have a feature-complete API surface. -* They are ready for production use but may contain bugs. +**quickie** relies on Google Jetpack libraries which are in pre-release state. CameraX has no stable release version yet and the Activity Result API is part of the latest AndroidX Activity and Fragment release candidates. Here is what Google says about this release state: +* A release candidate is a prospective stable release. +* It may contain critical last-minute fixes. -You should consider **quickie** to be in beta state too. I will raise the version to 1.0 once all dependent libraries hit stable. +You should consider **quickie** to be in pre-release state too. I will raise the version to 1.0 once all dependent libraries hit stable. ## Requirements * AndroidX diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index e947a91e..ff67df1c 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -6,9 +6,9 @@ object Deps { const val appcompat = "androidx.appcompat:appcompat:${Versions.appcompat}" const val core = "androidx.core:core:${Versions.core}" - const val camera = "androidx.camera:camera-camera2:${Versions.camera}" - const val cameraLifecycle = "androidx.camera:camera-lifecycle:${Versions.cameraLifecycle}" - const val cameraPreview = "androidx.camera:camera-view:${Versions.cameraPreview}" + const val camera = "androidx.camera:camera-camera2:${Versions.cameraX}" + const val cameraLifecycle = "androidx.camera:camera-lifecycle:${Versions.cameraX}" + const val cameraPreview = "androidx.camera:camera-view:${Versions.cameraView}" const val navigation = "androidx.navigation:navigation-fragment-ktx:${Versions.navigation}" } diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 41c1c46e..493c3475 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -15,9 +15,8 @@ object Versions { const val navigation = "2.3.2" - const val camera = "1.0.0-rc01" - const val cameraLifecycle = "1.0.0-rc01" - const val cameraPreview = "1.0.0-alpha20" + const val cameraX = "1.0.0-rc01" + const val cameraView = "1.0.0-alpha20" const val materialDesign = "1.2.1" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1f3fdbc5..80cf08e7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/quickie/build.gradle.kts b/quickie/build.gradle.kts index 896fc5bf..37a694c0 100644 --- a/quickie/build.gradle.kts +++ b/quickie/build.gradle.kts @@ -19,7 +19,11 @@ android { create("bundled").dimension("mlkit") create("unbundled").dimension("mlkit") } - sourceSets.getByName("main").java.srcDirs("src/main/kotlin") + sourceSets { + getByName("main").java.srcDirs("src/main/kotlin") + getByName("bundled").java.srcDirs("src/bundled/kotlin") + getByName("unbundled").java.srcDirs("src/unbundled/kotlin") + } } repositories { @@ -50,7 +54,7 @@ dependencies { } group = "com.g00fy2.quickie" -version = "0.4.0" +version = "0.5.0" tasks.register("androidJavadocJar") { archiveClassifier.set("javadoc") diff --git a/quickie/src/bundled/kotlin/com/g00fy2/quickie/utils/PlayServicesValidator.kt b/quickie/src/bundled/kotlin/com/g00fy2/quickie/utils/PlayServicesValidator.kt new file mode 100644 index 00000000..0c269d88 --- /dev/null +++ b/quickie/src/bundled/kotlin/com/g00fy2/quickie/utils/PlayServicesValidator.kt @@ -0,0 +1,9 @@ +package com.g00fy2.quickie.utils + +import android.app.Activity + +object PlayServicesValidator { + + @Suppress("UNUSED_PARAMETER") + fun handleGooglePlayServicesError(activity: Activity, exception: Exception) = false // always false when bundled +} \ No newline at end of file diff --git a/quickie/src/main/kotlin/com/g00fy2/quickie/QROverlayView.kt b/quickie/src/main/kotlin/com/g00fy2/quickie/QROverlayView.kt index ef4f3b61..dfc0b52d 100644 --- a/quickie/src/main/kotlin/com/g00fy2/quickie/QROverlayView.kt +++ b/quickie/src/main/kotlin/com/g00fy2/quickie/QROverlayView.kt @@ -30,7 +30,6 @@ internal class QROverlayView @JvmOverloads constructor( private val strokeColor = ContextCompat.getColor(context, R.color.quickie_stroke_color) private val highlightedStrokeColor = getAccentColor() private val backgroundColor = ContextCompat.getColor(context, R.color.quickie_background_color) - // alpha paint used for drawing the bitmap. So the final background alpha will be multiplied private val alphaPaint = Paint().apply { alpha = Color.alpha(backgroundColor) } private val strokePaint = Paint(Paint.ANTI_ALIAS_FLAG) private val transparentPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply { @@ -103,11 +102,7 @@ internal class QROverlayView @JvmOverloads constructor( private fun View.getAccentColor(): Int { return TypedValue().let { - if (context.theme.resolveAttribute(android.R.attr.colorAccent, it, true)) { - it.data - } else { - Color.WHITE - } + if (context.theme.resolveAttribute(android.R.attr.colorAccent, it, true)) it.data else Color.WHITE } } diff --git a/quickie/src/main/kotlin/com/g00fy2/quickie/QRScannerActivity.kt b/quickie/src/main/kotlin/com/g00fy2/quickie/QRScannerActivity.kt index b04e4a9d..e004976d 100644 --- a/quickie/src/main/kotlin/com/g00fy2/quickie/QRScannerActivity.kt +++ b/quickie/src/main/kotlin/com/g00fy2/quickie/QRScannerActivity.kt @@ -20,6 +20,7 @@ import androidx.core.content.ContextCompat import androidx.core.view.ViewCompat import com.g00fy2.quickie.databinding.QuickieScannerActivityBinding import com.g00fy2.quickie.extensions.toParcelableContentType +import com.g00fy2.quickie.utils.PlayServicesValidator import com.google.mlkit.vision.barcode.Barcode import java.util.concurrent.ExecutorService import java.util.concurrent.Executors @@ -32,10 +33,8 @@ internal class QRScannerActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val themedInflater = if (applicationInfo.theme != 0) { - layoutInflater.cloneInContext(ContextThemeWrapper(this, applicationInfo.theme)) - } else { - layoutInflater + val themedInflater = applicationInfo.theme.let { + if (it != 0) layoutInflater.cloneInContext(ContextThemeWrapper(this, it)) else layoutInflater } binding = QuickieScannerActivityBinding.inflate(themedInflater) setContentView(binding.root) @@ -73,21 +72,32 @@ internal class QRScannerActivity : ComponentActivity() { val imageAnalysis = ImageAnalysis.Builder() .setTargetResolution(Size(1280, 720)) .build() - .apply { setAnalyzer(cameraExecutor, QRCodeAnalyzer({ onSuccess(it) }, { onFailure(it) })) } + .apply { + setAnalyzer( + cameraExecutor, + QRCodeAnalyzer( + { onSuccess(it) }, + { + clearAnalyzer() + onFailure(it) + } + ) + ) + } val preview = Preview.Builder().build() cameraProvider.unbindAll() try { cameraProvider.bindToLifecycle(this, cameraSelector, imageAnalysis, preview) preview.setSurfaceProvider(binding.previewView.surfaceProvider) - binding.decorationView.visibility = View.VISIBLE + binding.overlayView.visibility = View.VISIBLE } catch (e: Exception) { onFailure(e) } } private fun onSuccess(result: Barcode) { - binding.decorationView.isHighlighted = true + binding.overlayView.isHighlighted = true setResult( Activity.RESULT_OK, Intent().apply { @@ -101,11 +111,10 @@ internal class QRScannerActivity : ComponentActivity() { private fun onFailure(exception: Exception) { setResult(RESULT_ERROR, Intent().putExtra(EXTRA_RESULT_EXCEPTION, exception)) - finish() + if (!PlayServicesValidator.handleGooglePlayServicesError(this, exception)) finish() } private fun setupEdgeToEdgeUI() { - // TODO migrate to androidx.core:core:1.5.0 once stable if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { window.setDecorFitsSystemWindows(false) } else { @@ -121,7 +130,7 @@ internal class QRScannerActivity : ComponentActivity() { } } } - ViewCompat.setOnApplyWindowInsetsListener(binding.decorationView) { v, insets -> + ViewCompat.setOnApplyWindowInsetsListener(binding.overlayView) { v, insets -> insets.systemWindowInsets.let { v.setPadding(it.left, it.top, it.right, it.bottom) } diff --git a/quickie/src/main/kotlin/com/g00fy2/quickie/content/QRContent.kt b/quickie/src/main/kotlin/com/g00fy2/quickie/content/QRContent.kt index 15c7351f..e3d33ac8 100644 --- a/quickie/src/main/kotlin/com/g00fy2/quickie/content/QRContent.kt +++ b/quickie/src/main/kotlin/com/g00fy2/quickie/content/QRContent.kt @@ -111,4 +111,4 @@ sealed class QRContent(val rawValue: String) { val utc: Boolean ) } -} +} \ No newline at end of file diff --git a/quickie/src/main/kotlin/com/g00fy2/quickie/extensions/IntentExtensions.kt b/quickie/src/main/kotlin/com/g00fy2/quickie/extensions/IntentExtensions.kt index 06eade8f..2c4105fc 100644 --- a/quickie/src/main/kotlin/com/g00fy2/quickie/extensions/IntentExtensions.kt +++ b/quickie/src/main/kotlin/com/g00fy2/quickie/extensions/IntentExtensions.kt @@ -122,7 +122,7 @@ private fun EmailParcelable.toEmail(rawValue: String) = address = address, body = body, subject = subject, - EmailType.values().getOrElse(type) { EmailType.UNKNOWN } + type = EmailType.values().getOrElse(type) { EmailType.UNKNOWN } ) private fun AddressParcelable.toAddress() = @@ -148,4 +148,4 @@ private fun CalendarDateTimeParcelable.toCalendarEvent() = seconds = seconds, year = year, utc = utc - ) + ) \ No newline at end of file diff --git a/quickie/src/main/res/layout/quickie_scanner_activity.xml b/quickie/src/main/res/layout/quickie_scanner_activity.xml index ae8d0d8e..cbe03fe8 100644 --- a/quickie/src/main/res/layout/quickie_scanner_activity.xml +++ b/quickie/src/main/res/layout/quickie_scanner_activity.xml @@ -13,7 +13,7 @@ />