| @@ -2,14 +2,14 @@ group 'net.touchcapture.qr.flutterqr' | |||
| version '1.0-SNAPSHOT' | |||
| buildscript { | |||
| ext.kotlin_version = '1.5.10' | |||
| ext.kotlin_version = '1.5.31' | |||
| repositories { | |||
| google() | |||
| mavenCentral() | |||
| } | |||
| dependencies { | |||
| classpath 'com.android.tools.build:gradle:4.2.1' | |||
| classpath 'com.android.tools.build:gradle:7.0.2' | |||
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | |||
| } | |||
| } | |||
| @@ -36,9 +36,7 @@ android { | |||
| testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | |||
| multiDexEnabled true | |||
| } | |||
| buildFeatures { | |||
| viewBinding = true | |||
| } | |||
| compileOptions { | |||
| // Flag to enable support for the new language APIs | |||
| coreLibraryDesugaringEnabled true | |||
| @@ -51,7 +49,7 @@ android { | |||
| dependencies { | |||
| implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |||
| implementation('com.journeyapps:zxing-android-embedded:4.1.0') { transitive = false } | |||
| implementation 'androidx.appcompat:appcompat:1.3.0' | |||
| implementation 'androidx.appcompat:appcompat:1.3.1' | |||
| implementation 'com.google.zxing:core:3.4.1' | |||
| coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.touchcapture.qr.flutterqr" | |||
| xmlns:tools="http://schemas.android.com/tools"> | |||
| <manifest package="net.touchcapture.qr.flutterqr" | |||
| xmlns:tools="http://schemas.android.com/tools"> | |||
| <uses-sdk tools:overrideLibrary="com.google.zxing.client.android" /> | |||
| </manifest> | |||
| @@ -1,50 +0,0 @@ | |||
| package net.touchcapture.qr.flutterqr; | |||
| import android.content.Context; | |||
| import android.graphics.Rect; | |||
| import android.util.AttributeSet; | |||
| import com.journeyapps.barcodescanner.BarcodeView; | |||
| import com.journeyapps.barcodescanner.Size; | |||
| public class CustomFramingRectBarcodeView extends BarcodeView { | |||
| private static final int BOTTOM_OFFSET_NOT_SET_VALUE = -1; | |||
| private int bottomOffset = BOTTOM_OFFSET_NOT_SET_VALUE; | |||
| public CustomFramingRectBarcodeView(Context context) { | |||
| super(context); | |||
| } | |||
| public CustomFramingRectBarcodeView(Context context, AttributeSet attrs) { | |||
| super(context, attrs); | |||
| } | |||
| public CustomFramingRectBarcodeView(Context context, AttributeSet attrs, int defStyleAttr) { | |||
| super(context, attrs, defStyleAttr); | |||
| } | |||
| @Override | |||
| protected Rect calculateFramingRect(Rect container, Rect surface) { | |||
| Rect containerArea = new Rect(container); | |||
| boolean intersects = containerArea.intersect(surface);//adjusts the containerArea (code from super.calculateFramingRect) | |||
| Rect scanAreaRect = super.calculateFramingRect(container, surface); | |||
| if (bottomOffset != BOTTOM_OFFSET_NOT_SET_VALUE) {//if the setFramingRect function was called, then we shift the scan area by Y | |||
| Rect scanAreaRectWithOffset = new Rect(scanAreaRect); | |||
| scanAreaRectWithOffset.bottom -= bottomOffset; | |||
| scanAreaRectWithOffset.top -= bottomOffset; | |||
| boolean belongsToContainer = scanAreaRectWithOffset.intersect(containerArea); | |||
| if(belongsToContainer){ | |||
| return scanAreaRectWithOffset; | |||
| } | |||
| } | |||
| return scanAreaRect; | |||
| } | |||
| public void setFramingRect(int rectWidth, int rectHeight, int bottomOffset) { | |||
| this.bottomOffset = bottomOffset; | |||
| this.setFramingRectSize(new Size(rectWidth, rectHeight)); | |||
| } | |||
| } | |||
| @@ -0,0 +1,45 @@ | |||
| package net.touchcapture.qr.flutterqr | |||
| import android.content.Context | |||
| import android.graphics.Rect | |||
| import android.util.AttributeSet | |||
| import com.journeyapps.barcodescanner.BarcodeView | |||
| import com.journeyapps.barcodescanner.Size | |||
| class CustomFramingRectBarcodeView : BarcodeView { | |||
| private var bottomOffset = BOTTOM_OFFSET_NOT_SET_VALUE | |||
| constructor(context: Context?) : super(context) {} | |||
| constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {} | |||
| constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super( | |||
| context, | |||
| attrs, | |||
| defStyleAttr | |||
| ) | |||
| override fun calculateFramingRect(container: Rect, surface: Rect): Rect { | |||
| val containerArea = Rect(container) | |||
| val intersects = | |||
| containerArea.intersect(surface) //adjusts the containerArea (code from super.calculateFramingRect) | |||
| val scanAreaRect = super.calculateFramingRect(container, surface) | |||
| if (bottomOffset != BOTTOM_OFFSET_NOT_SET_VALUE) { //if the setFramingRect function was called, then we shift the scan area by Y | |||
| val scanAreaRectWithOffset = Rect(scanAreaRect) | |||
| scanAreaRectWithOffset.bottom -= bottomOffset | |||
| scanAreaRectWithOffset.top -= bottomOffset | |||
| val belongsToContainer = scanAreaRectWithOffset.intersect(containerArea) | |||
| if (belongsToContainer) { | |||
| return scanAreaRectWithOffset | |||
| } | |||
| } | |||
| return scanAreaRect | |||
| } | |||
| fun setFramingRect(rectWidth: Int, rectHeight: Int, bottomOffset: Int) { | |||
| this.bottomOffset = bottomOffset | |||
| framingRectSize = Size(rectWidth, rectHeight) | |||
| } | |||
| companion object { | |||
| private const val BOTTOM_OFFSET_NOT_SET_VALUE = -1 | |||
| } | |||
| } | |||
| @@ -1,65 +1,43 @@ | |||
| package net.touchcapture.qr.flutterqr | |||
| import android.app.Activity | |||
| import android.content.pm.PackageManager | |||
| import androidx.annotation.NonNull | |||
| import io.flutter.embedding.engine.plugins.FlutterPlugin | |||
| import io.flutter.embedding.engine.plugins.activity.ActivityAware | |||
| import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding | |||
| import io.flutter.plugin.common.BinaryMessenger | |||
| import io.flutter.plugin.common.PluginRegistry | |||
| import io.flutter.plugin.platform.PlatformViewRegistry | |||
| import net.touchcapture.qr.flutterqr.Shared.activity | |||
| class FlutterQrPlugin : FlutterPlugin, ActivityAware { | |||
| /** Plugin registration embedding v1 */ | |||
| companion object { | |||
| @JvmStatic | |||
| fun registerWith(registrar: PluginRegistry.Registrar) { | |||
| FlutterQrPlugin().onAttachedToV1(registrar) | |||
| } | |||
| } | |||
| private fun onAttachedToV1(registrar: PluginRegistry.Registrar) { | |||
| Shared.registrar = registrar | |||
| onAttachedToEngines(registrar.platformViewRegistry(), registrar.messenger(), registrar.activity()) | |||
| } | |||
| /** Plugin registration embedding v2 */ | |||
| override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) { | |||
| onAttachedToEngines(flutterPluginBinding.platformViewRegistry, flutterPluginBinding.binaryMessenger, Shared.activity) | |||
| if (activity != null) { | |||
| activity = activity | |||
| } | |||
| flutterPluginBinding.platformViewRegistry | |||
| .registerViewFactory( | |||
| "net.touchcapture.qr.flutterqr/qrview", QRViewFactory(flutterPluginBinding.binaryMessenger)) | |||
| } | |||
| override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { | |||
| } | |||
| /** Plugin start for both embedding v1 & v2 */ | |||
| private fun onAttachedToEngines(platformViewRegistry: PlatformViewRegistry, messenger: BinaryMessenger, activity: Activity?) { | |||
| if (activity != null) { | |||
| Shared.activity = activity | |||
| } | |||
| platformViewRegistry | |||
| .registerViewFactory( | |||
| "net.touchcapture.qr.flutterqr/qrview", QRViewFactory(messenger)) | |||
| } | |||
| override fun onAttachedToActivity(activityPluginBinding: ActivityPluginBinding) { | |||
| Shared.activity = activityPluginBinding.activity | |||
| activity = activityPluginBinding.activity | |||
| Shared.binding = activityPluginBinding | |||
| } | |||
| override fun onDetachedFromActivityForConfigChanges() { | |||
| Shared.activity = null | |||
| activity = null | |||
| Shared.binding = null | |||
| } | |||
| override fun onReattachedToActivityForConfigChanges(activityPluginBinding: ActivityPluginBinding) { | |||
| Shared.activity = activityPluginBinding.activity | |||
| activity = activityPluginBinding.activity | |||
| Shared.binding = activityPluginBinding | |||
| } | |||
| override fun onDetachedFromActivity() { | |||
| Shared.activity = null | |||
| activity = null | |||
| Shared.binding = null | |||
| } | |||
| @@ -34,10 +34,6 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v | |||
| Shared.binding!!.addRequestPermissionsResultListener(this) | |||
| } | |||
| if (Shared.registrar != null) { | |||
| Shared.registrar!!.addRequestPermissionsResultListener(this) | |||
| } | |||
| channel.setMethodCallHandler(this) | |||
| Shared.activity?.application?.registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks { | |||
| override fun onActivityPaused(p0: Activity) { | |||
| @@ -304,14 +300,14 @@ class QRView(private val context: Context, messenger: BinaryMessenger, private v | |||
| permissions: Array<out String>?, | |||
| grantResults: IntArray): Boolean { | |||
| if(requestCode == Shared.CAMERA_REQUEST_ID + this.id) { | |||
| if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |||
| return if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |||
| permissionGranted = true | |||
| channel.invokeMethod("onPermissionSet", true) | |||
| return true | |||
| true | |||
| } else { | |||
| permissionGranted = false | |||
| channel.invokeMethod("onPermissionSet", false) | |||
| return false | |||
| false | |||
| } | |||
| } | |||
| return false | |||
| @@ -8,5 +8,4 @@ object Shared { | |||
| const val CAMERA_REQUEST_ID = 513469796 | |||
| var activity: Activity? = null | |||
| var binding: ActivityPluginBinding? = null | |||
| var registrar: PluginRegistry.Registrar? = null | |||
| } | |||
| @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' | |||
| apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" | |||
| android { | |||
| compileSdkVersion 30 | |||
| compileSdkVersion 31 | |||
| sourceSets { | |||
| main.java.srcDirs += 'src/main/kotlin' | |||
| @@ -36,7 +36,7 @@ android { | |||
| applicationId "net.touchcapture.qr.flutterqrexample" | |||
| // minSdkVersion is determined by Native View. | |||
| minSdkVersion 20 | |||
| targetSdkVersion 30 | |||
| targetSdkVersion 31 | |||
| versionCode flutterVersionCode.toInteger() | |||
| versionName flutterVersionName | |||
| testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |||
| @@ -56,7 +56,7 @@ flutter { | |||
| dependencies { | |||
| implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |||
| testImplementation 'junit:junit:4.13.1' | |||
| testImplementation 'junit:junit:4.13.2' | |||
| androidTestImplementation 'com.android.support.test:runner:1.0.2' | |||
| androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | |||
| } | |||
| @@ -16,17 +16,13 @@ | |||
| android:label="flutter_qr_example" | |||
| android:icon="@mipmap/ic_launcher"> | |||
| <activity | |||
| android:name=".MainActivity" | |||
| android:name="io.flutter.embedding.android.FlutterActivity" | |||
| android:launchMode="singleTop" | |||
| android:theme="@style/LaunchTheme" | |||
| android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density" | |||
| android:hardwareAccelerated="true" | |||
| android:exported='true' | |||
| android:windowSoftInputMode="adjustResize"> | |||
| <!-- Specify that the launch screen should continue being displayed --> | |||
| <!-- until Flutter renders its first frame. --> | |||
| <meta-data | |||
| android:name="io.flutter.embedding.android.SplashScreenDrawable" | |||
| android:resource="@drawable/launch_background" /> | |||
| <!-- Theme to apply as soon as Flutter begins rendering frames --> | |||
| <meta-data | |||
| android:name="io.flutter.embedding.android.NormalTheme" | |||
| @@ -1,6 +0,0 @@ | |||
| package net.touchcapture.qr.flutterqrexample | |||
| import io.flutter.embedding.android.FlutterActivity | |||
| class MainActivity: FlutterActivity() { | |||
| } | |||
| @@ -1,12 +1,12 @@ | |||
| buildscript { | |||
| ext.kotlin_version = '1.5.10' | |||
| ext.kotlin_version = '1.5.31' | |||
| repositories { | |||
| google() | |||
| mavenCentral() | |||
| } | |||
| dependencies { | |||
| classpath 'com.android.tools.build:gradle:4.2.1' | |||
| classpath 'com.android.tools.build:gradle:7.0.2' | |||
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | |||
| } | |||
| } | |||
| @@ -1,6 +1,6 @@ | |||
| #Thu Dec 10 21:49:57 CET 2020 | |||
| #Fri Oct 08 10:14:36 CEST 2021 | |||
| distributionBase=GRADLE_USER_HOME | |||
| distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip | |||
| distributionPath=wrapper/dists | |||
| zipStoreBase=GRADLE_USER_HOME | |||
| zipStorePath=wrapper/dists | |||
| distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip | |||
| zipStoreBase=GRADLE_USER_HOME | |||
| @@ -10,7 +10,7 @@ dependencies: | |||
| sdk: flutter | |||
| dev_dependencies: | |||
| pedantic: ^1.11.0 | |||
| flutter_lints: ^1.0.4 | |||
| flutter_test: | |||
| sdk: flutter | |||
| @@ -6,7 +6,7 @@ repository: https://github.com/juliuscanute/qr_code_scanner | |||
| environment: | |||
| sdk: '>=2.12.0 <3.0.0' | |||
| flutter: ">=1.10.0" | |||
| flutter: ">=1.12.0" | |||
| dependencies: | |||
| js: ^0.6.3 | |||
| @@ -16,7 +16,7 @@ dependencies: | |||
| sdk: flutter | |||
| dev_dependencies: | |||
| pedantic: ^1.11.0 | |||
| flutter_lints: ^1.0.4 | |||
| flutter: | |||
| plugin: | |||